Call C in Cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Call C in Cobol

Postby pong0 » Fri Aug 07, 2009 2:21 am

Hello world.
I need to call a c program from cobol, and I need to change the value of WKDATA.
wkdata is :
01 wk-data.
05 wk-ll pic xx.
05 wk-myparam pic x(10).
01 WKRETCODE pis s9(4) comp.
PROCEDURE DIVISION.
move 'aabbccddee' to wk-myparam.
display wk-myparam.
CALL "Cprogram" USING BY REFERENCE WKDATA RETURNING WKRETCODE.
display wk-myparam.
goback.

Cprogram
#incude...
#include..
int main(int argc, char *argv[])
{
cout << "\n Num. Param " << argc;
cout << "\n ..... Param " << argv[1]; //it shows aabbccddee and it's OK
//now i want to change this value argv[1]
strcpy(argv[1],"ffgghhiijj");
cout << "\n new value param " << argv[1] // it shows the new value ffgghhiijj and it's OK
return(strlen(argv[1])); //it returns the length of the first parameter in this case 10 and it's OK
}

Now the question.....when the Cprogram comes back in cobol program the value of wk-myparam doesn't change...
if i write the subprogram in cobol it works fine but i need the subprogram in C.
I need to change it wk-myparam.
How can i solve this problem? can u help me??

Thank's a lot.

R.
pong0
 
Posts: 2
Joined: Fri Aug 07, 2009 1:59 am
Has thanked: 0 time
Been thanked: 0 time

Re: Call C in Cobol

 

Re: Call C in Cobol

Postby dick scherrer » Fri Aug 07, 2009 3:25 am

Hello and welcome to the forum,

Sounds like a problem in the C program. . .

A call by reference only has one set of the data used by both routines. The called module is using the same menory as the caller "sent" (actually nothing was sent, merely addressability was established).

If the data is unchanged, i suspect the C code did not change it. It may have changed "something" but not the caller's data.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

Re: Call C in Cobol

Postby pong0 » Fri Aug 07, 2009 1:43 pm

Yes tnk's.

But so it minds it is not possbile!

Is there another way? Always calling a c program from cobol?


Tnk's
pong0
 
Posts: 2
Joined: Fri Aug 07, 2009 1:59 am
Has thanked: 0 time
Been thanked: 0 time

Re: Call C in Cobol

Postby dick scherrer » Sat Aug 08, 2009 1:40 am

Hello,

But so it minds it is not possbile!

Is there another way? Always calling a c program from cobol?
I'm confused :? Please clarify.

If the C program is written correctly, it should return the same result as a called cobol module. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

Re: Call C in Cobol

Postby panda » Mon Sep 07, 2009 10:20 am

dick scherrer wrote:Hello,

But so it minds it is not possbile!

Is there another way? Always calling a c program from cobol?
I'm confused :? Please clarify.

If the C program is written correctly, it should return the same result as a called cobol module. . .

中文能显示出来不。
我还不知道怎么样在COBOL里调用C/C++模块。
感觉里面的东西好难学啊,应该怎么系统的学习呢。
panda
 
Posts: 3
Joined: Wed Sep 02, 2009 10:01 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Call C in Cobol

Postby dick scherrer » Tue Sep 08, 2009 2:02 am

Hello,

中文能显示出来不。
我还不知道怎么样在COBOL里调用C/C++模块。
感觉里面的东西好难学啊,应该怎么系统的学习呢。
Hmmm. . . To repeat:
I'm confused :? Please clarify.
Only this time in English. . . ;)
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 92 times

Re: Call C in Cobol

Postby enrico-sorichetti » Wed Sep 09, 2009 8:03 pm

did You care to read the ILC guide ...
http://publibz.boulder.ibm.com/cgi-bin/ ... 0804124136

at a first glance the C subprogram/subroutine is badly defined
the called C subprogram/subroutine should be a function not a main

for cobol I would suggest somthing like
void subprog (parm1,parm2.parm3,...parmn)

taking good care of passing...
by value the parameters read by the subroutine and the pointers,
by reference the other ones
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2701
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 139 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post