I didn't see the original post; cnps must have
posted to the newsgroup instead of to the list.
So I'm piggybacking on Dave Rivers reply (but
my comments are bottom posted).


Thomas David Rivers wrote:
For Systems/C; you can use our Direct CALL runtime support
(DCALL) to accomplish this.

See the Dignus C library reference manual, at
http://www.dignus.com/dcc/clib.pdf for more information on our
Direct CALL support.

    - Dave Rivers -



cnps wrote:

Hi,

I am trying to call a C routine from COBOL pgm.
I have few questions.
Is it possible to statically call a C routine from a COBOL pgm?

yes.

If yes can we also return the result of the C routine(statically
called) to the COBOL pgm.

no.

Do i need to use #pragma for this?

no.

Can i return a string from the C routine to my COBOl pgm?

yes.

Copied below is my COBOL pgm and C routine.Can anyone please help me
with this?

see embedded suggestions ...


PROCESS NODYNAM MAP LIST
IDENTIFICATION DIVISION.
PROGRAM-ID.    CALLRT1.
AUTHOR.        CNPS.
DATA DIVISION.
WORKING-STORAGE SECTION.
   01  ONEARG  PIC X(10) VALUE "ABCDEFG123".
   01  B1            PIC X(30).
PROCEDURE DIVISION.
MAIN.
    DISPLAY "ONEARG IS " ONEARG.
    CALL "PADWPD" USING
       BY REFERENCE ONEARG
       RETURNING B1.

The problem is, if the object of your RETURNING
is anything other than a one byte character or a
binary integer, COBOL generates a different form
of the argument list than C expects.

One way around this:

       call "padwpd" using
        by reference b1, onearg

in other words, forget the "returning" here!

    DISPLAY "PADDED STRING  " B1.
    DISPLAY "PADWPD'S RC IS " RETURN-CODE.

When you CALL with the RETURNING option, RETURN-CODE
is undefined.

    MOVE 0 TO RETURN-CODE.
STOP RUN.

The STOP RUN statement must be shifted right into area-b.


#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
int PADWPD(char *onearg)
{
 char b??(30??);

 printf("onearg%s",onearg);
 strcpy(b,",");
 strcat(b, "###");
 strcat(b, onearg);
 strcat(b, "###");
 printf("Bvalue%s",b);
                       return b;                 }

I got an error in compiling this: a function
with a return type "int" may not return a value
of type "char". I changed the prototpye to be:

void PADWPD(char * b, char *onearg)

Note the first argument here matches the
first argument in the calling routine;
remove the declare of "b: after your prototype,
then...

Got these lines of output:

ONEARG IS ABCDEFG123
PADDED STRING  ,###ABCDEFG123###
PADWPD'S RC IS 0023
oneargABCDEFG123Bvalue,###ABCDEFG123###

There's probably at least one other way to
get this result, but you get the idea.

<ad>
You, young man, sound like a candidate for our
course "Secrets of Inter-Language Communication
in z/OS". We discuss passing and receiving data
between programs written in Assembler, C, COBOL,
and PL/I using static calls, dynamic calls, and
DLL linkages. Plus lots more.

Check out:

http://www.trainersfriend.com/Language_Environment_courses/m520descr.htm

</ad>

Kind regards,

-Steve Comstock
The Trainer's Friend, Inc.


Check out

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to