效果

ABAP 金额转大写函数重写,支持小数位_sql

调用程序

PARAMETERS:P_AMOUNT TYPE STRING.

DATA IV_AMOUNT TYPE STRING.
*DATA IV_CURRENCY TYPE SY-WAERS.
*DATA IV_LANGUAGE TYPE SY-LANGU.
DATA EV_NUMBER_UPPER TYPE STRING.


CALL FUNCTION 'ZZF_SPELL_AMOUNT'
EXPORTING
iv_amount = P_AMOUNT
IMPORTING
EV_NUMBER_UPPER = EV_NUMBER_UPPER
.

WRITE:'INPUT:',P_AMOUNT,/'OUTPUT:', EV_NUMBER_UPPER.

ENDFUNCTION.

Function
```sql
FUNCTION ZZF_SPELL_AMOUNT.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IV_AMOUNT) TYPE STRING
*" REFERENCE(IV_CURRENCY) TYPE SY-WAERS DEFAULT 'CNY'
*" REFERENCE(IV_LANGUAGE) TYPE SY-LANGU DEFAULT SY-LANGU
*" EXPORTING
*" VALUE(EV_NUMBER_UPPER) TYPE STRING
*"----------------------------------------------------------------------

DATA:LV_INTEGER TYPE STRING,"整数
LV_DEC TYPE STRING,"小数
LV_DOT TYPE CHAR1.

DATA:LS_WORDS_INTEGER TYPE SPELL,
LS_WORDS_DEC TYPE SPELL,
LV_LENGTH_DEC TYPE I.

SELECT SINGLE *
INTO @DATA(LS_USR01)
FROM USR01
WHERE BNAME EQ @SY-UNAME.

CASE LS_USR01-DCPFM .
WHEN ''.".'1.234.567,89'.
LV_DOT = '.'.
WHEN 'X'."'1,234,567.89'.
LV_DOT = '.'.
WHEN 'Y'."'1 234 567,89'.
LV_DOT = ','.
WHEN OTHERS.
ENDCASE.

SPLIT IV_AMOUNT AT LV_DOT INTO LV_INTEGER LV_DEC.
LV_LENGTH_DEC = STRLEN( LV_DEC ).
LV_INTEGER = LV_INTEGER && LV_DOT && '00'.


CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = LV_INTEGER
CURRENCY = IV_CURRENCY
FILLER = ''
LANGUAGE = IV_LANGUAGE
IMPORTING
IN_WORDS = LS_WORDS_INTEGER
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
.
EV_NUMBER_UPPER = LS_WORDS_INTEGER-WORD.
IF LV_DEC IS NOT INITIAL.
LV_DEC = LV_DEC && LV_DOT && '00'.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = LV_DEC
CURRENCY = IV_CURRENCY
FILLER = ''
LANGUAGE = IV_LANGUAGE
IMPORTING
IN_WORDS = LS_WORDS_DEC
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
.
DATA:LV_INT TYPE I,
LV_INT_CHAR TYPE CHAR2,
LV_STR_PRE TYPE STRING VALUE 'LS_WORDS_DEC-DIG',
LV_STR_AFTER TYPE STRING.
FIELD-SYMBOLS:<FS_VALUE> TYPE ANY.

LV_INT = LV_LENGTH_DEC.

EV_NUMBER_UPPER = EV_NUMBER_UPPER && '点'.

DO .
IF LV_INT = 0.
EXIT.
ENDIF.

LV_INT_CHAR = LV_INT.
LV_INT_CHAR = |{ LV_INT_CHAR ALPHA = IN }|.
LV_STR_AFTER = LV_STR_PRE && LV_INT_CHAR.
ASSIGN (LV_STR_AFTER) TO <FS_VALUE>.
IF <FS_VALUE> IS ASSIGNED.
EV_NUMBER_UPPER = EV_NUMBER_UPPER && <FS_VALUE>.
ENDIF.
LV_INT = LV_INT - 1.
ENDDO.
ENDIF.