Posted: Tue Aug 14, 2007 4:35 pm Post subject: Acessing the TWA using C
Hello folks,
We have a Natural program that is supposed to call a C program. In the very beginning I struggled because the Natural manuals gave a sample that does not take CICS into consideration.
Then I got to know about the CICS storage areas and how does CICS behaves when switching from one program to another under the same task. It just wipes the command line arguments sent from the caller and puts to the TWA (the choice on which area is based on some Natural setting). Then calls the target program supplying just a transaction id.
Still, I got some Cobol examples of retrieving the calling parameters from the TWA and also returning from it. But I do not grasp Cobol well.
So, I ask if anyone does have any C sample of acessing the TWA area or at least some documentation that shows its structure. The "CICS Programming Reference" nor the "CICS Programming Guide" detail it.
*I got a very simple C sample of getting a pointer to the TWA, but in that sample, the programmer had to parse the whole area and break the data every n bytes to get what he wanted. The Cobol sample seemed more elegant but I did not get the point on it...
int main(int argc, char *argv ){
/* argc and argv are overwritten by CICS, Natural or CICS (not sure) will
store the CALL parameters (made in the Natural program) in an area calles TWA.
Argc under CICS returns '1' and argv[0] returns the transaction id */
printf("\nTransaction id: %s", argv 0 );
int *twa;
unsigned char *data;
EXEC CICS ADDRESS TWA(twa);
data = (unsigned char *) *((int *) *twa); /* weird casting copied from a friend */
/* EIB is a memory area that contains status information about the context in
which the transaction is running. The example below shows getting the current
transaction id. Notice that if the pointer variable to this area was not created
before, the CICS translator solves this, freeing the programmer.
EXEC CICS ADDRESS EIB(dfheiptr);
printf("\nT id %s", dfheiptr->eibtrnid); */
printf("\nTWA lda_ex_data =");
for(int i=0;i<128;i++){
printf("%02X", twaarea->lda_ex_data[i]);
}
printf("\nTWA lda_md_data =");
for(int i=0;i<128;i++){
printf("%02X", twaarea->lda_md_data[i]);
}
/* Shows TWA contents, used for interprocess communication between a caller
Natural module and a called C module. It has the size of 1024 bytes, defined
on CICS for each transaction (custom up to 32kbytes). */
printf("\nFull hex dump =\n");
for(int i=0;i<1024;i++){
if((i+1)%40==0) printf("\n"); /* break line */
printf("%02X", *(data+i));
}
/* Send return back to the Natural module */
strcpy(twaarea->lda_return, "RETURN");
EXEC CICS RETURN;
return(0);
}
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum