Presentation is loading. Please wait.

Presentation is loading. Please wait.

Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax.

Similar presentations


Presentation on theme: "Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax."— Presentation transcript:

1 Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax Definition : CALL “subprogram-name” [ USING { [BY REFERENCE] identifier-1 … BY CONTENT identifier-2… } … ] [END-CALL] Examples : CALL “ConvertTime” USING military-time. CALL “tablesort” USING emp-table num-recs. For Your Information The CALL statement: is placed in the Procedure Division. represents a section of code which could have been placed at that logical point in the program, but instead is physically located elsewhere. passes the parameters to the subprogram The subprogram-name: does not include an extension! is case sensitive! can contain a path (like select stmt) The USING clause: identifies the fields in the calling program that are passed to the subprogram. These can be referred to as parameters or arguments. must list the passed fields in sequence that the subprogram requires. defines “by reference” to mean the address of the field in the calling program is passed; is default. defines “by content” to mean the passed data is stored in a new field in the subprogram.

2 Subprograms2 The SUBPROGRAM For Your Information A subprogram is a program that is called by a calling program. Before a subprogram can be called by another program, it must be compiled and ready for execution. NOTE: this is why it doesn’t matter what language the subprogram is in!!! Cannot be executed on its own Purpose: a program that is executed by another program Syntax Definition : 3 parts  Examples: SEE handouts LINKAGE SECTION. * Must be defined in the subprogram * Identifies items passed to and from * Does not exist if no parameters are passed * Value clauses are not permitted * Coded after the working-storage section PROCEDURE DIVISION USING… * Includes all fields defined in the linkage section * Must match up with variables in CALL statement (although order does not matter) * The name can be the same or different EXIT PROGRAM. * Passes execution control from the subprogram back to the calling program, passing the parameters back as well * Can have multiple statements

3 Subprograms3 Advantages of calling subprograms avoids duplication of effort improves programmer productivity simplification of main reduces overall development time takes advantage of individual programmer's strengths/talents separate compilation and testing easier to debug and maintain divides tasks for multiple programmers provides greater flexibility changes to the called program can be made without the need to modify the calling program. results in greater standardization DISADVANTAGES extra step to join program and subprogram together (linking) slightly longer execution time because of procedure calls can not be run independently


Download ppt "Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax."

Similar presentations


Ads by Google