BY CONTENT
Part of the Programs That Work Together section of Coddy's COBOL Programming journey. Lesson 6 of 16.
BY CONTENT passes a copy of the field. The subprogram can change its linkage field, and the caller's field stays as it was:
CALL "COUNTDN" USING BY CONTENT START-ATPass by content when a subprogram must not touch your data, for example a routine written by another team that uses its input as a work field.
One CALL can mix both. A mode applies to every field after it, until the next mode:
CALL "NETPAY" USING BY CONTENT GROSS
BY REFERENCE NETThe subprogram is written the same way for both: the CALL alone decides whether its changes reach the caller.
Challenge
EasyCOUNTDN counts down to 0 in the field it receives, so after the call START-AT is 0. Pass it BY CONTENT, so 3 prints the count and then Counted down from 3
Example input, one line per ACCEPT: 3.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. LAUNCH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 START-AT PIC 9.
PROCEDURE DIVISION.
ACCEPT START-AT
CALL "COUNTDN" USING START-AT
DISPLAY "Counted down from " START-AT
STOP RUN.