Read file :
DATA : lo_error TYPE REF TO cx_root,
lw_error TYPE string.
* ENCODING DEFAULT = ANSCII on main SAP system.
OPEN DATASET lw_fullname FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
" Manage erreur
ENDIF.
* For each line
DO.
* Read line
TRY.
READ DATASET lw_fullname INTO lw_string.
CATCH cx_sy_conversion_codepage INTO lo_error. " En cas d'erreur d`encodage,
lw_error = lo_error->get_text( ). " fichier en UTF-8 alors que
WRITE / lw_error. " lu en mode défaut par exemple
EXIT.
ENDTRY.
IF sy-subrc = 0.
" Treat data
APPEND lw_string TO li_string.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lw_fullname.
About the author