C calling a cobol db2 program-help



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

C calling a cobol db2 program-help

Postby sramven » Fri Jan 25, 2008 5:54 pm

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.
sramven
 
Posts: 2
Joined: Fri Oct 12, 2007 10:54 am
Has thanked: 0 time
Been thanked: 0 time

Re: C calling a cobol db2 program-help

Postby dick scherrer » Fri Jan 25, 2008 11:24 pm

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?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: C calling a cobol db2 program-help

Postby sramven » Mon Jan 28, 2008 11:49 am

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
sramven
 
Posts: 2
Joined: Fri Oct 12, 2007 10:54 am
Has thanked: 0 time
Been thanked: 0 time

Re: C calling a cobol db2 program-help

Postby dick scherrer » Mon Jan 28, 2008 9:26 pm

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: C calling a cobol db2 program-help

Postby thinkibm » Wed Aug 13, 2008 8:23 pm

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
thinkibm
 
Posts: 1
Joined: Wed Aug 13, 2008 8:17 pm
Has thanked: 0 time
Been thanked: 0 time

Re: C calling a cobol db2 program-help

Postby dick scherrer » Thu Aug 14, 2008 5:52 am

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post