12-28-2006 4:39 AM
what is the use of statment . read data set and open data set and where to use and how to use?
i want to upload a .txt file from non-sap to sap ie into an internal table.
advance Thanks to all the guys who are viewing .
12-28-2006 4:42 AM
Open dataset is to open a file in the application server either for reading or writing. Read dataset is used to read from a file on the application server that has been opened for reading.
If your txt file is on the local PC, you can use the function module GUI_UPLOAD to upload it into an internal table.
12-28-2006 4:43 AM
12-28-2006 4:43 AM
1)OPEN DATASET stmt is used to open a file on applicaiton server either for reading or writing.
2)READ DATASET - when we open a file for reading/uploading we use READ DATASET stmt.
Eg: READ DATASET <dsn> INTO <wa>.
TRANSFER - is the statement we use for writing data to a file.
3)Source Code:
a)Reading Data from Application Server:
open dataset fname for input in text mode encoding default.
if sy-subrc ne 0.
write:/ 'Unable to open file:', fname.
else.
do.
read datasset fname into <wa>.
if sy-subrc ne o.
exit.
else.
append <wa> to itab.
endif.
close dataset fname.
enddo.
endif.
b)Writing Data to Application Server:
open dataset fname for output in text mode encoding default.
if sy-subrc ne 0.
write:/ 'Unable to open file:', fname.
else.
loop at itab.
transfer itab to fname.
endloop.
close dataset fname.
endif.
12-28-2006 4:44 AM
when u are uploading files from PC then u have to use FMs like
WS_UPLOAD or UPLOAD_FILES or Upload in se37.
Regards
Prabhu
12-28-2006 4:44 AM
Hi ,
The commands read dataset and open dataset are basically used to access and read a file on the application server.
Since you want to upload a file from another system into sap , you will have to use OPEN Dataset and Transfer command for this.
Please see the help ON OPEN DATASET for more details.
Regards
Arun
12-28-2006 4:44 AM
HI,
OPEN dataset and READ dataset are used to transfer data between application server and presentation server.
For uploading data from a text file use 'GUI_UPLOAD'
check the example below.
report ZTEST2.
data: file_path type string.
data: file_tab type filetable.
data: wa_tab like line of file_tab.
data: rc type i.
data: itab type standard table of cskt.
data: wa like line of itab.
start-of-selection.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
FILE_FILTER = '.TXT'
CHANGING
FILE_TABLE = file_tab
RC = rc
.
READ TABLE file_tab into wa_tab index 1.
file_path = wa_tab-filename.
call method cl_gui_frontend_services=>gui_upload
exporting
filename = file_Path
HAS_FIELD_SEPARATOR = 'X'
changing
data_tab = itab.
Regards,
12-28-2006 4:45 AM
Hi Ranjith,
READ DATASET , OPEN DATASET, CLOSE DATASET, DELETE DATASET statements are related to files in application server.
In SAP Application server (UNIX/WINDOWS) you want to store the data these above statements will helpful for you.
Use GUI_UPLOAD function module to upload data form non-sap to internal table.
Regards
Bhupal Reddy
12-28-2006 4:49 AM
this program is used to upload a file from presentation server to internal table.
Then that data is passed to the application server using open dataset.
DATA : BEGIN OF WA_VENDOR ,
LIFNR LIKE LFA1-LIFNR,
BUKRS LIKE LFB1-BUKRS,
EKORG LIKE LFM1-EKORG,
KTOKK LIKE LFA1-KTOKK,
END OF WA_VENDOR.
DATA : IT_VENDOR LIKE TABLE OF WA_VENDOR.
DATA : HORIN TYPE ABAP_CHAR1 VALUE %_HORIZONTAL_TAB.
DATA : STR TYPE STRING.
DATA : FNAME TYPE STRING VALUE 'TEST1.TXT'.
*To load data from presentation cerver
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\VD.TXT'
tables
data_tab = IT_VENDOR.
*Transfer the data to application server
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT IT_VENDOR INTO WA_VENDOR.
TRANSFER WA_VENDOR TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.
again data is read from the application server to interna table
OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
READ DATASET FNAME INTO STR.
SPLIT STR AT HORIN INTO WA_VENDOR-LIFNR WA_VENDOR-BUKRS WA_VENDOR-EKORG WA_VENDOR-KTOKK.
APPEND WA_VENDOR TO IT_VENDOR .
CLOSE DATASET FNAME.
After writing the data into application server goto transaction AL11 & see ur txt file there