Sunday, 22 September 2013

COBOL CALL Statement.

COBOL CALL statement is used to transafer control from one program to another. The program containing the CALL statement is the calling program; the program identified in the CALL statement is the called subprogram. Called programs can contain CALL statements; however, only programs defined with the RECURSIVE clause can execute a CALL statement that directly or indirectly calls itself. Refer below figure.

 Syntax : CALL     identifier-1, literal-1, procedure-pointer-1, function-pointer-1
                 USING   BY REFERENCE
                         BY CONTENT
                         BY VALUE
                 RETURNING identifier-5
  • BY REFERENCE phrase : If the BY REFERENCE phrase is either specified or implied for a parameter, the corresponding data item in the calling program occupies the same storage area as the data item in the called program.
  • BY CONTENT phrase : If the BY CONTENT phrase is specified or implied for a parameter, the called program cannot change the value of this parameter as referenced in the CALL statement’s USING phrase, though the called program can change the value of the data item referenced by the corresponding data-name in the called program’s procedure division header. Changes to the parameter in the called program do not affect the corresponding argument in the calling program.
  • BY VALUE phrase  : The BY VALUE phrase applies to all arguments that follow until overridden by another BY REFERENCE or BY CONTENT phrase. If the BY VALUE phrase is specified or implied for an argument, the value of the argument is passed, not a reference to the sending data item. The called program can modify the formal parameter that corresponds to the BY VALUE argument, but any such changes do not affect the argument because the called program has access to a temporary copy of the sending data item.
  • The RETURNING data item :  which can be any data item defined in the data division. The return value of the called program is implicitly stored into identifier-5.
  • This explicit scope : terminator serves to delimit the scope of the CALL statement. END-CALL permits a conditional CALL statement to be nested in another conditional statement. END-CALL can also be used with an imperative CALL statement.
Note : Although BY VALUE arguments are primarily intended for communication with non-COBOL programs (such as C), they can also be used for COBOL-to-COBOL invocations. In this case, BY VALUE must be specified or implied for both the argument in the CALL USING phrase and the corresponding formal parameter in the procedure division USING phrase.

Created with Artisteer

No comments:

Post a Comment