SAP GET DATASET ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID GET-DATASET
• GET DATASET ABAP Statement

GET DATASET
Short Reference

ABAP_SYNTAX
GET DATASET dset $[POSITION pos$] $[ATTRIBUTES attr$].

ABAP Addition
1 ... POSITION pos
2 ... ATTRIBUTES attr

What does it do?
The addition POSITION is used by this statement to determine the current position of the file pointer in the file specified in dset and the addition ATTRIBUTES is used to get additional file attributes.
dset expects a character-like data object that contains the physical name of the file. The file must already be open, otherwise a catchable exception of the class CX_SY_FILE_OPEN_MODE is raised.
ABAP_SUBRC_GENERAL
The statement GET DATASET always sets sy-subrc to the value 0 or raises an exception.



Latest notes:

If no additions are specified, the statement can be used to determine whether the file is open using a TRY control structure.
ABAP_HINT_END



Example ABAP Coding

The statement GET DATASET raises an exception if the file is not yet open.
ABEXA 00299
ABAP_EXAMPLE_END
• POSITION GET DATASET

ABAP Addition

What does it do?
This addition assigns the current position of the file pointer to the data object pos. The following can be specified for pos:
An existing variable of the data type i or a variable to which the type i can be converted.
An inline declaration DATA(var) or FINAL(var), where a variable of type i is declared.
The position is specified in bytes, where the start of the file corresponds to position 0.
The addition POSITION cannot be specified for files that have been opened with the addition FILTER of the statement OPEN DATASET. This raises a catchable exception.



Latest notes:

For file sizes greater than 2 GB, a data object pos of data type i is not sufficient for recording all the possible positions of the file pointer.
ABAP_HINT_END



Example ABAP Coding

After the first literal is saved, the position of the file pointer is assigned to the variable pos, which is then used to position the file pointer before the read.
ABEXA 00300
ABAP_EXAMPLE_END
• ATTRIBUTES GET DATASET

ABAP Addition

What does it do?
This addition places the attributes used to open the file with the statement OPEN DATASET in the data object attr. The following can be specified for attr:
An existing variable of the data type dset_attributes from the type pool DSET.
An inline declaration DATA(var), where a variable of type dset_attributes is declared.
The data type is defined in the type pool as follows:
dset_attributes is a structured type with two substructures: fixed and changeable. The components of the substructure fixed record attributes of the file that cannot be changed using the statement SET DATASET (see Table 1). The components of the substructure changeable record attributes of the file that can be changed using the statement SET DATASET (see Table 2).
Table 1 ComponentMeaning indicatorStructure whose components mode, access_type, encoding, filter, and linefeed in attr contain the value X if the identically named components of the structure fixed are significant for the current file. modeStorage mode. Possible values in attr are T , LT, B, and LB for text files, legacy text files, binary files, and legacy binary files. The associated addition of the statement OPEN DATASET is IN mode. access_typeAccess mode. Possible values in attr are I, O, A, and U for files that were opened for reading, writing, appending, and changing. The associated addition of the statement OPEN DATASET is FOR access. encodingCharacter representation. Possible values in attr are NON-UNICODE and UTF-8. The associated addition of the statement OPEN DATASET is ENCODING ${ DEFAULT $| UTF-8 $| NON-UNICODE $}. filterIn attr, contains the filter command if the file was opened with the FILTER addition of the statement OPEN DATASET. linefeedContains the end-of-line marker used when accessing a text file or legacy text file.
Table 2 ComponentMeaning indicatorStructure whose components repl_char, conv_errors, code_page, endian, and linefeed_mode contain the value X in attr if the identically named components of the structure changeable are significant for the current file. repl_charAfter the file is opened, this component contains the replacement character in attr that was specified using the addition REPLACEMENT CHARACTER of the statement OPEN DATASET. conv_errorsAfter the file is opened, this component contains the value I in attr if it was opened using the addition IGNORING CONVERSION ERRORS of the statement OPEN DATASET, otherwise it contains the value R. code_pageAfter the file is opened, this component contains the code page in attr that was specified using the addition CODE PAGE of the statement OPEN DATASET. If no addition is used, the content of attr is initial. endianAfter the file is opened, this component contains the value B in attr if the addition BIG ENDIAN of the statement OPEN DATASET was used or L if the addition LITTLE ENDIAN was used. If no addition is used, the content of attr is initial. linefeed_modeAfter the file is opened, this component contains one of the values N, S, U, or W in attr if the corresponding addition WITH NATIVE$|SMART$|UNIX$|WINDOWS LINEFEED of the statement OPEN DATASET was used. If none of the additions is used, the content in attr is initial.
For some of the components, constants are defined in the type pool DSET as comparison values.



Latest notes:

The determinable attributes do not represent the attributes of the file in the operating system, but the attributes with which the file is opened and according to which it is handled in ABAP.
ABAP_HINT_END



Example ABAP Coding

In this example, the system first checks whether the file test.dat was opened using the FILTER addition. Only if this is not the case, is the current file position determined using GET DATASET.
ABEXA 00301
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SY_FILE_OPEN_MODE The file is not open.
CX_SY_FILE_POSITION The file could not be read because an invalid status exists or the type of file does not allow position specification.
CX_SY_CONVERSION_OVERFLOW The variable pos was assigned a type that is too small to include the current position.

Return to menu