Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Please help!!! Help with CA/ Append

Former Member
0 Likes
692

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.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
670

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

6 REPLIES 6
Read only

Former Member
0 Likes
670

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
671

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

Read only

0 Likes
670

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

Read only

0 Likes
670

Rich,

This is exactly what I was looking for. Thank You so much for your help.

Happy Holidays!

Read only

0 Likes
670

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

Read only

0 Likes
670

Thanks for the clarification Rich.

Regards

Eswar