Skip to Content
avatar image
Former Member

Reading from txt file

Hi all,

I need to read a TAB separated txt file line by line.

I know that I can use GUI_UPLOAD, but it uses an internal table where I have to define a structure and the field seperator.

I would need a function that works like the READ dataset statement which reads the input file line by line.

thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 07, 2010 at 02:33 PM

    This is pretty basic - you can use GUI_UPLOAD to read the file into an internal table that has a structure large enough to contain the full length of any record.

    Then parse each record as it is read and assign it to a separate internal table that has the structure of this record.

    Rob

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 07, 2010 at 01:05 PM

    Hello,

    upload the file from presentation server to application server using Tcode CG3Y/CG3Z and then read the data from application server using read dataset.

    Thanks.

    Ramya.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 07, 2010 at 01:07 PM

    try like this.

    data:it type table of string,
    i_tab TYPE TABLE OF string,
    wa type string.
      FIELD-SYMBOLS:
        <fs_line> TYPE string,
        <fs_comp> TYPE ANY.
    
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = 'C:\proddata\po.txt'
        FILETYPE                      = 'ASC'
      tables
        data_tab                      = it[].
    
    loop at it into wa.
    
    clear i_tab[].
    
        SPLIT wa AT
              cl_abap_char_utilities=>horizontal_tab
              INTO TABLE i_tab.
    
      LOOP AT i_tab ASSIGNING <fs_line>.
        ASSIGN COMPONENT sy-tabix OF STRUCTURE pc_marc TO <fs_comp>.
    if sy-subrc = 0.
        <fs_comp> = <fs_line>.
    endif.
      ENDLOOP.
    endloop.
    

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2010 at 07:01 AM

    Thanks

    Add comment
    10|10000 characters needed characters exceeded