How to pass linkage section data to another program's linkage section in COBOL
<p>I'm working on a Wrapper/Bridge COBOL program that handles program calls and performs cross-cutting operations like logging,security-check etc. 
Main motivation is checking the security access for consumer program whether it has access to call the producer program or not. </p>

<p>Let the bridge COBOL program be B1 and the producer program P1 and the consumer(client) C1.</p>

<p>When C1 wants to call P1, it have to make a call to B1. Then, B1 checks the accessibility. If C1 has access, then B1 calls P1 with C1's data.</p>

<pre><code>C1 -&gt; B1 -&gt; P1 
</code></pre>

<p>In here the linkage section of B1 and P1 are the same. Programs are using EXEC CICS LINK to call each other.</p>

<p>The COMMAREA,</p>

<pre><code>COMMAREA1 (DataSet Name)

01 COMMAREA-STRUCT, 
   03 a-field
   03 another-field      
    ...
</code></pre>

<p>The client;</p>

<pre><code>IDENTIFICATION DIVISION.
PROGRAM-ID.  Client.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY COMMAREA1
PROCEDURE DIVISION

 /* fill CommareaStruct with some values. */
 ....
 /* call B1 Bridge */ 
   EXEC CICS LINK PROGRAM  (B1Bridge)      NOHANDLE
     COMMAREA (COMMAREA-STRUCT) 
     LENGTH (LENGTH OF COMMAREA-STRUCT) 
    END-EXEC
 ....
</code></pre>

<p>The Bridge,</p>

<pre><code>IDENTIFICATION DIVISION.
PROGRAM-ID.  B1Bridge.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
COPY COMMAREA1
PROCEDURE DIVISION
 ...
 /* access control */
 /* logging */
 ...
 /* pass data to P1*/
    EXEC CICS LINK PROGRAM  (P1)      NOHANDLE
       COMMAREA (COMMAREA-STRUCT) 
       LENGTH (LENGTH OF COMMAREA-STRUCT) 
     END-EXEC
....
</code></pre>

<p>The producer ;</p>

<pre><code>IDENTIFICATION DIVISION.
PROGRAM-ID.  P1
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
COPY COMMAREA1
PROCEDURE DIVISION
....

*doing some business with data in COMMAREA1 
...
</code></pre>

<p>When I try above, I got a compile-time warning for Bridge Program B1 ;
"COMMAREA-STRUCT or one of its subordinates was referenced, but COMMAREA-STRUCT was a LINKAGE SECTION item that did not have addressability.  This reference will not be resolved succcessfully at execution." </p>

<p>What does it mean? How should I pass B1's linkage section to P1's linkage  section? </p>

<p>When I try like this, I got EIBRESP:22 and EIBRESP2: 26  (commarea length error) at runtime. </p>

<p>-- Edit --</p>

<p>I think I should give more details;</p>

<p>Main motivation;
Actually there are two companies that company COM1 and COM2. COM2 was an affiliate of COM1 for several years.
COM1 and COM2 have CICS1 and CICS2 respectively. And COM2 client programs uses COM1 producer programs. COM2 clients never call the COM1 producers directly. COM2 clients put the data into COMMAREA-STRUCT  and call a Generic Cobol Program (let it be GCP) remotely. COMMAREA-STRUCT has also "the producer program name" field that GCP figures out which program is wanted to be called. So, GCP exports the data from COMMAREA-STRUCT and maps to the fields of producer. GCP performs the mapping operations dynamically with addressing(not special for each producer). After the producer performs, GCP takes the result and passes back to the  client via COMMAREA-STRUCT. 
The system was designed like that several years ago. There are thousands of clients of COM2 and thousands of producers of COM1.</p>

<p><a href="https://i.stack.imgur.com/tmlPI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tmlPI.png" alt="enter image description here"></a></p>

<p>Now, COM2 wants to apart from COM1. So COM1 don't want to give full access to all COM1 resources(producers) any more. Thus, COM1 wants to put a new cics in front of the CICS1 which will be a handler CICS that runs only B1 Bridge program locally. This also about network security and company-political decisions.</p>

<p><a href="https://i.stack.imgur.com/O3Yhe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O3Yhe.png" alt="enter image description here"></a>
To seperate the companies from each other in a little while, neither the clients nor the producers should be affected. So, problem should be solved in GCP-Bridge layer.</p>

<p>That's why, B1 Bridge should behave like GCP to the COM2 Clients, should check the accessibility(somehow, we applied it) and should pass all the data that coming from the clients to the GCP without any modification.</p>

<p>Currenty the logging operation does not have any priority. We focus on part the companies in a little while.</p>

<p>So I'm very appreciated for your expert comments. </p>

<p>*We can't use CALL because B1 will be on another CICS and can not access the LOADLIB1 of COM1 thats why B1 should call GCP remotly by EXEC CICS LINK.</p>

<p>*Instead of passing commarea, passing the channel sounds good to me. We will discuss on it.</p>

<p>*By the way, i will check fullword-halfword conflict on LENGHT OF. You are right.</p>

<p>*For the security check, we will discuss on "EXEC CICS QUERY SECURITY".</p>

<p>*As mentioned above, we can not modify copy-books. Only we can change is,</p>

<pre><code> EXEC CICS LINK PROGRAM (GCP) 
</code></pre>

<p>to</p>

<pre><code> EXEC CICS LINK PROGRAM (B1) 
</code></pre>

<p>on the clients by find&amp;replace. Because there are thousands of clients. We don't want to change copy-book and touch them.</p>

<p>In lights of these details, I think the problem becomes more understandable.</p>