Upload Tab delimited file from PC into ABAP internal table

ABAP code for uploading a TAB delimited file into an internal table. See code below for structures. The code is base on uploading a simple txt file.

*&---------------------------------------------------------------------*
*& Report  ZLOTTO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZLOTTO.
TABLES: zlotresults.
PARAMETERS: p_infile  LIKE rlgrap-filename
                        OBLIGATORY DEFAULT  'C:/'.
*DATA: ld_file LIKE rlgrap-filename.
DATA: gd_file type string.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
    DRAWNO type string,
    DRAWDAY type string,
    DD type string,
    MMM type string,
    YYYY type string,
    NUM1 type string,
    NUM2 type string,
    NUM3 type string,
    NUM4 type string,
    NUM5 type string,
    NUM6 type string,
    BNUM type string,
    JACKPOT type string,
    WINS type string,
    MACHINE type string,
    BALLSET type string,
    END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
      wa_record TYPE t_record.
data: wa_results type zlotresults.
TYPES: begin of t_datatab,
  row type string,
 end of t_datatab.
data: it_datatab type STANDARD TABLE OF t_datatab,
      wa_datatab like line of it_datatab.
constants:
    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            def_filename     = p_infile
            mask             = ',*.txt.'
            mode             = 'O'
            title            = 'Upload File'(078)
       IMPORTING
            filename         = p_infile
       EXCEPTIONS
            inv_winsys       = 1
            no_batch         = 2
            selection_cancel = 3
            selection_error  = 4
            OTHERS           = 5.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
  gd_file = p_infile.
  CALL FUNCTION 'GUI_UPLOAD'
       EXPORTING
            filename        = gd_file
            filetype        = 'ASC'
       TABLES
            data_tab        = it_datatab
       EXCEPTIONS
            file_open_error = 1
            OTHERS          = 2.
  IF sy-subrc EQ 0.
    LOOP AT it_datatab into wa_datatab.
      SPLIT wa_datatab-row AT ',' INTO wa_record-DRAWNO
                                   wa_record-DRAWDAY
                                   wa_record-DD
                                   wa_record-MMM
                                   wa_record-YYYY
                                   wa_record-NUM1
                                   wa_record-NUM2
                                   wa_record-NUM3
                                   wa_record-NUM4
                                   wa_record-NUM5
                                   wa_record-NUM6
                                   wa_record-BNUM
                                   wa_record-JACKPOT
                                   wa_record-WINS
                                   wa_record-MACHINE
                                   wa_record-BALLSET.
*      MOVE-CORRESPONDING wa_uploadtxt TO wa_record.
      APPEND wa_record TO it_record.
    ENDLOOP.
  ENDIF.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
* Display report data for illustration purposes
LOOP AT it_record INTO wa_record.
  TRANSLATE wa_record-drawday to UPPER CASE.
  TRANSLATE wa_record-MMM to UPPER CASE.
  check wa_record-drawday ne 'DAY' and wa_record-MMM ne 'MMM'.
  wa_results-drawno  = wa_record-DRAWNO.
  case wa_record-mmm.
    when 'JAN'.
      wa_record-mmm = '01'.
    when 'FEB'.
      wa_record-mmm = '02'.
    when 'MAR'.
      wa_record-mmm = '03'.
    when 'APR'.
      wa_record-mmm = '04'.
    when 'MAY'.
      wa_record-mmm = '05'.
    when 'JUN'.
      wa_record-mmm = '06'.
    when 'JUL'.
      wa_record-mmm = '07'.
    when 'AUG'.
      wa_record-mmm = '08'.
    when 'SEP'.
      wa_record-mmm = '09'.
    when 'OCT'.
      wa_record-mmm = '10'.
    when 'NOV'.
      wa_record-mmm = '11'.
    when 'DEC'.
      wa_record-mmm = '12'.
  endcase.
  CONCATENATE wa_record-YYYY wa_record-MMM wa_record-DD
                                 into wa_results-drawdate.
  shift wa_record-drawday LEFT DELETING LEADING space.
  wa_results-drawday = wa_record-DRAWDAY.
  shift wa_record-machine LEFT DELETING LEADING space.
  wa_results-machine = wa_record-MACHINE.
  shift wa_record-ballset LEFT DELETING LEADING space.
  wa_results-ballset = wa_record-BALLSET.
  wa_results-NUM1    = wa_record-NUM1.
  wa_results-NUM2    = wa_record-NUM2.
  wa_results-NUM3    = wa_record-NUM3.
  wa_results-NUM4    = wa_record-NUM4.
  wa_results-NUM5    = wa_record-NUM5.
  wa_results-NUM6    = wa_record-NUM6.
  wa_results-BNUM    = wa_record-BNUM.
  wa_results-jackpot = wa_record-JACKPOT.
  wa_results-wins    = wa_record-WINS.
  modify  zlotresults from wa_results.
ENDLOOP.

Related Articles

SAP applications and ABAP reports that process data files stored on your PC or within SAP
HEX codes and there associated ABAP declaration within SAP
Display files on SAP Application Server(UNIX)
Browse files on SAP Application Server(UNIX)
Downloading files to PC(Presentation Server)
Downloading files to SAP Application Server
Popup window to select a File using function module WS_FILENAME_GET
Get list of files within specific directory or SAP Application server
Directory selection for ABAP report using SAP method DIRECTORY_BROWSE
File Selection for ABAP report using SAP object method FILE_OPEN_DIALOG
Save file location popup on ABAP report selection screen using FILE_SAVE_DIALOG
ABAP Upload and download Function Modules in SAP
SAP File Selection Window - various methods of adding a file selection popup to your ABAP report
Upload and download files into and out of SAP or your PC
ABAP to check if file exists before downloading from SAP
SAP Upload Excel document into internal table
ABAP to Upload Excel document into internal table on SAP system including .xlsx
Upload Excel document into ABAP internal table
ABAP Uploading files from PC to SAP R/3 system
ABAP to Upload files from SAP Application Server
Upload Tab delimited file from PC into ABAP internal table
Upload Tab delimited file from application server into ABAP internal table
Example Excel Spreadsheet used to demo SAP upload and download using ABAP
Download file from SAP unix system to your desktop using transaction SXDA