Sample Code Generate File XML SAP Directories with ABAP

   

SAP DIRECTORIES (Tcode AL11) dapat merujuk ke folder yang berada langsung di dalam folder share / drive share di dalam SAP yang sudah didaftarkan oleh konsultan BASIS.
Berikut contoh sample code dari project yang pernah saya buat:

TABLES: kna1, knb1.
TYPES: BEGIN OF ty_output,
         flag       TYPE icon-id,
         zmark      TYPE c,
         as4date    TYPE as4date,
         as4time    TYPE as4time,
         as4user    TYPE as4user,
         kunnr      TYPE kna1-kunnr,
         bukrs      TYPE knb1-bukrs,
         name1      TYPE kna1-name1,
         ort01      TYPE kna1-ort01, "city
         stras      TYPE kna1-stras, "street
         intf_date  TYPE sy-datum,
         intf_time  TYPE sy-uzeit,
         intf_uname TYPE sy-uname,
         intf_ret   TYPE c LENGTH 10,
       END OF ty_output.
DATA: lt_kna1            TYPE TABLE OF kna1 WITH HEADER LINE,
      lt_knb1            TYPE TABLE OF knb1 WITH HEADER LINE,
      lt_yinterface_br01 TYPE TABLE OF yinterface_br01 WITH HEADER LINE,
      lt_output          TYPE TABLE OF  ty_output WITH HEADER LINE,
      ld_message         TYPE c LENGTH 225,
      ld_count           TYPE i,
      ld_count_c         TYPE c LENGTH 4,
      lt_yinterface_st01 TYPE TABLE OF yinterface_st01 WITH HEADER LINE,
      ld_filename        TYPE c LENGTH 30,
      lt_yinterface_br02 TYPE TABLE OF yinterface_br02 WITH HEADER LINE.
DATA:
  lt_fcat   TYPE lvc_t_fcat,            "Field catalogue
  lt_layout TYPE lvc_s_layo.           "Layout
SELECTION-SCREEN: BEGIN OF BLOCK b1.
SELECT-OPTIONS: so_kunnr FOR kna1-kunnr,
                so_bukrs FOR knb1-bukrs OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
 
START-OF-SELECTION.
 
  PERFORM get_data.
  PERFORM alv_build_fieldcat.
  PERFORM alv_report_layout.
  PERFORM alv_grid_display.
 
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data.
  DATA lt_yinterface_br01_2 TYPE TABLE OF yinterface_br01 WITH HEADER LINE.
  REFRESH: lt_output[], lt_yinterface_br02[].
  SELECT * FROM knb1
    INTO TABLE lt_knb1
    WHERE kunnr IN so_kunnr
    AND bukrs IN so_bukrs.
  IF lt_knb1[] IS NOT INITIAL.
    SELECT * FROM yinterface_br02
      INTO TABLE lt_yinterface_br02
      FOR ALL ENTRIES IN lt_knb1
      WHERE erp_id = lt_knb1-kunnr.
    SELECT * FROM yinterface_br01
      INTO TABLE lt_yinterface_br01_2
      FOR ALL ENTRIES IN lt_knb1
      WHERE kunnr = lt_knb1-kunnr
      AND bukrs = lt_knb1-bukrs.
    SELECT * FROM kna1
      INTO TABLE lt_kna1
      FOR ALL ENTRIES IN lt_knb1
      WHERE kunnr = lt_knb1-kunnr.
    SELECT * FROM yinterface_br01
      INTO TABLE lt_yinterface_br01
      FOR ALL ENTRIES IN lt_knb1
      WHERE kunnr = lt_knb1-kunnr.
    LOOP AT lt_knb1.
      READ TABLE lt_kna1 WITH KEY kunnr = lt_knb1-kunnr.
      IF sy-subrc = 0.
        READ TABLE lt_yinterface_br01 WITH KEY kunnr = lt_knb1-kunnr bukrs = lt_knb1-bukrs.
        IF sy-subrc = 0.
          lt_output-flag = '@0A@'.
          lt_output-as4user = lt_yinterface_br01-as4user.
          lt_output-as4date = lt_yinterface_br01-as4date.
        ELSE.
          lt_output-flag = '@08@'.
 
        ENDIF.
        lt_output-kunnr = lt_knb1-kunnr.
        lt_output-bukrs = lt_knb1-bukrs.
        lt_output-name1 = lt_kna1-name1.
        lt_output-ort01 = lt_kna1-ort01.
        lt_output-stras = lt_kna1-stras.
        READ TABLE lt_yinterface_br01_2 WITH KEY kunnr = lt_knb1-kunnr bukrs = lt_knb1-bukrs.
        IF sy-subrc = 0.
          lt_output-flag = '@4A@'.
          lt_output-as4date = lt_yinterface_br01_2-as4date.
          lt_output-as4time = lt_yinterface_br01_2-as4time.
          lt_output-as4user = lt_yinterface_br01_2-as4user.
        ENDIF.
        "@S_OKAY@
        READ TABLE lt_yinterface_br02 WITH KEY erp_id = lt_knb1-kunnr.
        IF sy-subrc = 0.
          lt_output-flag = '@01@'.
          lt_output-intf_date = lt_yinterface_br02-as4date.
          lt_output-intf_time = lt_yinterface_br02-as4time.
          lt_output-intf_ret = lt_yinterface_br02-ret_id.
        ENDIF.
        APPEND lt_output.
        CLEAR lt_output.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFORM.                    "get_data
*&---------------------------------------------------------------------*
*&      Form  f03_my_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM f03_my_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'STANDARD'.
ENDFORM.                    "f03_my_status
*&---------------------------------------------------------------------*
*&      Form  u_comm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_UCOMM      text
*      -->PS_SELFIELD  text
*----------------------------------------------------------------------*
FORM u_comm USING p_ucomm LIKE sy-ucomm
        ps_selfield TYPE slis_selfield .
  DATA ref1 TYPE REF TO cl_gui_alv_grid.
  DATA lt_yinterface_br01 TYPE TABLE OF yinterface_br01 WITH HEADER LINE.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = ref1.
  CALL METHOD ref1->check_changed_data.
  CASE p_ucomm.
    WHEN '&GETXML'.
      SUBMIT yinterface_br02 AND RETURN.
      PERFORM get_data.
    WHEN '&DOWNLOAD'.
      ld_count = 0.
      REFRESH: lt_yinterface_st01 .
      CONCATENATE 'BR01' sy-datum sy-uzeit INTO ld_filename.
      CONCATENATE '/brftp/DIR_BR/' ld_filename '.SAPBR01' INTO lt_yinterface_st01-path.
      LOOP AT lt_output WHERE zmark = 'X'.
        ld_count = ld_count + 1.
        "KODE#NAMA#STREET#CITY#STATE#REGION#PINCODE#COUNTRY
        CONCATENATE lt_output-kunnr '#' lt_output-name1 '#' lt_output-stras '#' lt_output-ort01 '#Jakarta#Indonesia#42121#Indonesia' INTO lt_yinterface_st01-data01.
        APPEND lt_yinterface_st01.
        lt_yinterface_br01-kunnr = lt_output-kunnr.
        lt_yinterface_br01-bukrs = lt_output-bukrs.
        lt_yinterface_br01-as4date = sy-datum.
        lt_yinterface_br01-as4time = sy-uzeit.
        lt_yinterface_br01-as4user = sy-uname.
 
        lt_output-flag = '@4A@'.
        lt_output-as4date = lt_yinterface_br01-as4date.
        lt_output-as4time = lt_yinterface_br01-as4time.
        lt_output-as4user = lt_yinterface_br01-as4user.
        MODIFY lt_output.
        MODIFY yinterface_br01 FROM lt_yinterface_br01.
        CLEAR lt_yinterface_br01.
      ENDLOOP.
      IF ld_count > 0.
        CALL FUNCTION 'YINTERFACE_FM01'
          EXPORTING
            data         = lt_yinterface_st01
          TABLES
            data_intable = lt_yinterface_st01[].
        ld_count_c = ld_count.
        CONCATENATE  '(' ld_count_c ') Download Completed.' INTO ld_message.
        MESSAGE ld_message TYPE 'I'.
      ELSE.
        MESSAGE 'No Data Selected' TYPE 'I'.
      ENDIF.
 
 
  ENDCASE.
  ps_selfield-refresh = abap_true.
ENDFORM.                    "u_comm
*&---------------------------------------------------------------------*
*&      Form  alv_grid_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_grid_display.
  lt_layout-cwidth_opt  = 'X'.
  lt_layout-zebra       = 'X'.
  lt_layout-sel_mode    = 'A'.
  lt_layout-zebra       = 'X'.
  lt_layout-box_fname   = 'ZMARK'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
*     I_INTERFACE_CHECK        = ' '
*     I_BYPASSING_BUFFER       =
*     I_BUFFER_ACTIVE          =
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'F03_MY_STATUS'
      i_callback_user_command  = 'U_COMM'
*     I_CALLBACK_TOP_OF_PAGE   = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME         =
*     I_BACKGROUND_ID          = ' '
*     I_GRID_TITLE             =
*     I_GRID_SETTINGS          =
      is_layout_lvc            = lt_layout
      it_fieldcat_lvc          = lt_fcat
*     IT_EXCLUDING             =
*     IT_SPECIAL_GROUPS_LVC    =
*     IT_SORT_LVC              =
*     IT_FILTER_LVC            =
*     IT_HYPERLINK             =
*     IS_SEL_HIDE              =
*     I_DEFAULT                = 'X'
      i_save                   = 'X'
*     IS_VARIANT               = ''
*     IT_EVENTS                =
*     IT_EVENT_EXIT            =
*     IS_PRINT_LVC             =
*     IS_REPREP_ID_LVC         =
*     I_SCREEN_START_COLUMN    = 0
*     I_SCREEN_START_LINE      = 0
*     I_SCREEN_END_COLUMN      = 0
*     I_SCREEN_END_LINE        = 0
*     I_HTML_HEIGHT_TOP        =
*     I_HTML_HEIGHT_END        =
*     IT_ALV_GRAPHICS          =
*     IT_EXCEPT_QINFO_LVC      =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER  =
*     ES_EXIT_CAUSED_BY_USER   =
    TABLES
      t_outtab                 = lt_output
*   EXCEPTIONS
*     PROGRAM_ERROR            = 1
*     OTHERS                   = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.                    "alv_grid_display
 
*&---------------------------------------------------------------------*
*&      Form  alv_build_fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_build_fieldcat.
 
  DATA lv_fldcat TYPE lvc_s_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'FLAG'.
  lv_fldcat-scrtext_m = 'Flag'.
  lv_fldcat-just   = 'L'.
  lv_fldcat-icon   = 'X'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'AS4USER'.
  lv_fldcat-scrtext_m = 'User'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'AS4DATE'.
  lv_fldcat-scrtext_m = 'Date'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'KUNNR'.
  lv_fldcat-scrtext_m = 'Customer'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'BUKRS'.
  lv_fldcat-scrtext_m = 'CoCode'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'NAME1'.
  lv_fldcat-scrtext_m = 'Cust. Name'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'ORT01'.
  lv_fldcat-scrtext_m = 'City'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'STRAS'.
  lv_fldcat-scrtext_m = 'Street'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'INTF_DATE'.
  lv_fldcat-scrtext_m = 'Response (Date)'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'INTF_TIME'.
  lv_fldcat-scrtext_m = 'Response (Time)'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
  lv_fldcat-fieldname = 'INTF_RET'.
  lv_fldcat-scrtext_m = 'Response (Data)'.
  lv_fldcat-just   = 'L'.
  APPEND lv_fldcat TO lt_fcat.
  CLEAR lv_fldcat.
 
ENDFORM.                    "alv_build_fieldcat
 
*&---------------------------------------------------------------------*
*&      Form  alv_report_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_report_layout.
  lt_layout-cwidth_opt = 'X'.
  lt_layout-zebra = 'X'.
  lt_layout-col_opt = 'X'.
ENDFORM.                    "alv_report_layout
   

Wahyu Amaldi, M.Kom has written 177 articles

Hallo Pembaca,
Saya merupakan konsultan di dunia SAP dan merupakan Spesialis .Net Programming.
Saya gemar berbagi pengalaman mengenai SAP & Dunia Programming, dan jika ada sesuatu yang perlu ditanyakan, bisa hubungi saya di email berikut ini:

Email 1 : wahyu.amaldi@outlook.com
Email 2 : wahyu.amaldi@ilmuprogram.com

Semoga Artikel yang Anda baca di website ini berguna dan dapat membantu Anda dalam menemukan solusi.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>