Overview
1. Opening files
2. Reading data
3. Writing data
4. Runtime errors
To use interfaces to other systems, the SAP system needs to be able to convert code pages when reading
or writing to a file, or when performing data communication with other systems. The appropriate neue
Sprachelemente new language elements have been available to make this possible.
The OPEN DATASET dsn ... statement must include at least one of the following additions:
If you use the TEXT MODE addition, you must also use an ENCODING addition.
In addition, you must include at least one of the following additions:
FOR INPUT opens a file for read access. This means that the system will return a runtime error if you try to change the file using TRANSFER.
The ... AT POSITION pos addition always specifies the
position in bytes, regardless of whether the file was opened in TEXT MODE or BINARY MODE.
Notes
The system raises the exception CX_SY_FILE_OPEN if a file is opened, and then opened again without having been closed first. In earlier releases the file was often reopened to change the read/write position. You now use the SET DATASET to achieve this.
Your file names can also contain spaces in programs where Unicode checks are active.
Before you use the READ DATASET dsn INTO f statement, you must open the file explicitly using a OPEN DATASET statement. Otherwise an exception that can be handled, CX_SY_FILE_OPEN_MODE, occurs.
If the file is opened in TEXT MODE, f must be a character-type field ( C, N, D, or T), a string, or a purely character-type structure. This check does not take place until runtime.
If the file is opened in TEXT MODE, LEGACY TEXT MODE, or LEGACY BINARY MODE, conversion errors may occur. If the system opens the file and the you have not declared the IGNORING CONVERSION ERRORS addition, the catchable runtime error CONVT_CODEPAGE occurs.
The
... [ ACTUAL ] LENGTH len und ... MAXIMUM LENGTH len
additions specify the length of the file in characters if the file was opened in TEXT MODE, or in bytes otherwise.
Before you use the TRANSFER f TO dsn statement, you must open the file explicitly using a OPEN DATASET ... statement. Otherwise an exception that can be handled,CX_SY_FILE_OPEN_MODE, occurs.
If the file has been opened in a Unicode-Programm with the FOR INPUT addition, you cannot write to it. A TRANSFER causes an exception that can be handled, CX_SY_FILE_OPEN_MODE.
If the file is opened in TEXT MODE, f must be a character-type field ( C, N, D, or T), a string, or a purely character-type structure. This check does not take place until runtime.
If the file is opened in TEXT MODE, LEGACY TEXT MODE, or LEGACY BINARY MODE, conversion errors may occur. If the system opens the file and the you have not declared the IGNORING CONVERSION ERRORS addition, an exception that can be handled, CX_SY_CONVERSION_CODEPAGE occurs.
The ...LENGTH len addition specifies the length of the
file in characters if the file was opened in TEXT MODE, or in bytes otherwise.
CX_SY_FILE_OPEN | Error opening file |
CX_SY_FILE_OPEN_MODE | File opened in wrong mode |
CX_SY_CONVERSION_CODEPAGE | Conversion error |