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

Calling programs with more than 2 parameters


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

New User


Joined: 27 Aug 2008
Posts: 35
Location: Brazil

PostPosted: Thu Sep 22, 2011 3:03 am
Reply with quote

Hi,
I am calling progs B,C and D from prog A, with diferents parameters.
In prog A I have the following code

Code:
WORKING AREA.
01   WS-PARAMETERS.
       03 WS-REG-A.
            05 WS-A-NUM     PIC 9(02).       
            05 WS-A-TEXT    PIC X(10).
       03 WS-REG-B.
            05 WS-B-NUM     PIC 9(09).       
            05 WS-B-VAL      PIC 9(10)V99.
       03 WS-REG-C.
            05 WS-C-DATE    PIC 9(10).       
            05 WS-C-VAL      PIC 9(02)V99.

01    WS-PROGB            PIC  X(06) VALUE 'SBPGMB'.
01    WS-PROGC            PIC  X(06) VALUE 'SBPGMC'.
01    WS-PROGD            PIC  X(06) VALUE 'SBPGMD'.
....
PROCEDURE
....
CALL WS-PROGB USING WS-REG-A WS-REG-B.
CALL WS-PROGC USING WS-REG-A WS-REG-C.
CALL WS-PROGD USING WS-REG-B WS-REG-C.


Then in programs B, C and D, I have this:
Code:

Program SBPGMB
-----------
LINKAGE
01   WS-AREA.
       03 WS-REG-A.
            05 WS-A-NUM     PIC 9(02).       
            05 WS-A-TEXT    PIC X(10).
       03 WS-REG-B.
            05 WS-B-NUM     PIC 9(09).       
            05 WS-B-VAL      PIC 9(10)V99.

Program SBPGMC
-----------
LINKAGE
01   WS-AREA.
       03 WS-REG-A.
            05 WS-A-NUM     PIC 9(02).       
            05 WS-A-TEXT    PIC X(10).
       03 WS-REG-C.
            05 WS-C-DATE    PIC 9(10).       
            05 WS-C-VAL      PIC 9(02)V99.

Program SBPGMD
-----------
LINKAGE
01   WS-AREA.
       03 WS-REG-B.
            05 WS-B-NUM     PIC 9(09).       
            05 WS-B-VAL      PIC 9(10)V99.
       03 WS-REG-C.
            05 WS-C-DATE    PIC 9(10).       
            05 WS-C-VAL      PIC 9(02)V99.

I have different areas and these areas are used by multiple programs
I confirmed that the SBPGMC is receiving areas WS-REG-A, WS-REG-B and WS-REG-C, in that order. How is it possible? Is there any way this SBPGMC receive only the areas WS-REG-A and WS-REG-C using the WS-PARAMETERS that was shown?
If so can any body expalin it with example.
Thanks a lot.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 3:09 am
Reply with quote

You need to show the PROCEDURE DIVISION USING ... for each of the three called programs.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Thu Sep 22, 2011 3:23 am
Reply with quote

Not trying to critique the program, but I have one observation -

To distinguish LINKAGE fields from WS fields, LINKAGE fields should be prefixed whenever possible, with LS- instead of WS-.

IMHO, it will make your life (and whomever else does maintenance) MUCH easier....

Just my two cents.... icon_wink.gif

Mr. Bill
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: Thu Sep 22, 2011 3:44 am
Reply with quote

Quote:
I confirmed that the SBPGMC is receiving areas WS-REG-A, WS-REG-B and WS-REG-C, in that order.
How did you confirm this?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 4:02 am
Reply with quote

Pay attention to Mr Bill's comments. It will be a great help to anyone looking at the called programs.

You have two seperate things you are passing to the called programs, so you should have two 01-levels in the linkage sections of each of the called programs.

For program B, which wants A and B data, references to A and B in one linkage section item would actually "work" because the B data immediately follows the A data, and matches in definitions, in the called programs.

Programs C and D would get "valid" fields, but which would be a total mingle of data passed from the calling program and would not "work" in any resonable sense of the word, although they would not abend because all the data definitions are USAGE DISPLAY. Any processing using those fields would be rubbish, however.

As to your questions.

Quote:
I confirmed that the SBPGMC is receiving areas WS-REG-A, WS-REG-B and WS-REG-C, in that order. How is it possible?


When you pass an item to a sub-program on the USING of the CALL, all that is passed to the called program is the address of each item on the USING.

It is up to you to define the data as expected in the Linkage Section of the called program. For each item on the USING of the call, you need an item on the USING of the Procedure Division of the called program.

The two USING's (the CALL and Procedure Division) define the addresses passed and received. The compiler does not provide any information about the definitiojn of the data. That is entirely up to you to get right. The Linkage Editor/Binder does nothing either with respect to the data formats.

There is no "length" of the item passed to or defined in the sub-program. Nothing. No data-definition. No length.

So, you have passed WS-REG-A. This happens to be followed by WS-REG-B and WS-REG-C and whatever is after that in the working-storage section of the calling program, or indeed even the program code of the calling program. Remember, just the address is passed. If you "look" at a linkage-section item, you will "see" as much as continue to look.

Remember, just address, no length, no definition. The linkage section items are just a "mapping" for the data in the calling program at the address passed.

In the first sub-program, the data will "work" although this is clearly not as intended from the CALL in the other program.

In the second two programs, the data mapping does not match that of the data in the called program, so will not even "work".

You need,

Code:
CALL progb USING A B
CALL progc USING A C
CALL progd USING B C

PROCEDURE DIVISION USING A B in progb
with Linkage Section having two 01-levels with the layouts of A, B respectively
PROCEDURE DIVISION USING A C in progc
with Linkage Section having two 01-levels with the layouts of A, C respectively
PROCEDURE DIVISION USING B C in progd
with Linkage Section having two 01-levels with the layouts of B, C respectively


The Linkage Section names don't have to bear any relationship to those in the called prgrom as far as the compiler or anything is concerned. Good practice to do what Mr Bill has said, and change the prefix but leave the rest the same.

I hope this is not production code. It can't be, it can't have got through any level of testing at all.

Hopefully your second question is covered here.

Don't just try to take all this in from here. Check it out in the manuals, understand what they are describing. If you are not sure about what they are saying, do some experiments to clarify for yourself. If you are still stuck, tell us what you understand, how you have shown that it is the case, and what you are still having problems with.
Back to top
View user's profile Send private message
jackare

New User


Joined: 27 Aug 2008
Posts: 35
Location: Brazil

PostPosted: Thu Sep 22, 2011 5:02 am
Reply with quote

Thanks Mr Woodger, your explanation was perfect and clear.
It's works with level "01" and "PROCEDURE DIVISION USING A C".




Mr O'Boyle I will follow your tip.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 1:31 pm
Reply with quote

De nada, boa sorte. Se você tem duvidas, alguém vai estar aqui...
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

 


Similar Topics
Topic Forum Replies
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Calling an Open C library function in... CICS 1
No new posts Fetch data from programs execute (dat... DB2 3
No new posts Passing Parameters to Programs Invoke... PL/I & Assembler 5
Search our Forums:

Back to Top