Number of parameters in calling and called program in Cobol



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

Number of parameters in calling and called program in Cobol

Postby ravi11081992 » Mon Dec 03, 2018 11:14 pm

Hi All,

I have a COBOL main program which is calling sub program, the number of calling parameters used in main program are 4 whereas in sub program it's 5.

Sub program is passing 5 parameters back to main program

Will there be any compilation error? Or main program parameters displays junk values?

I have gone through IBM manual but couldn't find any information


Thanks
ravi11081992
 
Posts: 19
Joined: Mon Apr 30, 2018 5:47 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Number of parameters in calling and called program in C

Postby Robert Sample » Tue Dec 04, 2018 1:42 am

Page 319 of the Enterprise COBOL Language Reference manual version 6.2 states (with emphasis added by me)
Include the USING phrase in the CALL statement only if there is a USING phrase in the PROCEDURE DIVISION header or the ENTRY statement through which the
called program is run. The number of operands in each USING phrase must be identical.
For more information about the USING phrase, see “The PROCEDURE DIVISION header” on page 255.
The sequence of the operands in the USING phrase of the CALL statement and in the corresponding USING phrase in the called subprogram's PROCEDURE
DIVISION header or ENTRY statement determines the correspondence between the operands used by the calling and called programs. This correspondence is
positional.
The values of the parameters referenced in the USING phrase of the CALL statement are made available to the called subprogram at the time the CALL
statement is executed. The description of the data items in the called program must describe the same number of character positions as the description of the
corresponding data items in the calling program
Some points to consider:
- Using 4 operands in the CALL USING statement and 5 in the PROCEDURE DIVISION USING means that the odds are good that a storage violation will occur when the subprogram references the 5th operand.
- If a storage violation does not occur when the subprogram attempts to use the 5th operand, what value will that operand have?
- Positional in the quote MEANS positional -- at a previous employer, we ran into storage issues when we changed the subprogram from 1500 byte variables to 9999 byte variables as the new length requires 3 assembler offset addresses (4096, 4096, 1807 bytes referenced) and since the calling program wasn't passing 3 addresses per variable the offsets for the variables after the changed variable were completely off.

There won't be a compile error since COBOL cannot know at compilation time that there is a mismatch in the CALL USING and PROCEDURE DIVISION USING counts -- they are, after all, in different programs. You won't get "junk" data (since there is NO SUCH THING AS JUNK DATA to a computer), but the results certainly will not be predictable nor repeatable, necessarily. Can you get away with doing this? Maybe -- as long as your are intimately familiar with HLASM and how data passing works.
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: Number of parameters in calling and called program in C

Postby ravi11081992 » Wed Dec 05, 2018 12:03 am

There is a possibility of unpredictable results in all the variables or only in the extra variable i.e. 5th variable?

Is there any chance to get a runtime error? Or does it run fine?

Please share the knowledge on parameters passing in cobol

Thanks
ravi11081992
 
Posts: 19
Joined: Mon Apr 30, 2018 5:47 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Number of parameters in calling and called program in C

Postby Robert Sample » Wed Dec 05, 2018 1:15 am

here is a possibility of unpredictable results in all the variables or only in the extra variable i.e. 5th variable?

Is there any chance to get a runtime error? Or does it run fine?
As long as the first 4 variables are defined to have the same lengths (the PICTURE clauses don't have to be the same, merely the lengths), then you will not get any unpredictable results with them. Referencing the fifth variable in the PROCEDURE DIVISION USING list when the CALL USING only had four variables will have unpredictable results -- which can include a runtime error (but that is by no means guaranteed -- I just ran a couple of tests of this scenario with different lengths for the fifth variable and got a normal step condition code of zero for one of them, and a S0C4 ABEND on the other). Under no circumstances can you say that the subprogram will "run fine" -- it is attempting to use storage it does not have access to, so at best you're going to get misleading and erroneous results for anything using that variable even with a normal completion code for the step (in my test, I had a PIC X(08) variable that contained X'0130E81000000000'), and at worst you will get an ABEND.
Sub program is passing 5 parameters back to main program
This is not clear -- do you mean merely that the PROCEDURE DIVISION USING has 5 variables, or do you mean that you are using the RETURNING option of the PROCEDURE DIVISION?
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: Number of parameters in calling and called program in C

Postby ravi11081992 » Wed Dec 05, 2018 10:12 pm

Passing 5 variables to main program using returning option of procedure division

Please share the knowledge

Thanks
ravi11081992
 
Posts: 19
Joined: Mon Apr 30, 2018 5:47 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Number of parameters in calling and called program in C

Postby Robert Sample » Wed Dec 05, 2018 10:31 pm

The link to the Enterprise COBOL manuals is https://www-01.ibm.com/support/docview. ... wg27036733 and I recommend you start using this. You don't seem to be doing any of your own research -- it took me less than half an hour to code up and test both programs yesterday. You need to learn to start testing your own hypotheses. If you want to know about the RETURNING option -- TEST IT YOURSELF!

This forum is a HELP forum, not a READ-THE-MANUAL-FOR-YOU forum. Topic locked to prevent any further waste of time.
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


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post