본문 바로가기

ERP_Work/ABAP

주민등록번호 외국인등록번호 Check 프로그램

FUNCTION YFRANK_CHECK_SOCIAL_NUMBER.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(SOCIAL_NUMBER)
*"     VALUE(LAND1) TYPE  LAND1 DEFAULT 'KR'
*"  EXCEPTIONS
*"      INVALID_NUMBER
*"      INVALID_BIRTH_DAY
*"----------------------------------------------------------------------
*" Make by Franklee
*"----------------------------------------------------------------------

  DATA: LV_LENGTH TYPE I,
        LV_BIRTH_DAY TYPE CHAR8,
        LV_PARITY TYPE I.
  IF LAND1 = 'KR'.
    REPLACE ALL OCCURRENCES OF '-' IN SOCIAL_NUMBER WITH ''.
* 자리수 체크
    LV_LENGTH = STRLEN( SOCIAL_NUMBER ).
    IF LV_LENGTH <> 13.
      RAISE INVALID_NUMBER.
    ENDIF.
* 숫자 체크
    IF SOCIAL_NUMBER CN '0123456789 '.
      RAISE INVALID_NUMBER.
    ENDIF.
    CASE SOCIAL_NUMBER+6(1).
      WHEN '1' OR '2'  "1900년대 내국인
        OR '5' OR '6'. "1900년대 외국인
        CONCATENATE '19' SOCIAL_NUMBER+0(6) INTO LV_BIRTH_DAY.
      WHEN '3' OR '4'  "2000년대 내국인
        OR '7' OR '8'. "2000년대 외국인
        CONCATENATE '20' SOCIAL_NUMBER+0(6) INTO LV_BIRTH_DAY.
      WHEN '9' OR '0'. "1800년대 내국인
        CONCATENATE '18' SOCIAL_NUMBER+0(6) INTO LV_BIRTH_DAY.
      WHEN OTHERS.
        RAISE INVALID_BIRTH_DAY.
    ENDCASE.
*날짜 check
    CALL FUNCTION 'RP_CHECK_DATE'
      EXPORTING
        DATE         = LV_BIRTH_DAY
      EXCEPTIONS
        DATE_INVALID = 1.
    IF SY-SUBRC <> 0.
      RAISE INVALID_BIRTH_DAY.
    ENDIF.
* 페리티 계산
    LV_PARITY = SOCIAL_NUMBER+00(1) * 2
              + SOCIAL_NUMBER+01(1) * 3
              + SOCIAL_NUMBER+02(1) * 4
              + SOCIAL_NUMBER+03(1) * 5
              + SOCIAL_NUMBER+04(1) * 6
              + SOCIAL_NUMBER+05(1) * 7
              + SOCIAL_NUMBER+06(1) * 8
              + SOCIAL_NUMBER+07(1) * 9
              + SOCIAL_NUMBER+08(1) * 2
              + SOCIAL_NUMBER+09(1) * 3
              + SOCIAL_NUMBER+10(1) * 4
              + SOCIAL_NUMBER+11(1) * 5.
    LV_PARITY = LV_PARITY MOD 11.
    LV_PARITY = 11 - LV_PARITY.
    LV_PARITY = LV_PARITY MOD 10.
* 외국인 추가
    CASE SOCIAL_NUMBER+6(1).
      WHEN '5' OR '6'  "1900년대 외국인
        OR '7' OR '8'. "2000년대 외국인
        LV_PARITY = LV_PARITY + 2.
        LV_PARITY = LV_PARITY MOD 10.
    ENDCASE.
* 페리티 체크
    IF LV_PARITY NE SOCIAL_NUMBER+12(1).
      RAISE INVALID_NUMBER.
    ENDIF.
  ENDIF.

ENDFUNCTION.

'ERP_Work > ABAP' 카테고리의 다른 글

SAP Shotcut EnablePassword  (0) 2011.08.03
전화번호 Conversion Exit  (0) 2010.08.26
공급가액에 따른 부가세 자동계산 (KR)  (0) 2010.08.09
임시전표 Table에 대한 고찰  (0) 2009.03.09
FIEB_PASSWORD  (0) 2009.02.27