Skip to Content
author's profile photo Former Member
Former Member

What is opening, reading etc dataset

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:13 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:13 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:15 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:16 PM

    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......

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 11, 2007 at 12:16 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:17 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:19 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2007 at 12:31 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.