Operating System - OpenVMS
1760568 Members
3249 Online
108894 Solutions
New Discussion юеВ

Re: Calling COBOL sub-program from C

 
SOLVED
Go to solution
Jean-Fran├зois Pi├йronne
Trusted Contributor

Calling COBOL sub-program from C

Hi,

I need to call Cobol sub-program from C.

As I'm not an Cobolexpert I have 2 questions:

1. Is there any specific COBOL initialisation run time routine to call from the C progam (like you have to do for C when C is not the main program)?

2. The C main program need to pass some string using a descriptor, the length of the string may vary, how to declare this in the COBOL sub-program?

Thanks,

JF
4 REPLIES 4
Steven Schweda
Honored Contributor
Solution

Re: Calling COBOL sub-program from C

I know nothing, but have you looked at the
"HP COBOL User Manual"?

http://h71000.www7.hp.com/doc/82final/6297/6297pro.html

In particular, Chapter 12, "Interprogram
Communication":

http://h71000.www7.hp.com/doc/82final/6297/6297pro_088.html#interpro_com_chap

specifically Section 12.6, "Calling HP COBOL
Programs from Other Languages (Alpha, I64)":

http://h71000.www7.hp.com/doc/82final/6297/6297pro_092.html#other_lang_sec

Chpater 13 seems to cover going in the other
direction, too.

If the COBOL subprogram already exists,
wouldn't you want to write the C code to
accomodate the existing COBOL
argument-passing method, rather than
changing the declarations in the COBOL
subprogram? (And if the COBOL subprogram
does not already exist, why would you be
writing it COBOL?)
Hein van den Heuvel
Honored Contributor

Re: Calling COBOL sub-program from C

Salut JF, Comment ca va?!

1) Cobol use LIB$INITIALIZE, but I believe that will all happen automagically at image activation following magic psect contribution. No need for a caller to prep.

2) Cobol itself basically (sic) only works with fixed length strings. And program parameters, described in the LINKAGE SECTION, must all be passed by reference.

Of course one can play games and call passing a descriptor, but receiving it as a reference to a descriptor structure, which gives access to length, type, address.

If you are still at freedom to define your parameters then do the cobol folks a favor and you just pass a reference to the string (address of first byt) and seperately the address of an int holding the length.

On the cobol side you'll want to look at "refence modification" and STRING or INSPECT (if you opt for null terminated strings).

Check out some of (my) examples in topic 1052374

( http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1052374 )

Hth,
Hein.
Jean-Fran├зois Pi├йronne
Trusted Contributor

Re: Calling COBOL sub-program from C

Steven,

Thanks for the pointer. I had take a look at the documentation "HP COBOL User Manual" but probably too quickly because I have miss section 12.6 which is what I'm looking for.

The program COBOL exist as a program, but not as a subprogram so a rewrite in C is not a option but update are required.

JF
Jean-Fran├зois Pi├йronne
Trusted Contributor

Re: Calling COBOL sub-program from C

Salut Hein,

merci pour la reponse.

Thanks for the example reference, would be very useful.

As the COBOL parameters are not, currently, defined I will follow your advise and split the descriptors (dynamic string) in two part (length and string pointer). Seem to be the best option.

The last time I have wrote a COBOL program was probably 25 years ago...

Thanks again,

JF