Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COBOL to C++ CALL

Status
Not open for further replies.

KEJ

Programmer
Oct 17, 2000
2
US
I am trying to get a call from a COBOL program to a C++ function working properly on our IBM 0S/390 mainframe. I have the following code in my test COBOL program:

WORKING-STORAGE SECTION.

01 WS-WORK-FIELDS.
05 WS-TEST-1 PIC X(6).
05 WS-TEST-2 PIC X(6).

PROCEDURE DIVISION.
0000-MAINLINE.
STRING 'HELLO', '00'
DELIMITED BY SIZE INTO WS-TEST-1.
STRING 'WORLD', X'00'
DELIMITED BY SIZE INTO WS-TEST-2.

CALL 'TESTCPGM' USING BY CONTENT WS-TEST-1,
BY CONTENT WS-TEST-2.

DISPLAY 'BACK IN COBOL PROGRAM AFTER CALL '.

In my C++ program I have the following:

extern "C" {
void TESTCPGM( char* arg1, char* arg2);
}

#include <iostream.h>

void TESTCPGM( char* arg1, char* arg2 )
{
cout << &quot;Am here in C++ !!&quot; << endl;
cout << &quot;*&quot; << arg1 << &quot; &quot; << arg2 << &quot;*&quot; << endl;

cout << &quot;Am done with C++&quot; << endl;
}

When I run the COBOL program the output is the following:

*HELLO WORLD

when I am expecting *HELLO WORLD*
I never get the ending * after WORLD and it appears control is never passed back to the COBOL program.

If I pass both arguements to the C function but only use the first arguement, it runs fine and returns to the COBOL program, but whenever I try using the second arguement it doesn't work.

Any help with this would be appreciated. Thanks!
 
Make sure both char * are terminated by a \0, that is how c strings are terminated, and cout may not like a string that is not terminated. (These are null terminated strings). This may help you. I think that is what is happening, and should fix your problems. cout is looking for the null (\0) terminator for the string, and not getting it.

MWB.

As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top