Here's my version:
pgm
dcl var(&atfile) type(*char) len(10) value('FILE001')
dcl var(&nxref) type(*char) len(10)
dcl var(&suffix) type(*char) len(3)
chgvar var(&suffix) value(%sst(&atfile 5 3))
dowhile cond(%sst(&suffix 1 1) *eq '0')
chgvar var(%sst(&suffix 1 3)) value(%sst(&suffix 2 2) *cat ' ')
enddo
chgvar var(&nxref) value('XREF' *tcat &suffix)
dmpclpgm
endpgm
Result is FILE1.
HTH,
Loyd
Loyd Goodbar
Senior programmer/analyst
BorgWarner
TS Water Valley
662-473-5713
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Peter Vidal
Sent: Monday, August 13, 2007 12:45
To: Midrange Systems Technical Discussion
Subject: Re: Convert Character to Decimal in CL: Trimming leading zeros
I am doing this:
(&ATFILE (10/A) holds "FILE001 ")
======================================================
CHGVAR VAR(&SUFFIX) VALUE(%SST(&ATFILE 5 3))
CHGVAR VAR(&POS) VALUE(1)
DOWHILE COND(&POS *LE 3)
IF COND(%SST(&SUFFIX &POS 1) *EQ '0') +
THEN(CHGVAR VAR(%SST(&SUFFIX &POS 1)) +
VALUE(' '))
ELSE CMD(GOTO CMDLBL(PROCESS))
CHGVAR VAR(&POS) VALUE(&POS + 1)
ENDDO
CHGVAR VAR(&NXREF) VALUE('XREF' *TCAT &SUFFIX)
At this point,
&NXREF = "FILE 1 "
...instead of having this:
&NXREF = "FILE1 "
Peter Vidal
MAPICS IT Technical Support Team / SR System Analyst
10540 Ridge Rd., Ste 203, New Port Richey, FL 34654-5111
http://www.pall.com
"He who asks is a fool for five minutes, but he who does not ask remains
a
fool forever."
Chinese Proverb
CRPence <crp@xxxxxxxxxxxxxxxxxxxx>
Sent by: midrange-l-bounces@xxxxxxxxxxxx
08/13/2007 11:56 AM
Please respond to
Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
To
midrange-l@xxxxxxxxxxxx
cc
Subject
Re: Convert Character to Decimal in CL: Trimming leading zeros
Consider that such naming does not provide for "ordered" names. At
least not according to the numerical ascent. An example of such a list:
A1
A10
A100
A101
A102
A11
A110
A111
A12
A2
REXX is a much better choice for such string handling, but a CLP
subroutine can replace any '0' with ' ' in a loop starting from the
first position, and the result string can be *TCAT as the suffix.
stripzero: subr stripzero /* Input &sfx ; e.g. *char 10 */
chgvar &pos 1
dowhile (&pos *le &maxlen) /* &sfx max length; e.g. 10 */
if (%sst(&sfx &pos 1) *eq '0') then( +
chgvar (%sst(&sfx &pos 1)) ' ' )
else leave
chgvar &pos (&pos + 1)
enddo
endsubr
Regards, Chuck
As an Amazon Associate we earn from qualifying purchases.