Skip to main content

Problem:

How can one determine  how many parameters a COBOL program has been called with, for example "CALL 'A' USING A, B, C"?

On the mainframe it is possible to use an Assembler program to search the save area chain  to find the previous save area and retrieve reg 1 from that save area.   How can this be done in COBOL?

Resolution:

This can be acheived by using the routine CBL_GET_PROGRAM_INFO() to walk back up the call stack.  This will determine how many parameters each program was called with.  

See attached demo programs for an example of using this function.  These programs need to be compiled using the Non-Mainframe dialect in Mainframe Express

'proga' calls 'progb' with two parameters. 'progb' calls 'progc' to do the stack walking.

cobol proga gnt;

cobol progb gnt;

cobol progc gnt;

run proga

Attachments:

proga.cbl

Old KB# 2555

#MFDS
#EnterpriseDeveloper

Problem:

How can one determine  how many parameters a COBOL program has been called with, for example "CALL 'A' USING A, B, C"?

On the mainframe it is possible to use an Assembler program to search the save area chain  to find the previous save area and retrieve reg 1 from that save area.   How can this be done in COBOL?

Resolution:

This can be acheived by using the routine CBL_GET_PROGRAM_INFO() to walk back up the call stack.  This will determine how many parameters each program was called with.  

See attached demo programs for an example of using this function.  These programs need to be compiled using the Non-Mainframe dialect in Mainframe Express

'proga' calls 'progb' with two parameters. 'progb' calls 'progc' to do the stack walking.

cobol proga gnt;

cobol progb gnt;

cobol progc gnt;

run proga

Attachments:

proga.cbl

Old KB# 2555

#MFDS
#EnterpriseDeveloper

as a follow up question - can we get the pointer to the REG 1 of the save area using CBL_GET_PROGRAM_INFO()?  Situation is similar, where we have an assembler program which retrieves the Parameter Address from REG 1 of the prior-to-prior program parameters.  This address is used for subsequent calling of programs.