MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Acessing the TWA using C

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> CICS and Middleware
View previous topic :: View next topic  
Author Message
HenriqueS
Beginner


Joined: 01 Feb 2007
Posts: 29
Topics: 14

PostPosted: Tue Aug 14, 2007 4:35 pm    Post subject: Acessing the TWA using C Reply with quote

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...

Thanks in advance.
Back to top
View user's profile Send private message
CICS Guy
Intermediate


Joined: 30 Apr 2007
Posts: 292
Topics: 3

PostPosted: Tue Aug 14, 2007 5:58 pm    Post subject: Reply with quote

Relax and give it a chance for somebody knowledgeable it the areas you need help to respond.....
Back to top
View user's profile Send private message
HenriqueS
Beginner


Joined: 01 Feb 2007
Posts: 29
Topics: 14

PostPosted: Thu Aug 23, 2007 12:49 pm    Post subject: Reply with quote

For the good of mankind, my working implementation below, I hope someone one day someone using a search engine for help will reach this...

Acessing the TWA using C:

Code:

struct mystruct{                 
 unsigned char lda_label[65];   
 int lda_tam_exp;               
 unsigned char lda_ex_data[128];
 unsigned char lda_md_data[128];
 unsigned char lda_return 10 ;   
};                               
struct mystruct *twaarea;       

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); */                     
                                                                 
  twaarea=(struct mystruct*)data;                               
  printf("\nTWA lda_label = %s", twaarea->lda_label);             
                                                                 
  printf("\nTWA lda_tam_exp = %02X", twaarea->lda_tam_exp);       
                                                                 
  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);                                                           
 }                                                                     
}
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Aug 23, 2007 7:08 pm    Post subject: Reply with quote

HenriqueS,

Thanks for the solution.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> CICS and Middleware All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group