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

To append zeros

Former Member
0 Likes
1,387

Hi all,

I have a requirement in that i have to append zeors to the left of a character variable which is having length 10. While using shift statement the default character is space, then i tried with the 'IN BYTE MODE' option but there the representation is different,Each byte is represented as two characters.Is there any easy way to append zeros to a character variable using any of the ABAP keywords.

Thanks in Advance,

Shaju

Hi all,

I have a requirement in that i have to append zeors to the left of a character variable which is having length 10. While using shift statement the default character is space, then i tried with the 'IN BYTE MODE' option but there the representation is different,Each byte is represented as two characters.Is there any easy way to append zeros to a character variable using any of the ABAP keywords.

Thanks in Advance,

Shaju

12 REPLIES 12
Read only

Former Member
0 Likes
1,350

use FM CONVERSION_EXIT_ALPHA_INPUT

Read only

0 Likes
1,350

Hi,

It is not working.

Sometimes the character field can have Alphanumeric data.

I want to append zeros even if the field has alphanumeric data like C123

This FM will append zeros only if the field has numeric value like 123.

waiting for ur reply,

Regards,

Shaju

Read only

0 Likes
1,350

You can do something like this

REPORT ychatest.

DATA : v_char(10) VALUE 'C1234',
       v_len TYPE i.

v_len = STRLEN( v_char ).

v_len = 10 - v_len.
DO v_len TIMES.
  CONCATENATE '0' v_char INTO v_char.
ENDDO.
WRITE : / v_char.

Read only

0 Likes
1,350

Hi,

Thanks for ur info

I am looking for an ABAP keyword which gives the same result.

Is there any such keyword.

Thanks,

Shaju

Read only

0 Likes
1,350

Hi,

Use UNPACK

santhosh

Read only

0 Likes
1,350

Hi,

Since it contains alphanumeric character the UNPACK statement leads to a

runtime short dump.

Any alternate solution ?

Regards,

Shaju

Read only

0 Likes
1,350

can this help u

REPORT ychatest.

DATA : v_char(10) VALUE 'C1234',
WRITE :  v_char TO v_char RIGHT-JUSTIFIED.
TRANSLATE v_char USING ' 0'.

WRITE:  / v_char.

Read only

0 Likes
1,350

thanks alot

my problem got solved

Read only

0 Likes
1,350

I doubt that you can do via a single statement but with the combination of below two statements would resolve your issue.

lets say your value is in lalpha(10).

concatenate '0000000000' & lalpha into ltemp.

write ltemp to lapha using edit mask 'RR__________'.

Regards

Anurag

Read only

Former Member
0 Likes
1,350

Hi Shaju

CONVERSION_EXIT_ALPHA_INPUT This function module is used to append leading zeroes...

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wf_version

IMPORTING

output = wf_version.

Example:

input = 123

output = 0000000000000...000000000000123

Hope this resolves your query.

<b>Reward all the helpful answers.</b>

Regards

Read only

Former Member
0 Likes
1,350

1. Open the perticular field in SE11.

2. Find the domein

3. Go to the definition tab

4. If there is a convertion routine, double click that

5. You will find a list of conversion routine there. Among them use the conversion for output.

Ex: 

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = l_anlkl
        IMPORTING
          output = l_anlkl.

Here the output l_anlkl will have zeros appended with it.

If there is no conversion routine you have to write code for appending zeros.

Read only

Former Member
0 Likes
1,350

use like this

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa_lifnr

IMPORTING

output = wa_lifnr.

Regards,

Venkat