For Programmers: Free Programming Magazines  


Home > Archive > Cobol > March 2004 > loading a numeric array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author loading a numeric array
mark

2004-03-26, 11:00 pm

Sorry if this question sounds too basic...

I have a numeric stucture to be loaded with known computational
values.

Example:

01 MY-STRUCT.
03 MY-VALUES OCCURS 200 PIC S9(4) COMP VALUES 10, 20, 30, ...

I know the above syntax is not correct, but is there a similar compact
way for achieving this? There is a way to do it if the array is
defined as PIC X, using REDEFINEs, but I could not find any for a
computational one. I do not want to write lots of MOVE statements and
I would like to keep it in working storage section.

Thanks in advance.
Howard Brazee

2004-03-26, 11:00 pm


On 23-Mar-2004, mgungora@yahoo.ca (mark) wrote:

> 01 MY-STRUCT.
> 03 MY-VALUES OCCURS 200 PIC S9(4) COMP VALUES 10, 20, 30, ...
>
> I know the above syntax is not correct, but is there a similar compact
> way for achieving this? There is a way to do it if the array is
> defined as PIC X, using REDEFINEs, but I could not find any for a
> computational one. I do not want to write lots of MOVE statements and
> I would like to keep it in working storage section.


Trying not to say too much (It sounds like homework)...

You can redefine an 03 level filled with comp s9(4) fields with another 03 level
filled with comp s9(4) fields.
Robert Jones

2004-03-26, 11:00 pm

bOTTOM pOSTING

mgungora@yahoo.ca (mark) wrote in message

news:<508f8f02.0403230653.4ac93090@posting.google.com>...
> Sorry if this question sounds too basic...
>
> I have a numeric stucture to be loaded with known computational
> values.
>
> Example:
>
> 01 MY-STRUCT.
> 03 MY-VALUES OCCURS 200 PIC S9(4) COMP VALUES 10, 20, 30, ...
>
> I know the above syntax is not correct, but is there a similar compact
> way for achieving this? There is a way to do it if the array is
> defined as PIC X, using REDEFINEs, but I could not find any for a
> computational one. I do not want to write lots of MOVE statements and
> I would like to keep it in working storage section.
>
> Thanks in advance.


Whlle you can do it in the way suggested by Howard, if your
computational series forms an arithmetic or geometric progression, as
suggested by your example, then it might be easier, less long-winded
and less error-prone to do the initialisation in a procedure rather
than hard-code it in the data division.

Robert
Howard Brazee

2004-03-26, 11:00 pm


On 23-Mar-2004, rjones0@hotmail.com (Robert Jones) wrote:

> Whlle you can do it in the way suggested by Howard, if your
> computational series forms an arithmetic or geometric progression, as
> suggested by your example, then it might be easier, less long-winded
> and less error-prone to do the initialisation in a procedure rather
> than hard-code it in the data division.


And 200 initializations is still cheap.
JerryMouse

2004-03-26, 11:00 pm

Howard Brazee wrote:
> On 23-Mar-2004, rjones0@hotmail.com (Robert Jones) wrote:
>
>
> And 200 initializations is still cheap.


Can't be cheaper than

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 200
COMPUTE Dataname(I) = f(I)
END-PERFORM



mark

2004-03-26, 11:00 pm

"Howard Brazee" <howard@brazee.net> wrote in message news:<c3pmjj$h82$1@peabody.colorado.edu>...
> On 23-Mar-2004, mgungora@yahoo.ca (mark) wrote:
>
>
> Trying not to say too much (It sounds like homework)...
>
> You can redefine an 03 level filled with comp s9(4) fields with another 03 level
> filled with comp s9(4) fields.


It is not homework.

According to your suggestion I will have to declare filler fields as
many as the size of the array, one line for each. docdwarf has already
suggested that, but I was hoping for something else. I thought there
might be a way to do it just like doing it for a PIC X array:
01 MY-STRUCT.
03 MY-VALUES OCCURS 200 PIC X.
01 MY-STRUCT-X REDEFINES MY-STRUCT.
03 MY-VALUES-X PIC X(200) VALUE 'ABCDEF................'.

This is more compact then doing:
01 MY-STRUCT.
03 MY-VALUES OCCURS 200 PIC X.
01 MY-STRUCT-X REDEFINES MY-STRUCT.
03 FILLER PIC X VALUE 'A'.
03 FILLER PIC X VALUE 'B'.
03 FILLER PIC X VALUE 'C'.
03 FILLER PIC X VALUE 'D'.
....

Apparently there is no similar way to do it for computational data...
Is that correct?

Regards
Howard Brazee

2004-03-26, 11:00 pm


On 23-Mar-2004, mgungora@yahoo.ca (mark) wrote:

> According to your suggestion I will have to declare filler fields as
> many as the size of the array, one line for each. docdwarf has already
> suggested that, but I was hoping for something else. I thought there
> might be a way to do it just like doing it for a PIC X array:
> 01 MY-STRUCT.
> 03 MY-VALUES OCCURS 200 PIC X.
> 01 MY-STRUCT-X REDEFINES MY-STRUCT.
> 03 MY-VALUES-X PIC X(200) VALUE 'ABCDEF................'.
>
> This is more compact then doing:
> 01 MY-STRUCT.
> 03 MY-VALUES OCCURS 200 PIC X.
> 01 MY-STRUCT-X REDEFINES MY-STRUCT.
> 03 FILLER PIC X VALUE 'A'.
> 03 FILLER PIC X VALUE 'B'.
> 03 FILLER PIC X VALUE 'C'.
> 03 FILLER PIC X VALUE 'D'.
> ....
>
> Apparently there is no similar way to do it for computational data...
> Is that correct?


No good way.

My question is - why do you prefer compact over clear?
Howard Brazee

2004-03-26, 11:00 pm


On 23-Mar-2004, "JerryMouse" <nospam@bisusa.com> wrote:

>
> Can't be cheaper than
>
> PERFORM VARYING I FROM 1 BY 1 UNTIL I > 200
> COMPUTE Dataname(I) = f(I)
> END-PERFORM


I would have done the 200 initializations without the "f" above. What did that
do?
William M. Klein

2004-03-26, 11:00 pm

Check with your compiler vendor and/or current documentation to see if you
already support the ISO 2002 VALUE Clause enhancements - or if not, when the
vendor plans on supporting it.

Doing almost exactly what you have coded below is allowed in the ISO 2002 COBOL
Standard (but not before in Standard COBOL).

--
Bill Klein
wmklein <at> ix.netcom.com
"mark" <mgungora@yahoo.ca> wrote in message
news:508f8f02.0403230653.4ac93090@posting.google.com...
> Sorry if this question sounds too basic...
>
> I have a numeric stucture to be loaded with known computational
> values.
>
> Example:
>
> 01 MY-STRUCT.
> 03 MY-VALUES OCCURS 200 PIC S9(4) COMP VALUES 10, 20, 30, ...
>
> I know the above syntax is not correct, but is there a similar compact
> way for achieving this? There is a way to do it if the array is
> defined as PIC X, using REDEFINEs, but I could not find any for a
> computational one. I do not want to write lots of MOVE statements and
> I would like to keep it in working storage section.
>
> Thanks in advance.



JerryMouse

2004-03-26, 11:00 pm

Howard Brazee wrote:
> On 23-Mar-2004, "JerryMouse" <nospam@bisusa.com> wrote:
>
>
> I would have done the 200 initializations without the "f" above.
> What did that do?


Oh, sorry. The "f(x)" notation is mathematical standing for "some function
of "x". In the original case, the actual code would have been:

COMPUTE MYVALUES(I) = I * 10


Kevin M

2004-03-30, 3:30 pm

Ignore DocDickhead, he is just an old grouch that jumps to rapid
conclusions.
<docdwarf@panix.com> wrote in message news:c3pkh5$r9a$1@panix5.panix.com...
> In article <508f8f02.0403230653.4ac93090@posting.google.com>,
> mark <mgungora@yahoo.ca> wrote:
>
> Please do your own homework.
>
> DD



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com