I am struggling with calling C from COBOL. Basically, I need a working sample COBOL calling C with *parm parameters. I was trying to call using BY REFERENCE, I tried to call USING BY REFERENCE to a pointer and it is clear that it does not work. Let me please show you my latest attempt (bear in mind that it is only a test attempt, not the real program):
Here is the COBOL
000001 identification division.
000002 Program-ID. cobapi.
000003 ENVIRONMENT DIVISION.
000004 data division.
000005 working-storage section.
000006 * int TESTAPI(const char *subject,
000007 * int *ovector, int stringcount,
000008 * const char ***listptr)
000009
000010 01 subject.
000011 05 FILLER PIC X(5) VALUE 'ABCDE'.
000012 05 FILLER PIC X VALUE X'00'.
000013 01 OVECTOR PIC S9(8) VALUE 96.
000014 01 STRINGCOUNT PIC S9(8) VALUE 396.
000015 01 LISTPTR USAGE POINTER VALUE NULL.
000016 01 RESULT PIC S9(8) VALUE 0.
000017 LINKAGE SECTION.
000018 PROCEDURE DIVISION.
000019 CALL 'TESTAPI' USING by content
000020 subject ,
000021 OVECTOR ,
000022 STRINGCOUNT ,
000023 LISTPTR
000024 RETURNING RESULT.
000025 DISPLAY "RESULT " RESULT.
000026 GOBACK.
000002 Program-ID. cobapi.
000003 ENVIRONMENT DIVISION.
000004 data division.
000005 working-storage section.
000006 * int TESTAPI(const char *subject,
000007 * int *ovector, int stringcount,
000008 * const char ***listptr)
000009
000010 01 subject.
000011 05 FILLER PIC X(5) VALUE 'ABCDE'.
000012 05 FILLER PIC X VALUE X'00'.
000013 01 OVECTOR PIC S9(8) VALUE 96.
000014 01 STRINGCOUNT PIC S9(8) VALUE 396.
000015 01 LISTPTR USAGE POINTER VALUE NULL.
000016 01 RESULT PIC S9(8) VALUE 0.
000017 LINKAGE SECTION.
000018 PROCEDURE DIVISION.
000019 CALL 'TESTAPI' USING by content
000020 subject ,
000021 OVECTOR ,
000022 STRINGCOUNT ,
000023 LISTPTR
000024 RETURNING RESULT.
000025 DISPLAY "RESULT " RESULT.
000026 GOBACK.
and here is the C:
#include "zatoolib.h"
int TESTAPI(const char *subject, int *ovector, int stringcount,
const char ***listptr)
{
printf ("SUBJECT %s\n", *subject);
printf ("OVECTOR %d\n", *ovector);
/*intf ("STRINGCOUNT %d\n", stringcount);*/
/*printf ("LISTPTR %s\n", ***listptr); */
return 100;
}
int TESTAPI(const char *subject, int *ovector, int stringcount,
const char ***listptr)
{
printf ("SUBJECT %s\n", *subject);
printf ("OVECTOR %d\n", *ovector);
/*intf ("STRINGCOUNT %d\n", stringcount);*/
/*printf ("LISTPTR %s\n", ***listptr); */
return 100;
}
and the results on the mainframe:
SUBJECT
OVECTOR 293264496
RESULT 0000000{
OVECTOR 293264496
RESULT 0000000{
Obviously, not what I expected.
The COBOL compiler is IBM Enterprise COBOL for z/OS 3.3.1
The C is 15647A01 V2 R10 OS/390 C
Any suggestions what am I doing wrong
I do not use the #pragma linkage... this would be my next attempt tonight.
Thanks
ZA