|
Transfer data to a system file
Ever want to save data to a system file from an SAP R/3 ABAP program? Its pretty straightforward. In this case we assume the internal table data_tab contains the information you want to store in the file system. dsn holds the Data set name. The directory must exist in the file structure of your system; record is the record to be written to the file.
data: dsn(20) value '/transfer/matnr',
record(460).
open dataset dsn for output in text mode.
loop at data_tab.
clear record.
move data_tab to record.
transfer record to dsn length 460.
endloop.
close dataset dsn.
- or -
As subroutines to add to a program
*&---------------------------------------------------------------------*
*& Form opendataset
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form opendataset.
open dataset dsn for output in text mode.
if sy-subrc <> 0.
write: / 'Error opening',dsn, sy-subrc.
stop.
endif.
endform. " opendataset
*&---------------------------------------------------------------------*
*& Form closedataset
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form closedataset.
close dataset dsn.
if sy-subrc ne 0.
write: / 'Error closing', dsn, sy-subrc.
stop.
endif.
endform. " closedataset
*&---------------------------------------------------------------------*
*& Form transfertodsn
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form transfertodsn.
transfer outfile to dsn length 66.
endform. " transfertodsn
|