Page 1 of 1

Call C in Cobol

PostPosted: Fri Aug 07, 2009 2:21 am
by pong0
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.

Re: Call C in Cobol

PostPosted: Fri Aug 07, 2009 3:25 am
by dick scherrer
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.

Re: Call C in Cobol

PostPosted: Fri Aug 07, 2009 1:43 pm
by pong0
Yes tnk's.

But so it minds it is not possbile!

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


Tnk's

Re: Call C in Cobol

PostPosted: Sat Aug 08, 2009 1:40 am
by dick scherrer
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. . .

Re: Call C in Cobol

PostPosted: Mon Sep 07, 2009 10:20 am
by panda
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++模块。
感觉里面的东西好难学啊,应该怎么系统的学习呢。

Re: Call C in Cobol

PostPosted: Tue Sep 08, 2009 2:02 am
by dick scherrer
Hello,

中文能显示出来不。
我还不知道怎么样在COBOL里调用C/C++模块。
感觉里面的东西好难学啊,应该怎么系统的学习呢。
Hmmm. . . To repeat:
I'm confused :? Please clarify.
Only this time in English. . . ;)

Re: Call C in Cobol

PostPosted: Wed Sep 09, 2009 8:03 pm
by enrico-sorichetti
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