× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jevgeni, if I understand you correctly, you want to retrieve a return code
value returned by a C program, inside a CL program.
One way I know how to do that is by calling the QUSRJOBI API with format
JOBI0600.
Here is sample CL source that calls my C program (ELVIS/RTNCDE), retrieves
the return code and then displays it to the end-user's screen.
NOTE: I used an &input argument to a C program just for illustration of
what's possible in CL, it's not required.

============================================================================
=======================================

pgm (&input)



dcl &input *int



dcl &ret type(*char) len(112) /* receiver variable for qusrjobi call */

dcl &len type(*char) len(4) /* length of the receiver variable */

dcl &rcc type(*char) len(4) /* raw 4 byte version of the return code */

dcl &rc type(*dec) len(10 0) /* decimal version of the integer return
code */
dcl &rtncdechar *char 10 /* character version of the return code */



call elvis/rtncde parm(&input) /* call a C program that returns 4 byte int
*/


chgvar %binary(&len) value(112) /* set the length of the receiver variable
*/
/* call qusrjobi system API */

call qusrjobi (&ret &len 'JOBI0600' +

'* ' +

' ')

chgvar &rcc %sst(&ret 109 4) /* move return code to a local &rcc variable
*/
chgvar &rc %binary(&rcc) /* convert *INT 4 to *DEC (10 0) value
*/
chgvar &rtncdechar &rc /* convert rtncde to char for display
purpose*/


sndpgmmsg ('RTNCDE = ' *CAT &RTNCDECHAR) /* display return code */



endpgm

============================================================================
=======================================

An easier way to accomplish this would be to make C's arguments into output
arguments. Then you can have a C program alter one or all of the output
arguments and CL can easily examine them since the storage is allocated in
the CL program itself. That option of course assumes you have access to
both C and CL source members.

That said, there are many other, better ways to have C and CL interoperate.
I strongly recommend you get up to snuff on ILE and CALLPRC. That way you
can create a single program from CL and C modules (and RPG, COBOL etc.) and
they can call each other's functions (procedures) and pass values back and
forth quite easily.

HTH, Elvis

Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com


-----Original Message-----
Subject: [C400-L] Returning parameters from C to CL

Hi, everybody.
Reading AS/400 manuals makes me sick.
Tried to understand how to return value from a C program to a CL.
That is CL program calls C program and C program wants to return value to
it.
Actually C program is mine, so whatever value can be returned - string or
integer.
It must be treated by CL as boolean - YES or NO.
If I call C program with a one parameter variable from CL and then modify
this parameter in C, then the changed value will be available in CL on
return. Yes?
But is there a way to receive the return() value?
That is if I complete my C program with return(172), then CL somehow knows,
that 172 is returned?

Below is an extract from the manual (ILE/C programming guide, v.4,
p.265-266), it should be the thing I'm looking for
----------------------------------------------
The following example shows how to retrieve a return value from main(). A CL
command called SQUARE calls an ILE C program SQITF. The program SQITF calls
another ILE C program called SQ. The program SQ returns a value to program
SQITF.
Note: Returning an integer value from an ILE C program may affect
performance.
1. To create a CL command prompt SQUARE usng the source shown below, type:
CRTCMD CMD(MYLIB/SQUARE) PGM(MYLIB/SQITF) SRCFILE(MYLIB/QCMDSRC)

CMD PROMPT('CALCULATE THE SQUARE')
PARM KWD(VALUE) TYPE(*INT4) RSTD(*NO) RANGE(1 +
9999) MIN(1) ALWUNPRT(*YES) PROMPT('Value ')


You use the CL command prompt SQUARE to enter the item name, price, and
quantity for the ILE C program SQITF.
------------------------------------------------
But I cannot understand, where the command SQUARE calls C program SQIFT and
HOW it reads returned value.
Sorry for my english, its not native. May be that's the problem :-(

Jevgeni.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.