Register Login

Writing currency amount to string without thousands seperator

Updated May 18, 2018

This is usefull e.g. i connection with batch input/call transaction an duploading to Excel.

Method 1

* GI_OUTPUT-WRBTR: Field type Currency with amount
* L_AMOUNT_STRING: Field type c with amount

PERFORM AMOUNT_TO_STRING USING GI_OUTPUT-WRBTR
CHANGING L_AMOUNT_STRING.





FORM AMOUNT_TO_STRING USING P_AMOUNT
CHANGING P_AMOUNT_STRING.
DATA L_SEP(1) TYPE C.

PERFORM GET_THOUSAND_SEPERATOR USING L_SEP.

WRITE P_AMOUNT TO P_AMOUNT_STRING.

REPLACE L_SEP WITH ' ' INTO P_AMOUNT_STRING.
CONDENSE P_AMOUNT_STRING NO-GAPS.
WRITE P_AMOUNT_STRING TO P_AMOUNT_STRING RIGHT-JUSTIFIED.

ENDFORM.



FORM GET_THOUSAND_SEPERATOR USING P_SEP.
DATA: L_AMOUNT LIKE BSEG-DMBTR,
L_AMOUNT_STRING(15) TYPE C.


* Find 1000 seperator. If decimal seperator = . then
* 1000 seperator = , else 1000 seperator = .
L_AMOUNT = '1.00'.
WRITE L_AMOUNT TO L_AMOUNT_STRING.
IF L_AMOUNT_STRING CS ','.
P_SEP = '.'.
ELSE.
P_SEP = ','.
ENDIF.

ENDFORM.


Method 2 - Using an edit mask

data:
* Decimal point used in Excel
l_dec(1) type c,
* Field for formatted amount
l_stramount(20) type c,

* Field for formatted quantity
l_strquant(20) type c,
* Edit mask for amount
l_edit_mask_amount(20) type c,
* Edit mask for quantity
l_edit_mask_quant(20) type c.

l_dec = ','.

* Create dit masks:
* RR = Right justified
* V = Use sign
* Note that the length og the edit mask must be exactly the same length as the output field (Here = 20)
* to place the decimal correctly. The mask length includes RRV

concatenate 'RRV______________' l_dec '__' into l_edit_mask_amount.
concatenate 'RRV_____________' l_dec '___' into l_edit_mask_amount.

write my_amount to l_stramount using edit mask l_edit_mask_amount.

write my_quant to l_strquant using edit mask l_edit_mask_quant.


×