Register Login

Formatting Dates, Quantities and amounts for batch input

Updated May 18, 2018

data: l_sep(1) type c,
l_amount_string(15) type c,
l_date_string(10) TYPE c,
l_menge_string(30) type c.


* Get thousand seperator for amount
perform get_thousand_seperator using l_sep.


loop at gi_mytab.
* Format amount
perform amount_to_string using gi_mytab-wrbtr
l_sep
changing l_amount_string.


* Format dates
CALL FUNCTION 'DATUMSAUFBEREITUNG'
EXPORTING

idate = gi_mytab-date
IMPORTING
tdat8 = l_date_string
EXCEPTIONS
datfm_ungueltig = 1
datum_ungueltig = 2
OTHERS = 3.
IF sy-subrc 0.
ENDIF.


* Format quantity
perform format_quantity using gi_mytab-gsmng
changing l_menge_string.

....... Call BDC.........................

endloop.


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. " GET_THOUSAND_SEPERATOR



form amount_to_string using p_amount
p_sep
changing p_amount_string.


* Remove decimals if they are 0, to avoid problems with
* currencies without decimals

WRITE P_AMOUNT TO P_AMOUNT_STRING.
IF P_AMOUNT_STRING CA P_DECIMAL_POINT.
SHIFT P_AMOUNT_STRING RIGHT DELETING TRAILING SPACE.
SHIFT P_AMOUNT_STRING RIGHT DELETING TRAILING '0'.
SHIFT P_AMOUNT_STRING RIGHT DELETING TRAILING P_DECIMAL_POINT.
ENDIF.

* Remove 1000 seperators
DO 5 TIMES.
REPLACE P_SEP WITH ' ' INTO P_AMOUNT_STRING.

CONDENSE P_AMOUNT_STRING NO-GAPS.
ENDDO.
WRITE P_AMOUNT_STRING TO P_AMOUNT_STRING RIGHT-JUSTIFIED.

endform. "AMOUNT_TO_STRING


form format_quantity using p_gsmng
changing p_gsmng_string.
data: l_thousand_SEPERATOR(1) type c.

perform GET_THOUSAND_SEPERATOR changing l_thousand_SEPERATOR.

* Remove thousand seperator
write p_gsmng to p_gsmng_string.
replace l_thousand_SEPERATOR with ' '
into p_gsmng_string.
condense p_gsmng_string no-gaps.


endform. " format_quantity


×