IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Declare a array/table(using occurs class) in the linkage sec


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Fri May 28, 2010 3:16 pm
Reply with quote

Code:

STRING PAY-DATA               
       DELIMITED BY SPACE     
       PAYMENT-MANNER(COUNTER)
       DELIMITED BY SIZE     
       PAYMENT-NOTES(COUNTER)
       DELIMITED BY SIZE     
INTO PAY-DATA 


pay-data is all spaces, payment-manner(counter) and payment-note(counter) has a single character, what is the output of the above code??
icon_question.gif

one more question is can we declare a array/table(using occurs class) in the linkage section icon_question.gif icon_question.gif if i can't, then is there any way to return an array from the calling program to the called program???

Thanks,
shan icon_biggrin.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri May 28, 2010 4:28 pm
Reply with quote

What did you get when you tested the STRING statement yourself?

Why on earth would you even question whether or not an array can be defined in the LINKAGE SECTION? This is a question answered in the manual (link at the top of the page).
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Fri May 28, 2010 4:56 pm
Reply with quote

As I am using some datasets from production environment, I was not able to predict the behaviour from the tests i ve done, All looked like junk characters,

I also have many restrictions('coz it is a production dataset).

One small thing i have identified is, All those characters in the output was preceded by a lot of spaces.

I have used 'delimited by spaces', In 'pay-data' everything is just spaces initially. So, I guess all those spaces should be eliminated and after executing the code given pay-data should have character only.

Correct me if I am wrong.

Note: The code mentioned above is in a loop in the real code.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri May 28, 2010 5:03 pm
Reply with quote

shankarm wrote:
one more question is can we declare a array/table(using occurs class) in the linkage section icon_question.gif icon_question.gif if i can't, then is there any way to return an array from the calling program to the called program???


first of all, forget about the type of structure - cobol internal table or array

regardless of the definition of a data area by one module,
another module can have completely different definitions.

point is, how do you establish addressability?

from CALLer to CALLed is no problem

CALL pgm using data-area

Procedure division using data-area


from CALLed to CALLer, one way is to use pointers.

Pgm-A CALLs Pgm-B
using a pointer (defined in PGM-A W-S).

>>Pgm-A has a structure defined in Pgm-A Linkage. but is not referenced in Pgm-A at this time<<

Pgm-B Procedure Division using pointer

Pgm-B has a pointer defined in Linkage
and a structure defined in W-S

Pgm-B SET POINTER TO ADDRESS OF STRUCTURE

Pgm-B GOBACK

Pgm-A SET STRUCTURE TO POINTER
STRUCTURE is area defined in PGM-A Linkage
POINTER is defined in PGM-A W-S
now Pgm-A can access Pgm-B's working-storage - structure
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Fri May 28, 2010 5:21 pm
Reply with quote

Dick Brenholtz,

That was really useful,
Thanks a lot.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Fri May 28, 2010 5:26 pm
Reply with quote

People, Sorry if I am asking silly questions.
I am new to Mainframes. icon_razz.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 28, 2010 8:22 pm
Reply with quote

Hello,

Quote:
All looked like junk characters,

I also have many restrictions('coz it is a production dataset).

One small thing i have identified is, All those characters in the output was preceded by a lot of spaces.
They are most likely not junk characters - they are probably packed-decimal or binary data.

You might not be able to post the data here, but you obviously can read it on your system. . .

Suggest you learn the name and expected content of the "input" and then proceed - rather than slinging some code and hoping for the best.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 12:19 pm
Reply with quote

Am trying to use pointers as suggested, but when i use set statement it says,
Quote:
IGYPS2160-S The "ADDRESS OF" operand "WS-PAY-EXP-DATA" was found as the sending operand of a "SET" statement, but was not a "LINKAGE SECTION" item, or was a level-66 or level-88 item. The statement was discarded.


ws-pay-exp-data is a working storage variable in the called program(say B).
Am passing a pointer from the calling program(say A).
Pointer variable name in program 'A' is ws-ptr (A working storage variable).
I have declared the pointer in program 'B's linkage section.
when i try to set the pointer to the address of a working storage variable the above error message is displayed.

Thanks,
Shan.. icon_smile.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon May 31, 2010 12:32 pm
Reply with quote

Hello,

If you want someone to help, you need to post the relevant code that is causing the error.

Why are you passing a pointer? I suspect that all you need to do is a basic "CALL. . .USING" and have the appropriate definitions in the LINKAGE of the called module.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 12:47 pm
Reply with quote

my requirement is,
Program 'A' calls program 'B'.
Program 'B' has an array which is a working storage variable and I want that array in program 'A'.

call statement in program 'A'
Code:
CALL 'TRDSERCC' USING IN-DUNS WS-PDX18 IN-PDX12 WS-PTR


linkage section of program 'B'
Code:

LINKAGE SECTION.                                 
01 INPDUNS                       PIC S9(9).       
01 PAYDEX18                      PIC 9(3).       
01 PAYDEX12                      PIC 9(3).       
01 PTR                           USAGE IS POINTER.


Procedure division in program 'B'
Code:
PROCEDURE DIVISION USING INPDUNS PAYDEX18 PAYDEX12 PTR.


working storage in program 'B'
Code:

01 WS-PAY-EXP-DATA.                         
   02 WS-PAYMENT-INDICATOR OCCURS 900 TIMES.
      03 WS-PAYMENT-MANNER PIC X.           
      03 WS-PAYMENT-NOTES  PIC X.           

Finally set, in program 'B'.

Code:
SET PTR TO ADDRESS OF WS-PAY-EXP-DATA.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon May 31, 2010 1:01 pm
Reply with quote

Hello,

I believe you are making something more difficult than it needs to be. . .

Why not define the full array in the calling program and let the called program fill it? It should all be the same memory either way and more people who work on your system will probably understand the "straight call" rather than dealing with pointers.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 2:05 pm
Reply with quote

called program is already written, am just making use of the program.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 31, 2010 2:13 pm
Reply with quote

what is your linkage and working storage from a?.

you have something wrong but have not provided us with enough info to provide an answer.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 2:17 pm
Reply with quote

AS you said, A's linkage section has the structure defined, and working storage has the pointer..
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 31, 2010 2:22 pm
Reply with quote

if you want help, cut&paste the code.

the instruction will work in both COBOL II and newer.
the only reason it does not pass the compiler is because you have done something wrong.

Quote:
AS you said, A's linkage section has the structure defined, and working storage has the pointer..


ok and b's linkage should have the pointer defined and the structure should be in working-storage.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 2:32 pm
Reply with quote

Program A.

Code:
01 WS-PAY-DATA             PIC X(2800).     
01 WS-PTR                  USAGE IS POINTER.

**END OF WORKING STORAGE********   
                   
LINKAGE SECTION.                           
01 PAY-EXP-DATA.                           
   02 PAYMENT-INDICATOR OCCURS 900 TIMES.   
      03 PAYMENT-MANNER PIC X.             
      03 PAYMENT-NOTE   PIC X.             



other details, i have given previously, I cannot copy paste the whole code, it runs for 10000+ lines.. If you want any specific part ask me, i ll copy and paste.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 31, 2010 2:41 pm
Reply with quote

ok, we have the data description entries for the two modules,
now,
  1. what are the two different SET statements
    (one for each program)
  2. and which is giving you an error?
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 2:42 pm
Reply with quote

01 WS-PAY-DATA PIC X(2800).
01 WS-PTR USAGE IS POINTER.
****END OF WORKING STORAGE *****
LINKAGE SECTION.
01 PAY-EXP-DATA.
02 PAYMENT-INDICATOR OCCURS 900 TIMES.
03 PAYMENT-MANNER PIC X.
03 PAYMENT-NOTE PIC X.

Is Program A's linkage and working storage section's.
Other details i ve given already. The whole program runs for 1000+ lines, so I cannot copy and paste the entire program.

If u want any specific part of it, Just tell me i ll send you.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 2:45 pm
Reply with quote

set statement in program 'B'.
Code:
SET PTR TO ADDRESS OF WS-PAY-EXP-DATA.

Gives error.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 31, 2010 3:11 pm
Reply with quote

Sorry,
you are using cobol II,

as a result,
from pgm-b you must
CALL pgm-c using PTR and WS-PAY-EXP-DATA


pgm-c consists of

no working storage,
linkage:
01 ptr usage is pointer
01 data-area pic x(01).

procedure division using ptr data-area

set ptr to data-area
goback

COBOL II requires that everything be in linkage for sets and pointers.
e-cobol is a little more realistic.

you need the third module which will load the address into the ptr from the call by pgm-b.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 3:15 pm
Reply with quote

WS-PAY-EXP-DATA is an array, occurs 900 times.
can i pass it like that???
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 31, 2010 3:36 pm
Reply with quote

come on!

I apologize for showing you a method, which in cobol II is a little obtuse.

in cobol ii you must have everything in linkage to perform a set.

that is why the third module.

looks like you will need a fourth.

one pgm which you call for pgm-b:
to set the ptr in B's linkage
to the address of the array defined in b's working-storage.

pgm-b CALLs pgm-c using ptr (defined in linkage) data-area (defined in W-S).
pgm-c using ptr data-area
set ptr to address of data-area

and one pgm which you call for pgm-a:
to set the address of the array defined in a's linkage
to the pointer in A's working-storage.

pgm-a CALLs pgm-d using ptr (defined in w-s) data-area (defined in linkage)
pgm-d using ptr data-area
set address of data-area to ptr

that is how you have to do it, to access a sub-modules data area.

sorry to have lead you to thinking that it would be easy.
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 3:43 pm
Reply with quote

Dick Brenholtz,

Thanks for the effort and time you spent. I understand that am bothering you soo much. I don't wanna bother you anymore.

Thanks again, I will look into it. icon_smile.gif
Back to top
View user's profile Send private message
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Mon May 31, 2010 6:05 pm
Reply with quote

dick Brenholtz,

Its working, Thanks for your time.
I wrote four programs and is working fine.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 31, 2010 6:46 pm
Reply with quote

I apologize for getting you involved with this,

but, now you have the basis
(the extra prgms to
  • set a pointer to the address of an area
  • set the address of an area to a pointer)
to do this with new code.

Using pointers allows you silly stuff like this,
accessing sub-module working-storage,
but also,
if you have a little sub-system you have to write, are using dynamic calls,
you can define all the data areas in one module,
(to include any and all dclgened copybooks that can be used to transfer db2 data between modules)
load the address of each structure in a pointer
(define a structure that is passed in linkage that contains all the pointers)
then you CALL everybody using the same USING structure (the pointer list)
and each module addresses the data defined in linkage to the pointer.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top