Tuesday, October 26, 2021

How to pass data to a program present many levels down the calling chain

Let us say we have below calling chain

Program A --> Program B ---> Program C ---> Program D --> Program E

And we want to pass data from "Program B" to "Program E"

Common approaches for passing data between programs include:
  • Passing data through the LINKAGE section from Program B → Program C → Program D → Program E
  • Storing the data in a VSAM file
  • Storing the data in a DB2 table
  • Using CICS TSQ/TDQ in online environments
  • Channels/Containers in CICS

While these methods are widely used and appropriate in many scenarios, they may require changes to multiple programs, additional I/O operations. For example, passing data through the LINKAGE section requires every intermediate program in the call chain to receive and forward the data, even when those programs have no need for it. Similarly, storing data in VSAM, DB2, or CICS queues introduces persistence and access overhead that may be unnecessary for small amounts of transient data.

Channels and Containers work only in CICS programs. They cannot be used in batch jobs, so they are not suitable if the solution must support both online and batch processing.

In situations where a small piece of data needs to be shared between non-adjacent COBOL programs during the same execution path, a lightweight cache program can provide a simple alternative. This approach avoids modifications to intermediate programs while keeping the data readily accessible to programs located several levels down the calling chain.

This technique works well in both online and batch environments.

Here I am using a sub program called "CACHEPGM" as a cache. 

       IDENTIFICATION DIVISION.  
       PROGRAM-ID.    CACHEPGM.
       ENVIRONMENT DIVISION. 
       DATA DIVISION.       
       WORKING-STORAGE SECTION.  
       01 WS-SAVE-DATA PIC X(80) VALUE SPACES. 
       LINKAGE SECTION.                        
       01 LS-PARAMETERS.  
          05 LS-FUNC          PIC X(4) VALUE SPACES. 
               88 LS-SET-DATA           VALUE 'SET'.  
               88 LS-GET-DATA           VALUE 'GET'.      
           05 LS-DATA         PIC X(80). 
       PROCEDURE DIVISION USING LS-PARAMETERS. 
           EVALUATE TRUE  
             WHEN LS-SET-DATA  
               MOVE LS-DATA      TO WS-SAVE-DATA   
             WHEN LS-GET-DATA 
               MOVE WS-SAVE-DATA TO LS-DATA  
           END-EVALUATE   
           GOBACK.    

From Program B, call CACHEPGM with the SET function and the data that needs to be shared. CACHEPGM stores the data in its Working-Storage area for later use.

From Program E, call CACHEPGM with the GET function to retrieve the previously stored data. CACHEPGM returns the value from its Working-Storage area to the calling program.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.