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

Data Element Truncation

Former Member
0 Likes
1,167

I have a custom data element definition (used in many places). It is defined as CHAR 2.

Problem is when something gets added such as 05 or 09 the 0 gets truncated.

Any idea how to prevent this?

11 REPLIES 11
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,127

You have to use a conversion routine in your data element, such as ALPHA. Or you can change data type to NUMC.

REgards,

Rich Heilman

Read only

0 Likes
1,127

Is that available in ECC 5 to use?

Read only

0 Likes
1,127

Yes, it is actually under the domain. Go to SE11. In the box next to "Domain", enter VBELN and click the display button. Click on the "Definition" tab, and you will see the conversion routine field. Here it is ALPHA, which means it will store the value with leading zeros.

Regards,

Rich Heilman

Read only

0 Likes
1,127

Thanks Rich.

I checked and interestingly my definition is set to ALPHA. So now unsure why no leading zeros..

Read only

0 Likes
1,127

Hmmm... maybe that is only used for output. Maybe you have to do the conversion manually before writing to the DB. You can use the function CONVERSION_EXIT_ALPHA_INPUT to convert your value before writing to the DB table.

Regards,

Rich Heilman

Read only

0 Likes
1,127

Maybe I need clarification...

Are you saying I should remove ALPHA? and the data will be saved exactly how it is entered?

Or ALPHA is required to keep the leading zeros

Read only

0 Likes
1,127

It is ok that ALPHA is there. I think it is only used when doing the conversion during output, say for example, if you where to use the value in a WRITE statement. You can leave it as is, but use the function that I mentioned to convert to internal format before writing to the DB.

Regards,

Rich Heilman

Read only

0 Likes
1,127

Also, if the value is coming from a dynpro, you maybe be able to set the conversion routine in the screen itself, and it will do the conversion for you without having to call the function module.

Regards,

Rich Heilman

Read only

0 Likes
1,127

So I would have to identify all code that writes data to the field and edit the code in each program to use that FM?

Read only

0 Likes
1,127

Not sure. I would first make sure that any program that writes to the DB from a dynpro has the conversion routine defined for that screen element, that will probably take care of it. But if you want to ensure that it always has a leading zero, then you can use the FM. This is a very good case for a DAO layer class. You mentioned that you may have to change all the programs that write to this table, if you had a Data Access Object(DAO) layer class which control the write to the DB for this table, then you would only have to make your change in one place.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,127

Hi,

Create Data Element with new Domain.

While creating Domain, in Definition TAB Convers. Routine is available.

Create Conversion Routine as per you requirement.

To create Conversion Exit follow the below steps

SE37- Create- CONVERSION_EXIT_TEST_INPUT

Give Z function Group name

With in this function module Write your appropriate Code.

Follow the same procedure for CONVERSION_EXIT_TEST_OUTPUT also.

Give the TEST name in Domain.

While updating, the value will be automatically truncated.

Regards,

Veera.