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

Appending zeros

Former Member
0 Likes
1,553

Hi,

I have written a query like this.

DATA: number TYPE C VALUE 0.

DATA: l_name LIKE thead-tdname.

l_length = strlen( l_name ).

IF l_length < 10.

CONCATENATE number l_name INTO l_name.

ENDIF.

I want to apend a zero infront of the number if its total length is less than 10.But sometimes some character values are getting stored in l_name variable.Then in that case i want to give an if condition like if l_name is not equal to numeric value then the control should come out of if condition.How can I give this condition in my program?

1 ACCEPTED SOLUTION
Read only

former_member673464
Active Contributor
0 Likes
1,512

hi,

You can use the condition l_name cn '0123456789'. for checking whether it contains any characters other than numerics.

Regards,

Veeresh

Hi,

I have written a query like this.

DATA: number TYPE C VALUE 0.

DATA: l_name LIKE thead-tdname.

l_length = strlen( l_name ).

IF l_length < 10.

CONCATENATE number l_name INTO l_name.

ENDIF.

I want to apend a zero infront of the number if its total length is less than 10.But sometimes some character values are getting stored in l_name variable.Then in that case i want to give an if condition like if l_name is not equal to numeric value then the control should come out of if condition.How can I give this condition in my program?

10 REPLIES 10
Read only

Former Member
0 Likes
1,512

HI,

Try using fn. module:

CONVERSION_EXIT_ALPHA_INPUT

Pass the variable to which you want to append zeros and this fn. module will append and return.

Read only

former_member673464
Active Contributor
0 Likes
1,513

hi,

You can use the condition l_name cn '0123456789'. for checking whether it contains any characters other than numerics.

Regards,

Veeresh

Read only

Former Member
0 Likes
1,512

Hi Hema,

Just wondering why don't you just use data type N (numeric), it will automatically appending zero.

Thanks,

Victor.

Read only

Former Member
0 Likes
1,512

HI,

Check the below code....

If l_name CA sy-abcde.

exit.

else.

l_length = strlen( l_name ).

IF l_length < 10.

CONCATENATE number l_name INTO l_name.

ENDIF.

ENDIF.

Rgds,

Bujji

Read only

Former Member
0 Likes
1,512

hi!

Raise a check using the relational operator 'CS' and compare whether the variable contains Numeric r character.

if the condition is true, then call the FM - CONVERSION_EXIT_ALPHA_INPUT to include Zero prefix to the value.

Reward me if useful.

Regards,

Nagulan

Read only

Former Member
0 Likes
1,512

hi.....

you can pass your variable in the function 'conversion_exit_alpha_input.

Whatever blankpces you have inyour variable,it will be replaces by zeroes.The zeroes will be appended in front of the number.

This is a better method to append zeroes.

Read only

Former Member
0 Likes
1,512

Hi Hema,

Try the below code.

Example

DATA :n_c(10) TYPE n,

c_n(10) TYPE c.

START-OF-SELECTION.

n_c = '10'.

IF n_c IS INITIAL.

WRITE: 'Char'.

ELSE.

WRITE: n_c.

ENDIF.

your changed code

DATA: l_name LIKE thead-tdname,

l_n(10) TYPE n.

l_name = '10'.

l_n = l_name.

if l_n is not initial.

  • Numaric

else.

  • Char.

endif.

// l_name = 'AB'.

// l_n = l_name.

Reward if found helpful

Regards,

Boobalan Suburaj

Read only

Former Member
0 Likes
1,512

Hi,

Try using FM CONVERSION_EXIT_ALPHA_INPUT

or


datav : num(10) type n,
          num1 type i value '90880'.

num = num1.
write : num.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
1,512

hiii

use like below code

ls_data-matnr        = ls_excel-value.
        w_matnr = ls_data-matnr.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            input  = w_matnr
          IMPORTING
            output = w_matnr.

        ls_data-matnr  = w_matnr.

reward if useful

thx

twinkal

Read only

Former Member
0 Likes
1,512

hi,

instead of doin this ,there is a function module

CONVERSION_EXIT_ALPHA_INPUT for 0 padding..

use this one..