<?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: formatting the file in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363858#M523197</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The SORT statement is definitly causing your problem, but if you want to sort by SSN in the file, then you must add the field names after the fact.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

* Add detail records
itab-EEN = ' 2348907'.
itab-LNAME = ' XYZ'.
itab-FNAME = 'ABC'.
itab-SSN = ' 011224567'
APPEND ITAB.
CLEAR ITAB.


* Check for line count
DESCRIBE TABLE ITAB LINES COUNTK.

IF COUNTK GT 0.

* SOrt by SSN
SORT ITAB BY SSN.


* Add your Field names now, using the INSERT statement.
itab-EEN = 'Emp ID'.
itab-LNAME = 'Last Name'.
itab-FNAME = 'First Name'.
itab-SSN = 'SSN'.
INSERT ITAB index 1.
CLEAR ITAB.

* Get the file
CALL FUNCTION 'FILE_GET_NAME'
        EXPORTING
             LOGICAL_FILENAME = 'EFGH'
*           WITH_FILE_EXTENSION = 'X'
          IMPORTING
            FILE_NAME = FNAME.

* Open and Write.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.
IF sy-subrc &amp;lt;&amp;gt; 0.
   WRITE / msg.
   STOP.
ENDIF.

LOOP AT ITAB.
    TRANSFER ITAB TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;RIch Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Jun 2007 18:49:34 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2007-06-05T18:49:34Z</dc:date>
    <item>
      <title>formatting the file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363855#M523194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question, need to format the file that I generate through the logical file path. i.e., The file has the data for various field values, however I need get the field names displayed at the start of the file. &lt;/P&gt;&lt;P&gt;I did something like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;itab -EEN = 'Emp ID'.&lt;/P&gt;&lt;P&gt;itab-LNAME = 'Last Name'.&lt;/P&gt;&lt;P&gt;itab-FNAME = 'First Name'.&lt;/P&gt;&lt;P&gt; itab-SSN = 'SSN'.&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt;CLEAR ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then loop through the internal table that had data for these fields and stored the data&lt;/P&gt;&lt;P&gt;itab -EEN = ' 2348907'.&lt;/P&gt;&lt;P&gt;itab-LNAME = ' XYZ'.&lt;/P&gt;&lt;P&gt;itab-FNAME = 'ABC'.&lt;/P&gt;&lt;P&gt; itab-SSN = ' 011224567'&lt;/P&gt;&lt;P&gt;APPEND ITAB.&lt;/P&gt;&lt;P&gt;CLEAR ITAB.&lt;/P&gt;&lt;P&gt;*****************&lt;/P&gt;&lt;P&gt;DESCRIBE TABLE ITAB LINES COUNTK.&lt;/P&gt;&lt;P&gt;IF COUNTK GT 0.&lt;/P&gt;&lt;P&gt; SORT ITAB BY SSN.&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'FILE_GET_NAME'&lt;/P&gt;&lt;P&gt;   EXPORTING&lt;/P&gt;&lt;P&gt;      LOGICAL_FILENAME = 'EFGH'&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    WITH_FILE_EXTENSION = 'X'&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;   IMPORTING&lt;/P&gt;&lt;P&gt;      FILE_NAME = FNAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.&lt;/P&gt;&lt;P&gt;IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;  WRITE / msg.&lt;/P&gt;&lt;P&gt;  STOP.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB.&lt;/P&gt;&lt;P&gt;  TRANSFER ITAB TO FNAME.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;CLOSE DATASET FNAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The file is getting generated  with the values first and then the text and I want the other way around. How can i do that? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Sk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2007 18:26:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363855#M523194</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-05T18:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: formatting the file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363856#M523195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data v_data(1024) type c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;concatenate itab-fld1 ',' itab-fld2 ','  into v_data.&lt;/P&gt;&lt;P&gt;TRANSFER v_data TO FNAME.&lt;/P&gt;&lt;P&gt;clear v_data.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2007 18:35:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363856#M523195</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-05T18:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: formatting the file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363857#M523196</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;Remove the line from your code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT ITAB BY SSN
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aRs&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2007 18:40:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363857#M523196</guid>
      <dc:creator>former_member194669</dc:creator>
      <dc:date>2007-06-05T18:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: formatting the file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363858#M523197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The SORT statement is definitly causing your problem, but if you want to sort by SSN in the file, then you must add the field names after the fact.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

* Add detail records
itab-EEN = ' 2348907'.
itab-LNAME = ' XYZ'.
itab-FNAME = 'ABC'.
itab-SSN = ' 011224567'
APPEND ITAB.
CLEAR ITAB.


* Check for line count
DESCRIBE TABLE ITAB LINES COUNTK.

IF COUNTK GT 0.

* SOrt by SSN
SORT ITAB BY SSN.


* Add your Field names now, using the INSERT statement.
itab-EEN = 'Emp ID'.
itab-LNAME = 'Last Name'.
itab-FNAME = 'First Name'.
itab-SSN = 'SSN'.
INSERT ITAB index 1.
CLEAR ITAB.

* Get the file
CALL FUNCTION 'FILE_GET_NAME'
        EXPORTING
             LOGICAL_FILENAME = 'EFGH'
*           WITH_FILE_EXTENSION = 'X'
          IMPORTING
            FILE_NAME = FNAME.

* Open and Write.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE MESSAGE msg.
IF sy-subrc &amp;lt;&amp;gt; 0.
   WRITE / msg.
   STOP.
ENDIF.

LOOP AT ITAB.
    TRANSFER ITAB TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;RIch Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2007 18:49:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363858#M523197</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-06-05T18:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: formatting the file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363859#M523198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks guys. It worked. However, can I format the data further like storing into a table? &lt;/P&gt;&lt;P&gt;SK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2007 19:52:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363859#M523198</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-05T19:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: formatting the file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363860#M523199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry. storing the data in the table format.&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;SK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2007 19:53:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/formatting-the-file/m-p/2363860#M523199</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-05T19:53:41Z</dc:date>
    </item>
  </channel>
</rss>

