Sending data from C to COBOL on HP Tandem

174 Views Asked by At

I am trying to call a C function from COBOL and expecting a reply from it. I am new to this interfacing.

COBOL code:

ENTER C "ADD" USING A,B.

C code:

int ADD(int a,int b)
{
    return a+b;
}

I want to get the sum value from the C function for further processing in COBOL.

3

There are 3 best solutions below

3
On BEST ANSWER

In COBOL

EXTENDED-STORAGE SECTION.
01 MYVAR EXTERNAL.
   05 DATA-01 PIC X(20).

In C

 /*Add necessary includes */
 extern char MYVAR[21];

 void change_Cobol_Variable()
 {
   /*you can use MYVAR as normal C-variable*/
   sprintf(MYVAR, "%s","Something");
 }

If it is integer declare appropriate variables as per your need :)

0
On

In Cobol:

EXTENDED-STORAGE SECTION.
01 C EXTERNAL.
   05 DATA-01 PIC 9(1).

In C:

/*Add necessary includes */
extern int C;

void ADD(int A,int B)
{
/*you can use C as normal C-variable*/
  C=A+B;
}
0
On

You can use GIVING

ENTER C "ADD" USING A,B GIVING ANS.

so your a+b value will be stored in ANS