Sample Code Upload Excel SAP ABAP with ALSM_EXCEL_TO_INTERNAL_TABLE

   

Seringkali, Programmer ABAP dan pengguna SAP memerlukan upload data dari Excel ke SAP.
Upload data ke sistem SAP dapat dikelola menggunakan alat SAP pihak ketiga atau menggunakan modul fungsi ABAP bawaan seperti ALSM_EXCEL_TO_INTERNAL_TABLE.
modul fungsi ALSM_EXCEL_TO_INTERNAL_TABLE membantu programmer ABAP untuk upload Excel ke tabel internal SAP (ITAB) dalam kode ABAP mereka.
Berikut merupakan contoh sample kode untuk Upload XLS menggunakan ALSM_EXCEL_TO_INTERNAL_TABLE:

  PARAMETERS pa_fname TYPE localfile OBLIGATORY LOWER CASE MEMORY ID fnm.
 
START-OF-SELECTION.
PERFORM readExcel CHANGING lt_data.
 
FORM readExcel CHANGING pt_data TYPE tt_data.
 
  DATA:
    lt_excel TYPE STANDARD TABLE OF alsmex_tabline,
    ls_excel TYPE alsmex_tabline,
    lv_data  TYPE tv_data,
    lv_error TYPE string.
 
 
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = pa_fname
      i_begin_col             = 1
      i_begin_row             = 1
      i_end_col               = co_max_col
      i_end_row               = co_max_row
    TABLES
      intern                  = lt_excel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
 
  IF sy-subrc NE 0.
    WRITE: / 'SY-SUBRC = ', sy-subrc.
    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_error.
    WRITE: / lv_error.
    STOP.
  ENDIF.
 
  LOOP AT lt_excel INTO ls_excel.
    lv_data = ls_excel-value.
    PERFORM itab_insert_value USING ls_excel-col ls_excel-row lv_data
                              CHANGING pt_data.
  ENDLOOP.
ENDFORM. 
 
FORM itab_insert_value USING    pi_col   TYPE tv_index
                                pi_row   TYPE tv_index
                                pi_value TYPE tv_data
                       CHANGING pt_data  TYPE tt_data.
 
ENDFORM.
   

Wahyu Amaldi, M.Kom has written 112 articles

Hi Reader, thank you for read this article, i hope this article can be useful.
If you will share knowladge to me, dont forget contact to me.

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

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>