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

concatenate zeros with the variable

Former Member
0 Likes
1,768

hi all

how to concatenate zeros to my variable

hi all

how to concatenate zeros to my variable

12 REPLIES 12
Read only

athavanraja
Active Contributor
0 Likes
1,639

concatenate '0' variable into variable.

Regards

Raja

Read only

0 Likes
1,639

or if you want all the remain space in the variable to be prefixed with zeros you can use numc variable.

data: var1(5) ,

var2(5) type n.

var1 = '10' .

move: var1 to var2 .

run the above code and check

Regards

Raja

Read only

Former Member
0 Likes
1,639

hi,

You can concatenate the string directly or fill the string with '0' using overlay function also.

<b>Concatenate '00000' str into str1.</b>

overlay str1 with '00000'.

Hope this helps.

Read only

Former Member
0 Likes
1,639

take the variable as type N. it will pad zeros

Read only

Former Member
0 Likes
1,639

hi if you want to zero pad the variable

use the foll FM

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = variable

IMPORTING

OUTPUT = variable

.

This FM will help you zero pad the remaining characters

Message was edited by: Dominic Pappaly

Read only

Former Member
0 Likes
1,639

actually i will get the length of the zero's to be padded in run time only how will i do that

my req is like this my parameters variable length is of 10 character but my input is of only 5 character so i need to concatenate the remaining character with zeros can anyone help me n doin this

Read only

0 Likes
1,639

hi,

You can use unpack to fill the remaining spaces in the variable with zero's.

unpack str1 to str1.

Hope this helps.

Read only

0 Likes
1,639

the best way is as described below...

pval -> your parameter.

data : lval(10) type n.

lval = pval.

<b>Here lval will have the value of pval left padded with zeroes...hope your pval is a numeric field.</b>

Read only

0 Likes
1,639

then simply use a type N variable for parameter

Read only

0 Likes
1,639

What I understand is during u runtime you have your output as 12345 but you want to display it as 0000012345.

data : w_len TYPE i,

w_zeros TYPE i,

w_maxlen TYPE i VALUE 10,

w_tempqty TYPE p,

w_charqty.

w_tempqty = itab-(your field name).

w_charqty = w_tempqty.

CONDENSE w_charqty.

w_len = ( STRLEN( w_charqty ) ).

w_zeros = w_maxlen - w_len.

DO w_zeros TIMES.

CONCATENATE '0' w_charqty INTO w_charqty.

ENDDO.

hope this helps.

shejal shetty.

Read only

Former Member
0 Likes
1,639

Hi,

Here is the code.

parameters: p_val type char10.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = p_val

IMPORTING

OUTPUT = p_val.

write: p_val.

Mark the helpful answers.

Thanks

eswar

Read only

Former Member
0 Likes
1,639

<b>Option 1 :</b>

data : v_numc(6) type n,

v_char(3) type c.

v_char = '3'.

move v_char to v_numc.

now V_NUMC will have value '000003'.

<b>Option 2 :</b>

by using Concatenate

LETS SAY Your Variable is V_VBELN of 10 characters.

data : v_char(10) type c value '0000000000',
       v_length type i.

  V_LENGTH = STRLEN( V_VBELN ).
  IF V_LENGTH < 10 . 
*--if LENGTH less than 10, in this case only we have to pad the value with zeroes.
    V_LENGTH = 10 - V_LENGTH. 
<b>    CONCATENATE V_CHAR+0(V_LENGTH)
                V_VBELN
                INTO V_VBELN.</b>
  ENDIF.

This will help you.

Regards,

Srikanth.<b></b>

Message was edited by: Srikanth Kidambi