+ -

Pages

Saturday, July 26, 2014

Reading and writing to a flatfile

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

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
5 ABAP Tips: Reading and writing to a flatfile Use transaction AL11  to view the files on the apllication server. Writing to a flatfile Note: If  the path is not inlcuded in the file n...

No comments:

Post a Comment

< >