|
Here is an example I wrote just now: /* C source */ #include <string.h> int main(int argc, char * argv[]) { int x = 3; memcpy(argv[1],&x,sizeof(x)); } /* CL source */ PGM dcl &var1 *char 4 dcl &var1char *char 11 call elvis/clptest parm(&var1) chgvar &var1char %bin(&var1 1 4) sndpgmmsg &var1char ENDPGM This will print to the screen: 00000000003 Your critical line of code would be: memcpy(argv[2],&riofb_fwd->rrn,sizeof(riofb_fwd->rrn)); You can also convert binary to char in C program to make it easier for CL to handle it by doing something like this instead of memcpy: sprintf(argv[2],"%d",riofb_fwd->rrn); This will convert binary to char string, but it will null terminate it, which is unfriendly to CL. To put space back in the CL buffer you could follow sprintf with: argv[2][strlen(argv[2])] = ' '; Now your CL buffer is just characters and you don't have to use %BIN in your cl program to deal with it. Many ways to skin a cat. Oh, btw, welcome to C programming. Elvis -----Original Message----- From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of David C. Shea Sent: Friday, October 01, 2004 2:06 PM To: C programming iSeries / AS400 Subject: RE: [C400-L] RE: Passing parameter back to calling CL Elvis: We're getting warmer... Your *argv[3] approach allows the C program to compile. Now, I'm getting a decimal data error when trying to CHGVAR the returned parameter back to the CL variable... When I look at the dump, I see: &RRN9 *DEC 15 0 ' ' 1E0000000000000F What should the format of the passed variable from the CL be? So... here's what I'm doing. . . . DCL VAR(&FULLNAME ) TYPE(*CHAR) LEN(40) DCL VAR(&RRN9) TYPE(*DEC) LEN(15 0) . . CALL PGM(ARCPGM/RCLDSPYC) PARM(&FULLNAME &RRN9) CHGVAR VAR(&RRN ) VALUE(&RRN9) In the C program: . . int main(int argc, char * argv[]) . . *argv[2] = riofb_fwd->rrn; . . I'm guessing that I need to convert a field format someplace... ******************************************************** Go... FASTER! Without an Upgrade! ARCTOOLS/400(tm) and ReorgWizard(tm) http://www.arctools.com DCSoftware, Inc. Ph: (508) 435-8243 Fax: (508) 435-4498 ******************************************************** -----Original Message----- From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of Elvis Budimlic Sent: Friday, October 01, 2004 2:07 PM To: 'C programming iSeries / AS400' Subject: RE: [C400-L] RE: Passing parameter back to calling CL You should be able to set values in a C program as long as CL program passes in the variable. You simply need to dereference the argv parameter and set it, i.e.: *argv[3] = rrn; Elvis -----Original Message----- From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of Chris Wolcott Sent: Friday, October 01, 2004 12:29 PM To: c400-l@xxxxxxxxxxxx Subject: RE: [C400-L] RE: Passing parameter back to calling CL My Bad. The way I showed you was if you were calling an exported procedure. (From a *MODULE or *SRVPGM) I rarely CALL a program anymore. - = - = - = - = - When creating a new CL, use CLLE for your Source Type. You may have to compile your CL as a *MODULE (use opt 15) and then use CRTPGM to create the final program. Define the two variables as below, and use the CALLPRC command instead of the CALL command to run your C code. (You can prompt it if needed.) The odd thing is you have to use the %BIN function twice. When used in the RTNVAL option, it tells the compiler that you will be getting back an integer. Since CL has no INT type, it is stored as a 4 byte character field. (Hence the defintion of &wrkINT as *CHAR 4) The CHGVAR use of %BIN actually changes the value to a packed format. DCL VAR(&wrkINT ) TYPE(*CHAR) LEN( 4) DCL VAR(&RRN ) TYPE(*DEC ) LEN( 15 0) CALLPRC PRC(program) PARM(parm1 parm2 . . . parmX) RTNVAL(%BIN(&wrkINT)) CHGVAR VAR(&RRN) VALUE(%BIN(&wrkINT)) - = - = - = - = - RTVJOBATR can give you a return code from a CALLed program, but the help says just COBOL, RPG, DFU and sorts. I've never used it. -----Original Message----- subject: RE: Do you have or do you know where I can find an example of this approach? I'm not familiar with CLLE,so if I could see a sample, I could clone it... _______________________________________________ This is the C programming iSeries / AS400 (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/c400-l or email: C400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/c400-l. _______________________________________________ This is the C programming iSeries / AS400 (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/c400-l or email: C400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/c400-l. _______________________________________________ This is the C programming iSeries / AS400 (C400-L) mailing list To post a message email: C400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/c400-l or email: C400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/c400-l.
As an Amazon Associate we earn from qualifying purchases.
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.