<?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: Create file in background in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189619#M466685</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;Please try this statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;open dataset &amp;lt;b&amp;gt;outputfilename&amp;lt;/b&amp;gt; for output in text mode encoding utf-8 ignoring&lt;/P&gt;&lt;P&gt;conversion errors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works very fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vijaya Chamundi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 May 2007 06:26:00 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-15T06:26:00Z</dc:date>
    <item>
      <title>Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189613#M466679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to create a file on the application server through background. When I go see my jobs there is nothing there and the file is not being created. I use open/close dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have an idea??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 16:42:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189613#M466679</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T16:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189614#M466680</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;  How did you create the job??Is it through program..Or in SM36..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Did you release the job in SM36..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Naren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 16:44:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189614#M466680</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T16:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189615#M466681</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;U should show us your code where u use OPEN statament, generally the file is not created because the authorizations to write on SAP SERVER are missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 16:45:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189615#M466681</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T16:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189616#M466682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;ensure that you are not using any GUI fun modules like (GUI_DOWNLOAD or GUI_UPLOAD)&lt;/P&gt;&lt;P&gt;in the code. because if you use them the code can not function in background.&lt;/P&gt;&lt;P&gt;otherwise it should create a file if you use OPEN DATASET..READ...TRANSFER  commands&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Anji&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 16:46:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189616#M466682</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T16:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189617#M466683</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;          Please check this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; Opening a File for Read Access 

To open a file for reading, use the FOR INPUT addition to the OPEN DATASET statement.

Syntax

OPEN DATASET &amp;lt;dsn&amp;gt; FOR INPUT.

The file must already exist, otherwise, the system sets SY-SUBRC to 8, and ignores the statement. 

If the file exists and is already open (for read or write access, or for appending), the position is reset to the beginning of the file. However, it is good programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File).



DATA FNAME(60) VALUE 'myfile'.

OPEN DATASET FNAME FOR INPUT.

IF SY-SUBRC = 0.
WRITE / 'File opened'.
.....
ELSE.
WRITE / 'File not found'.
ENDIF.

This example opens the file "myfile" for reading. 

-----------------------------
To open a file for writing, use the FOR OUTPUT addition to the OPEN DATASET statement.

Syntax

OPEN DATASET &amp;lt;dsn&amp;gt; FOR OUTPUT.

If the file does not already exist, it is created automatically. If it does already exist, but is closed, its contents are overwritten. If the file exists and is already open (for read or write access, or for appending), the position is reset to the beginning of the file. If the system can open the file &amp;lt;dsn&amp;gt; successfully, SY-SUBRC is set to 0. If not, it is set to 8.



DATA: MESS(60),
FNAME(10) VALUE '/tmp'.

OPEN DATASET FNAME FOR OUTPUT MESSAGE MESS. 

IF SY-SUBRC &amp;lt;&amp;gt; 0.
WRITE: 'SY-SUBRC:', SY-SUBRC,
/ 'System Message:', MESS.
ENDIF.

If the R/3 System is ruining under UNIX, the output looks like this: 



The system cannot open the file, since the name you specified is that of a directory.

-----------------------------
To open a file so that you can append data to the end of it, use the FOR APPENDING addition in the OPEN DATASET statement:

Syntax

OPEN DATASET &amp;lt;dsn&amp;gt; FOR APPENDING.

This statement opens a file to which you can append data. If the file does not already exist, it is created automatically. If it does exist, but is closed, the system opens it, and sets the position to the end of the file. If the file exists and is already open (for read or write access, or for appending), the position is set to the end of the file. SY-SUBRC is always 0.



It is good programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File).



DATA FNAME(60) VALUE 'myfile'.

DATA NUM TYPE I.

OPEN DATASET FNAME FOR OUTPUT.
DO 5 TIMES.
NUM = NUM + 1.
TRANSFER NUM TO FNAME.
ENDDO.

OPEN DATASET FNAME FOR INPUT.

OPEN DATASET FNAME FOR APPENDING.
NUM = 0.
DO 5 TIMES.
NUM = NUM + 10.
TRANSFER NUM TO FNAME.
ENDDO.

OPEN DATASET FNAME FOR INPUT.
DO.
READ DATASET FNAME INTO NUM.
IF SY-SUBRC &amp;lt;&amp;gt; 0.
EXIT.
ENDIF.
WRITE / NUM.
ENDDO.

The output appears as follows:

1
2
3
4
5
10
20
30
40
50&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't forget to reward if useful... &lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Deepu.K&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2007 16:47:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189617#M466683</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-10T16:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189618#M466684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try this open statement&lt;/P&gt;&lt;P&gt;  OPEN DATASET outfile FOR APPENDING IN TEXT MODE ENCODING DEFAULT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 May 2007 10:23:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189618#M466684</guid>
      <dc:creator>former_member189059</dc:creator>
      <dc:date>2007-05-11T10:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189619#M466685</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;Please try this statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;open dataset &amp;lt;b&amp;gt;outputfilename&amp;lt;/b&amp;gt; for output in text mode encoding utf-8 ignoring&lt;/P&gt;&lt;P&gt;conversion errors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works very fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vijaya Chamundi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2007 06:26:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189619#M466685</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-15T06:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189620#M466686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;          Refer this code :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*TO DOWNLOAD FILE ONTO APPLICATION SERVER&lt;/P&gt;&lt;P&gt; OPEN DATASET FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.&lt;/P&gt;&lt;P&gt; LOOP AT I_DATA INTO WA_DATA.&lt;/P&gt;&lt;P&gt; TRANSFER WA_DATA TO FILE.&lt;/P&gt;&lt;P&gt; ENDLOOP.&lt;/P&gt;&lt;P&gt; CLOSE DATASET FILE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt; MESSAGE I002.&lt;/P&gt;&lt;P&gt; ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; CLEAR FILE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hemant&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2007 06:32:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189620#M466686</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-15T06:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189621#M466687</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;First execute your program online to check whether it is downloading the file on application server or not?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. If your program is not downloading the file on application server &amp;lt;b&amp;gt;online&amp;lt;/b&amp;gt;, check your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. If your program is downloading the file online than use appropriate messages in your program and check the job log to find the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Neeraj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2007 06:44:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189621#M466687</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-15T06:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create file in background</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189622#M466688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all for ur answers!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2007 13:23:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-file-in-background/m-p/2189622#M466688</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-15T13:23:10Z</dc:date>
    </item>
  </channel>
</rss>

