Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Varying array length dynamically in the cobol program
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Tue Mar 30, 2010 7:22 pm    Post subject: Varying array length dynamically in the cobol program
Reply with quote

Hi All,

I want to create a 1-D variable length array in cobol using 'DEPENDING' Clause. I want to know how the array length will vary dynamically in the cobol program; if i go with this.

Regards
Back to top
View user's profile Send private message

CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Mar 30, 2010 7:40 pm    Post subject:
Reply with quote

Code:
01  data-area.
  05  data-size pic s9(4) comp.
  05  data-array occurs (maximum) times depending on data-size pix x(?).

move (number greater than zero and not greater than maximum) to data-size.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Tue Mar 30, 2010 7:41 pm    Post subject:
Reply with quote

If the variable with the OCCURS DEPENDING ON clause is in WORKING STORAGE, the array length will not vary. If you explain more of what you are wanting to do, we can provide guidance.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 30, 2010 7:52 pm    Post subject: Reply to: COBOl QUERY
Reply with quote

Are you using a FILE to populate the array? If so, is this a VSAM file?

Bill
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Tue Mar 30, 2010 8:10 pm    Post subject: COBOl QUERY
Reply with quote

Hi,

Below is the 1-D variable length array that i have created. I am loading this array by reading a flat file. The problem with the input file is it has variable amount of records (part of daily job) daily. Further the array created below is used to update a second (sorted file) file based on the match if found. My aim is to reduce the CPU time flactuation that may happen because of above variation in input file records. The Array declaration for the same is as below:
Code:
01  CONFIG-TABLE.
    05  CFG-ENTRIES  OCCURS 1 TO 100000  TIMES DEPENDING
        ON MAX-VALUE ASCENDING KEY IS
                                 CFG-TBL-A
                                 CFG-TBL-B
                                 CFG-TBL-C
                      INDEXED BY CFG-INDX.
      10  CFG-TBL-A        PIC X(4).
      10  CFG-TBL-B         PIC X(8).
      10  CFG-TBL-C         PIC X(3).
      10  CFG-TBL-D         PIC X(1).
      10  CFG-TBL-E         PIC X(2).
      10  CFG-TBL-F         PIC X(2).
      10  CFG-TBL-G         PIC X(1).

Also i am using binary search technique while looking for a match in the above array.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 30, 2010 8:16 pm    Post subject: Reply to: COBOl QUERY
Reply with quote

Are you anticipating up to a maximum of 100,000 records on the flat-file at any given time? Is the flat-file in the sorted-order that you're expecting?

Would you know actual number of records on the file before the program gets invoked?

Bill
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Tue Mar 30, 2010 8:35 pm    Post subject: COBOl QUERY
Reply with quote

Hi Bill,

I am putting '100000' as a maximum limit to be just on safer side. Normally this varies between 1000-1500 records. And yes the input file is a sorted file based on the three fields (A,B and C) as mentioned above. Yes i can get the number (total input records) before the program get invokes if this can help me in any way.

Regards
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Mar 30, 2010 9:04 pm    Post subject:
Reply with quote

Quote:
I want to know how the array length will vary dynamically in the cobol program



length / size . COBOL does not have 'dynamic' arrays. If the COBOL Internal Table (array) is defined in Working-Storage with the ODO (occurs depending on) phrase, it will always be mapped to max potential size.

The main purpose of ODO is to increase the efficiency of the Binary Search.

The only way to have a 'dynamic' array, is to acquire storage (via the LE equivalent of a getmain) at runtime basing your size requirement on the number of items you will have.

even at 100,000 items at 21 bytes per is only a 2 meg table, which isn't that big - but is a lot bigger that 2000 items at 21 per (42,000 bytes).

though I am not a big proponent of dynamically allocating storage at run time (program stops if not enough available memory) as apposed to the job waiting to start until enough memory is available, the point is moot since most jobs have more than one step.

I would spend more time analyzing your process.
If both files are sorted,
a simple 2-file match merge would allow your program to be smaller, the repeated I/O would suspend your program (therefore I/O bound)
thus being more user friendly to other jobs in the system - size and interrupts.
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Tue Mar 30, 2010 9:18 pm    Post subject: COBOl QUERY
Reply with quote

Actually the second file referred above contains Approx 40 Million records. And i need to compare each of that record with input (usually 1500-2000 in number) file and doing this comparison i need to reduce no of transactions. I am beliving binary search will give me the fastest search. Please let me know how i should proceed.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 30, 2010 9:21 pm    Post subject: Reply to: COBOl QUERY
Reply with quote

Here's a previous post on Dynamic arrays -

http://www.ibmmainframes.com/viewtopic.php?p=209663&highlight=#209663

Bill
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Tue Mar 30, 2010 9:26 pm    Post subject: COBOl QUERY
Reply with quote

Thanks Bill,

I will see if i can get something out from this for my use.

Regards
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Mar 30, 2010 9:34 pm    Post subject:
Reply with quote

Arun Nehra,

it appears that you have decided on the commands that you will use
and are just looking for justification for your process.

I ask again,
will any record in your 2nd INPUT file be matched with more that 1 record of your 1st input file.

IF so, yes you need to table your first input file.

IF NOT, then you need to go to the trouble of writing a 2 file match and process,
which will make you program smaller and more user friendly to the rest of the system.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Tue Mar 30, 2010 9:39 pm    Post subject: Re: COBOl QUERY
Reply with quote

arun nehra wrote:
I am putting '100000' as a maximum limit to be just on safer side. Normally this varies between 1000-1500 records.
No matter how high you set the max, you will want to check the current index against the max while loading the array and abort before exceeding it.
Personally, if 2000 was the probable max, I'd set the max to 3000 and start warning messages as the filled array approached something like 2700. Warnings would allow the max to be raised in a timely manner without effecting production.
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Wed Mar 31, 2010 3:30 pm    Post subject: COBOl QUERY
Reply with quote

I am still unclear about the concept of 'DEPENDING' clause and the 'MAX' value that is put with variable length array declaration.

As suggested above i reduce the MAX record limit for occurs clause to 3000. And ran my program with the expection that it will reduce my CPU/Lapse time significantly; but to my surprise there was no significant reduction in CPU time and Elapse time was almost same.

As can be seen above (top) the two records corresponding to two files are just 21 bytes long and i need to compare all records of File A (1500-2000 records) with each record of File B (40 M records) and update File B if there is match found.

Please help.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 31, 2010 4:43 pm    Post subject:
Reply with quote

CPU time and elapsed time do not depend upon the maximum number of occurrences in an array, they depend upon how many elements of the array you are using.
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Wed Mar 31, 2010 5:22 pm    Post subject: COBOl QUERY
Reply with quote

Hi Robert,

05 CFG-ENTRIES OCCURS 1 TO 100000 TIMES DEPENDING
ON MAX-VALUE ASCENDING KEY IS

Does that mean (referring above) changing 100000 to 3000 will not make any difference when i make a binary search on the array after loading.

Also how MAX-VALUE will impact the loading of array.

Regards
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 31, 2010 5:35 pm    Post subject:
Reply with quote

Changing the number of occurrences will change the amount of memory required by the program. It will have no impact on CPU time used, nor on the elapsed time -- other than the small amount required to load the program from the load library. The COBOL Language Reference manual in section 6.2.32.3 states that
Quote:
To ensure correct execution of a SEARCH statement for a variable-length table, make sure the object of the OCCURS DEPENDING ON clause (data-name-1) contains a value that specifies the current length of the table.
so it does not appear that the extra table elements would be searched -- so no impact on CPU time or elapsed time.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 31, 2010 7:05 pm    Post subject: Reply to: Varying array length dynamically in the cobol prog
Reply with quote

As an experiment, remove the DEPENDING ON and change it to a hardcoded OCCURS 3000 or whatever maximum you choose.

Before populating the ARRAY, initialize it to all HIGH-VALUES and then load it. By initializing to HIGH-VALUES, the SEARCH ALL will work for you.

This is just a suggestion and I'm unsure whether CPU will be increased or reduced using a hardcoded OCCURS as opposed to a DEPENDING ON.

However, a COBOL SEARCH ALL always causes a BALR (CALL) to a COBOL run-time routine, regardless.

YMMV....

Bill
Back to top
View user's profile Send private message
arun nehra

New User


Joined: 29 Nov 2008
Posts: 62
Location: mumbai

PostPosted: Wed Mar 31, 2010 8:18 pm    Post subject: COBOl QUERY
Reply with quote

Thanks Bill for your suggestion.

Also another thing that i am currently looking for; As per Dick in the previous post:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
length / size . COBOL does not have 'dynamic' arrays. If the COBOL Internal Table (array) is defined in Working-Storage with the ODO (occurs depending on) phrase, it will always be mapped to max potential size.

The main purpose of ODO is to increase the efficiency of the Binary Search.

The only way to have a 'dynamic' array, is to acquire storage (via the LE equivalent of a getmain) at runtime basing your size requirement on the number of items you will have.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thus even though i am writting 'Depending' on clause above, the table size still will be maximum size as i am doing it in WS section. How i should declare my array (don't know the syntax) as Dick has suggested to get the array size dynamically allocated.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 31, 2010 8:31 pm    Post subject: Reply to: Varying array length dynamically in the cobol prog
Reply with quote

Yes, as others (including Dick) have said, if you have an ARRAY with a fixed-number or an ODO (both of these are defined to WS), then the amount of storage occupied is the same.

Only an ARRAY in LINKAGE is a true ODO. If you define this ARRAY as an ODO 1 to 3000 and you determine you only have 100 entries, then only the actual storage will be allocated.

Example: (100 * entry-length) + 4. The four is the binary-fullword (this is my own preference) that contains the high-water mark for the ODO (a value of 100).

FWIW (and IMHO) a SEARCH ALL is not worth it if the number of entries does not exceed 128. You'd be better off with either a sequential SEARCH or your own in-line PERFORM.

Note that in some cases, a sequential SEARCH can cause the compiler to BALR to a COBOL Run-Time routine.

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts I can not compile my program PL1 V3.R... Miguel Fernandez PL/I & Assembler 13 Tue Dec 06, 2016 8:30 pm
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us