‎2006 Dec 22 2:07 AM
Hey all Gurus,
I really need to get this done by tomorrow. What I am looking for is suppose I have
a number - XYZ54, I need to first check if there are 5 digits after xyz, if yes ignore, if no I have to add zeros before so that the number becomes XYZ00054.
Can anyone please help me with this?
Thanks, Nina.
‎2006 Dec 22 3:05 AM
Assuming that the first three are always the same, this code is a little simpler.
report zrich_0001.
data: str type string value 'XYZ54'.
data: sub(5) type n.
data: len type i.
data: n_len type i.
data: result type string.
len = strlen( str ).
n_len = len - 3.
sub = str+3(n_len).
concatenate str+0(3) sub into result.
write:/ result.
Regards,
Rich Heilman
‎2006 Dec 22 2:37 AM
Hi,
Run this sample.
data : st type string value 'XYZ754',
st1 type string value 'XYZ',
st2 type string.
data: len type i,
len1 type i,
off type i.
len = strlen( st ). "5
if st(3) = 'XYZ'.
len1 = len - 3.
if len < 8.
st2 = 'XYZ'.
off = 8 - len.
do off times.
concatenate st2 '0' into st2.
enddo.
concatenate st2 st+3(len1) into st2.
endif.
write st2.
endif.
Regds,
Vinsa.R
Message was edited by:
vinsar chand
Message was edited by:
vinsar chand
‎2006 Dec 22 3:05 AM
Assuming that the first three are always the same, this code is a little simpler.
report zrich_0001.
data: str type string value 'XYZ54'.
data: sub(5) type n.
data: len type i.
data: n_len type i.
data: result type string.
len = strlen( str ).
n_len = len - 3.
sub = str+3(n_len).
concatenate str+0(3) sub into result.
write:/ result.
Regards,
Rich Heilman
‎2006 Dec 22 3:25 AM
Hi Nina
Rich has specified the first assumption that first 3 chars will be XYZ.
There hides the second assumption. Later part in the string after 3 chars is always numeric.
Just incase, it can be alpha numeric, you might consider using FM: CONVERSION_EXIT_ALPHA_INPUT with the output variable of length 5.
For numeric cases, Rich's example would just be perfect.
Rich,
Correct me if i am wrong.
Kind Regards
Eswar
‎2006 Dec 22 2:32 PM
Rich,
This is exactly what I was looking for. Thank You so much for your help.
Happy Holidays!
‎2006 Dec 22 8:45 PM
Eswar, you are very much correct, my assumptions were that, the first 3 characters we really don't care what they are, but as long as it is 3 characters, and that the next few characters, regardless of length(and must be <= 5) must be numeric, the code that I have written is VERY speicifc to the data presented, of course, other code could be written to handle more exceptions.
Regards,
RIch Heilman
‎2006 Dec 23 11:57 AM