30 likes | 126 Views
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… } … ]
E N D
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. Subprograms
The SUBPROGRAM Purpose: a program that is executed by another program Syntax Definition: 3 parts Examples: SEE handouts LINKAGESECTION. * 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 PROCEDUREDIVISIONUSING… * 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 EXITPROGRAM. * Passes execution control from the subprogram back to the calling program, passing the parameters back as well * Can have multiple statements 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 Subprograms
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 Subprograms