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

Append zeros

Former Member
0 Likes
921

I have one variable of type character size 35, whose value can be 7 or 8 digit number, if it is 7 digit i want to append 3 zeros to it and if it is 8 digit i want to append 2 zeros eg.

if value is 7123456 i want 0007123456 and if it is 71234567 i want 0071234567

if m using FM 'CONVERSION_EXIT_ALPHA_INPUT' it is appending 28 zeros.

Thanks

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
885

Hi

Follow this procedure.

<b>Data: Var(35) value '1234567',

temp(10) type N.

temp = var. "Now the value is stored with Leading Zeroes

Var = Temp.

write: var.</b>

Reward if Helpful.

7 REPLIES 7
Read only

varma_narayana
Active Contributor
0 Likes
886

Hi

Follow this procedure.

<b>Data: Var(35) value '1234567',

temp(10) type N.

temp = var. "Now the value is stored with Leading Zeroes

Var = Temp.

write: var.</b>

Reward if Helpful.

Read only

Former Member
0 Likes
885

hi,

do this way ...


describle field lv_var length len.

if len = '7'.
 concatenate '000' lv_var into lv_var.
elseif len = '8'.
 concatenate '00' lv_var into lv_var.
endif.   

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
885

Hi,

DO like this

DATA: num10(10) type n.

num10 = your number.

Regards,

Sesh

Read only

Former Member
0 Likes
885

Hello,

Check this code. It's working :


DATA: gv_var TYPE char35.
DATA: gv_len TYPE i.
DATA: gv_corrector TYPE i.


gv_var = '7123456'.
gv_len = STRLEN( gv_var ).

WRITE:/ gv_var.

gv_corrector = 10 - gv_len.

DO gv_corrector TIMES.
  CONCATENATE '0' gv_var INTO gv_var.
ENDDO.
WRITE:/ '**************************'.
WRITE:/ gv_var.

Regards,

Deepu.K

Read only

Former Member
0 Likes
885

Hi,

Try decalring the output variable with type character and length 10.

data : p_input(35) type c.

data : p_output(10) type c.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = p_input

IMPORTING

OUTPUT = p_output.

Reward points if it was useful.

Regards,

Hema.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
885

data: test(35).

test = '1234567'.

val = strlen ( test ).

while val < 10.

concatenate '0' 'test' into test.

val = val + 1.

endwhile.

reward if usefull

Read only

naveen1241
Participant
0 Likes
885

hi lucky,

declare a variable like

data: temp(8).

pack ur_variable.to temp.

unpack temp .

ur_variable = temp.

check this...

Regards,

Naveen Natarajan