Formatting Amounts, Quantities and Dates for Batch Input and
Call Transaction
- Amount
- Quantities
- Dates
Amount
The problem with formating of amount arises beceause the decimal
point and thouasnd seperators depends on the user settings.
Use the subroutines below to format the amount correctly.
p_amount = '5.000,25'.
PERFORM format_amount
USING p_amount
CHANGING l_formatted_amount.
If the decimal point is '.' then l_formatted_amount will be:
5000.25
FORM format_amount USING p_amount
CHANGING p_formatted_amount.
DATA: l_thousand_sep(1) TYPE c,
l_decimal_point(1) TYPE c.
PERFORM get_seperators
CHANGING l_thousand_sep
l_decimal_point.
WRITE p_amount TO p_formatted_amount.
* Remove decimals if they are 0, to avoid problems with
* currencies without decimals
IF p_formatted_amount CA l_decimal_point.
SHIFT p_formatted_amount RIGHT DELETING TRAILING space.
SHIFT p_formatted_amount RIGHT DELETING TRAILING '0'.
SHIFT p_formatted_amount RIGHT DELETING TRAILING l_decimal_point.
ENDIF.
* Remove 1000 seperators
DO 5 TIMES.
REPLACE l_thousand_sep WITH ' ' INTO p_formatted_amount.
CONDENSE p_formatted_amount NO-GAPS.
ENDDO.
WRITE p_formatted_amount TO p_formatted_amount RIGHT-JUSTIFIED.
ENDFORM. " format_amount
* Get decimal point and thousand seperator
FORM get_seperators
CHANGING p_thousand_sep
p_decimal_point.
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_thousand_sep = '.'.
p_decimal_point = ','.
ELSE.
p_thousand_sep = ','.
p_decimal_point = '.'.
ENDIF.
ENDFORM.
Quantities
perform format_quantity using MyGsmng
changing menge_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
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
Dates
When you enter a date on line, the SAP system will verify the user
input with the date format setup. If the date format is set
to
'YYYY/MM/DD', then the system will reject a user input
'1997-09-12'. For batch input, the date format setup is not
available any more,
what format should we use for a date field? Should it be
'YYYYMMDD'?
The other thing to remember is that the batch input uses the
user's
default profile as the date it expects. Make sure the
BATCHUSER format is identical to the one your program is expecting
or it will generate an
error when you are processing updates.
You can get the appropriate date format by calling the function
module ''DATUMSAUFBEREITUNG''. Make sure that the user who
process the session has the same date format.
CALL FUNCTION 'DATUMSAUFBEREITUNG'
EXPORTING
idate =
MyDate
IMPORTING
tdat8 =
MyDateString
EXCEPTIONS
datfm_ungueltig = 1
datum_ungueltig = 2
OTHERS =
3.
IF sy-subrc <> 0.
ENDIF.
|
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)
|