Use the following utility to increment your string, 1 char, up to 256
characters.
If the return value, creates an exception; returns a number rather than
a character, monitor for it and make the appropriate adjustment.
Example:
DCL VAR(&STRING) TYPE(*CHAR) LEN(256)
DCL VAR(&STRLEN) TYPE(*DEC) LEN(3 0)
DCL VAR(&RTNSTRING) TYPE(*CHAR) LEN(256)
CALLPRC PRC(RTNSTRINC) PARM(&STRING &STRLEN) +
RTNVAL(&RTNSTRING)
D***********************************************************************
***|
D* Return incremented string
D***********************************************************************
***|
DRtnStrInc PR 256 Extproc(*CL:'RTNSTRINC')
D Str_text 256 Const
D Str_size 3 0 Const
P RtnStrInc B Export
D RtnStrInc PI 256
D Str_text 256 Const
D Str_size 3 0 Const
D Counters C 'ABCDEFGHIJKLMNOPQRSTUVWXYZ+
D 0123456789'
D I s 10i 0
D Cur s 10i 0
D Digit s 10i 0
D LastChar s 1a
D FirstChar s 1a
D CurChar s 1a
D Wrk_Text s 256
C Eval Wrk_Text = Str_Text
C Eval FirstChar = %subst(counters : 1 : 1)
C Eval LastChar = %subst(counters :
C %len(counters) : 1)
C For Digit = Str_size downto 1
C Eval CurChar = %subst(Wrk_Text : digit : 1)
C Eval Cur = %scan(curChar : counters)
C If Cur = %len(counters)
C Eval %subst(Wrk_Text : digit : 1) = firstChar
C Else
C Eval %subst(Wrk_Text : digit : 1) =
C %subst(counters : cur + 1 : 1)
C Leave
C Endif
C Endfor
C Return Wrk_Text
P RtnStrInc E
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Peter Vidal
Sent: Friday, May 23, 2008 12:33 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Increment an alpha field by "1"
Rob, I tried your version and you are the closest to the solution I am
looking for.
Now, the catch here is that I need positions 3-4 to be only letter
(alpha) and 5-6 to be only numbers...
PETER VIDAL
MAPICS IT TECHNICAL SUPPORT TEAM / SR SYSTEM ANALYST
10540 Ridge Rd., Suite 203, New Port Richey, FL 34654-5111
Tel:727-849-9999, x2414 Fax:727-815-3120
WWW.PALL.COM
"The beginning of anxiety is the end of faith; and the beginning of true
faith is the end of anxiety."
George Muller.
rob@xxxxxxxxx
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
05/22/2008 04:07 PM
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
To
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
cc
Subject
RE: Increment an alpha field by "1"
call aa
DSPLY TAA02
DSPLY TAA10
DSPLY TB000
h dftactgrp(*no) actgrp(*caller)
d ds
d string 5a inz('TAA01')
d ds
d rplValues 36A
inz('0123456789ABCDEFGHIJKLMNOPQRSTU-
d VWXYZ')
d rplAry 1a dim(%len(rplValues))
d overlay(rplValues)
/free
*inlr=*on;
string='TAA01';
exsr bubble;
dsply string;
string='TAA0Z';
exsr bubble;
dsply string;
string='TAZZZ';
exsr bubble;
dsply string;
return;
begsr bubble;
if %subst(string:5:1)=rplAry(%elem(rplAry));
%subst(string:5:1)=rplAry(1);
if %subst(string:4:1)=rplAry(%elem(rplAry));
%subst(string:4:1)=rplAry(1);
if %subst(string:3:1)=rplAry(%elem(rplAry));
%subst(string:3:1)=rplAry(1);
if %subst(string:2:1)=rplAry(%elem(rplAry));
// oh shucks!
else;
%subst(string:2:1)=rplAry(%lookup(%subst(string:2:1):rplAry)+1);
ENDIF;
Else;
%subst(string:3:1)=rplAry(%lookup(%subst(string:3:1):rplAry)+1);
ENDIF;
Else;
%subst(string:4:1)=rplAry(%lookup(%subst(string:4:1):rplAry)+1);
ENDIF;
else;
%subst(string:5:1)=rplAry(%lookup(%subst(string:5:1):rplAry)+1);
ENDIF;
endsr;
Rob Berendt
As an Amazon Associate we earn from qualifying purchases.