Thursday, December 22, 2011

COBOL : Static and Dynamic calls

The mode of a CALL statement (as static or dynamic) is controlled by the compiler option DYNAM and  by form of the CALL statement i.e., whether the subprogram to be called is specified through an identifier or through a literal). This is illustrated below:

 
          FORM OF CALL                   MODE
    -------------------------       --------------

    CALL identifier                 Always dynamic

    CALL literal with DYNAM         Dynamic
    CALL literal with NODYNAM       Static


  So as per the above, for the following cases it can be concluded  as,
 1. Program compiled with DYNAM option and having statement:
    CALL 'PGMA' USING WS-AREA
    -  Dynamic call

 2. Program compiled with DYNAM option and having statements:
    MOVE 'PGMA' TO WS-PGM
    CALL WS-PGM USING WS-AREA
    -  Dynamic call

 3. Program compiled with NODYNAM option and having statement:
    CALL 'PGMA' USING WS-AREA
   -  Static call

 4. Program compiled with NODYNAM option and having statements:
    MOVE 'PGMA' TO WS-PGM
    CALL WS-PGM USING WS-AREA
    -  Dynamic call

Performance considerations of static and dynamic calls

    Because 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 all.

    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 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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.