Page 1 of 1

COBOL Subroutines

PostPosted: Thu Dec 20, 2012 11:44 am
by hvats83
Please suggest if there is any way to refer working storage variables of subprogram in main program.

Re: COBOL Subroutines

PostPosted: Thu Dec 20, 2012 12:35 pm
by BillyBoyo
Why would you want to do that?

If you have some "result" that the sub-program has produced, you'd MOVE it to a Linkage Section item, defined in the main program specifically for that purpose, and given good names so you know what it is being used for.

Re: COBOL Subroutines

PostPosted: Thu Dec 20, 2012 2:57 pm
by hvats83
There is a client business value copybook(used to set certain conditions in our system which differs for each customers.Every time we make change to program using this copybook we need to compile the source code every time(by giving copylib order).

Hence to reduce this effort I am trying to write a subroutine which will use this copybook and set the required conditions and main program can refer to working storage variable of sub program.This subprogram will be called dynamically(so that whenever we make change to main program no need to compile sub program)

Re: COBOL Subroutines

PostPosted: Thu Dec 20, 2012 4:09 pm
by BillyBoyo
So, you call the sub-program with the 01 on the USING. MOVE from the Working-Storage in the sub-program to the 01 defined in the Linkage and on the USING of the Procedure Division.

Even better, define the data on a dataset. Read the dataset. No need to compile anything. Just an application to maintain the dataset.

Re: COBOL Subroutines

PostPosted: Thu Dec 20, 2012 5:46 pm
by Robert Sample
Directly refer to it? No -- this violates all rules of modular programming as well as creating nightmares for debugging, and if the subprogram is dynamically called it may not even be possible (when the calling program issues a CANCEL for example).

Indirectly refer to it? Yes -- use the LINKAGE SECTION variables and have the subprogram move data to and from the LINKAGE SECTION varaibles as appropriate.