CALLing a C program from Natural under CICS

Hello,

I am a C programmer and I am trying to make a small Natural program that calls my C program, acessing a specific function inside of it and handling the correct parameters.

I got an example from the CALL documentation that seems pretty simple, but at same time is odd.

The example does a call like below (Natural):

CALL ‘ADD’ #OP1 #OP2 'SUM
DISPLAY #SUM

The called C program is like this:

NATFCT ADD (int *op1, int *op2, int *sum){

}

At runtime, in the moment the Nat program called the C program, CICS complained that there wasn

I only know a little about this (and I work in COM-PLETE, not CICS, so I may be leading you off base because of that.) What I’m going to say applies if your Natural was built with LE=NO; if this isn

I remembered some other things I had to do:

  • [list]
    All the C function names were upper case.
    [/list]
    [list]
    For the function directly called from Natural, “#pragma environment(function-name,nolib)”
    [/list]
  • :6ca7f8e3aa]“#pragma runopts(heap(4k,4k,any),stack(4k,4k,any))”

Thanks for your feedback Curtis,

I have found the following:

Apparently, when a Natural program calls another program UNDER CICS, the command line arguments are pushed into a CICS storage area, the most common are:
CWA: Common Work Area - stores data accross regions
TWA: Transaction Work Area - store data across a transaction - some docs don

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:


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>lda_ex_data[i]);                     
  }                                                               
  printf("\nTWA lda_md_data =");                                  
  for(int i=0;i<128>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>lda_return, "RETURN");                                
  EXEC CICS RETURN;                                                    
  return(0);                                                           
 }                                                                     
}