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

calling COBOL from C


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sedireswarapu

New User


Joined: 18 Jun 2008
Posts: 28
Location: India

PostPosted: Wed Sep 24, 2008 5:54 pm
Reply with quote

Hi

I have been trying to invoke a Cobol program from C program. I was able to call Cobol from C program perfectly but my cobol source inturn does a STATIC call to external lib routine. There it actually abends, in many sites they say it as some library missing in link-edit step but am able to run the Cobol as a stand alone ( executes external lib routine also) but when i invoke the same Cobol from C it just abends with SOC1.


Find below the JCL snippet i used for compile, Prelink and Link-edit

Code:
//*---------------------------------------------------
//** COMPILE C MODULE
//*---------------------------------------------------
//CB2V EXEC EDCCLIB,
// INFILE='ABMWBG1.BITSP3.C(MVS2CSAM)',
// LIBPRFX='SYS1.LE',
// LNGPRFX='SYS1.IBMCPP',
// LIBRARY='ABMWBG1.BITSP3.OBJLIBZ',
// MEMBER='MVS2CSAM',
// CPARM='OPTFILE(DD:CCOPTS)',
// CPARM2='DEF(_XOPEN_SOURCE_EXTENDED)'
//CCOPTS DD DSN=ABMWBG1.BITSP3.JCLZ(CCOPTS1),DISP=SHR
//SYSLIB DD DSN=&LIBPRFX..SCEEH.SYS.H,DISP=SHR
// DD DSN=&LIBPRFX..SCEEH.H,DISP=SHR
// DD DSN=XMQS11.SCSQC370,DISP=SHR
// DD DSN=ABMWBG1.BITSP3.LOADLIB,DISP=SHR
//USERLIB DD DSN=XBMW01.BMWV5R0.H,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*---------------------------------------------------
//** PRE - LINK C MODULE
//*---------------------------------------------------
//PLKED EXEC PGM=EDCPRLK,
// REGION=5000K,
// PARM='MAP, NOER,NONCAL'
//STEPLIB DD DSN=SYS1.LE.SCEERUN,DISP=SHR
// DD DSN=SYS1.LE.SCEELKED,DISP=SHR
//SYSMSGS DD DSN=SYS1.LE.SCEEMSGP(EDCPMSGE),DISP=SHR
//SYSLIB DD DSN=SYS1.LE.SCEECPP,DISP=SHR
//SYSIN DD DSN=ABMWBG1.BITSP3.OBJLIBZ(MVS2CSAM),DISP=SHR
// DD DSN=XBMW01.BMWV5R0.IMPORTS(BMWDLLB),DISP=SHR
//SYSMOD DD DSN=&&PLKSET,DISP=(,PASS),
// UNIT=SYSDA,
// SPACE=(3200,(30,30)),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=3200)
//SYSDEFSD DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*---------------------------------------------------
//** COMPILE COBOL MODULE
//*---------------------------------------------------
//STEP1 EXEC IGYWCPL,PARM='OBJECT,XREF'
//SYSIN DD DSN=ABMWBG1.BITSP3.COBOL(BITSCOB),DISP=SHR
//STEPLIB DD DSN=SYS1.IGY.COBOL.V34.SIGYCOMP,DISP=SHR
//COBOL.SYSLIB DD DISP=SHR,DSN=PEDV01.PROD.COMMON.COPYLIB
//COBOL.SYSLIN DD DSN=ABMWBG1.BITSP3.OBJLIBZ(BITSCOB),DISP=SHR
//*---------------------------------------------------
//** PRE - LINK COBOL MODULE
//*---------------------------------------------------
//PLKED.SYSIN DD DSN=ABMWBG1.BITSP3.OBJLIBZ(BITSCOB),DISP=SHR
// DD DSN=XBMW01.BMWV5R0.IMPORTS(BMWDLLB),DISP=SHR
//* DD DSN=XBMW01.BMWPROD.OBJLIB(BMWBSTUB),DISP=SHR
//*---------------------------------------------------
//** LINK - EDIT C AND COBOL OBJECT
//*---------------------------------------------------
//*KED EXEC PGM=HEWL,PARM='
//* REGION=1024K
//LKED.SYSLMOD DD DSN=ABMWBG1.BITSP3.LOADLIB(MVSC2COB),DISP=SHR
//LKED.SYSLIB DD DSN=SYS1.LE.SCEELKED,DISP=SHR
// DD DISP=SHR,DSN=SYS1.LE.SCEERUN
// DD DSN=XMQS11.SCSQLOAD,DISP=SHR
// DD DSN=XBMW01.BMWPROD.OBJLIB,DISP=SHR
// DD DSN=ABMWBG1.BITSP3.OBJLIBZ,DISP=SHR
// DD DSN=XBMW01.BMWV5R0.IMPORTS,DISP=SHR
//SYSPRINT DD SYSOUT=*
//LKED.SYSLIN DD DSN=*.PLKED.SYSMOD,DISP=(OLD,DELETE)
// DD DSN=ABMWBG1.BITSP3.OBJLIBZ(BITSCOB),DISP=SHR
// DD DDNAME=SYSIN
//LKED.SYSIN DD *
INCLUDE SYSLIB(CEEROOTB)
INCLUDE SYSLIB(CSQBSTUB)
INCLUDE SYSLIB(BMWBSTUB) --> EXTERNAL METHOD STUB
INCLUDE SYSLIB(EDCSTART)
INCLUDE SYSLIB(@@CBL2C)
INCLUDE SYSLIB(BITSCOB) --> COBOL OBJECT
INCLUDE SYSLIB(MVS2CSAM) --> C OBJECT
NAME MVSC2COB(R)
//SYSUT1 DD UNIT=SYSDA,DCB=BLKSIZE=1024,
// SPACE=(1024,(200,20))



C source :

Code:
#pragma linkage (BITSCOB,COBOL)
void BITSCOB(long,long*,long*);
void main ()
{
BITSCOB(Options, &CompCode, &Reason);
}

Cobol Module (BITSCOB) :
Code:
CBL NODYNAM,LIB,OBJECT,RENT,APOST
*
IDENTIFICATION DIVISION.
*
PROGRAM-ID. BITSCOB.
*
DATA DIVISION.
LINKAGE SECTION.
01 OPTIONS PIC 9(5) COMP-5.
01 COMPCODE PIC 9(5) COMP-5.
01 REASON PIC 9(5) COMP-5.
PROCEDURE DIVISION USING OPTIONS,COMPCODE,REASON.
DISPLAY "OPTIONS : " OPTIONS.
CALL 'EXTMETHOD' USING OPTIONS,
COMPCODE,
REASON.

Am invoking cobol from C and abends in the 'CALL' statement of Cobol.

Please advise what am missing in this whole flow.
Looking forward to all your suggestions.

Thanks
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Sep 24, 2008 9:50 pm
Reply with quote

Hello,

You need to post any informational/disgnostic information presented by either of the compiles or the link edits. You also need to post the disgnostic information from the abended run as well as the execute jcl.

When posting this information be sure to include thd message ids along with the message text. Please ust copy/paste and the "Code" tag for posting your info.

It sounds like the C program is calling the "wrong" version of the cobol
program. As you are using static calls, you may want to recompile/link all of the modules from the bottom up.
Back to top
View user's profile Send private message
sedireswarapu

New User


Joined: 18 Jun 2008
Posts: 28
Location: India

PostPosted: Thu Sep 25, 2008 2:56 pm
Reply with quote

Find below the Abend dump which shows call chain it abends ( widh SOC1 ) where i have the CALL statement the subprogram is inturn a C program.

So my total flow of execution of load module (MVSC2COB) would be :

My C pgm -> My COBOL pgm (BITSCOB) ->C extern lib routine.

Code:
z/OS Language Environment V1 R8                                     
      Current and initial condition information is not available.   
                                                                     
Load module MVSC2COB  - cannot identify link date/library           
  (IDR information not available)                                   
                                                                     
Call chain (Top 3 user levels in chain of 8)                         
      Program  Language          Last executed statement             
      C                          failed with Abend Code S0C1 at     
                                   address 00000000                 
      BITSCOB  Cobol/zOS         called C from offset 3D2           
      MVSC2COB                   called BITSCOB from                 
                                   address 10000166 MVSC2COB + X'166'


My JESMSGLG for the submitted Runjcl :

Code:
IEA995I SYMPTOM DUMP OUTPUT  412                         
SYSTEM COMPLETION CODE=0C1  REASON CODE=00000001         
 TIME=11.01.26  SEQ=00676  CPU=0000  ASID=00A8           
 PSW AT TIME OF ERROR  078D1400   80000002  ILC 2  INTC 01
   NO ACTIVE MODULE FOUND                                 
   NAME=UNKNOWN                                         



Note : Am able to succesfully invoke the static call when i run my COBOL as a stand alone. Am confused why am not able to make it when i run the same cobol pgm thorugh C program.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 25, 2008 5:42 pm
Reply with quote

Sriram: have you read z/OS Language Environment Writing Interlanguage
Communication Applications
, Document Number SA22-7563? Chapter 4.8 of this manual has an example of a C main program calling a COBOL subroutine calling a C subroutine, which sounds close to what you're doing.

One note: your EXTMETHOD cannot have a MAIN() declared in it. The chapter 4.8 C called subroutine does not have main.
Back to top
View user's profile Send private message
sedireswarapu

New User


Joined: 18 Jun 2008
Posts: 28
Location: India

PostPosted: Thu Sep 25, 2008 9:27 pm
Reply with quote

Thanks for the document its really helpful.

But still am not able to get this through. Getting same SOC1 abend
I changed my Linkedit statements like :

Code:
INCLUDE SYSLIB(CEEROOTB)
INCLUDE SYSLIB(CSQBSTUB) -> MQstub
INCLUDE SYSLIB(BMWBSTUB) -> external lib stub
INCLUDE SYSLIB(EDCSTART)
INCLUDE SYSLIB(@@CBL2C) -> for making cobol to C communication
INCLUDE SYSLIB(@@C2CBL) -> for making C to cobol communication
INCLUDE SYSLIB(BITSCOB) -> Object module for Cobol
INCLUDE SYSLIB(MVS2CSAM) -> Object module for C
NAME MVSC2COB(R)


As you can see my JCL from above posts:
What am actually doing in my JCL (compile, Prelink, Link-edit) :

step 1: compiling C pgm and obtain Object module
step 2: compile Cobol pgm and obtain Cobol object and catalogue
step 3: link-edit both the object module and include all the private libs
as mentioned above.

Now newly i have included
Code:
INCLUDE SYSLIB(@@C2CBL)

yet no luck.

I did find a C program having VOID MAIN () calling COBOL routine. So its really same am doing and whatever mentioned in the document i have done it. But really can't find out where the error is. Pls assist me on this.

I have posted my code also in the previous post.

Thanks.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 25, 2008 10:52 pm
Reply with quote

Sriram, you keep focusing on your C main program and the COBOL routine. They don't appear to be your problem; the problem is whatever EXTMETHOD is and how it relates to COBOL and C. Since you said the COBOL program can call EXTMETHOD without a problem if the COBOL program is the main routine, it appears that introducing the C environment is where the problem comes from. You might try having the C program directly call EXTMETHOD to see if there's a problem. Otherwise, you're probably going to have to find out where EXTMETHOD came from and talk to the vendor who supplied it to find out why your program is not working the way you've coded it.

You may have to give up on the idea of having a C main program and use the COBOL program to drive the work, since that appears to be the only way it has worked so far.
Back to top
View user's profile Send private message
sedireswarapu

New User


Joined: 18 Jun 2008
Posts: 28
Location: India

PostPosted: Fri Oct 03, 2008 6:52 pm
Reply with quote

Hi all..

Atlast successfully invoked a static call in Cobol from C pgm.

I just want to share the idea of it here to avoid ppl breaking their head for a long time ...

As you have seen my C and Cobol code. The cobol code is called from a Main () c program and cobol invokes a external routine.

What need to be done ?
Include the statements in the Main() module C:

Code:
#pragma csect(code,"BITSMVSC")
#pragma csect(static,"$BITSC")
#pragma linkage (BITSCOB,COBOL)


and in the Link-edit of JCL :

Code:
ENTRY   CEESTART



the #pragma csect and CEESTART actually help in identifying the main() routine when the load module has mixed programming language.

Thanks to all for your help.
Cheers !!!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Oct 04, 2008 12:29 am
Reply with quote

Hello Sriram,

Good to hear it is working - congrats icon_smile.gif

Thank you for posting your solution - as you say, it could prevent someone else from "breaking their head" one day icon_wink.gif

d
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
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
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top