<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: loop and parse a text file in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227037#M478738</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If u know exactly the number of fields u can solve this problem i guess.&lt;/P&gt;&lt;P&gt;keep a counter variable for counting the fields moved to ur internal table.&lt;/P&gt;&lt;P&gt;Try the following code.&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;move fields to internal table work area.&lt;/P&gt;&lt;P&gt;if count = 7.&lt;/P&gt;&lt;P&gt;append.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if helpful.&lt;/P&gt;&lt;P&gt;Bye.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 May 2007 14:12:09 GMT</pubDate>
    <dc:creator>pradeep_nellore</dc:creator>
    <dc:date>2007-05-04T14:12:09Z</dc:date>
    <item>
      <title>loop and parse a text file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227034#M478735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 3 different text files that are tab delimited.  My problem is that data for each instance could be spread over 2 or more different text lines, such as a company name and address  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ABC Co.&lt;/P&gt;&lt;P&gt;1234 My Dr.&lt;/P&gt;&lt;P&gt;Anywhere, VA 12345&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEF Co.&lt;/P&gt;&lt;P&gt;5678 My Dr.&lt;/P&gt;&lt;P&gt;Anywhere, VA 67890&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to just open the file, loop through all lines, and parse out the relevant data to put into internal tables?  Get Company name, Street Address, City, State, Zip?  Basically the files are reports from some program that export out to text file format.  The have header records and have page breaks that causes some data to be spread out over 2 pages.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't think the GUI_UPLOAD &amp;amp; GUI_DOWNLOAD will help in my case&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help or suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2007 18:44:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227034#M478735</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-01T18:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: loop and parse a text file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227035#M478736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it will imply some errors if you do not have any record type for the different text lines. What I see in your example ist 3 text lines per company followed by 1 space line (?).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could use this as a rough pattern: After a blank line comes the company name. next line contains street No folloewd by street name. Next line is city name folowed by comma, followed by state abbreviation followed by postal code. Use patterns to verify/identify line content; i.e. line starting with digits is for street, line containing comma is city etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to identify the pattern structure of your input file and do some tests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AFAIK SAP does not offer any standard method for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2007 19:27:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227035#M478736</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2007-05-01T19:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: loop and parse a text file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227036#M478737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;could you explain the record type functionality a little further?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 May 2007 13:37:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227036#M478737</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-04T13:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: loop and parse a text file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227037#M478738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If u know exactly the number of fields u can solve this problem i guess.&lt;/P&gt;&lt;P&gt;keep a counter variable for counting the fields moved to ur internal table.&lt;/P&gt;&lt;P&gt;Try the following code.&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;move fields to internal table work area.&lt;/P&gt;&lt;P&gt;if count = 7.&lt;/P&gt;&lt;P&gt;append.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if helpful.&lt;/P&gt;&lt;P&gt;Bye.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 May 2007 14:12:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227037#M478738</guid>
      <dc:creator>pradeep_nellore</dc:creator>
      <dc:date>2007-05-04T14:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: loop and parse a text file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227038#M478739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in file transfer it is a common method to use the first 1-3 characters of a record to distinguish the record structure; i.e. '01' for header, '02' for item and '03' for trailer or consistency check. Or in your case '01' for company name, '02' street, '03' state or whatever.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each record type defines/expects it's own structure. Using this you can parse the file an handle the records according to their type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each record processed you would use a case statement for the record types.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But a precondition for this is that the exporting program creates the record type prefix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope you got what I'm talking about.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 May 2007 14:25:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227038#M478739</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2007-05-04T14:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: loop and parse a text file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227039#M478740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok now i can open a file and loop using this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPEN DATASET v_fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.&lt;/P&gt;&lt;P&gt;IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  DO.&lt;/P&gt;&lt;P&gt;    READ DATASET v_fname INTO srow.&lt;/P&gt;&lt;P&gt;    IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;    WRITE: / srow.&lt;/P&gt;&lt;P&gt;  ENDDO.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;CLOSE DATASET v_fname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now I have sRow equal to lines like this:&lt;/P&gt;&lt;P&gt;  DATE    DOCUMENT        VENDORID   NAME                               GROSS AMT      DISCOUNT      NET CHECK&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------------------------------------------------------------------------" /&gt;&lt;P&gt;04/26/07  40012081        COFFEE      COFFEE HOUSE                           56.00          0.00          56.00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to be able to parse out each field into their own variables for later use.  Split probably will NOT work in this case because the only character to split would be a blank space, but that would split the vendor name and that can't happen.  Is there a string function that goes like this:&lt;/P&gt;&lt;P&gt;var1 = substring(sRow, 1, &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;   '04/26/07&lt;/P&gt;&lt;P&gt;var2 = substring(sRow, 9, &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;   '40012081&lt;/P&gt;&lt;P&gt;var3 = substring(sRow, 12, 10)  'COFFEE&lt;/P&gt;&lt;P&gt;var4 = substring(sRow, 23, 15)  'COFFEE HOUSE&lt;/P&gt;&lt;P&gt;var5 = substring(sRow, 39, &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;  ' 56.00&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for all the help so far&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 May 2007 19:58:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-parse-a-text-file/m-p/2227039#M478740</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-07T19:58:42Z</dc:date>
    </item>
  </channel>
</rss>

