IT WORK/SAP FI and ABAP

[ABAP] Unicode 관련 if_http_client->get_cdata 한글 깨짐

Bathildis 2023. 7. 26. 10:25
반응형

get_cdata로 한글이 깨지면 get_data로 bytes 형태로 받은 뒤 변환해주면 된다.

 

 



REPORT YEDIT.

DATA: CLIENT   TYPE REF TO IF_HTTP_CLIENT,
      XCONTENT TYPE XSTRING,
      CONTENT  TYPE STRING.

DATA: FE_MESSAGE TYPE STRING.

CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
  EXPORTING
    URL                = 'URL'
    SSL_ID             = 'SSL_ID'
  IMPORTING
    CLIENT             = CLIENT
  EXCEPTIONS
    ARGUMENT_NOT_FOUND = 1
    PLUGIN_NOT_ACTIVE  = 2
    INTERNAL_ERROR     = 3
    OTHERS             = 4.

IF SY-SUBRC <> 0.
  EXIT.
ENDIF.

CALL METHOD CLIENT->SEND
  EXCEPTIONS
    HTTP_COMMUNICATION_FAILURE = 1
    HTTP_INVALID_STATE         = 2.
IF SY-SUBRC <> 0.
  EXIT.
ENDIF.

CALL METHOD CLIENT->RECEIVE
  EXCEPTIONS
    HTTP_COMMUNICATION_FAILURE = 1
    HTTP_INVALID_STATE         = 2
    HTTP_PROCESSING_FAILED     = 3
    OTHERS                     = 4.
IF SY-SUBRC <> 0.
  CALL METHOD CLIENT->GET_LAST_ERROR
    IMPORTING
      MESSAGE = FE_MESSAGE.
  WRITE : FE_MESSAGE.
  EXIT.
ENDIF.

CLEAR XCONTENT.
XCONTENT = CLIENT->RESPONSE->GET_DATA( ).

CLEAR CONTENT.
CL_BCS_CONVERT=>XSTRING_TO_STRING(
      EXPORTING
        IV_XSTR   = XCONTENT
        IV_CP     = 8500
      RECEIVING
        RV_STRING = CONTENT
    ).

 

참고: codepage 8500은 한글임

Character encoding conversion - ABAP Development - Support Wiki (sap.com)

반응형