Google Search - Blog...........

Showing posts with label handle system exceptions using catch statement. Show all posts
Showing posts with label handle system exceptions using catch statement. Show all posts

Catch And Endcatch In System Exceptions

REPORT zcatch_endcatch.

DATA: BEGIN OF ifile OCCURS 0,
rec(150),
END OF ifile.

PARAMETERS: path(99) TYPE c LOWER CASE
DEFAULT '/usr/sap/TST/SYS/TEST001.txt'.

OPEN DATASET path FOR INPUT IN TEXT MODE ENCODING DEFAULT.

CATCH SYSTEM-EXCEPTIONS dataset_cant_open = 1.
DO.
READ DATASET path INTO ifile-rec.
IF sy-subrc EQ 0.
APPEND ifile.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDCATCH.

IF sy-subrc = 1.
WRITE:/ 'File could not be opened'.
ENDIF.