Reading and writing to a flatfile



Use transaction AL11  to view the files on the apllication server.

  1. Writing to a flatfile
  2. Reading a file
  3. Authority check


Writing to a flatfile

Note: If  the path is not inlcuded in the file name, the file is
qwritten to the default directory on the apllication server (The system
uses the directory defined in the profile parameter DIR_HOME.)

DATA: dsn LIKE authb-filename VALUE 'HFNK.DAT'.


OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
WRITE: 'Error opening :', dsn.
ENDIF.

LOOP AT it_doc INTO wa_doc.

TRANSFER wa_doc TO dsn.

IF sy-subrc <> 0.
WRITE /: 'Error writing'.

ENDIF.

ENDLOOP.

CLOSE DATASET dsn.


Reading a file

DATA:  g_delimiter(1) TYPE c VALUE 'ยค',
dsn LIKE authb-filename VALUE 'HFNK.DAT'.

OPEN DATASET g_dsn FOR INPUT IN TEXT MODE.
IF sy-subrc <> 0.
write 'Error'.
EXIT.
ENDIF.


DO.
READ DATASET g_dsn INTO fline.
IF sy-subrc <> 0.
EXIT.
ELSE.
CLEAR wa_document.
* Split line into fields using the constant delimiter
SPLIT fline AT g_delimiter INTO
wa_document-bukrs
wa_document-gjahr
wa_document-belnr.
APPEND wa_document TO it_document.

ENDIF.

ENDDO.

CLOSE DATASET g_dsn.



Authority check

You can use the function module below to check for the necessary authorization.  If the default value for the PROGRAM parameters is the current program .

CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
* PROGRAM =
activity = 'WRITE'
filename = dsn
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)