Tutorial Name

Reading and Writing data on application server in SAP

Tutorial Description

Reading a file stored in application server in SAP ABAP, writing a file to application server in SAP ABAP

Tutorial Area Core ABAP
Prerequisites ABAP
Learning Level Basic
Estimated Time to learn 30
Save to Learning List Save to your Learning List
+ -

Step1:OPEN DATASET for Application server SAP Normal Top^

Most of the times in real-time business application we need to store data in application server for further operations and we need to read data from application server.

In order to do operations on application server, we need to open dataset for a particular file, we use the below syntax to open a data set.
OPEN DATASET <FILE NAME> FOR OUTPUT IN <MODE> MODE ENCODING DEFAULT.
**Do file operations like writing file, reading file
CLOSE DATASET <FILE NAME>. "Close data set for file
In the above syntax <FILE NAME> is the name of the application server file, <MODE> is the out put mode like BINARY MODE or TEXT MODE or LEGACY BINARY MODE or LEGACY TEXT MODE.
In the next step, example program explains you how to read data from application server and how to write data to application server.

Step2:Reading and Writing data from Application Server SAP Normal Top^

The below example program explains you of writing data into application server using OPEN DATASET and reading data from application server using OPEN DATASET.

REPORT ZSAPN_APPLICATION_SERVER.

PARAMETERS FILE TYPE string DEFAULT 'testtemp.txt' .
PARAMETERS P_MTART TYPE MARA-MTART.

DATA IT_MARA TYPE TABLE OF MARA.
DATA WA_MARA TYPE MARA.
DATA LV_STRING TYPE STRING.
SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS
  WHERE MTART = P_MTART .
OPEN DATASET FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT IT_MARA INTO WA_MARA .

  CONCATENATE WA_MARA-MATNR WA_MARA-MTART WA_MARA-MEINS INTO LV_STRING.
  TRANSFER LV_STRING TO FILE.
ENDLOOP.

CLOSE DATASET FILE.

DATA LV_DATA TYPE STRING.

OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
  READ DATASET FILE INTO LV_DATA.
  IF SY-SUBRC <> 0.
  EXIT.
  ELSE.
  WRITE:/ LV_DATA.
  ENDIF.

ENDDO.
CLOSE DATASET FILE.

Author | Last Updated| | 2 Comments | F Share

Tutorial Comments

Total Comments: Add your Comment
16 Feb 2014

Tutorial is good.. and its better if we explain all addition of open dataset statement like IN BINARY MODE, LEGACY BINARY MODE etc...i mean when we use particular addition.

28 Apr 2016

Easily understandable ..good work.

Leave a Comment

Enter Comment Text