Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

What is opening, reading etc dataset

Former Member
0 Kudos

Hi all,

What does the following code do?

I do not know why to open a dataset etc.

Thanks in advance.

Deniz.

*-- Open dataset for reading 

DATA: 
  dsn(20) VALUE '/usr/test.dat', 
  rec(80). 

OPEN DATASET dsn FOR INPUT IN TEXT MODE. 
IF sy-subrc = 0. 
  DO. 
    READ DATASET dsn INTO rec. 
    IF sy-subrc <> 0. 
      EXIT. 
    ELSE. 
      WRITE / rec. 
    ENDIF. 
  ENDDO. 
ENDIF. 
CLOSE DATASET dsn. 

*-- Open dataset for writing 

DATA rec(80). 

OPEN DATASET dsn FOR OUTPUT IN TEXT MODE. 
  TRANSFER rec TO '/usr/test.dat'. 
CLOSE DATASET dsn.

9 REPLIES 9

Former Member
0 Kudos

datasets are files stored in application server.

to get data of files into internal table....

we open the file ...read the file.....close the file.......

Regards

Vasu

Former Member
0 Kudos

Hi Deniz,

To open a file on the application server, OPEN DATASET statement is used.

This statement opens the file <dsn>. If you do not specify any additions for the mode, the file is opened in binary mode for reading. SY-SUBRC returns 0 if the system opens the file. Otherwise, SY-SUBRC is set to 8.

Hope this helps.

null

Former Member
0 Kudos

Hi..

<b>OPEN DATASET dset FOR access IN mode [position]

[ os_addition]

[error_handling].</b>

<b>Effect</b>

This statement opens the file specified in dset for the access specified in access in a storage mode specified in mode. For dset, a character-type data object is expected, which contains the platform-specific name of the file.

Use additions position, os_addition and error_handling to determine the position at which to open the file, to specify platform-specific additions and to influence error handling.

In Unicode programs, the access and storage modes access and mode must be specified explicitly. If the additions are missing in non-Unicode programs, the file is opened implicitly as a binary file for read access.

In Unicode programs, the file must not yet be open in the current program; otherwise a treatable exception occurs. In non-Unicode programs, the file may already be open. The statement <b>OPEN DATASET</b> then does not reopen the file but moves the read or write position depending on the access mode. In this case, you should not change the access or storage mode.

Former Member
0 Kudos

OPEN DATASET dsn FOR INPUT IN TEXT MODE.

means we are opening dataset named dsn....for reading.......text mode means it reads sentence at a time.......

READ DATASET dsn INTO rec.

this statement reads dataset contents into rec.

OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.

TRANSFER rec TO '/usr/test.dat'.

CLOSE DATASET dsn.

transfer is used to transfer contents to the file......

former_member404244
Active Contributor
0 Kudos

hI,

WE USE the open dataset statement inorder to read or write the data from or to application server...

so when we want to read data from application server we write teh command.

OPEN DATASET <DATASET NAME> FOR INPUT IN TEXT MODE ENCODING DEFAULT.

When we want to write the data into appication server we write like this

OPEN DATASET <DATASET NAME> FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

also have a look at the below links.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/content.htm

<b><REMOVED BY MODERATOR></b>

Regards,

Nagaraj

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

Hi

Open, Read and Close Dataset are used to download and upload data to and from the application server.

First u have to open the file in input or output or appending mode.

Next u have to read that file into or from internal table

Then the last step is to close the file using close data set.

Opening the file in Input Mode means u r creating that file and entering some data into that file. Then using Read Dataset u insert data into the file through internal table.

Opening the file in Output Mode means u r opening a file which is already created and then u will read that file into an internal table.

Opening the file in Appending Mode means u r appending some more data into the already existing file.

For an already existing file if u use input mode then it will over write the existing data, where as if u use appending mode it will append the new data to the already existing data.

Regards

Haritha.

Former Member
0 Kudos

Hi,

Try to use this syntax for writing reading from application server

for writing <b>OUTPUT</b>

OPEN DATASET L_FILENAME FOR <b>OUTPUT</b> IN TEXT MODE.

for reading <b>INPUT</b>

OPEN DATASET L_FILENAME FOR <b>INPUT IN</b> TEXT MODE.

AND FOR downloading application server file we have 2 transaction

<b>CG3Y , CG3Z</b> using this transaction we can download to descktop or any place in ur system

<b><REMOVED BY MODERATOR></b>

praveen

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

files on Application server are called datasets. when you need to perform some operation on such a file you will have to open it, perform the operation you need like UPDATE/READ/WRITE etc. and then close the file.

Its as simple as that! in your code you are opening a file, writing into it and closing it.

regards,

srinivas

0 Kudos

Thanks for your answers.

Why do we need file (what kind of file?) on application server?

Excel or txt files are not enough?

What is the primary reason to use this dataset keyword related items....

Thanks.

Deniz.