Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

C program calling a cobol db2 program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> FAQ & Off Topics
View previous topic :: :: View next topic  
Author Message
shankarramv

New User


Joined: 20 Nov 2007
Posts: 5
Location: India

PostPosted: Fri Jan 25, 2008 6:08 pm    Post subject: C program calling a cobol db2 program
Reply with quote

here is my problem.
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.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Sat Jan 26, 2008 2:33 am    Post subject:
Reply with quote

I would start with this modification:
Code:

EXEC SQL OPEN CUR END-EXEC

IF SQLCODE <> 0
THEN
    MOVE SQLCODE TO EMP
   DISPLAY 'SQL ERROR ON CURSOR OPEN: '  EMP
   GOBACK
END-IF   

EXEC SQL FETCH CUR INTO :EMP END-EXEC

IF SQLCODE = 0
THEN
    DISPLAY EMP
    COMPUTE X = X + EMP
    DISPLAY X.
ELSE
    MOVE SQLCODE TO EMP
   DISPLAY 'SQL ERROR ON FETCH: '  EMP
END-IF
   
GOBACK.
Back to top
View user's profile Send private message
shankarramv

New User


Joined: 20 Nov 2007
Posts: 5
Location: India

PostPosted: Mon Feb 04, 2008 4:10 pm    Post subject:
Reply with quote

Thanks for the tip. that helped me. icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> FAQ & Off Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Writing a file using online program grvtomar PL/I & Assembler 3 Fri Jun 30, 2017 1:06 pm
No new posts pre-compiler for program in an HFS Pedro DB2 0 Fri Jun 23, 2017 11:13 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us