IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

C program calling a cobol db2 program


IBM Mainframe Forums -> FAQ & Basics
Post new topic   Reply to topic
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> FAQ & Basics

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top