SAP Database

ABAP Programs: Transferring data to a file

Print This Post Email This Post Written by admin on Jan 31st, 2008 | Filed under: ABAP Programs

Here is a little program, which will teach you to transfer the data to a file.

REPORT ZSOURCE2601.
* Data declarations for later use
PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat'
                         LOWER CASE.
TABLES CUSTOMERS.
DATA MSG_TEXT(50).
* Get data for file transfer
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
                   WITH HEADER LINE.

SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.
SORT ALL_CUSTOMERS BY CITY.
LOOP AT ALL_CUSTOMERS.
  WRITE: / ALL_CUSTOMERS-CITY,
           ALL_CUSTOMERS-NAME.
ENDLOOP.
* Opening the File
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
                      MESSAGE MSG_TEXT.
IF SY-SUBRC NE 0.
  WRITE: 'File cannot be opened. Reason:', MSG_TEXT.
  EXIT.
ENDIF.
* Transferring Data
LOOP AT ALL_CUSTOMERS.
  TRANSFER ALL_CUSTOMERS-NAME TO FILENAME.
ENDLOOP.
* Closing the File
CLOSE DATASET FILENAME.

If you like this post, you may as well like these too:

  1. ABAP Program:Transferring data to a file (presentation server) REPORT ZSOURCE2603. * Data declarations for later use PARAMETERS FILENAME(128) DEFAULT 'c:\users\default\testfile.dat' LOWER CASE. TABLES CUSTOMERS. DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE. * Get data for...
  2. ABAP Program:Reading data from a file REPORT ZSOURCE2602. * Data declarations for later use TABLES CUSTOMERS. PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat' LOWER CASE. DATA: MSG_TEXT(50), ALL_CUSTOMER_NAMES LIKE CUSTOMERS-NAME OCCURS 100 WITH HEADER LINE. * Opening the...
  3. ABAP Programs:Reading data from a file (presentation server) REPORT ZSOURCE2604. * Data declarations for later use PARAMETERS FILENAME(128) DEFAULT 'c:\users\default\testfile.dat' LOWER CASE. TABLES CUSTOMERS. DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE. CALL FUNCTION 'WS_UPLOAD' EXPORTING...
  4. ABAP Programs: Importing from the ABAP/4 Memory REPORT ZSOURCE1402. * Internal tables which will be imported DATA: ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE, ALL_BOOKINGS LIKE BOOKINGS OCCURS 10 WITH HEADER LINE, NEW_BOOKINGS LIKE BOOKINGS...
  5. ABAP Programs: Working with hide statements REPORT ZSOURCE1704. * work area TABLES CUSTOMERS. * Internal table DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE. * Processing data START-OF-SELECTION. SELECT * FROM CUSTOMERS INTO TABLE...



Leave a Reply

  • Help Support CRY