<?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 Modify File Content in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/modify-file-content/m-p/1787602#M339093</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to read the line by line of a CSV file and replace string1 in the line with string2 in the same line and update the file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have the following code,&lt;/P&gt;&lt;P&gt;but the below code will add a new line with the replaced string, instead i want to modify the same line instead of adding a new line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPEN DATASET chq_ip_file_path for UPDATE in text mode encoding default.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHILE sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  READ DATASET chq_ip_file_path INTO xtext.&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;     split xtext at ';' into xone xtwo xthree xfour.&lt;/P&gt;&lt;P&gt;     if xthree &amp;lt;&amp;gt; 'CCAHIER' and xthree(3) = 'CCA'.&lt;/P&gt;&lt;P&gt;        REPLACE ALL OCCURRENCES OF '0ACCOUNT'&lt;/P&gt;&lt;P&gt;                    IN xtext WITH 'ICSKOBLA'.&lt;/P&gt;&lt;P&gt;        TRANSFER xtext TO chq_ip_file_path.&lt;/P&gt;&lt;P&gt;     endif.&lt;/P&gt;&lt;P&gt;  ELSE.&lt;/P&gt;&lt;P&gt;    EXIT.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDWHILE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Dec 2006 12:12:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-12-28T12:12:51Z</dc:date>
    <item>
      <title>Modify File Content</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/modify-file-content/m-p/1787602#M339093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to read the line by line of a CSV file and replace string1 in the line with string2 in the same line and update the file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have the following code,&lt;/P&gt;&lt;P&gt;but the below code will add a new line with the replaced string, instead i want to modify the same line instead of adding a new line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPEN DATASET chq_ip_file_path for UPDATE in text mode encoding default.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHILE sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  READ DATASET chq_ip_file_path INTO xtext.&lt;/P&gt;&lt;P&gt;  IF sy-subrc = 0.&lt;/P&gt;&lt;P&gt;     split xtext at ';' into xone xtwo xthree xfour.&lt;/P&gt;&lt;P&gt;     if xthree &amp;lt;&amp;gt; 'CCAHIER' and xthree(3) = 'CCA'.&lt;/P&gt;&lt;P&gt;        REPLACE ALL OCCURRENCES OF '0ACCOUNT'&lt;/P&gt;&lt;P&gt;                    IN xtext WITH 'ICSKOBLA'.&lt;/P&gt;&lt;P&gt;        TRANSFER xtext TO chq_ip_file_path.&lt;/P&gt;&lt;P&gt;     endif.&lt;/P&gt;&lt;P&gt;  ELSE.&lt;/P&gt;&lt;P&gt;    EXIT.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDWHILE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Dec 2006 12:12:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/modify-file-content/m-p/1787602#M339093</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-28T12:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Modify File Content</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/modify-file-content/m-p/1787603#M339094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have to switch the cursor position when updating the dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  ZUS_SDN_DATASET_UPDATE
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*

REPORT  zus_sdn_dataset_update.


CONSTANTS:
  gc_file    TYPE string  VALUE 'dataset_update.txt'.


DATA:
  gd_string    TYPE string,
  gd_pos_old   TYPE i,
  gd_pos_curr  TYPE i.


START-OF-SELECTION.


  DELETE DATASET gc_file.

  OPEN DATASET gc_file FOR OUTPUT IN TEXT MODE
                                  ENCODING DEFAULT.
  gd_string = 'MODIFY;THIS;TEXT'.
  TRANSFER gd_string TO gc_file.
  gd_string = 'REPLACE;THIS;TEXT'.
  TRANSFER gd_string TO gc_file.
  gd_string = 'DISPLAY;THIS;TEXT'.
  TRANSFER gd_string TO gc_file.

  CLOSE DATASET gc_file.
* NOTE: create sample dataset with three lines


  OPEN DATASET gc_file FOR UPDATE IN TEXT MODE
                                  ENCODING DEFAULT.

  WHILE ( syst-subrc = 0 ).
*   Store old cursor position before reading line
    GET DATASET gc_file POSITION gd_pos_old.
    READ DATASET gc_file INTO gd_string.
    IF ( syst-subrc = 0 ).
*     Store current cursor position after reading line
      GET DATASET gc_file POSITION gd_pos_curr.

      IF ( gd_string CS 'REPLACE' ).
        REPLACE ALL OCCURRENCES OF 'T' IN gd_string WITH '?'.

*       Set cursor to old position to overwrite line
        SET DATASET gc_file POSITION gd_pos_old.
        TRANSFER gd_string TO gc_file.
*       Set cursor back to last (= current) position
        SET DATASET gc_file POSITION gd_pos_curr.
      ENDIF.

    ENDIF.
  ENDWHILE.
  CLOSE DATASET gc_file.

END-OF-SELECTION.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Dec 2006 13:00:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/modify-file-content/m-p/1787603#M339094</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2006-12-28T13:00:55Z</dc:date>
    </item>
  </channel>
</rss>

