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
 

 

Declare a array/table(using occurs class) in the linkage sec
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
shankarm

Active User


Joined: 17 May 2010
Posts: 175
Location: India

PostPosted: Fri May 28, 2010 3:16 pm    Post subject: Declare a array/table(using occurs class) in the linkage sec
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: 7913
Location: Bellevue, IA

PostPosted: Fri May 28, 2010 4:28 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri May 28, 2010 8:22 pm    Post subject:
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    Post subject: Reply to: Declare a array/table(using occurs class) in the l
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

Site Director


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

PostPosted: Mon May 31, 2010 12:32 pm    Post subject:
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    Post subject: code.
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

Site Director


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

PostPosted: Mon May 31, 2010 1:01 pm    Post subject:
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    Post subject: hi,
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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
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 Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm
No new posts Updating online Db2 table kishpra DB2 3 Fri Aug 12, 2016 2:44 pm
No new posts XFACILIT class setting for Fault Anal... egrove IBM Tools 2 Thu Aug 11, 2016 8:02 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm


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