SAP Database

SAP Certification, Ebooks, PDF’s, Articles, News, Tips and Tricks
Bookmark : Del.icio.us | Digg it | StumbleUpon

Online Resources on Certification, Learning, Ebooks, PDF's, Programs, Articles, Tips & Tricks, CBT's and News on SAP.

SAP Forums
SAP Forums - Get your SAP Issues resolved.
Write on this blog - Showcase your talent and make your ideas reach thousands.

ABAP Program:Reading data from a file

Written by admin on Feb 4th, 2008 | Filed under: ABAP Programs
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 File
OPEN DATASET FILENAME FOR INPUT IN TEXT MODE
                      MESSAGE MSG_TEXT.

IF SY-SUBRC NE 0.
  WRITE: 'File cannot be opened. Reason:', MSG_TEXT.
  EXIT.
ENDIF.
* Reading Data
DO.
  READ DATASET FILENAME INTO ALL_CUSTOMER_NAMES.
  IF SY-SUBRC NE 0.
    EXIT.
  ENDIF.
  APPEND ALL_CUSTOMER_NAMES.
ENDDO.
* Closing the file
CLOSE DATASET FILENAME.
* Display the result
LOOP AT ALL_CUSTOMER_NAMES.
  WRITE / ALL_CUSTOMER_NAMES.
ENDLOOP.

Related topics:



Leave a Reply

  • Sponsers

  • AMAZON Books