Page 1 of 1

C calling a cobol db2 program-help

PostPosted: Fri Jan 25, 2008 5:54 pm
by sramven
here is my problem. i am very new to mainframes. so bare with me.
i need to call a cobol+db2 program from a c program. my problem is not in calling. i am able to perfectly compile and run the program. but the "EXEC SQL" statements in cobol program are completely ingnored. all other statements alone execute. i dont know how to make sql statements execute. please help me.
here is my c code.
#pragma linkage(COB1,COBOL)
#include<stdio.h>
void COB1(int *);
int main()
{
int c;
c=10;
COB1(&c);
printf("%d\n",c);
return 0;
}
my cobol code:
IDENTIFICATION DIVISION.
PROGRAM-ID. COB1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL INCLUDE SQLCA END-EXEC.
EXEC SQL INCLUDE DCL END-EXEC.
EXEC SQL DECLARE CUR CURSOR FOR SELECT * FROM TAB1
END-EXEC.
LINKAGE SECTION.
01 X PIC S9(9) USAGE BINARY.
PROCEDURE DIVISION USING BY REFERENCE X.
EXEC SQL OPEN CUR END-EXEC.
EXEC SQL FETCH CUR INTO :EMP END-EXEC.
DISPLAY EMP.
COMPUTE X = X + EMP.
DISPLAY X.
GOBACK.
the output from cobol
000000000
000000010

here tab1 is a table with one column as EMP with one row with value 70. so for the first display statement i should be getting 70 instead of 0 and for the second one 80. please help me.

Re: C calling a cobol db2 program-help

PostPosted: Fri Jan 25, 2008 11:24 pm
by dick scherrer
Hello,

Write a COBOL program that does the same thing as the C program and see if that works.

It appears that the sql in the cobol program is not working. Did you use your site-standard compile jcl for a db2 program?

Re: C calling a cobol db2 program-help

PostPosted: Mon Jan 28, 2008 11:49 am
by sramven
i tried to see the sqlstate using display command in cob program. the sqlstate is 51006. isearched in websitres and many have told to include DSNELI in the link part. i donot know where to include this. can anyone anyone help me please

Re: C calling a cobol db2 program-help

PostPosted: Mon Jan 28, 2008 9:26 pm
by dick scherrer
Hello,

Have you run the test i mentioned?

If you code will not work when called by a cobol module, you need to resolve that before you worry about calling the code from another language.

Re: C calling a cobol db2 program-help

PostPosted: Wed Aug 13, 2008 8:23 pm
by thinkibm
hi.. am new to mainframe ILE programming things. I have the same requirement but am not able to invoke the COBOL program itself. My code looks similar to the above code. I just pass a double value from C to Cobol and accept the value in LINKAGE Section. Am able to compile C and COBOL perfectly and have load module created for both of them and have them in two different libs one for each. My problem is in running the C program. I specified the module name of C inEXEC PGM = CLOADMOD and have the two load libs in the STEPLIB but i get SOC4 abend with Reason = 4.

Any help would be great ..pls advise.Thanks

Re: C calling a cobol db2 program-help

PostPosted: Thu Aug 14, 2008 5:52 am
by dick scherrer
Hello and welcome to the forums,

As i asked before (for the original requestor), can the cobol subprogram be successfully called from a simple cobol "caller"?

You need to be able to successfully call a module in your environment first.

Please post the results of calling your subprogram from another cobol program.