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

adding leading zeros in abap objects.

Former Member
139,531

Can anyone explain me

1. How to add leading zeros to a field in abap objects.

For eg:

data: dmb(6) type c value '123456',

actually the output value of c should have leading zeros added to it for length 16.

i.e '0000000000123456' . If the length of dmb is less than 16 then leading zeros should be added to that value to make it 16 as length.

Please tell me how to do it in ABAP Objects.

14 REPLIES 14
Read only

Former Member
56,715

Hi,

U can use the FM "CONVERSION_EXIT_ALPHA_INPUT"

Passing the dmb

Just make sure that ur variabl should be of char(16) in ur case.

Regards,

Ranjit Thakur.

<b>Please Mark The Helpful Answer.</b>

Read only

Former Member
0 Likes
56,715

Hi,

Take another character variable of length 16 and assign this dmb to that variable.

Regards,

Suruchi

Message was edited by:

Suruchi Mahajan

Read only

Former Member
0 Likes
56,715

Hi

Declare a TYPE N field with 16 length

data: dmb(6) type c value '123456',

dmb1(16) type N.

Move dmb to dmb1.

use DMB1 in your code

Reward points for useful Answers

Regards

Anji

Read only

Former Member
56,715

Hi Camila ,

You can use the unpack command.

Here is a sample program for the same

DATA : v1(16),
        v2(6) TYPE c VALUE '123456'.
unpack v2 to v1.
write /: v1 , v2

Regards

Arun

Read only

Former Member
0 Likes
56,715

U can try this .

data: dmb(16) type c value '123456',

i_value(16) type n .

i_value = dmb .

write i_value .

~ Laxmi

  • Reward helpful answers

Read only

0 Likes
56,715

Hi laxmi,

If the dmb value has decimal points like '123456.20' then the

i_value should have '0000000123456.20'. How this can be done. if i apply

the logic which u told then it is removing the decimal places. Could u please help

me in this.

Read only

0 Likes
56,715

Hi Laxmi,

It perfectly works, if you integer type data type.

Thanks for your suggestion.

Regards,

Naveen

Read only

Former Member
0 Likes
56,715

hi,

use Fm 'CONVERSION_EXIT_ALPHA_OUTPUT'

EX:

Data: Dat(16) type c. -> how much length u want while creating a variable itself.

Dat = '9999999'.

CALL FUNCTION 'CONVERTION_EXIT_ALPHA_OUTPUT'.

Exporitng

FIELD = Dat

Importing

FIELD = Dat.

Write: Dat.

if useful reward some points.

with regards,

suresh.

Read only

Former Member
0 Likes
56,715

Hi Camila

Try to use the statement

DATA: ALPHABET(15) VALUE '     ABCDEFGHIJ', 
      M1(4)        VALUE 'ABCD', 
      M2(6)        VALUE 'BJJCA '. 
SHIFT ALPHABET LEFT DELETING LEADING M1.

The field

ALPHABET

remains unchanged.

SHIFT ALPHABET LEFT DELETING LEADING SPACE.

The field ALPHABET now has the following contents:

'ABCDEFGHIJ     '.

SHIFT ALPHABET RIGHT DELETING TRAILING M2.

<b>ALPHABET</b> now has the following contents:

'      ABCDEFGHI'.

<u><b>IN CHARACTER MODE</b></u>

<b>Effect</b>

This is the default setting (see above), and the addition is therefore optional.

<b>Note

Performance:</b>

For performance reasons, you should avoid using SHIFT in WHILE loops.

The runtime required to shift a field with length 10 by one character to the right or left requires about 5 msn (standardized microseconds). A cyclical shift requires around 7 msn. The runtime for the ...

LEFT DELETING LEADING

... variant is around 3.5 msn, for ...

RIGHT DELETING TRAILING

... around 4.5 msn.

Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
56,714

Hi Camila,

Use FM "CONVERSION_EXIT_ALPHA_INPUT" like below:-

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = V1

IMPORTING

OUTPUT = V1

If it is integer type say "1234" , leading zeros will be added to it, if it is some character or string type say "ABCD", it will remain same.

The data type of both INPUT and OUTPUT should be same, it can be any, this is the mandatory condition. Whether you use same variable for both or different.

Hope this may help you.

Regards,

Swati

Read only

Former Member
0 Likes
56,714

What is DMB ?

If it is something that already exists in SAP such as a material number (but with a different use in the same way that you have 'Material Number' and 'Old Material Number'),  then define a custom data element with a domain of MATNR.

If however,  it is totally custom and does not appear anywhere in SAP then create a domain with the relevant characteristics (ie C with a length of 16),  and define the conversion exit as 'ALPHA'.  Make sure you document the domain.

Then create a data element based upon the domain you have created.  Document this data element since it is this documentation that will appear when the user presses the F1 key.

Use the data element to define your fields.  When you use it as a parameter the zeroes will be added automatically.  When you write it out to a report the zeroes will be removed. ie it will work in exactly the same way as a material number.

This avoids the need to keep calling the relevant conversion exits.

Regards

Rich

Read only

Former Member
0 Likes
56,714

Hi,

Kindly use the fm "CONVERSION_EXIT_ALPHA_INPUT".

Pass the input field and it will add the leading zero.

Read only

matt
Active Contributor
56,714

Old post resurrected for no good reason - locked. People - please check the date of the start of the thread before posting.

Read only

former_member744614
Discoverer
0 Likes
56,714

first of all... please check fields domain routine..if there is any FM mention for converion then use it..

for example for field matnr you must use "CONVERSION_EXIT_MATN1_INPUT" .

if there no routine mention in the domain then you can use "CONVERSION_EXIT_ALPHA_INPUT" .

Thank You .