Occurs clause in COB-DB2



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Occurs clause in COB-DB2

Postby russel » Fri Mar 08, 2013 3:41 pm

Hi all,

I am writing a cob-db2 program, where in i want to send the data to the calling program through linkage section.
But size of the linkage is not known prior to the start of the program, it can only be determined during execution.

for e.g.
WS-DATA occurs 99 times is the variable i want to send through linkage

So my question is can we declare it as

WS-DATA occurs ws-count times and value of ws-count will be determined during run time.

OR

Is there any otther solution for this..????
russel
 
Posts: 7
Joined: Wed Feb 13, 2013 4:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Occurs clause in COB-DB2

Postby BillyBoyo » Fri Mar 08, 2013 3:51 pm

All that a CALL does is pass the address of a piece of data.

The relationship between the length of the item in the CALL and the length of the item in the LINKAGE SECTION is down to you. There is no "need" to define a limited number of OCCURS with OCCURS DEPENDING ON (usually).

Do you have some problem you are looking into, or did you just think that this would cause a problem?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Occurs clause in COB-DB2

Postby russel » Fri Mar 08, 2013 4:36 pm

its a 2nd case ,It would cause a problem..
linkage section size in calling and called program should match right??
So how to keep the same size in both progarm??
russel
 
Posts: 7
Joined: Wed Feb 13, 2013 4:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Occurs clause in COB-DB2

Postby BillyBoyo » Fri Mar 08, 2013 4:44 pm

Whether using ODO or not, your table has storage for all 99 entries, so there is no problem with them being different lengths. As long as you don't define more storage in the LINKAGE SECTION, you won't have a problem anyway - you can define less, if you don't want to use the undefined parts.

The point is, Cobol doesn't care. It is down to you. It is good practice to keep the lengths the same, but neither at run time nor compile time will Cobol have the information to think there is a problem.

That is why I asked if you have an actual problem and feel this might be a "resolution" or if you are just "thinking" there would be a problem.

If still unclear, post you code, and we can explain further.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Occurs clause in COB-DB2

Postby Robert Sample » Fri Mar 08, 2013 6:03 pm

I think you are trying to worry about things before you test them to see how they work.
So how to keep the same size in both progarm??
is a simple question to answer. Calling program WORKING-STORAGE SECTION:
01  WS-CALL-PARMS.
    05  WS-TABLE-SIZE     PIC 9(04).
    05  WS-DATA           OCCURS 0 TO 99
                          DEPENDING ON WS-TABLE-SIZE.
and continue with your definition
and called program LINKAGE SECTION:
01  LS-PARMS.
    05  LS-TABLE-SIZE  PIC 9(04).
    05  LS-DATA        OCCURS 0 TO 99
                       DEPENDING ON LS-TABLE-SIZE.
and continue with your definition
As long as you move the correct value to WS-TABLE-SIZE before the subprogram is invoked, your parameters will match.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Occurs clause in COB-DB2

Postby russel » Fri Mar 08, 2013 6:42 pm

thnx guys for your repiles..
but problem is ..
My calling program will call a program by providing TIMESTAMP only,
So based on that I will query my database, so the size of the data which i ll get after query cannot be determined. there may be some thosands of records.

So is there any way to pass that much amount of data through linkage without knowing its size priorly ??
for e.g.
inside called program.
i am having this structure
01 ws-data occures [will be determined dynamically] times
05 ws-name
05 ws-add

and at end i ll move WS-DATA to LS-DATA. LS-DATA is linkage section variable.
russel
 
Posts: 7
Joined: Wed Feb 13, 2013 4:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Occurs clause in COB-DB2

Postby Robert Sample » Fri Mar 08, 2013 6:52 pm

I think you've got things backwards. You need to declare the MAXIMUM size your program will handle in the CALLING program's WORKING-STORAGE section and pass the entire data structure to the CALLED program.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Occurs clause in COB-DB2

Postby BillyBoyo » Fri Mar 08, 2013 7:50 pm

You define a table in the CALLing program which is expected to be able to hold the maximum amount of data that would be possible.

Your program monitors use of this, so that if the limit is approached, something can be done about it (change a program).

There are other possibilities, but perhaps as a beginner you'd need help from some of your colleagues with them. You could, for instance, "obtain storage" from Language Environment in the CALLed program. Then pass a POINTER to this back to the CALLing program, which assigns the address contained in the POINTER to an item defined in the CALLing program's LINKAGE SECTION.

This can be more flexible, as the "limit" to your OCCURS then depends on available memory, not on something at compile time. However, you'd need to spend more time designing, coding, experimenting, testing, documenting, etc. If you have no clue where to start with that, then you'd only be able to consider it with support from someone more senior at your site.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Occurs clause in COB-DB2

Postby dick scherrer » Sun Mar 10, 2013 10:57 am

Hello,

So how to keep the same size in both progarm??
One way is to use a common "copybook" for all of the modules that use this layout - caller or called.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Occurs clause in COB-DB2

Postby russel » Fri Mar 29, 2013 9:35 am

Hi all,

I am using the following solution.

I am using same copybook on both side...whose length is occurs 99 times.....
once this limit is crossed , i am SETTING one indicator and sending it to calling program.....
and inside calling program i am checking this indicator, if it is SET then call that module again,

In this way i am fetching entire set of data...

Thanks,
All.
russel
 
Posts: 7
Joined: Wed Feb 13, 2013 4:20 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post