|
On Sun, 06 Mar 2005 13:52:21 -0600, Vernon Hamberg <vhamberg@xxxxxxxxxxx> wrote: > You're right, I see. And QCLSCAN does not have the ability to scan from the > right. > > But I found something that works directly from CL in V5R3 and above - the > MI function TRIML (Trim Length). Here is a sample that shows how it works. > Member type must be CLLE-- > > PGM PARM(&TESTSTRING) > > DCL VAR(&TESTSTRING) + > TYPE(*CHAR) + > LEN(50) > DCL VAR(&STRING) + > TYPE(*CHAR) + > LEN(51) > DCL VAR(&TRIMCHAR) + > TYPE(*CHAR) + > LEN(1) + > VALUE(' ') > DCL VAR(&TRIMLEN) + > TYPE(*INT) + > LEN(4) > DCL VAR(&NULL) + > TYPE(*CHAR) + > LEN(1) + > VALUE(x'00') > DCL VAR(&TRIMLENC) + > TYPE(*CHAR) + > LEN(10) > > CHGVAR VAR(&STRING) + > VALUE((&TESTSTRING *cat &NULL)) > CALLPRC PRC('triml') + > PARM(&STRING (&TRIMCHAR *BYVAL)) + > RTNVAL(&TRIMLEN) I did not think of this and I didnt know v5r3 could pass arguments by value. You can also use *tcat to put the null immed after the last non blank and then call the "strlen" c runtime. dcl &ch4 *char 4 dcl &lx *dec 5 chgvar &string (&string *tcat &null) CALLPRC PRC('strlen') PARM(&String) RTNVAL(%BIN(&CH4)) chgvar &lx %bin(&ch4) I like the approach of writing your own proc in RPG that way, you dont have to do any pre or post work in the CL program: CALLPRC PRC('CharLx') PARM(&ADDR) RTNVAL(&LX) the RPG proc uses the OPDESC info that is automatically passed when CL calls a procedure to calc the size of the CL character variable that holds the string: ** ------------------ CharLx ----------------------------- ** calc the length of cl character variable pCharLx b export dCharLx pi 7p 0 opdesc d InCharVar 9999a const options(*VarSize) d # s 10i 0 d Sx s 10i 0 /free ceedod( 1: #: #: #: #: Sx: *Omit ) ; return %len(%trimr(%subst(InCharVar:1:Sx))) ; /end-free p e -Steve > CHGVAR VAR(&TRIMLENC) + > VALUE(&TRIMLEN) > SNDPGMMSG MSG('Trimmed length of "' *CAT &TESTSTRING *CAT '" is' *BCAT > &TRIMLENC) > > ENDPGM > > The 'triml' function needs a null-terminated string as input (append it to > incoming parameter here), the second parameter has to be passed by value, > so earlier versions cannot use this - create a command that uses RPGLE and > returns the length. > > You will need to bind to a system service program, so create the module > first - assume the member name is YOURLIB/TESTTRIML. Then > > CRTPGM PGM(YOURLIB/TESTTRIML) BNDSRVPGM(QC2UTIL1) > > to create the program. > > (NOTE: Use any suitable debug or activation group parameters you want.) > > It MIGHT be possible to restore this to a V5R2 machine, if correctly saved. > i did not have success, however, in my short test. It DID compile and save > to V5R2, however. > > In my test > > call vern/testtriml 'This is a string' > > resulted in the message > > Trimmed length of "This is a string " is > 0000000016 > > Of course, you could always build a command around the BIFs of RPGLE. ;-) > > HTH > Vern > > At 09:05 AM 3/6/2005, you wrote: > >Isn't the problem with QCLSCAN that you cannot test for a multiple word > >variable? When you see the first blank the scan stops and the result is > >invalid. > > > >-----Original Message----- > >From: midrange-l-bounces@xxxxxxxxxxxx > >[mailto:midrange-l-bounces@xxxxxxxxxxxx]On Behalf Of Vernon Hamberg > >Sent: Sunday, March 06, 2005 1:19 AM > >To: Midrange Systems Technical Discussion > >Subject: Re: Any way in the CL program to find the length of the > >character datastored in a variable? > > > > > >This is interesting - which really is the bigger hit on performance. I > >think it depends. Using %SST in a loop could very likely take more time > >than a single call to a program that uses a more efficient loop - probably > >in some way that uses pointers and doesn't need to resolve the %SST for > >each test character. I can see that a 256-character variable that has only > >the 1st 3 characters filled would take longer with %SST than with a call to > >QCLSCAN. But it probably does not matter too much, unless this is repeated > >over several hundreds of thousands of records or values, say. > > > >Still, it would be an interesting test. Maybe I'll try it when I have some > >time. > > > >Vern > > > >At 10:43 AM 3/5/2005, you wrote: > > >Here's the V5R2 link: > > > > > >http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/apis/qclsc > >a > > >n.htm > > > > > >But I would use a substring method myself - no reason to call another > > >program and take the performance hit when you can do it in a loop with > >%SST. > > > > > > > > > > Siva > > > > <matchrefree@yaho > > > > o.com> To > > > > Sent by: Midrange Systems Technical > > > > midrange-l-bounce Discussion > > > > s@xxxxxxxxxxxx <midrange-l@xxxxxxxxxxxx> > > > > cc > > > > > > > > 03/04/2005 11:26 Subject > > > > PM RE: Any way in the CL program to > > > > find the length of the character > > > > datastored in a variable? > > > > Please respond to > > > > Midrange Systems > > > > Technical > > > > Discussion > > > > <midrange-l@midra > > > > nge.com> > > > > > > > > > > > > > > > > > > > > > > > > > > > > Thanks Doug.... > > > > Is it an API?... Wats the Parm list for this... Coudnt get any in my > > > > manuals... > > > > > > > > Thanks > > > > Siva. > > > > > > > > > > > > Doug Hart <DougHart@xxxxxxxxxxxx> wrote: > > > > > > > > QCLSCAN > > > > > > > > > > > > --- > > > > Doug Hart > > > > > > > > > > > > > > > > -----Original Message----- > > > > From: midrange-l-bounces@xxxxxxxxxxxx > > > > [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Siva > > > > Sent: Friday, March 04, 2005 11:02 PM > > > > To: MIDRANGE-L@xxxxxxxxxxxx > > > > Subject: Any way in the CL program to find the length of the character > > > > datastored in a variable? > > > > > > > > > > > > Is there any way in the CL program to find the length of the character > >data > > > > stored in a variable? > > > > > > > > I find there is no direct CL command to acheive this... may be some > > > > roundabout way there to do this... but nothing striking at this > >moment.... > > > > > > > > i think of some prgm calls with the required variable as the parm and > >the > > > > receiviong prgm process the variable etc... but couldnt get any logic > >here > > > > :-)...... > > > > > > > > > > > > Thanks > > > > Siva. > > > > > >-- > > >This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list > > >To post a message email: MIDRANGE-L@xxxxxxxxxxxx > > >To subscribe, unsubscribe, or change list options, > > >visit: http://lists.midrange.com/mailman/listinfo/midrange-l > > >or email: MIDRANGE-L-request@xxxxxxxxxxxx > > >Before posting, please take a moment to review the archives > > >at http://archive.midrange.com/midrange-l. > > > >-- > >This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list > >To post a message email: MIDRANGE-L@xxxxxxxxxxxx > >To subscribe, unsubscribe, or change list options, > >visit: http://lists.midrange.com/mailman/listinfo/midrange-l > >or email: MIDRANGE-L-request@xxxxxxxxxxxx > >Before posting, please take a moment to review the archives > >at http://archive.midrange.com/midrange-l. > > > >-- > >This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list > >To post a message email: MIDRANGE-L@xxxxxxxxxxxx > >To subscribe, unsubscribe, or change list options, > >visit: http://lists.midrange.com/mailman/listinfo/midrange-l > >or email: MIDRANGE-L-request@xxxxxxxxxxxx > >Before posting, please take a moment to review the archives > >at http://archive.midrange.com/midrange-l. > > -- > This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list > To post a message email: MIDRANGE-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/midrange-l > or email: MIDRANGE-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/midrange-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.