메뉴 건너뛰기

SAP 한국 커뮤니티

API

sapjoy 2022.11.02 19:30 조회 수 : 314

*&---------------------------------------------------------------------*
*& Report ZAPI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAPI.
* Declaración de tipos.
TYPES: BEGIN OF ty_datos,
name1 LIKE lfa1-name1,
sortl LIKE lfa1-sortl,
land1 LIKE lfa1-land1,
spras LIKE lfa1-spras,
END OF ty_datos.

DATA : lo_http_client TYPE REF TO if_http_client.
DATA : l_str_length     TYPE i.
DATA : mime      TYPE w3mimetabtype.
  DATA: l_datos TYPE ty_datos,
        t_datos TYPE STANDARD TABLE OF ty_datos.
  DATA gv_json_output TYPE string.
*SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-s01.
*PARAMETERS: p_inv TYPE belnr_d DEFAULT '12345'.
*SELECTION-SCREEN: END OF BLOCK b1.
START-OF-SELECTION.
*Data variables for storing response in xstring and string
  DATA  : lv_xstring   TYPE xstring,
          lv_string    TYPE string,
          lv_node_name TYPE string.
  CLEAR : lv_xstring, lv_string, lv_node_name.
  DATA  : lv_cdata     TYPE string.
  DATA  : lv_content_length_value TYPE i.
  CLEAR : lv_cdata, lv_content_length_value.
*Pass the URL to get Data
    CLEAR : lv_xstring, lv_string, lv_node_name.
  lv_string = 'https://openapi.naver.com/v1/papago/n2mt?source=ko&target=en&text=안녕.'.
*Creation of New IF_lo_http_client Object
  cl_http_client=>create_by_url(
  EXPORTING
    url                = lv_string
  IMPORTING
    client             = lo_http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    ).
  IF sy-subrc IS NOT INITIAL.
* Handle errors
  ENDIF.
  lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
* lo_http_client->request->set_method( 'POST' ).
  CALL METHOD lo_http_client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = 'POST'.
*  CALL METHOD lo_http_client->request->set_header_field
*    EXPORTING
*      name  = 'content-type:'
*      value = 'application/x-www-form-urlencoded'.

  CALL METHOD lo_http_client->request->set_header_field
    EXPORTING
      name  = 'Content-Type:'
      value = 'application/x-www-form-urlencoded;charset=UTF-8'.


  CALL METHOD lo_http_client->request->set_header_field "We pass header and value
    EXPORTING
      name  = 'X-Naver-Client-Id:'
      value = 'Rh6y2FN_54MoIYIXHdDq'.

    CALL METHOD lo_http_client->request->set_header_field "We pass header and value
    EXPORTING
      name  = 'X-Naver-Client-Secret:'
      value = 'Q4GcM0CQmV'.

*
*  CALL METHOD lo_http_client->request->set_form_field
*    EXPORTING
*      name  = 'grant_type'
*      value = 'password'.
*  CALL METHOD lo_http_client->request->set_form_field
*    EXPORTING
*      name  = 'username'
*      value = 'admin'.
*  CALL METHOD lo_http_client->request->set_form_field
*    EXPORTING
*      name  = 'password'
*      value = 'abc123'.
  CALL METHOD lo_http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.
  CALL METHOD lo_http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.
  IF sy-subrc NE 0.
    DATA subrc TYPE sysubrc.
    DATA errortext TYPE string.
    CALL METHOD lo_http_client->get_last_error
      IMPORTING
        code    = subrc
        message = errortext.
    WRITE: / 'communication_error( receive )',
           / 'code: ', subrc, 'message: ', errortext.
    EXIT.
  ELSE.
****Get the response content in Character format
*  content = client->response->get_cdata( ).
  ENDIF.
**  lo_client->receive( ).
**  IF sy-subrc IS NOT INITIAL.
*** Handle errors
**  ENDIF.
END-OF-SELECTION.
**Return the HTTP body of this entity as binary data
*lv_xstring = lo_http_client->response->get_data( ).
*Return the HTTP body of this entity as string data
  DATA(lv_string2) = lo_http_client->response->get_cdata( ).
*  BREAK-POINT.
  /ui2/cl_json=>deserialize(
    EXPORTING json = lv_string2
              pretty_name = /ui2/cl_json=>pretty_mode-camel_case
    CHANGING  data = t_datos ).

번호 제목 글쓴이 날짜 조회 수
669 <b>easy abap 소스 전체 파일 입니다. [188] file sapjoy 2008.05.01 10120
668 REPORT z18_033 [47] sapjoy 2008.10.13 9031
667 REPORT Z15_003 [49] sapjoy 2008.04.15 7498
666 report zunicode_027. [4] sapjoy 2008.11.21 6262
665 REPORT Z20_01. sapjoy 2012.08.01 5056
664 REPORT z18_03. sapjoy 2012.08.01 4550
663 Z01_012 [9] sapjoy 2006.12.02 4543
662 Z_EXPORT_GRAPHIC_FROM_SE78 [1] sapjoy 2011.03.28 4443
661 report zsapdoi_002. sapjoy 2008.12.26 4405
660 REPORT zsmw0010 sapjoy 2010.10.11 4313
659 REPORT z18_028 sapjoy 2007.04.09 4278
658 report zsalv_045 . sapjoy 2010.08.20 4262
657 Dynamic Table Maintenance [1] sapjoy 2006.12.04 4093
656 REPORT ZTABLE_UTIL sapjoy 2010.10.09 4010
655 REPORT Z19_02. sapjoy 2012.08.01 3921
654 report zsaptip_009 [1] sapjoy 2010.12.10 3852
653 INCLUDE ZXF04U01 sapjoy 2008.12.15 3695
652 REPORT ZTEST_ABAPTPDF sapjoy 2010.10.09 3691
651 REPORT Z_3DGRAPH. [1] sapjoy 2010.10.17 3659
650 REPORT zfalv_011. sapjoy 2011.02.16 3624