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

Remove leading zeros in sapscript

mgross1
Participant
0 Likes
2,256

In my sapscript form, there is a variable LTAP-NLENR which has value '000000000010000000712'.

All I want to do is remove the leading zeros so it becomes '10000000712'.

I have read so many discussions and they all say just use &variable(Z)&. So I tried that:

ST       &LTAP-NLENR(Z)&

But the leading zeros were still there. Why?

So then I tried changing the print program (shown below) but this still didn't work.

/:         DEFINE &LV_NLENR& = &LTAP-NLENR&

/:         PERFORM GET_PALLETID IN PROGRAM ZWM_1043_DATA_INC

/:         USING &LTAP-NLENR&

/:         CHANGING &LV_NLENR&

/:         ENDPERFORM

ST      &LTAP-NLENR&

FORM get_palletid  TABLES in_tab  structure itcsy
                                              out_tab structure itcsy.

   DATA: lv_nlenr type ltap-nlenr.


   CLEAR lv_nlenr.
   REFRESH out_tab.

   READ TABLE in_tab WITH KEY NAME = 'LTAP-NLENR'.

   lv_nlenr = in_tab-value.

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
     EXPORTING
       INPUT  = lv_nlenr
     IMPORTING
       OUTPUT = lv_nlenr.


   CLEAR out_tab.
   out_tab-name  = 'LTAP-NLENR'.
   out_tab-value = lv_nlenr.
   APPEND out_tab.


ENDFORM.



What am I doing wrong?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,900

Hi,

where did you test your formular? same mandant? dont forget that changing the script has to be transported to other mandants. did you check that your new changes did take effect? are you sure, you changed the right programm-part?

sometimes its in loop and there are several statements printing the same variable. what value does the global variable has, when you call the script-call?

screenhot debugger

screenshot script (in target mandant)

(Z) should work. does CONVERSION_EXIT_ALPHA_OUTPUT drop the leading 0? should also work.

it was long ago since i worked with scripts. what type does your field has?

maybe add K -> &symbol(KZ)& for ignoring conversion exits.

LG

Stefan Seeburger

In my sapscript form, there is a variable LTAP-NLENR which has value '000000000010000000712'.

All I want to do is remove the leading zeros so it becomes '10000000712'.

I have read so many discussions and they all say just use &variable(Z)&. So I tried that:

ST       &LTAP-NLENR(Z)&

But the leading zeros were still there. Why?

So then I tried changing the print program (shown below) but this still didn't work.

/:         DEFINE &LV_NLENR& = &LTAP-NLENR&

/:         PERFORM GET_PALLETID IN PROGRAM ZWM_1043_DATA_INC

/:         USING &LTAP-NLENR&

/:         CHANGING &LV_NLENR&

/:         ENDPERFORM

ST      &LTAP-NLENR&

FORM get_palletid  TABLES in_tab  structure itcsy
                                              out_tab structure itcsy.

   DATA: lv_nlenr type ltap-nlenr.


   CLEAR lv_nlenr.
   REFRESH out_tab.

   READ TABLE in_tab WITH KEY NAME = 'LTAP-NLENR'.

   lv_nlenr = in_tab-value.

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
     EXPORTING
       INPUT  = lv_nlenr
     IMPORTING
       OUTPUT = lv_nlenr.


   CLEAR out_tab.
   out_tab-name  = 'LTAP-NLENR'.
   out_tab-value = lv_nlenr.
   APPEND out_tab.


ENDFORM.



What am I doing wrong?

6 REPLIES 6
Read only

roberto_vacca2
Active Contributor
0 Likes
1,900

Hi.

(Z) option command is correct but NLENR field has got CONVERSION_EXIT_LENUM_INPUT/OUTPUT as conversion routine set.

I suggest you to use  CONVERSION_EXIT_LENUM_OUTPUT routine conversion or

to use a local field l_nlenr(20) TYPE n OR c and assign your LFTAP-NLENR.


Hope to help

Bye

Read only

0 Likes
1,900

I changed the code but it still doesn't work:

FORM get_palletid  TABLES in_tab  STRUCTURE itcsy
                            out_tab STRUCTURE itcsy.

   DATA: lv_nlenr(20) TYPE n.

   CLEAR lv_nlenr.
   REFRESH OUT_TAB.

   READ TABLE in_tab WITH KEY NAME = 'LTAP-NLENR'.

   lv_nlenr = in_tab-value.

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
     EXPORTING
       INPUT  = lv_nlenr
     IMPORTING
       OUTPUT = lv_nlenr.


   CLEAR out_tab.
   out_tab-NAME  = 'LTAP-NLENR'.
   out_tab-VALUE = lv_nlenr.
   APPEND out_tab.

ENDFORM.      " GET_PALLETID


What am I doing wrong?

Read only

0 Likes
1,900

Hi.

Conversion routine works for type declaration.

You should work on Internal tables and referenced fields that has no TYPE LTAP-NLENR.

Command (Z) is for leading zeros and there's an option to say how many zeros if you need.

Let us know.

Bye

Read only

0 Likes
1,900

Can you please give me a code example?

I have tried so many ways and none of them have worked.

Thank you in advance.

Read only

Former Member
0 Likes
1,901

Hi,

where did you test your formular? same mandant? dont forget that changing the script has to be transported to other mandants. did you check that your new changes did take effect? are you sure, you changed the right programm-part?

sometimes its in loop and there are several statements printing the same variable. what value does the global variable has, when you call the script-call?

screenhot debugger

screenshot script (in target mandant)

(Z) should work. does CONVERSION_EXIT_ALPHA_OUTPUT drop the leading 0? should also work.

it was long ago since i worked with scripts. what type does your field has?

maybe add K -> &symbol(KZ)& for ignoring conversion exits.

LG

Stefan Seeburger

Read only

0 Likes
1,900

&symbol(KZ)&

This worked! Thank you so much.