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

error when read dataset - file not open

dear all,

I m having a text file in my 'C:\' , say - p_file = 'C:\test.txt' i m trying to open this file using

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE encoding default.

and tried reading the file using

do

READ DATASET p_file into line.

endloop.

but im getting runtime error saying " file not open". how to read the file.

regs,

Raja

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 11:03 AM

    Hi Raja,

    it seems you are reading file from Local system. Use GUI_UPLOAD to read text file from local system.

    Reward Points if this helps,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 20, 2007 at 11:03 AM

    Hi,

    OPEN DATASET p_file FOR I<b>NPUT</b> IN TEXT MODE encoding default.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 11:04 AM

    OPEN DATASET works only on app server files, for presentation server files, u have to use GUI_UPLOAD function module

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 20, 2007 at 11:06 AM

    Hi,

    FOR OUTPUT means ur trying to write, but i think ur trying to write in existing file. If file is already exist then use FOR APPENDING, otherwise FOR OUTPUT

    will create new file automatically for write.

    EX.

    form open_file.

    if p_aserv eq 'X'.

    open dataset p_path for output in text mode encoding default.

    if sy-subrc ne 0.

    • WRITE :/ 'Download Failed'.

    message e000(8i) with 'Error in File opening for download'.

    endif.

    endif.

    endform. " open_file

    Regards,

    Prashant

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 11:50 AM

    first check whether u r having authorization or not to create file in application server because i faced the same problem

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hi Raja,

    u cant use OPEN DATASET statemen to handel the in the presentation server.

    while using the presentation server, u have to use UPLOAD FM and u should read into internal table and then u can start using the records from itab...

    if u use OPEN DATASET statemen to handel the in the presentation server, then u will get sy-subrc = 8 ( Operating system could not open file ).

    sample code...

    TYPES: BEGIN OF INREC,

    KUNNR LIKE KNA1-KUNNR,

    REGIO LIKE KNA1-REGIO,

    TELF1 LIKE KNA1-TELF1,

    END OF INREC.

    DATA: IN_ITAB TYPE INREC

    OCCURS 10 WITH HEADER LINE.

    CALL FUNCTION ‘UPLOAD’

    EXPORTING

    FILENAME = ‘c:\bc180_file2’

    TABLES

    DATA_TAB = IN_ITAB.

    LOOP AT IN_ITAB.

    WRITE: / IN_ITAB-KUNNR,

    IN_ITAB-REGIO,

    IN_ITAB-TELF1.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 12:35 PM

    Hi Raja,

    i write a code for ur problem and i check whether it is executing or not.The code that i written is executed sucessfully.

    I am sending two programs both output the data to dataset and also input the data to dataset.

    First execute the first program and then run the second program.ok

    If u are satisfy with the code PLZ give me the REWARD POINTS..

    CODE FOR OUTPUT:

    ----


    • Internal Table

    ----


    DATA: BEGIN OF itab OCCURS 0,

    text(50),

    END OF itab.

    ----


    • Append data to Internal Table

    ----


    itab-text = 'DEMO BDC FIRST LINE'.

    APPEND itab.

    itab-text = 'DEMO BDC SECOND LINE'.

    APPEND itab.

    ----


    • OPEN THE DATASET

    ----


    OPEN DATASET 'ZBDCDEMO' FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

    ----


    • Transfer the data to APPSERVER

    ----


    LOOP AT itab.

    TRANSFER itab TO 'ZBDCDEMO'.

    ENDLOOP.

    ----


    • Close the Dataset

    ----


    CLOSE DATASET 'ZBDCDEMO'.

    CODE FOR INPUT:

    ----


    • Internal Table

    ----


    DATA: BEGIN OF itab OCCURS 0,

    text(50),

    END OF itab.

    ----


    • OPEN THE DATASET

    ----


    OPEN DATASET 'ZBDCDEMO' FOR INPUT IN TEXT MODE ENCODING DEFAULT.

    if sy-subrc = 0.

    ----


    • READ THE DATA FROM THE DATASET AND PLACE THEM IN ITAB

    ----


    do.

    read dataset 'ZBDCDEMO' into itab.

    if sy-subrc = 0.

    append itab.

    else.

    exit.

    endif.

    enddo.

    endif.

    ----


    • Display the Data

    ----


    loop at itab.

    write: / itab-text.

    endloop.

    ----


    • Display the Data

    ----


    close dataset 'ZBDCDEMO'.

    Add a comment
    10|10000 characters needed characters exceeded

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.