2008 May 22 7:12 AM
hello all
open dataset <dataset name> for input in text mode encoding default.
in above syntax
what is text mode and what is binary mode?
what is encoding default and what is the use of encoding default?
hello all
open dataset <dataset name> for input in text mode encoding default.
in above syntax
what is text mode and what is binary mode?
what is encoding default and what is the use of encoding default?
2008 May 22 7:13 AM
Hi,
datasets are the file son the application server.
open dataset opens the file for reading / writing or appending records.
read dataset reads the data from teh file to the work area / variables of the program
close dataset closes the file on the application server.
Open Dataset is used to read or write on to application server ... other than that i am not sure that there exists any way to do the same ... here is a short description for that
FILE HANDLING IN SAP
Introduction
u2022 Files on application server are sequential files.
u2022 Files on presentation server / workstation are local files.
u2022 A sequential file is also called a dataset.
Handling of Sequential file
Three steps are involved in sequential file handling
u2022 OPEN
u2022 PROCESS
u2022 CLOSE
Here processing of file can be READING a file or WRITING on to a file.
OPEN FILE
Before data can be processed, a file needs to be opened.
After processing file is closed.
Syntax:
OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}
IN {TEXT/BINARY} MODE
This statement returns SY_SUBRC as 0 for successful opening of file or 8, if unsuccessful.
OUTPUT: Opens the file for writing. If the dataset already exists, this will place the cursor at the start of the dataset,
the old contents get deleted at the end of the program or when the CLOSE DATASET is encountered.
INPUT: Opens a file for READ and places the cursor at the beginning of the file.
FOR APPENDING: Opens the file for writing and places the cursor at the end of file. If the file does not exist, it is generated.
BINARY MODE: The READ or TRANSFER will be character wise. Each time u2018nu2019u2019 characters are READ or transferred.
The next READ or TRANSFER will start from the next character position and not on the next line.
IN TEXT MODE: The READ or TRANSFER will start at the beginning of a new line each time.
If for READ, the destination is shorter than the source, it gets truncated.
If destination is longer, then it is padded with spaces.
Defaults: If nothing is mentioned, then defaults are FOR INPUT and in BINARY MODE.
PROCESS FILE:
Processing a file involves READing the file or Writing on to file TRANSFER.
TRANSFER Statement
Syntax:
TRANSFER <field> TO <file name>.
<Field> can also be a field string / work area / DDIC structure.
Each transfer statement writes a statement to the dataset. In binary mode, it writes the length of the field to the dataset.
In text mode, it writes one line to the dataset.
If the file is not already open, TRANSFER tries to OPEN file FOR OUTPUT (IN BINARY MODE) or using the last OPEN DATASET statement for this file.
IF FILE HANDLING, TRANSFER IS THE ONLY STATEMENT WHICH DOES NOT RETURN SY-SUBRC
READ Statement
Syntax:
READ DATASET <file name> INTO <field>.
<Field> can also be a field string / work area / DDIC structure.
Each READ will get one record from the dataset.
In binary mode it reads the length of the field and in text mode it reads each line.
CLOSE FILE:
The program will close all sequential files, which are open at the end of the program.
However, it is a good programming practice to explicitly close all the datasets that were opened.
Syntax:
CLOSE DATASET <file name>.
SY-SUBRC will be set to 0 or 8 depending on whether the CLOSE is successful or not.
DELETE FILE:
A dataset can be deleted.
Syntax:
DELETE DATASET <file name>.
SY-SUBRC will be set to 0 or 8 depending on whether the DELETE is successful or not.
Pseudo logic for processing the sequential files:
For reading:
Open dataset for input in a particular mode.
Start DO loop.
Read dataset into a field.
If READ is not successful.
Exit the loop.
Endif.
Do relevant processing for that record.
End the do loop.
Close the dataset.
For writing:
Open dataset for output / Appending in a particular mode.
Populate the field that is to be transferred.
TRANSFER the filed to a dataset.
Close the dataset.
Reward for useful answers.
Regards,
Raj.
2008 May 22 7:14 AM
Addition 4
... IN BINARY MODE
Effect
The contents of the file are not interpreted by the read and write operations READ DATASET and TRANSFER . The data areas specified with these key words are directly input or output. The addition IN BINARY MODE does not have to be specified explicitly.
Addition 5
... IN TEXT MODE
Effect
If a file is opened with this addition, the system assumes that the file has a line structure. Each time READ DATASET or TRANSFER occurs, exactly one line is input or output. If the data area is too big for the line read, the remaining area is padded with blanks. If it is too small, the remainder of the line is lost.
2008 May 22 7:15 AM
Hi,
BINARY MODE
Effect:
The addition IN BINARY MODE opens the file as a binary file. When writing in a binary file, the binary content of a data object is transferred unchanged into the file. When reading from a binary file, the binary content of the file is transferred unchanged into a data object.
The addition BINARY MODE has the same meaning in Unicode programs and non-Unicode programs.
TEXT MODE ENCODING {DEFAULT|UTF-8|NON-UNICODE}
Effect:
The addition IN TEXT MODE opens the file as a text file. The addition ENCODING defines how the characters are represented in the text file. When writing in a text file, the content of a data object is converted to the representation entered after ENCODING, and transferred to the file. If the data type is character-type and flat, trailing blanks are cut off. In the data type string, trailing blanks are not cut off. The end-of-line marking of the relevant platform is applied to the transferred data by default. When reading from a text file, the content of the file is read until the next end-of-line marking, converted from the format specified after ENCODING into the current character format, and transferred to a data object.
The end-of-line marking depends on the operating system of the application server. In the MS Windows operating systems, the markings "CRLF" and " LF" are possible, while under Unix, only "LF" is used. If, when using Windows, an existing file is opened without the TYPE addition (see os_addition), the first end-of-line marking is found and used for the whole file. If a new file is created without the TYPE addition, the content of the profile parameter abap/NTfmode is used. If the profile parameter is not set, "CRLF" is used. If a file with the TYPE addition is opened and a valid value is contained in attr, this value is used.
Reward if useful.
Regards,
Swetha.