I am trying to call a LE C program (test program that just prints the arguments) from my COBOL program.
I pass a structure to my C program and print the received values. However, as you can see in the output, the first 2 bytes of function are missing when printing argv[1]. Could anyone help fix this?
Is this the correct way to call a LE C program from COBOL program (I need to pass upto 3 structures like CALL cpgm USING struct1 struct2 struct3) or is there a better way? Any examples would really help.
COBOL program:
IDENTIFICATION DIVISION.
PROGRAM-ID. COBPGM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 EXPARM.
05 FUNKTION PIC X(4) VALUE SPACES
05 FUNC REDEFINES FUNKTION.
10 FILLER PIC X(03).
10 FUNC-SUFFIX PIC X.
05 STAT PIC X(2) VALUE SPACES
05 ID-CODE PIC S9(4) COMP.
05 ID-NAME PIC X(08).
PROCEDURE DIVISION.
MOVE 'FUNC' TO FUNKTION.
MOVE '1' TO FUNC-SUFFIX.
MOVE 'OK' TO STAT.
MOVE 1234 TO ID-CODE.
MOVE 'IDNAME ' TO ID-NAME.
CALL 'CPGM' USING EXPARM.
STOP RUN.
C program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
typedef struct EXPARM1{
char FUNCTION[4];
char STATUS[3];
int ID_CODE;
char ID_NAME[9];
}EXPARM;
int main(int argc, char **argv) {
printf("argc : %dn",argc);
if (argc>=1) {
printf("argv[0] : %sn",argv[0]);
printf("argv[1] : %sn",argv[1]);
}
return 0;
}
Output:
argc : 2
argv.0. : COBPGM
argv.1. : N1OK.KIDNAME ENDMBLK-.s..
the above ‘.K’ in the output is 1234 in HEX and not sure where ENDMBLK is coming from.
Tried to run the program and it printed the above output which I can’t make sense of.
rahul bajaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.