GET DATASET dsn.
1. ... POSITION
pos
2. ... ATTRIBUTES attr
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. For details, see File Interface.
Used to get the properties of a file already open. You can use this statement without additions to determine
whether the file is open. If the file is not open, an exception of the type CX_SY_FILE_OPEN_MODE is triggered.
... POSITION pos
The current read or write position in the file dsn is stored in the field pos. When you access the file again later, you can use this value to return to a specific read or write position.
The variable pos must be large enough to hold the position specified. In particular, this is important if the file is very large (> 2 GByte) since the position can then no longer be stored in a field of the type I. You must then use fields of a type which is more appropriate (P or F). If you use a field which is too small, the system triggers a conversion exception CX_SY_CONVERSION_OVERFLOW.
You may only use this statement for files which can be positioned.
This means that you cannot use this statement for files which were opened using the
FILTER addition for OPEN
DATASET. If you apply the statement to a file which cannot be positioned, the system triggers the exception CX_SY_FILE_POSITION.
DATA:
dsn TYPE string VALUE `bin.dat`,
buf TYPE xstring,
pos TYPE i.
....
OPEN DATASET dsn IN BINARY MODE
FOR INPUT.
....
READ DATASET dsn INTO buf MAXIMUM LENGTH 2365.
GET DATASET dsn POSITION
pos.
....
CLOSE DATASET dsn.
....
OPEN DATASET dsn IN BINARY MODE FOR INPUT AT POSITION pos.
... ATTRIBUTES attr
You can use this addition to read the properties of a file at runtime. The values of attr are passed in a structure of the type dset_attributes which is defined in the type group dset. In order to be able to create a variable of this type in the DATA statement, you must first include the type group by specifying TYPE-POOLS dset.
The structure dset_attributes is set up as follows:
fixed | Specifies all properties of the file that cannot be changed |
changeable | Specifies all properties that can be changed using the statement SET DATASET |
fixed and changeable are themselves structures (of the type dset_fixed_attributes and dset_changeable_attributes) and set up as follows:
dset_fixed_attributes
indicator | Specifies which of the following fields are significant for the current file |
mode | Mode in which the file was opened ([LEGACY] TEXT or [LEGACY] BINARY) |
access_type | Type of access to the file ( FOR INPUT, FOR OUTPUT, FOR UPDATE, FOR APPENDING) |
encoding | Specifies for text files if they were opened in UTF-8 or NON-UNICODE |
filter | Filter statement if the file was opened using the FILTER addition |
dset_changeable_attributes
indicator | Specifies which of the following fields are significant for the current file |
repl_char | Specifies the replacement character to be used for non-existing characters in the target code page during conversion |
conv_errors | Specifies if a conversion error is to be signalized (R) or ignored (I) |
code_page | Specifies the code page in which the file is interpreted if opened using the CODE PAGE addition |
endian | Specifies if the file is interpreted based on the convention BIG ENDIAN or LITTLE ENDIAN |
indicator is a structure with the same basis elements
but this time of the DDIC type <EX>INDICA</>
which allows the values'X' and ' ' to indicate if a field is significant or not.
TYPE-POOLS:
dset.
DATA:
dsn TYPE STRING,
pos TYPE
i,
attr TYPE dset_attributes.
....
GET DATASET dsn ATTRIBUTES attr.
IF attr-fixed-indicator-filter
= ' '.
GET DATASET dsn POSITION pos.
ELSE.
WRITE / attr-fixed-filter.
ENDIF.
IF attr-changeable-indicator-code_page = 'X'.
WRITE / attr-changeable-code_page.
ENDIF.
In the example, before GET DATASET POSITION is called,
the system first checks if the call is valid. If it is not (since the file was opened using the
FILTER addition), the filter command is output. The system
then checks if the file was opened with an explicit code page. If this is the case, the code page is also output.
The file
dsn must be open. For the variable pos, only
the numeric types I, P,
and F are allowed. If pos
is of the type P or F, it is also possible to save file positions > 2 Gigabytes.
SET DATASET, OPEN DATASET, READ DATASET