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"

We can pass data between programs using Files, DB2 tables, Linkage section, TSQs(in case of CICs) etc.

There is another way. We can create a simple program to act as a cache. 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" invoke CACHEPGM with SET parameter and data to be stored in the cache.

From "Program E" invoke CACHEPGM with GET parameter and to retrieve the data stored in the working storage section of CACHEPGM.

No comments:

Post a Comment

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