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: 6966
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 RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm


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