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: 6967
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
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts Need help in REXX CALL program Raje1002 CLIST & REXX 5 Wed Apr 19, 2017 11:18 pm


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