Skip to Content
author's profile photo Former Member
Former Member

with comma delimiter file read

Hi All,

I'm trying to read (READ DATASET file_name INTO itab) a file from app. server using "open dataset" statement and appending fetched data into internal table.

But I like to read the data fields with comma delimiter.

Please let me know Any method available.

Thank You,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jan 08, 2007 at 09:43 PM

    Here is basically what you need to do, of source you can shorten this up a bit.

    
    report zrich_0001.
    
    
    data: begin of itab occurs 0,
          field type string,
          end   of itab.
    
    data: begin of itab2 occurs 0,
          fld1(10) type c,
          fld2(10) type c,
          fld3(10) type c,
          end   of itab2.
    
    data:
          dsn(100) value '/usr/sap/TST/sys/test.txt'.
    
    
    clear itab.  refresh itab.
    clear itab2. refresh itab2.
    
    * Read the data.
    open dataset dsn for input in binary mode.
    do.
      read dataset dsn into itab-field.
      if sy-subrc = 0.
        append itab.
      else.
        exit.
      endif.
    enddo.
    close dataset dsn.
    
    * Split the record into specific fields of another itab and append
    loop at itab.
       split itab-field at ',' into itab2-fld1 itab2-fld2 itab2-fld3.
       append itab2.
    endloop.
    
    Loop at itab2.
      write:/ itab2-fld1, itab2-fld2, itab2-fld3.
    endloop.
    
    

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

    • For example, this is probably better way to go.

      
      report zrich_0001.
      
      data: str type string.
      
      data: begin of itab occurs 0,
            fld1(10) type c,
            fld2(10) type c,
            fld3(10) type c,
            end   of itab.
      
      data:
            dsn(100) value '/usr/sap/TST/sys/test.txt'.
      
      clear itab.  refresh itab.
      
      * Read the data.
      open dataset dsn for input in binary mode.
      do.
        read dataset dsn into str.
        if sy-subrc = 0.
         split str at ',' into itab-fld1 itab-fld2 itab-fld3.
          append itab.
        else.
          exit.
        endif.
      enddo.
      close dataset dsn.
      
      
      Loop at itab.
        write:/ itab-fld1, itab-fld2, itab-fld3.
      endloop.
      
      

      Regards,

      Rich Heilman

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 09:39 PM

    After the read, you can:

    SPLIT itab AT ',' INTO TABLE wa_itab.
    

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.