SAP® Documentation

Single view

ABAPOPEN_DATASET_ERROR_HANDLING - OPEN DATASET ERROR HANDLING

General Material Data   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

OPEN DATASET - error_handling

Short Reference



Syntax

... $[MESSAGE msg$]
    $[IGNORING CONVERSION ERRORS$]
    $[REPLACEMENT CHARACTER rc$] ...

Additions

1. ... MESSAGE msg

2. ... IGNORING CONVERSION ERRORS

3. ... REPLACEMENT CHARACTER rc

Effect

In the case of errors, these additions enable operating system messages to be received, exceptions to be suppressed, and a replacement character to be defined for unknown characters.

Addition 1

... MESSAGE msg

Effect

If an error occurs when a file is opened, the associated operating system message is assigned to the data object msg. A character-like variable can be specified for msg.

Example

Produces the operating system message after an attempt to open a file with an empty name.

DATA mess TYPE string.

OPEN DATASET `` FOR INPUT IN BINARY MODE MESSAGE mess.

IF sy-subrc = 8.
  MESSAGE mess TYPE 'I'.
ENDIF.

Addition 2

... IGNORING CONVERSION ERRORS

Effect

This addition can be used to suppress a handleable exception defined by the class CX_SY_CONVERSION_CODEPAGE. This exception can be raised by reads or writes if a conversion between code pages takes place and a character cannot be converted to the target code page.

This addition is possible when opening text files, legacy text files, or legacy binary files, but not when opening binary files.

Notes

  • Each non-convertible character is replaced in the conversion either by the character "#" or by the character defined by the addition REPLACEMENT CHARACTER. The addition IGNORING CONVERSION ERRORS defines whether or not the user is notified of this by an exception.
  • This setting can be changed in an opened file using the statement SET DATASET.


Example

See the addition REPLACEMENT CHARACTER.

Addition 3

... REPLACEMENT CHARACTER rc

Effect

If a conversion between code pages takes place while data is being read or written, every character that cannot be converted to the target code page is replaced by the character specified in rc. rc expects a character-like data object containing a single character. If the addition is not specified, the character "#" is used as a replacement character.

This addition is possible when opening text files, legacy text files, or legacy binary files, but not when opening binary files.

Notes

  • If at least one character is replaced by a replacement character in a read or write, the exception defined in the class CX_SY_CONVERSION_CODEPAGE is raised after the conversion, if this is not suppressed by the addition IGNORING CONVERSION ERRORS.
  • The replacement character of an opened file can be changed using the statement SET DATASET.


Example

When a legacy text file is opened with ID 1101 for codepage 7-Bit USA ASCII, the exception of class CX_SY_CONVERSION_CODEPAGE is suppressed and a replacement character is specified. When data is being written to a file, the character ü is replaced by u without an exception being raised. Compare the example to addition CODE PAGE.

DATA(dset) = 'test.dat'.

OPEN DATASET dset FOR OUTPUT IN LEGACY TEXT MODE CODE PAGE '1101'
                                REPLACEMENT CHARACTER 'u'
                                IGNORING CONVERSION ERRORS.
TRY.
    TRANSFER 'Blahblahblah...' TO dset.
  CATCH cx_sy_conversion_codepage INTO DATA(exc).
    cl_demo_output=>write( 'Error writing to 7-Bit USA ASCII' ).
ENDTRY.
CLOSE DATASET dset.

DATA text TYPE string.
OPEN DATASET dset FOR INPUT IN LEGACY TEXT MODE CODE PAGE '1101'.
READ DATASET dset INTO text.
CLOSE DATASET dset.

cl_demo_output=>display( text ).

DELETE DATASET dset.






ROGBILLS - Synchronize billing plans   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 7397 Date: 20200330 Time: 155151     sap01-206 ( 38 ms )

Our Service

Looking for Support? Questions?

The

Consolut

Callback-Service

Leave us your contact details and we will call you back. Panels marked with * are mandatory.