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: 

adding zeros before quantity or price

Former Member
0 Kudos

hey can you people tell me how to add Zeros in front of quantity field or price field.

I used conversion_alpha_input FM before writing to file but its not writing with front zeros..

any alternatives.

Ambichan

8 REPLIES 8

former_member480923
Active Contributor
0 Kudos

Hi,

The easy solution is to convert the filed to a character filed and then apply a conversion exit function module (for eg. the FM attached to MATNR) and this could give a good output.

Hope it helps

Anirban

0 Kudos

could you please be more specific..

please tell me which FM.

thanks.

Ambcihan

0 Kudos

Have you tried using a NUMC variable?

It always has leading zeros.

Code would be:

data: amount(9) type c,

numc_amount(9) type n.

  • If char field only contains numeric data

if amount co '0123456789 '. "Added a space in here!"

numc_amount = amount.

endif.

  • If the numc amount is filled.

if not numc_amount is initial.

  • Do something with it! (for example: WRITE)

write: / 'Number is: ' numc_amount.

endif.

0 Kudos

Hi

I was talking about <b>FM CONVERSION_EXIT_MATN1_INPUT</b>

Hope it helps

Anirban

andreas_mann3
Active Contributor
0 Kudos

Hi,

i think, it's only possible by fileds with type c or n

Andreas

Former Member
0 Kudos

hi,

a small logic to provide leading zeroes. i am not aware that is there any function module for this purpose.

*--To provide leading zeroes

DATA : V_CURR TYPE VBAK-NETWR,

LV_CHAR17(17) TYPE C VALUE '00000000000000000',

V_CHAR(17) TYPE C,

v_char2(17) type c.

V_CURR = '10.58'.

WRITE V_CURR TO V_CHAR.

CONDENSE V_CHAR NO-GAPS.

DATA : V_STRLEN TYPE I.

BREAK-POINT.

V_STRLEN = STRLEN( V_CHAR ).

if v_strlen < 17.

v_strlen = 17 - v_strlen.

CONCATENATE LV_CHAR17+0(V_strlen)

v_char

INto v_char.

endif.

NOW you can use V_CHAR field. (this will be prefixed with leading zeroes)

regards

srikanth

Message was edited by: Srikanth Kidambi

Former Member
0 Kudos

Hi,

Please have a look, logic is quite simple.

REPORT ZLEADQUANTZEROS .

DATA: L_MENGE(17).

DATA: L_DEC(13), L_FRACTION(3).

DATA: T_MSEG TYPE STANDARD TABLE OF MSEG WITH HEADER LINE.

SELECT * FROM MSEG

INTO TABLE T_MSEG

UP TO 100 ROWS.

LOOP AT T_MSEG.

L_MENGE = T_MSEG-MENGE.

SPLIT L_MENGE AT '.' INTO L_DEC L_FRACTION.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = L_DEC

IMPORTING

OUTPUT = L_DEC.

CONCATENATE L_DEC L_FRACTION INTO L_MENGE

SEPARATED BY '.' .

WRITE: / L_MENGE.

ENDLOOP.

former_member534411
Participant
0 Kudos

Hi,

Do not required any programming to do this.

Just define them as NUMC data type- it will automatcally add initial zero's.

Regards,

Suresh