‎2007 May 10 5:42 PM
Hi all,
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.
Does anyone have an idea??
Thanks
‎2007 May 10 5:44 PM
Hi,
How did you create the job??Is it through program..Or in SM36..
Did you release the job in SM36..
Thanks,
Naren
‎2007 May 10 5:45 PM
Hi
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.
Max
‎2007 May 10 5:46 PM
Hi
ensure that you are not using any GUI fun modules like (GUI_DOWNLOAD or GUI_UPLOAD)
in the code. because if you use them the code can not function in background.
otherwise it should create a file if you use OPEN DATASET..READ...TRANSFER commands
Reward points if useful
Regards
Anji
‎2007 May 10 5:47 PM
Hello,
Please check this.
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 <dsn> 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 <dsn> 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 <dsn> 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 <> 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 <dsn> 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 <> 0.
EXIT.
ENDIF.
WRITE / NUM.
ENDDO.
The output appears as follows:
1
2
3
4
5
10
20
30
40
50Don't forget to reward if useful...
regards,
Deepu.K
‎2007 May 11 11:23 AM
try this open statement
OPEN DATASET outfile FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
‎2007 May 15 7:26 AM
Hi
Please try this statement.
open dataset <b>outputfilename</b> for output in text mode encoding utf-8 ignoring
conversion errors.
This works very fine.
Vijaya Chamundi
‎2007 May 15 7:32 AM
Hi ,
Refer this code :
*TO DOWNLOAD FILE ONTO APPLICATION SERVER
OPEN DATASET FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT I_DATA INTO WA_DATA.
TRANSFER WA_DATA TO FILE.
ENDLOOP.
CLOSE DATASET FILE.
IF SY-SUBRC = 0.
MESSAGE I002.
ENDIF.
CLEAR FILE.
Reward points if helpful.
Regards,
Hemant
‎2007 May 15 7:44 AM
Hi,
First execute your program online to check whether it is downloading the file on application server or not?
1. If your program is not downloading the file on application server <b>online</b>, check your code.
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.
Regards,
Neeraj
‎2007 May 15 2:23 PM