Your SlideShare is downloading. ×
0
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Call
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
228
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. The CALL Verb
  • 2. CALL Verb
    • A COBOL statement for accessing a subprogram.
    • Called program is a subprogram or program called into a user program as needed.
    • Calling program is a program that calls a subprogram.
    • CALL Syntax
  • 3. Call Parameters
    • 1. PROGNAME IDENTIFIER OR LITERAL
    • It is possible not to specify the name of the called subprogram as an explicit literal, as the following example:
    • If response=“M”
    • move “MONTHLY” to sub-name
    • else
    • move “QUARTERLY” to sub-name.
    • CALL sub-name.
  • 4. Call Parameters
    • USING BY CONTENT/REFERENCE
    • 1. BY REFERENCE
    • This clause may be omitted, in which case it is specified by default.
    • Means to associate subprogram data-names in the linkage and procedure division using… specifications with the address of the corresponding data-names in the calling program.
  • 5. Call Parameters
    • USING BY CONTENT/REFERENCE
    • 2. BY CONTENT
    • The CALL statement makes available to the subprogram the content of the data-names listed in the CALL statement.
    • The subprogram then does not make reference to the actual data-name storage locations in the calling program and cannot alter the contents of the data-names in the calling program.
    • The calling program passes data, not references, to the called program.
    • CALL “STATS” USING BY CONTENT NO-OF-RECS,
    • SALES-TABLE.
  • 6. CALL Example. IDENTIFICATION DIVISION. PROGRAM-ID DateValidate IS INITIAL. DATA DIVISION. WORKING-STORAGE SECTION. ? ? ? ? ? ? ? ? ? ? ? ? LINKAGE SECTION. 01 DateParam PIC X(8). 01 DateResult PIC 9. PROCEDURE DIVISION USING DateParam, DateResult. Begin. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EXIT PROGRAM. ??????. ? ? ? ? ? ? ? ? ? ? ? ? CALL "DateValidate" USING BY CONTENT TempDate USING BY REFERENCE DateCheckResult.
  • 7. CALL Parameters CALL "ProgramName" USING P1, P2, P3, P4. PROCEDURE DIVISION USING P2, P4, P1, P3.
  • 8. CALL Parameters
    • Positions Correspond - Not Names
    CALL "ProgramName" USING P1, P2, P3, P4. PROCEDURE DIVISION USING P2, P4, P1, P3.
  • 9. Parameter Passing Mechanisms CALL .. BY REFERENCE CALLed Program
  • 10. Parameter Passing Mechanisms CALL .. BY REFERENCE CALLed Program Address of Data Item Direction of Data Flow
  • 11. Parameter Passing Mechanisms CALL .. BY REFERENCE CALLed Program Address of Data Item CALL .. BY CONTENT CALLed Program Copy of Data Item Direction of Data Flow
  • 12. Parameter Passing Mechanisms CALL .. BY REFERENCE CALLed Program Address of Data Item Direction of Data Flow Direction of Data Flow CALL .. BY CONTENT CALLed Program Copy of Data Item Address of Copy Data Item
  • 13. Call Parameters
    • ON OVERFLOW
    • This conditional specifies execution of imperative-statement-1 if the CALL cannot be executed because of insufficient storage, and the like.
    • END-CALL
    • This is a scope terminator that can be used as follows:
    • if N>zero
    • call “STATS” using…
    • on overflow
    • perform abc
    • move a to z
    • end-call
    • end-if.
  • 14. Called Program Requirements
    • 1. PROGRAM-ID
    • In the calling program, we code CALL ‘literal-1’ USING …
    • In the called program, we code PROGRAM-ID. literal-1.
    • With COBOL 85, the PROGRAM-ID paragraph of the called program may have the following INITIAL PROGRAM clause:
    • PROGRAM-ID. Program-name [IS INITIAL PROGRAM].
    • If this clause is used, the called program will be restored to its initial state each time it is called.
    • This means that all identifiers in Working-storage will contain their original values, as specified by their VALUE clauses, before and after each call.
  • 15. Called Program Requirements
    • 2. LINKAGE SECTION
    • A Linkage Section must be defined in the called program for identifying those items that:
    • (1) will be passed to the called program from the calling program
    • (2) passed back from the called program to the calling program.
    • The Linkage Section, if used, is coded after the File and Working-storage Sections of the called program.
    • Similar to the Working-storage Section except that VALUE clauses for initializing fields are not permitted in the Linkage Section.
  • 16. Called Program Requirements
    • 3. PROCEDURE DIVISION USING
    • The identifiers specified in the USING clause in the PROCEDURE DIVISION entry include all fields defined in the LINKAGE SECTION; these identifiers will be passed from one program to the other.
    • They passed to and from corresponding identifiers in the CALL … USING of the main program.
    • 4. EXIT PROGRAM
    • The last executed statement in the called program must be the EXIT PROGRAM.
    • It signals the computer to return control back to the calling program.
  • 17. Avoiding “State Memory” - The IS INITIAL phrase.
    • 12
    • Total = 62
    • 5
    • Total = 55
    • 12
    • Total = 62
    $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Steadfast IS INITIAL . DATA DIVISION. WORKING-STORAGE SECTION. 01 RunningTotal PIC 9(7) VALUE 50. LINKAGE SECTION. 01 ParamValue PIC 99. PROCEDURE DIVISION USING ParamValue. Begin. ADD ParamValue TO RunningTotal. DISPLAY "Total = ", RunningTotal. EXIT PROGRAM.
  • 18. Avoiding “State Memory” - The IS INITIAL phrase.
    • 12
    • Total = 62
    • 5
    • Total = 67
    • 12
    • Total = 79
    $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Fickle. DATA DIVISION. WORKING-STORAGE SECTION. 01 RunningTotal PIC 9(7) VALUE 50. LINKAGE SECTION. 01 ParamValue PIC 99. PROCEDURE DIVISION USING ParamValue. Begin. ADD ParamValue TO RunningTotal. DISPLAY "Total = ", RunningTotal. EXIT PROGRAM.
  • 19. The CANCEL command.
    • 12
    • Total = 62
    • 12
    • Total = 62
    $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Fickle. DATA DIVISION. WORKING-STORAGE SECTION. 01 RunningTotal PIC 9(7) VALUE 50. LINKAGE SECTION. 01 ParamValue PIC 99. PROCEDURE DIVISION USING ParamValue. Begin. ADD ParamValue TO RunningTotal. DISPLAY "Total = ", RunningTotal. EXIT PROGRAM. CALL "Fickle" USING BY CONTENT IncValue. CANCEL "Fickle" CALL "Fickle" USING BY CONTENT IncValue.
  • 20. Question?
    • 1. When subprograms are used, there must be one and only one ____ program but there may be several ____.
    • MAIN;SUBPROGRAM
    • 2. The statement that terminates execution of the subprogram and returns execution to the statement following the corresponding CALL statement is the ___ command.
    • EXIT PROGRAM
    • 3. A called subprogram [can/cannot] itself include a CALL statement that results in execution of another subprogram.
    • Can
    • 4. A called subprogram [can/cannot] itself include a CALL statement that results in execution of the main program.
    • Cannot
  • 21. Question?
    • 5. Because each subprogram has its own DATA DIVISION, and yet there are data that are to be used in both the main program and subprogram, the DATA DIVISION of the subprogram must include a special ____ SECTION to identify such data.
    • LINKAGE
    • 6. For data that are used in both main program and subprogram, the data names [must/need not] be the same in the two programs.
    • Need not
    • 7. For shared data items, what is important in the LINKAGE SECTION is the ___ description for each data-name.
    • PIC
    • 8. For shared data items, the order of the data-names in the LINKAGE SECTION [is/is not] relevant.
    • Is not
  • 22. Contained Sub-Programs $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. MainProgram. ? ? ? ? ? ? ? ? ? 01 TableItem IS GLOBAL . PROCEDURE DIVISION. ? ? ? ? ? ? ? ? ? CALL PutToTable USING BY CONTENT DataItem ? ? ? ? ? ? ? ? ? CALL ReportFromTable. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. PutToTable. ? ? ? ? ? ? ? ? ? END-PROGRAM PutToTable. IDENTIFICATION DIVISION. PROGRAM-ID. ReportFromTable. ? ? ? ? ? ? ? ? ? END-PROGRAM ReportFromTable. END-PROGRAM MainProgram.
  • 23. Contained Sub-Programs $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. MainProgram. ? ? ? ? ? ? ? ? ? 01 TableItem IS GLOBAL . PROCEDURE DIVISION. ? ? ? ? ? ? ? ? ? CALL PutToTable USING BY CONTENT DataItem ? ? ? ? ? ? ? ? ? CALL ReportFromTable. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. PutToTable. ? ? ? ? ? ? ? ? ? END-PROGRAM PutToTable. IDENTIFICATION DIVISION. PROGRAM-ID. ReportFromTable. ? ? ? ? ? ? ? ? ? END-PROGRAM ReportFromTable. END-PROGRAM MainProgram.
  • 24. Contained Sub-Programs $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. MainProgram. ? ? ? ? ? ? ? ? ? 01 TableItem IS GLOBAL . PROCEDURE DIVISION. ? ? ? ? ? ? ? ? ? CALL PutToTable USING BY CONTENT DataItem ? ? ? ? ? ? ? ? ? CALL ReportFromTable. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. PutToTable. ? ? ? ? ? ? ? ? ? END-PROGRAM PutToTable. IDENTIFICATION DIVISION. PROGRAM-ID. ReportFromTable. ? ? ? ? ? ? ? ? ? END-PROGRAM ReportFromTable. END-PROGRAM MainProgram.
  • 25. The COMMON PROGRAM Phrase $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. MainProgram. ? ? ? ? ? ? ? ? ? 01 TableItem IS GLOBAL . PROCEDURE DIVISION. ? ? ? ? ? ? ? ? ? EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. PutToTable. ? ? ? ? ? ? ? ? ? CALL ReportFromTable. ? ? ? ? ? ? ? ? ? END-PROGRAM PutToTable. IDENTIFICATION DIVISION. PROGRAM-ID. ReportFromTable IS COMMON PROGRAM. ? ? ? ? ? ? ? ? ? CALL PutToTable USING ???? ? ? ? ? ? ? ? ? ? END-PROGRAM ReportFromTable. END-PROGRAM MainProgram.
  • 26. The COMMON PROGRAM Phrase $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. MainProgram. ? ? ? ? ? ? ? ? ? 01 TableItem IS GLOBAL . PROCEDURE DIVISION. ? ? ? ? ? ? ? ? ? EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. PutToTable. ? ? ? ? ? ? ? ? ? CALL ReportFromTable. ? ? ? ? ? ? ? ? ? END-PROGRAM PutToTable. IDENTIFICATION DIVISION. PROGRAM-ID. ReportFromTable IS COMMON PROGRAM. ? ? ? ? ? ? ? ? ? CALL PutToTable USING ???? ? ? ? ? ? ? ? ? ? END-PROGRAM ReportFromTable. END-PROGRAM MainProgram. YES
  • 27. The COMMON PROGRAM Phrase $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. MainProgram. ? ? ? ? ? ? ? ? ? 01 TableItem IS GLOBAL . PROCEDURE DIVISION. ? ? ? ? ? ? ? ? ? EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. PutToTable. ? ? ? ? ? ? ? ? ? CALL ReportFromTable. ? ? ? ? ? ? ? ? ? END-PROGRAM PutToTable. IDENTIFICATION DIVISION. PROGRAM-ID. ReportFromTable IS COMMON PROGRAM. ? ? ? ? ? ? ? ? ? CALL PutToTable USING ???? ? ? ? ? ? ? ? ? ? END-PROGRAM ReportFromTable. END-PROGRAM MainProgram. YES NO
  • 28. Creating Abstract Data Types? $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Stack. DATA DIVISION. WORKING-STORAGE SECTION. 01 StackHolder IS GLOBAL. 02 StackItem OCCURS 20 TIMES PIC X(10). PROCEDURE DIVISION USING ????. Begin. EVALUATE TRUE WHEN PushStack CALL "Push" USING ??? WHEN PopStack CALL "Pop" USING ??? END-EVALUATE. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. Push. ? ? ? ? ? ? ? ? ? END-PROGRAM Push. IDENTIFICATION DIVISION. PROGRAM-ID. Pop. ? ? ? ? ? ? ? ? ? END-PROGRAM Pop. END-PROGRAM Stack. Stack Push Pop Main
  • 29. Creating Abstract Data Types? $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Stack. DATA DIVISION. WORKING-STORAGE SECTION. 01 StackHolder IS GLOBAL. 02 StackItem OCCURS 20 TIMES PIC X(10). PROCEDURE DIVISION USING ????. Begin. EVALUATE TRUE WHEN PushStack CALL "Push" USING ??? WHEN PopStack CALL "Pop" USING ??? END-EVALUATE. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. Push. ? ? ? ? ? ? ? ? ? END-PROGRAM Push. IDENTIFICATION DIVISION. PROGRAM-ID. Pop. ? ? ? ? ? ? ? ? ? END-PROGRAM Pop. END-PROGRAM Stack. Stack Push Pop Main
  • 30. Creating Abstract Data Types? $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Stack. DATA DIVISION. WORKING-STORAGE SECTION. 01 StackHolder IS GLOBAL. 02 StackItem OCCURS 20 TIMES PIC X(10). PROCEDURE DIVISION USING ????. Begin. EVALUATE TRUE WHEN PushStack CALL "Push" USING ??? WHEN PopStack CALL "Pop" USING ??? END-EVALUATE. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. Push. ? ? ? ? ? ? ? ? ? END-PROGRAM Push. IDENTIFICATION DIVISION. PROGRAM-ID. Pop. ? ? ? ? ? ? ? ? ? END-PROGRAM Pop. END-PROGRAM Stack. Stack Push Pop Main
  • 31. The IS EXTERNAL phrase. FD CommonFileArea IS EXTERNAL. WORKING-STORAGE SECTION. 01 SharedRec IS EXTERNAL. 02 PartA PIC X(4). 02 PartB PIC 9(5).
  • 32. The IS EXTERNAL phrase. WORKING-STORAGE SECTION. 01 SharedRec IS EXTERNAL. 02 PartA PIC X(4). 02 PartB PIC 9(5). SharedRec Mike12345 ProgramA 01 SharedRec etc ProgramD ProgramC 01 SharedRec etc ProgramB
  • 33. The IS EXTERNAL phrase. WORKING-STORAGE SECTION. 01 SharedRec IS EXTERNAL. 02 PartA PIC X(4). 02 PartB PIC 9(5). SharedRec PUT Mike12345 Mike12345 ProgramA 01 SharedRec etc ProgramD ProgramC 01 SharedRec etc ProgramB
  • 34. The IS EXTERNAL phrase. WORKING-STORAGE SECTION. 01 SharedRec IS EXTERNAL. 02 PartA PIC X(4). 02 PartB PIC 9(5). SharedRec PUT GET Mike12345 Mike12345 Mike12345 ProgramA 01 SharedRec etc ProgramD ProgramC 01 SharedRec etc ProgramB

×