SET DATASET

Basic form

SET DATASET dsn.

Extras:

1. ... POSITION [ pos | END-OF-FILE ]

2. ... ATTRIBUTES attr

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. For more details, refer to the chapter File Interface.

Effect

This commmand is used to change properties of a file that has already been opened. For this, you must use at least one of the above additions and the file must be opened.

Addition 1

... POSITION [ pos | END-OF-FILE ]

Effect

Sets the current read or write position in the file
dsn to the value specified under pos or positions at the end of the file.

The value from pos is retrieved preferably by a call GET DATASET since, if you calculate the offsets yourself on the basis of the lengths of the written data using conversions or platform-specific features, this is very unreliable.

The positionability within the file is the prerequisite for usage of this command. Files that were opened using the FILTER addition for OPEN DATASET, for example, cannot be positioned.

If you have large files (> 2 GByte), then you can also position here in these files using suitable variables or literals.

Example

DATA:
  dsn TYPE STRING value `text.txt`,
  fld TYPE STRING,
  pos TYPE i.
....
OPEN DATASET dsn IN TEXT MODE ENCODING DEFAULT FOR INPUT.
....
GET DATASET dsn POSITION pos.
READ DATASET dsn INTO fld.
WRITE / fld.
SET DATASET dsn POSITION pos.
READ DATASET dsn INTO fld.
WRITE / fld.
....
CLOSE DATASET dsn.

In this example, the current position is saved before a read command is called using GET DATASET. After the read action, the system goes to the old position using SET DATASET. The next call by READ DATASET, therefore, reads exactly the same data.

Addition 2

... ATTRIBUTES attr

Effect

Using this addition, you can change some of the propertiies of a file at runtime. These are properties that were defined at file opening using OPEN DATASET.

The changes are made by passing a structure attr, which must be of the type dset_changeable_attributes. This type is defined in the type group dset and it must be included, before usage, using TYPE-POOLS dset.

The structure is itself a substructure of dset_attributes, which describes all the properties of a file and is used by GET_DATASET to get information on the current status of a file. It has the following structure:

indicator Specifies which of the following properties are to be changed for the current file.
repl_char Specifies the replacement character that is to be inserted during conversion for characters that are not in the target code page.
conv_errors Specifies whether a conversion error is to be signalized (R) or ignored (I).
code_page Specifies the code page in which the file is to be interpreted.
endian Specifies whether the file is to be interpreted according to the convention BIG ENDIAN or LITTLE ENDIAN.

indicator is the respective structure that is again based on the same elements, except that this time they are of the DDIC type INDICA. This allows the values 'X' and ' ' and thus shows whether a property is to be changed or not.

In addition, the changes must be compatible with the other properties of the file. For example, for a file that was opened IN BINARY MODE, no replacement characters are specified. The allowed combinations are taken from the syntax for OPEN DATASET. Setting an invalid combination causes the exception CX_SY_FILE_OPEN_MODE with the addition INCOMPATIBLE_MODE.

Example

TYPE-POOLS:
  dset.
DATA:
  dsn  TYPE STRING,
  fld  TYPE STRING,
  attr TYPE dset_attributes.
....
OPEN DATASET dsn IN LEGACY TEXT MODE FOR INPUT.
attr-changeable-indicator-code_page = 'X'.
attr-changeable-code_page           = '0100'.
attr-changeable-indicator-repl_char = 'X'.
attr-changeable-repl_char           = '*'.
SET DATASET dsn ATTRIBUTES attr-changeable.
READ DATASET dsn INTO fld.
WRITE / fld.
CLOSE DATASET dsn.

In this example, the code page and the replacement character are changed only after the file has been opened.

Exceptions

Catchable Exceptions

CX_SY_CODEPAGE_CONVERTER_INIT

CX_SY_CONVERSION_CODEPAGE

CX_SY_FILE_OPEN_MODE

CX_SY_FILE_POSITION

Non-Catchable Exceptions

Related

OPEN DATASET, GET DATASET, READ DATASET