본문 바로가기
ERP-SAP/ABAP

<ABAP> 숫자 금액을 한글로 변환 -> 1320원 ->일천삼백이십원

by 행복한워니의 기록 2013. 7. 2.
728x90
반응형

스텐다드 에서 제공해주는 함수가 있지만,
Korean이 자기 멋대로 동작한다.(내가 잘 못한건지..)

그래서 그런지 아래와같은 방식으로 사용자들이 함수를 직접 만드는거같다.

erp 사랑넷에도 비슷한 소스가 있었는데... 필요할때 아래 함수를 쓰면 유용할것 같다.


>> Test DATA SAMPLE
Import 매개변수 값

W_MONEY 100200
W_CENT 00
W_CURR KRW
W_MODE KO


>> Test Result
Export 매개변수 값

W_CHAR 일십만 이백원 정



FUNCTION ZEX_MONEY_TO_CHAR.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(W_MONEY) TYPE C
*" REFERENCE(W_CENT) TYPE NUMC2 OPTIONAL
*" REFERENCE(W_CURR) TYPE C
*" REFERENCE(W_MODE) TYPE C
*" EXPORTING
*" REFERENCE(W_CHAR) TYPE C
*" EXCEPTIONS
*" CHAR_OVER
*" NUMBER_OVER
*"----------------------------------------------------------------------

DATA : TEMP_MODE(002) TYPE C,
LEN TYPE I,
W_LEN TYPE I,
LEN_CHAR TYPE I VALUE 0,
NO TYPE I,
TEMP_CHAR(150) TYPE C,
TEMP_MONEY(030) TYPE C,
TEMP_CURR(003) TYPE C,
VAL.

CLEAR : TEMP_MODE, LEN, W_LEN,
TEMP_MONEY, TEMP_CURR, TEMP_CHAR,
NO, VAL.
DATA : W_FLAGL , W_FLAGV.
*-------------SETTING-------------*
W_FLAGV = 'N'.
W_FLAGL = 'N'.
NO = 0.
TEMP_MONEY = W_MONEY.
TEMP_CURR = W_CURR.
TEMP_MODE = W_MODE.
*----------',' 표시 없애기.--------*
DO.
REPLACE ',' WITH SPACE INTO TEMP_MONEY.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
ENDDO.
CONDENSE TEMP_MONEY NO-GAPS.

*----------개수---------------------*
LEN = STRLEN( TEMP_MONEY ).
W_LEN = LEN.

*-----------------------------------*
CASE TEMP_MODE.
IF W_LEN GT 16.
RAISE NUMBER_OVER.
ENDIF.
WHEN 'KO'.
DO LEN TIMES.
IF NO EQ 0.
IF ( W_LEN = '5' OR W_LEN = '9' OR W_LEN = '13' ).
W_FLAGL = 'Y'.
ENDIF.
ENDIF.
VAL = TEMP_MONEY+NO(1).
PERFORM CONVERT_NO_TO_CHAR
USING VAL W_LEN
CHANGING W_FLAGV W_FLAGL TEMP_CHAR.
LEN_CHAR = STRLEN( TEMP_CHAR ).
IF LEN_CHAR GT 100.
RAISE CHAR_OVER.
ENDIF.
NO = NO + 1.
W_LEN = W_LEN - 1.
ENDDO.
CASE TEMP_CURR.
WHEN 'KRW'.
CONCATENATE TEMP_CHAR '원 정' INTO TEMP_CHAR.
WHEN 'USD'.
CONCATENATE '미화' TEMP_CHAR ' 달러' INTO TEMP_CHAR.
WHEN OTHERS.
ENDCASE.

IF W_CENT NE '0' AND W_CENT NE '00'.
PERFORM CHANGE_CENT_TO_KOCHAR USING W_CENT
CHANGING TEMP_CHAR.
ENDIF.

WHEN 'EN'.
IF W_LEN GT 14.
RAISE NUMBER_OVER.
ENDIF.
DO LEN TIMES.
IF NO EQ 0.
IF ( W_LEN = '11' OR W_LEN = '8' OR
W_LEN = '5' OR W_LEN = '2' ).
W_FLAGL = 'Y'.
ENDIF.
ENDIF.

VAL = TEMP_MONEY+NO(1).
PERFORM CONVERT_NO_TO_ENG
USING VAL W_LEN NO
CHANGING W_FLAGV W_FLAGL TEMP_CHAR.
LEN_CHAR = STRLEN( TEMP_CHAR ).
IF LEN_CHAR GT 100.
RAISE CHAR_OVER.
ENDIF.
NO = NO + 1.
W_LEN = W_LEN - 1.
ENDDO.
CASE TEMP_CURR.
WHEN 'KRW'.
CONCATENATE TEMP_CHAR ' WON' INTO TEMP_CHAR.
WHEN 'USD'.
CONCATENATE 'US DOLLARS' TEMP_CHAR INTO TEMP_CHAR.
WHEN 'JPY'.
CONCATENATE 'JAPANESE YEN' TEMP_CHAR INTO TEMP_CHAR.
WHEN 'EUR'.
CONCATENATE 'EURO DOLLARS' TEMP_CHAR INTO TEMP_CHAR.
WHEN OTHERS.
ENDCASE.

IF W_CENT NE '0' AND W_CENT NE '00'.
PERFORM CHANGE_CENT_TO_ENCHAR USING W_CENT
CHANGING TEMP_CHAR.
ENDIF.
*> SAY ~~~ ONLY는 항상 출력한다.
CONCATENATE 'SAY' TEMP_CHAR 'ONLY'
INTO TEMP_CHAR SEPARATED BY SPACE.
*<
WHEN OTHERS.
ENDCASE.

W_CHAR = TEMP_CHAR.


ENDFUNCTION.

*------------------------------------------------*
FORM CONVERT_NO_TO_CHAR USING VAL W_LEN
CHANGING W_FLAGV W_FLAGL TEMP_CHAR.

DATA: WL_CHAR(10) TYPE C,
WL_CHAC(10) TYPE C.

CASE VAL.
WHEN '1'.
WL_CHAR = '일'.
WHEN '2'.
WL_CHAR = '이'.
WHEN '3'.
WL_CHAR = '삼'.
WHEN '4'.
WL_CHAR = '사'.
WHEN '5'.
WL_CHAR = '오'.
WHEN '6'.
WL_CHAR = '육'.
WHEN '7'.
WL_CHAR = '칠'.
WHEN '8'.
WL_CHAR = '팔'.
WHEN '9'.
WL_CHAR = '구'.
WHEN '0'.
WL_CHAR = ''.
ENDCASE.
CONCATENATE TEMP_CHAR WL_CHAR INTO TEMP_CHAR
SEPARATED BY SPACE.

CASE W_LEN.
WHEN '2' OR '6' OR '10' OR '14'.
IF VAL NE '0'.
WL_CHAC = '십'.
W_FLAGL = 'Y'.
ENDIF.
WHEN '3' OR '7' OR '11' OR '15'.
IF VAL NE '0'.
WL_CHAC = '백'.
W_FLAGL = 'Y'.
ENDIF.
WHEN '4' OR '8' OR '12' OR '16'.
IF VAL NE '0'.
WL_CHAC = '천'.
W_FLAGL = 'Y'.
ENDIF.
WHEN '5'.
IF W_FLAGL = 'Y'.
WL_CHAC = '만'.
W_FLAGL = 'N'.
ENDIF.
WHEN '9'.
IF W_FLAGL = 'Y'.
WL_CHAC = '억'.
W_FLAGL = 'N'.
ENDIF.
WHEN '13'.
IF W_FLAGL = 'Y'.
WL_CHAC = '조'.
W_FLAGL = 'N'.
ENDIF.
ENDCASE.

CONCATENATE TEMP_CHAR WL_CHAC INTO TEMP_CHAR.

ENDFORM. "CONVERT_NO_TO_CHAR

*------------------------------------------------*
FORM CONVERT_NO_TO_ENG USING VAL W_LEN NO
CHANGING W_FLAGV W_FLAGL TEMP_CHAR.

DATA: WL_ECHAR(11) TYPE C,
WL_ECHAC(11) TYPE C.


CASE W_LEN.
WHEN '12' OR '9' OR '6' OR '3'.
CASE VAL.
WHEN '1'.
WL_ECHAR = 'ONE'.
WHEN '2'.
WL_ECHAR = 'TW0'.
WHEN '3'.
WL_ECHAR = 'THREE'.
WHEN '4'.
WL_ECHAR = 'FOUR'.
WHEN '5'.
WL_ECHAR = 'FIVE'.
WHEN '6'.
WL_ECHAR = 'SIX'.
WHEN '7'.
WL_ECHAR = 'SEVEN'.
WHEN '8'.
WL_ECHAR = 'EIGHT'.
WHEN '9'.
WL_ECHAR = 'NINE'.
WHEN '0'.
WL_ECHAR = ''.
ENDCASE.

IF VAL NE '0'.
WL_ECHAC = 'HUNDRED'.
W_FLAGL = 'Y'.
ENDIF.
WHEN '11' OR '8' OR '5' OR '2'.
IF VAL NE '1'.
CASE VAL.
WHEN '1'.
WL_ECHAR = ''.
WHEN '2'.
WL_ECHAR = 'TWENTY'.
WHEN '3'.
WL_ECHAR = 'THIRTY'.
WHEN '4'.
WL_ECHAR = 'FORTY'.
WHEN '5'.
WL_ECHAR = 'FIFTY'.
WHEN '6'.
WL_ECHAR = 'SIXTY'.
WHEN '7'.
WL_ECHAR = 'SEVENTY'.
WHEN '8'.
WL_ECHAR = 'EIGHTY'.
WHEN '9'.
WL_ECHAR = 'NINETY'.
WHEN '0'.
WL_ECHAR = ''.
ENDCASE.

ELSE.
W_FLAGV = 'Y'.
ENDIF.
IF VAL NE 0.
W_FLAGL = 'Y' .
ENDIF.
WHEN '10' OR '7' OR '4' OR '1'.
IF W_FLAGV EQ 'Y'.
CASE VAL.
WHEN '1'.
WL_ECHAR = 'ELEVEN' .
WHEN '2'.
WL_ECHAR = 'TWELVE' .
WHEN '3'.
WL_ECHAR = 'THIRTEEN' .
WHEN '4'.
WL_ECHAR = 'FOURTEEN' .
WHEN '5'.
WL_ECHAR = 'FIFTEEN' .
WHEN '6'.
WL_ECHAR = 'SIXTEEN' .
WHEN '7'.
WL_ECHAR = 'SEVENTEEN'.
WHEN '8'.
WL_ECHAR = 'EIGHTEEN'.
WHEN '9'.
WL_ECHAR = 'NINETEEN'.
WHEN '0'.
WL_ECHAR = 'TEN'.
ENDCASE.
W_FLAGV = 'N'.
ELSE.
CASE VAL.
WHEN '1'.
WL_ECHAR = 'ONE'.
WHEN '2'.
WL_ECHAR = 'TWO'.
WHEN '3'.
WL_ECHAR = 'THREE'.
WHEN '4'.
WL_ECHAR = 'FOUR'.
WHEN '5'.
WL_ECHAR = 'FIVE'.
WHEN '6'.
WL_ECHAR = 'SIX' .
WHEN '7'.
WL_ECHAR = 'SEVEN'.
WHEN '8'.
WL_ECHAR = 'EIGHT'.
WHEN '9'.
WL_ECHAR = 'NINE'.
WHEN '0'.
WL_ECHAR = ''.
ENDCASE.
ENDIF.
CASE W_LEN.
WHEN '4'.
IF NO EQ 0.
WL_ECHAC = 'THOUSAND'.
ENDIF.
IF W_FLAGL EQ 'Y'.
WL_ECHAC = 'THOUSAND'.
W_FLAGL = 'N'.
ENDIF.
WHEN '7'.
IF NO EQ 0.
WL_ECHAC = 'MILLION'.
ENDIF.
IF W_FLAGL EQ 'Y'.
WL_ECHAC = 'MILLION'.
W_FLAGL = 'N'.
ENDIF.
WHEN '10'.
IF NO EQ 0.
WL_ECHAC = 'BILLION'.
ENDIF.
IF W_FLAGL EQ 'Y'.
WL_ECHAC = 'BILLION'.
W_FLAGL = 'N'.
ENDIF.

ENDCASE.
* ENDIF.

ENDCASE.
CONCATENATE TEMP_CHAR WL_ECHAR INTO TEMP_CHAR
SEPARATED BY SPACE.
CONCATENATE TEMP_CHAR WL_ECHAC INTO TEMP_CHAR
SEPARATED BY SPACE.

ENDFORM. "CONVERT_NO_TO_ENG

*&---------------------------------------------------------------------*
*& Form CHANGE_CENT_TO_ENCHAR
*&---------------------------------------------------------------------*
FORM CHANGE_CENT_TO_ENCHAR USING P_CENT
CHANGING P_CHAR.

DATA : WL_CHAR TYPE I,
WL_TEMP1,
WL_TEMP2.

DATA: WL_ECHAR(11) TYPE C.

* 소수점 첫째자리
WL_TEMP1 = P_CENT+0(1).
* 소수점 둘째자리
WL_TEMP2 = P_CENT+1(1).

IF P_CENT NE '01'.
CONCATENATE P_CHAR 'AND CENTS'
INTO P_CHAR SEPARATED BY SPACE.
ELSE.
CONCATENATE P_CHAR 'AND CENT'
INTO P_CHAR SEPARATED BY SPACE.
ENDIF.


CLEAR WL_ECHAR.

IF WL_TEMP1 NE '1'.
CASE WL_TEMP1.
WHEN '2'.
WL_ECHAR = 'TWENTY'.
WHEN '3'.
WL_ECHAR = 'THIRTY'.
WHEN '4'.
WL_ECHAR = 'FORTY'.
WHEN '5'.
WL_ECHAR = 'FIFTY'.
WHEN '6'.
WL_ECHAR = 'SIXTY'.
WHEN '7'.
WL_ECHAR = 'SEVENTY'.
WHEN '8'.
WL_ECHAR = 'EIGHTY'.
WHEN '9'.
WL_ECHAR = 'NINETY'.
ENDCASE.

CONCATENATE P_CHAR WL_ECHAR
INTO P_CHAR SEPARATED BY SPACE.

CLEAR WL_ECHAR.

CASE WL_TEMP2.
WHEN '1'.
WL_ECHAR = 'ONE'.
WHEN '2'.
WL_ECHAR = 'TWO'.
WHEN '3'.
WL_ECHAR = 'THREE'.
WHEN '4'.
WL_ECHAR = 'FOUR'.
WHEN '5'.
WL_ECHAR = 'FIVE'.
WHEN '6'.
WL_ECHAR = 'SIX' .
WHEN '7'.
WL_ECHAR = 'SEVEN'.
WHEN '8'.
WL_ECHAR = 'EIGHT'.
WHEN '9'.
WL_ECHAR = 'NINE'.
WHEN '0'.
WL_ECHAR = ''.
ENDCASE.

CONCATENATE P_CHAR WL_ECHAR
INTO P_CHAR SEPARATED BY SPACE.

ELSE.

CASE P_CENT.
WHEN '11'.
WL_ECHAR = 'ELEVEN' .
WHEN '12'.
WL_ECHAR = 'TWELVE' .
WHEN '13'.
WL_ECHAR = 'THIRTEEN' .
WHEN '14'.
WL_ECHAR = 'FOURTEEN' .
WHEN '15'.
WL_ECHAR = 'FIFTEEN' .
WHEN '16'.
WL_ECHAR = 'SIXTEEN' .
WHEN '17'.
WL_ECHAR = 'SEVENTEEN'.
WHEN '18'.
WL_ECHAR = 'EIGHTEEN'.
WHEN '19'.
WL_ECHAR = 'NINETEEN'.
WHEN '10'.
WL_ECHAR = 'TEN'.
ENDCASE.

CONCATENATE P_CHAR WL_ECHAR
INTO P_CHAR SEPARATED BY SPACE.

ENDIF.

* CONCATENATE 'SAY' P_CHAR 'ONLY'
* INTO P_CHAR SEPARATED BY SPACE.

ENDFORM. " CHANGE_CENT_TO_ENCHAR

*&---------------------------------------------------------------------*
*& Form CHANGE_CENT_TO_KOCHAR
*&---------------------------------------------------------------------*
FORM CHANGE_CENT_TO_KOCHAR USING P_CENT
CHANGING P_CHAR.

DATA : WL_CHAR TYPE I,
WL_TEMP1,
WL_TEMP2.

DATA: WL_ECHAR(11) TYPE C.

* 소수점 첫째자리
WL_TEMP1 = P_CENT+0(1).
* 소수점 둘째자리
WL_TEMP2 = P_CENT+1(1).

CLEAR WL_ECHAR.

CASE WL_TEMP1.
WHEN '1'.
WL_ECHAR = '십'.
WHEN '2'.
WL_ECHAR = '이십'.
WHEN '3'.
WL_ECHAR = '삼십'.
WHEN '4'.
WL_ECHAR = '사십'.
WHEN '5'.
WL_ECHAR = '오십'.
WHEN '6'.
WL_ECHAR = '육십'.
WHEN '7'.
WL_ECHAR = '칠십'.
WHEN '8'.
WL_ECHAR = '팔십'.
WHEN '9'.
WL_ECHAR = '구십'.
ENDCASE.

CONCATENATE P_CHAR WL_ECHAR
INTO P_CHAR SEPARATED BY SPACE.

CLEAR WL_ECHAR.

CASE WL_TEMP2.
WHEN '1'.
WL_ECHAR = '일'.
WHEN '2'.
WL_ECHAR = '이'.
WHEN '3'.
WL_ECHAR = '삼'.
WHEN '4'.
WL_ECHAR = '사'.
WHEN '5'.
WL_ECHAR = '오'.
WHEN '6'.
WL_ECHAR = '육' .
WHEN '7'.
WL_ECHAR = '칠'.
WHEN '8'.
WL_ECHAR = '팔'.
WHEN '9'.
WL_ECHAR = '구'.
WHEN '0'.
WL_ECHAR = ''.
ENDCASE.

CONCATENATE P_CHAR WL_ECHAR
INTO P_CHAR SEPARATED BY SPACE.

CONCATENATE P_CHAR '센트정'
INTO P_CHAR SEPARATED BY SPACE.

ENDFORM. " CHANGE_CENT_TO_KOCHAR

728x90
반응형