7 Replies Latest reply: Jul 19, 2010 6:23 AM by Dillip Sahoo RSS

OPEN DATASET FOR  {INPUT, OUTPUT AND UPDATE}

saritha pyla
Currently Being Moderated

1)In OPEN DATASET syntax

when a) input is used

        b) output is used and

       c) update is used.

 

2) what is the difference between a) input

             b) output and

            c) update .

 

explain me with example.

  • Re: OPEN DATASET FOR  {INPUT, OUTPUT AND UPDATE}
    khasimsa shaik
    Currently Being Moderated

    for input: opens a file on application server for READ and place the cursor at beginning of the file.

     

    for output:  open a file on application server for writting  it the data set already exists this will place the cursor at the start of the dataset, the old contents get deleted at the end of the program or when the CLOSE DATASET is encountered

     

    for Appending  opens the file for writing and places the cursor at the end of the file. if file does not exists then it is generated other wise the new contents will be added at the end of the existing contents.

  • Re: OPEN DATASET FOR  {INPUT, OUTPUT AND UPDATE}
    shankar tm
    Currently Being Moderated

    Hi saritha,

     

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

     

    U have three specific additions such as..

     

    Opening a File for Read Access

     

    Opening a File for Write Access

     

    Opening a File for Appending Data

     

     

    Opening a File for Read Access

     

    1.To open a file for reading, use the FOR INPUT addition to the OPEN DATASET statement.

     

    Syntax:OPEN DATASET <dataset> FOR INPUT.

     

    The file must already exist, otherwise, the system sets SY-SUBRC to 8, and ignores the statement.

     

     

    DATA FNAME(60) VALUE 'TEST'.

     

    OPEN DATASET FNAME FOR INPUT.

     

    IF SY-SUBRC = 0.

      WRITE / 'File opened'.

      .....

    ELSE.

      WRITE / 'File not found'.

    ENDIF.

     

    This example opens the file "TEST" for reading.

     

    2.Opening a File for Write Access

    -


     

    To open a file for writing, use the FOR OUTPUT addition to the OPEN DATASET statement.

     

    Syntax: OPEN DATASET <dataset> FOR OUTPUT.

     

    If the file does not already exist, it is created automatically. If it does already exist, but is closed, its contents are overwritten.

     

    DATA FNAME(60) VALUE 'TEST'.

    DATA NUM TYPE I.

     

    OPEN DATASET FNAME FOR OUTPUT.

     

    DO 5 TIMES.

      NUM = NUM + 1.

      TRANSFER NUM TO FNAME.

    ENDDO.

     

    PERFORM INPUT.

     

    OPEN DATASET FNAME FOR OUTPUT.

     

    NUM = 0.

    DO 5 TIMES.

      NUM = NUM + 10.

      TRANSFER NUM TO FNAME.

    ENDDO.

     

    PERFORM INPUT.

     

    CLOSE DATASET FNAME.

     

    OPEN DATASET FNAME FOR OUTPUT.

     

    NUM = 0.

    DO 5 TIMES.

      NUM = NUM + 20.

      TRANSFER NUM TO FNAME.

    ENDDO.

     

    PERFORM INPUT.

     

    FORM INPUT.

      SKIP.

      OPEN DATASET FNAME FOR INPUT.

      DO.

        READ DATASET FNAME INTO NUM.

        IF SY-SUBRC <> 0.

          EXIT.

        ENDIF.

        WRITE / NUM.

      ENDDO.

    ENDFORM.

     

     

    3.Opening a File for Appending Data

     

    To open a file so that you can append data to the end of it, use the FOR APPENDING addition in the OPEN DATASET statement:

     

    Syntax : OPEN DATASET <dataset> FOR APPENDING.

     

    This statement opens a file to which you can append data. If the file does not already exist, it is created automatically. If it does exist, but is closed, the system opens it, and sets the position to the end of the file.

     

    DATA FNAME(60) VALUE 'test'.

     

    DATA NUM TYPE I.

     

    OPEN DATASET FNAME FOR OUTPUT.

    DO 5 TIMES.

       NUM = NUM + 1.

       TRANSFER NUM TO FNAME.

    ENDDO.

     

    OPEN DATASET FNAME FOR INPUT.

     

    OPEN DATASET FNAME FOR APPENDING.

    NUM = 0.

    DO 5 TIMES.

       NUM = NUM + 10.

       TRANSFER NUM TO FNAME.

    ENDDO.

     

    OPEN DATASET FNAME FOR INPUT.

    DO.

      READ DATASET FNAME INTO NUM.

      IF SY-SUBRC <> 0.

        EXIT.

      ENDIF.

      WRITE / NUM.

    ENDDO.

     

     

    generally INPUT is used to read the flatfile..and OUTPUT is used to write data to the flatfile..and APPENDING is used to append the data to already existing file..

     

    Hope u might have got the clear idea.

     

    regards

    shankar

  • Re: OPEN DATASET FOR  {INPUT, OUTPUT AND UPDATE}
    AK D
    Currently Being Moderated

    normally flat files will be kept on the presentation servers. for more security flat files

     

    will be kept on the application server. when we want to do some operations on the files

     

    present in the application server like READING,WRITING or OVERWRITING we use open dataset

     

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

     

    it has three options FOR INPUT,FOR OUTPUT,FOR UPDATE.

     

    basic syntax for open dataset statement is OPEN DATASET <filename>. This statement

     

    accompanied by necessary additions depending upon the requirement.

     

    OPEN DATASET FOR INPUT:- To read the contents in a file which is present in an application server we use

     

    OPEN DATASET FOR INPUT. The syntax for OPEN DATASET FOR INPUT is OPEN DATASET <filename> FOR INPUT.

     

    This statement only works when the file really exists in the application server.

     

    OPEN DATASET FOR OUTPUT:- we use this statement whenever we want dump the contents into a file

     

    present in the application server.The syntax for that is OPEN DATASET <filename> FOR OUTPUT.

     

    when the specified filename is not present in the application server then a file with a name

     

    specified in the OPEN DATASET STATEMENT is created and the contents will dumped into that

     

    file.

     

    OPEN DATASET FOR APPENDING:- This statement is used when we want to add new data to  a file

     

    which is already having data on the application server. The new data will added at the end

     

    of the file. The syntax for this statement is OPEN DATASET <filename> FOR APPENDING.

     

    here also if the necessary file is not present in the application server is not present then

     

    a file with a name specified in the OPEN DATASET STATEMENT is created and the data is dumped

     

    into that file.

  • Re: OPEN DATASET FOR  {INPUT, OUTPUT AND UPDATE}
    satish kotian
    Currently Being Moderated

    hi

    i am trying to read more than 1 files . I am having this issue with abap code.i have like more than 100 files but program is abending reading after 50files..

    Program failing in  open dataset error  can u help me please?

    143

    144 * Each file is getting into an internal table

    >>>   OPEN DATASET w_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

    146   IF sy-subrc <> 0.

    147     CONTINUE.

    148   ELSE.

    149     DO.

    150       READ DATASET w_file INTO s700_delta.

    What command I should give here

    Error analysis

        An exception occurred that is explained in detail below.

        The exception, which is assigned to class 'CX_SY_TOO_MANY_FILES', was not

         caught and

        therefore caused a runtime error.

        The reason for the exception is:

        The maximum number of open files (100) has been exceeded.

    can u help me

  • Re: OPEN DATASET FOR  {INPUT, OUTPUT AND UPDATE}
    Dillip Sahoo
    Currently Being Moderated

    HI saritha,

     

    The below link will give you a clear idea.

    [Basic Form of the OPEN DATASET Statement.|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3c8c358411d1829f0000e829fbfe/frameset.htm]

     

    Regards

    DKS

Actions