Subroutines(Sub Programs)

     1.     What is the LINKAGE SECTION used for?
The linkage section is used to pass data from one program to another program or to pass data from a PROC to a program.
     2.     What is the difference between static call and dynamic call in COBOL?
A statically called program is link-edited into the same load module as the calling program; a static call is faster than a dynamic call. A static call is the preferred method if your application does not require the services of the dynamic call.

Statically called programs cannot be deleted (using CANCEL), so static calls might take more main storage. If storage is a concern, think about using dynamic calls. Storage usage of calls depends on whether:

The subprogram is called only a few times. Regardless of whether it is called, a statically called program is loaded into storage; a dynamically called program is loaded only when it is called.

You subsequently delete the dynamically called subprogram with a CANCEL statement.

You cannot delete a statically called program, but you can delete a dynamically called program. Using a dynamic call and then a CANCEL statement to delete the dynamically called program after it is no longer needed in the application (and not after each call to it) might require less storage than using a static call. 

Dynamically called modules are those that are not bound with the calling program at link edit time (IEWL for IBM) and so are loaded from the program library (job lib or step lib) associated with the job. For DYNAMIC calling of a module the DYNAM compiler option must be chosen, else the linkage editor will not generate an executable as it will expect null address resolution of all called modules. A Statically called module is one that is bound with the calling module at link edit, and therefore becomes part of the executable load module.

     3.     How can I tell if a module is being called DYNAMICALLY or STATICALLY?
The ONLY way is to look at the output of the linkage editor (IEWL) or the load module itself. If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module.
Calling a working storage variable, containing a program name, does not make a DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable.
     4.     PGM-A calls PGM-B. What will happen when PGM-B issues STOP RUN?
The control will not come back to PGM-A afternd the execution of PGM-B and hence PGM-B will stop abruptly.
     5.     PGM-A calls PGM-B recursively. What will happen to the Data Items declared in PGM-B?
The status of Data Items will get changed whenever the PGM-B is called. Thus when control leaves a subroutine, it is not likely to be in the same state in which it was entered. If the same sub routine is called again, it will be entered in its last used state.
I f youew want to have the subroutine in its initial state, the subroutine should be called after having cancelled its current state by means of a CANCEL statement.


Computers TopOfBlogs Technology Blogs Mainframe interview question and answers,mainframe jobs,cobol,vsam,jcl,cics,db2,rdbms,mvs,tso,ispf,ibm,hcl,tcs,cts,wibro Blog Directory