Upload text file to internal table

Pada posting sebelumnya telah dijelaskan bagaimana get file dari local directory untuk mengambil file text yang akan diupload. Nah, pada postingan kali ini adalah contoh penggunaan function module untuk memproses file text yang diupload ke dalam internal table. Function yang digunakan untuk upload adalah GUI_UPLOAD.

*&---------------------------------------------------------------------*
*&      Data Declaration
*&---------------------------------------------------------------------*
TABLES: rlgrap.

TYPES: BEGIN OF ty_item,
        ebeln LIKE ekpo-ebeln,
        ebelp LIKE ekpo-ebelp,
      END OF ty_item.

DATA: t_item TYPE STANDARD TABLE OF ty_item WITH HEADER LINE.

SELECT-OPTIONS: s_file FOR rlgrap-filename NO INTERVALS NO-EXTENSION.

*&---------------------------------------------------------------------*
*&      Events
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_file-low.
  PERFORM f_help_for_file CHANGING s_file-low.

START-OF-SELECTION.
  PERFORM f_upload_data TABLES t_item.

  LOOP AT t_item.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = t_item-ebeln
      IMPORTING
        output = t_item-ebeln.
    MODIFY t_item.
  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  f_help_for_file
*&---------------------------------------------------------------------*
FORM f_help_for_file  CHANGING s_file-low.

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      static    = 'X'
    CHANGING
      file_name = s_file-low.

ENDFORM.                    " F_HELP_FOR_FILE

*&---------------------------------------------------------------------*
*&      Form  f_upload_data
*&---------------------------------------------------------------------*
FORM f_upload_data TABLES ft_table.
  DATA: ld_string TYPE string.

  ld_string = s_file-low.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = ld_string
      filetype                = 'ASC'
      has_field_separator     = ' '
    TABLES
      data_tab                = ft_table
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc NE 0.
    WRITE: 'error', sy-subrc.
    STOP.
  ENDIF.

ENDFORM.                    " F_UPLOAD_DATA
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s