Application Development 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: 

removing leading zero on a char field (MATNR) on an ALV grid

Former Member
0 Kudos

Hi all,

I am having trouble removing the leading zeros on a char field (MATNR) in an ALV grid.

When I select the option no-zero in the field catalog, it doesn't work as MATNR is a char field.

If i process the line item manually, using

SHIFT lt_data LEFT DELETING LEADING '0'.

It appears to work when I check the table contents in the debugger. However, the ALV grid output shows all MATNR fields converted this way as blank. Why is this happening, and what can I do to avoid it?

Cheers

15 REPLIES 15

Former Member
0 Kudos

Use FM: CONVERSION_EXIT_ALPHA_OUTPUT

to remove leading zero's

0 Kudos

I tried this; it has the same effect as SHIFT LEFT -

When I look in the table, the field looks ok, however when I run the program, the ALV grid displays these values as blank.

I've even tried setting up a temporary variable like this:

-


DATA: l_temp(18) TYPE c.

lv_temp = l_data-matnr

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = lv_temp

IMPORTING

OUTPUT = lv_temp.

l_output-matnr = lv_temp.

APPEND l_output.

-


But when my ALV grid displays the table l_output, the matnr column is blank, even though there are correctly formatted values in this field. Any other suggestions?

former_member182354
Contributor
0 Kudos

Try using Search statement.....

Former Member
0 Kudos

Hi,

Use the below code.

data: v_matnr(18) type c value '000000001234'.

data: v_len type i, v_num type i.

v_len = strlen( v_matnr ).

do v_len times.

if v_matnr+v_num(1) <> '0'.

v_matnr = v_matnr+v_num.

exit.

endif.

v_num = v_num + 1.

enddo.

write:/ v_matnr.

Former Member
0 Kudos

Hi,

use this

SHIFT MATNR LEFT DELETING LEADING '0'.

Regards,

Raj.

0 Kudos

Please read my original post Raj; that was the first thing I tried.

S0025444845
Active Participant
0 Kudos

Hi,

Use this statement only but in loop.

like this

loop at lt_data into wa_data.

move wa_data-matnr to c_field.

SHIFT c_field LEFT DELETING LEADING '0'.

clear: c_field.

endloop.

regards,

Sudha

Edited by: sudha yadav on Apr 22, 2008 12:17 PM

0 Kudos

Hi,

Yes, I tried this, it didn't work either. Every time I am getting an empty MATNR column.

0 Kudos

hi,

can u send me ur code,

I will check.

Regards,

sudha

0 Kudos

Thanks for your offer, unfortunately I can't send my code. However, I have discovered that if I modify the table field to contain a zero trimmed number, it won't display, but if I modify it to contain letters and numbers, or a number starting with zero, it will appear.

Eg:

00142525 Will display

0023ABC Will display

142525 Will not display

Is there an option in the fieldcatalog that I have missed or something? MATNR is declared as standard (char 18)

0 Kudos

Hi Dakha,

Try with

wA_fcat-datatype = 'CHAR'

wa_fcat-LZERO = ' '.

LZERO - Leading Zero

0 Kudos

Thanks for your suggestion. I have tried this and it doesn't work unfortunately. Very confusing!

0 Kudos

Hi Dakha Dakha, Check this one. while building final internal table , change material no even though it is Char field. It works.

DATA:l_matnr TYPE mard-matnr VALUE '00000845'.
WRITE l_matnr to l_matnr no-ZERO.
WRITE l_matnr.
Regards, Venkat.O

0 Kudos

Venkat O is correct.

Because you are using the Data Element MATNR, the domain provides for a conversion routine MATN1 and reguardless of what you do it will still process this routine when displaying it.

Create your display value as a CHAR and you should be able to resolve your issue.

0 Kudos

Hi,

you are right do this way.

FIND '-' IN wa_data-matnr.

IF sy-subrc IS NOT INITIAL.

SHIFT wa_data-matnr LEFT DELETING LEADING '0'.

ENDIF.

regards,

Sudha