04-04-2006 5:26 AM
Hi All,
Could you please help me, how to read the contents of an application server file which is in binary mode.
Thanks for your help in advance.
04-04-2006 5:30 AM
Suresh,
You can open the files for input / output in BINARY mode.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE
OPEN DATASET FNAME FOR INPUT IN BINARY MODE
regards,
Ravi
Note : Please mark the helpful answers
04-04-2006 5:32 AM
04-04-2006 5:38 AM
Hai suresh,
To read data from a file on the application server, use the READ DATASET statement:
Syntax
READ DATASET <dsn> INTO <f> [LENGTH <len>].
regards,
praba.
04-04-2006 5:42 AM
hi praba, i need syntax for read dataset in the case of binary file reading, can you help me
04-04-2006 5:47 AM
Hi Suresh,
The way in which the file was opened during the statement OPEN DATASET determines how records are read from the dataset.
If the file was opened in text mode (addition IN TEXT MODE or IN LEGACY TEXT MODE beim OPEN DATASET), the system assumes that the file is structured line by line. Accordingly, read commands always refer to one line. Line separators are viewed as structuring units and therefore automatically filtered.
If the file was opened in binary mode (addition IN BINARY MODE or IN LEGACY BINARY MODE with OPEN DATASET), the system expects an unstructured sequence of bytes. Length specifications accordingly refer to the number of bytes.
The number of characters or bytes read by calling READ DATASET depends, on the one hand, on the opening mode of the file, and, on the other hand, on the type of target field f.
So, the read has to be used in the same way for both binary and text modes. Its the opening of the dataset that makes the difference.
Hope this will help.
Thanks,
Rashmi.
04-04-2006 6:06 AM
Hi Rashmi , if my file is of structure
File Name K01 MIFILE A 10
Member Name MIMBR A 10
Creation Date Yymmdd K02 MICRTDT P 6 0
Creation Time Hhmmss K03 MICRTTM P 6 0
Nbr of Current Rcds MINCRCDS P 10 0
then can you please tell me the syntax to read it
04-04-2006 6:24 AM
Hi,
Declare the variable to number of characters that you have in one line.
As per teh structure that you have given i think one line for you will be around 42 characters.
So,
Open dataset <dataset name> for input in binary mode.
read dataset <dataset name> into <var> length 42.
Here 42 is the length in bytes. for example char is 1 byte, int will be 2 bytes. So based on this we have to see the length.
Thanks,
Rashmi.
04-04-2006 6:46 AM
Hi Rashmi,
Thanks for helpful answer, cab you pls send your yahoo mail id.
04-04-2006 5:46 AM
hai suresh,
here is an example program for it,
while working in binary mode, you can use the LENGTH addition to find out the length of the data transferred to <f>. The system sets the value of the variable <len> to this length.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT1(12) VALUE 'abcdefghijkl',
TEXT2(5),
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2, LENG.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
hope this will be helpful for u.
regards,
praba.
04-04-2006 5:59 AM
Hi
To read data from a file on the application server, use the READ DATASET statement:
Syntax
READ DATASET <dsn> INTO <f> [LENGTH <len>].
This statement reads data from the file <dsn> into the variable <f>. In order to determine into which variable you should read data from a file, you need to know the structure of the file.
You can specify the transfer mode in the OPEN DATASET statement. If you have not already opened the file for reading, the system tries to open it either in binary mode, or using the additions from the last OPEN DATASET statement. However, it is good practice only to open files using the OPEN DATASET statement. For further information about the OPEN DATASET statement and the naming conventions for files, refer to Opening a File.
If the system was able to read data successfully, SY-SUBRC is set to 0. When the end of the file is reached, SY-SUBRC is set to 4. If the file could not be opened, SY-SUBRC is set to 8.
If you are working in binary mode, you can use the LENGTH addition to find out the length of the data transferred to <f>. The system sets the value of the variable <len> to this length.
DATA FNAME(60) VALUE 'myfile'.
DATA: TEXT1(12) VALUE 'abcdefghijkl',
TEXT2(5),
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2, LENG.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
I hope this will help you to solve your problem.
Thanks
Mrutyunjaya Tripathy
04-04-2006 6:30 AM
sy-subrc = 0 Record read from file
sy-subrc = 4 End of file reached
data: w_dataset1(27) value '/var/textfile.txt',
w_dataset2(27) value '/var/outfile.txt'.
data:begin of itab1 occurs 0, "Text file format
MIFILE A 10
MIMBR A 10
MICRTDT P 6 0
MICRTTM P 6 0
MINCRCDS P 10 0
end of itab1.
*Uploading of text file from Application server.
open dataset w_dataset1 for input in text mode.
do.
if sy-subrc <> 0.
exit.
endif.
read dataset w_dataset1 into itab1.
append itab1.
clear itab1.
enddo.
close dataset w_dataset1.
U have to handle all time and date relatlated changes after reading file.
Hope it will be useful.
regards
vinod