‎2009 May 15 2:54 PM
Hi
I had an requirement to read the data file in .txt format form sap application server.I am using the opendata set comanda,but its giving me dump saying,the file is not open.
please tell me how to resolve it,my file save as bdc.txt on application server which is on unix server.
code:
DATA:BEGIN OF itab OCCURS 0,
matl_type(4) TYPE c,
matl_group(9) TYPE c,
matl_desc(40) TYPE c,
char_prof(18) TYPE c,
END OF itab.
DATA:wa LIKE itab.
DATA file TYPE string VALUE `/sap/inbound/bdc.txt`.
OPEN DATASET file FOR OUTPUT IN BINARY MODE.
WRITE:'ok'.
FIELD-SYMBOLS <hex_container> TYPE x.
ASSIGN wa TO <hex_container> CASTING.
DO.
READ DATASET file INTO <hex_container>.
IF sy-subrc = 0.
WRITE: / wa-matl_type,
wa-matl_group,
wa-matl_desc,
wa-char_prof.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET file.
‎2009 May 15 3:41 PM
Hi,
You should open in input mode for reading.
Local variable Declaration
DATA l_msg(60) TYPE c.
Opening the file for output in text mode
OPEN DATASET ....
MESSAGE l_msg.
In debugging mode, you can get the message in l_msg.
‎2009 May 15 2:56 PM
If you are trying to read a file, why are you opening it for output?
‎2009 May 15 3:07 PM
I had a req to use the data,from bdc.txt file to perform a bdc.
so i am just displaying is for test & if sucessful,will load in table to execute as required.
‎2009 May 15 3:21 PM
Hi,
I have made some changes on your code ,.
Now it is working fine.
Please check the following --
DATA:BEGIN OF ITAB OCCURS 0,
MATL_TYPE(4) TYPE C,
MATL_GROUP(9) TYPE C,
MATL_DESC(40) TYPE C,
CHAR_PROF(18) TYPE C,
END OF ITAB.
DATA:WA LIKE ITAB.
*DATA file TYPE string VALUE `/sap/inbound/bdc.txt`. " Commented
DATA FILE TYPE STRING VALUE 'BDC'. " Added
OPEN DATASET FILE FOR INPUT IN BINARY MODE. " Not output, specify INPUT
IF SY-SUBRC EQ 0. " Added
WRITE:'ok'.
FIELD-SYMBOLS <HEX_CONTAINER> TYPE X.
ASSIGN WA TO <HEX_CONTAINER> CASTING.
DO.
READ DATASET FILE INTO <HEX_CONTAINER>.
IF SY-SUBRC = 0.
WRITE: / WA-MATL_TYPE,
WA-MATL_GROUP,
WA-MATL_DESC,
WA-CHAR_PROF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF. " Added
CLOSE DATASET FILE.Regards
Pinaki
‎2009 May 15 3:41 PM
Hi,
You should open in input mode for reading.
Local variable Declaration
DATA l_msg(60) TYPE c.
Opening the file for output in text mode
OPEN DATASET ....
MESSAGE l_msg.
In debugging mode, you can get the message in l_msg.
‎2009 May 15 3:42 PM
Hi Vipin,
Actullly Your OPEN DATASET .... statement was unsuccessful to open the
file `/sap/inbound/bdc.txt`.
And without checking SY-SUBRC the code was trying to read data from a file
which is not opened at all.That was causing the runtime error.
So after your OPEN DATASET ... statement you need to cheeck SY-SUBRC and
if it success then only you need to proceed.
Another thing is that if you want to read from a file to your report in that case
you need to open the file FOR INPUT .
Specify the file value properly.
Regards
Pinaki