‎2010 Aug 10 2:38 PM
Hello Experts,
DATA: lv_file_str TYPE string VALUE 'Z:\ECD Direct Input\YCOMMPR01_IN\test.txt' .
TYPES:BEGIN OF gty_rel_001,
matnr1(40),
matnr2(40),
matnr3(40),
END OF gty_rel_001.
DATA: gt_rel_001 TYPE TABLE OF gty_rel_001 WITH HEADER LINE.
data: lv_data type string.
OPEN DATASET lv_file_str
FOR INPUT IN TEXT MODE ENCODING UTF-8.
IF sy-subrc = 0.
READ dataset lv_file_str INTO gt_rel_001.
CLOSE DATASET lv_file_str.
ENDIF.
I dont understand why , at open dataset-- sy-subrc = 0.
at read dataset --sy-subrc = 4.
Please help.
‎2010 Aug 10 2:46 PM
Did u mean u didnt understand sy-subrc value meaning here in the code?
Sy-subrc value meaning for open data set
0 File was opened.
8 Operating system could not open file.
Sy-subrc value meaning for read data set
0 Data was read without reaching end of file.
4 Data was read and the end of the file was reached or there was an attempt to read after the end of the file.
‎2010 Aug 10 2:49 PM
I think there is no data in the file... sy-subrc = 4 after read dataset statement indicates it has reached end of file...
<a href=" http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d42358411d1829f0000e829fbfe/frameset.htm ">http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3d42358411d1829f0000e829fbfe/frameset.htm</a>
‎2010 Aug 10 2:51 PM
Hi guyz ,
I understand what is sy-subrc = 4 , but the thing is if it reached end of the file then I should see data in my internal table but my internal table is empty? confused..
‎2010 Aug 10 2:55 PM
then I should see data in my internal table
Your code doesnt indicate and internal table operations.
Firts of all check whether the file has any contents, it might also contain blank lines.
‎2010 Aug 10 2:56 PM
shudnt I see the data in gt_rel_001 after read dataset ?
The file has contents but its not uploading , i dont know why?
Edited by: BrightSide on Aug 10, 2010 2:57 PM
‎2010 Aug 10 3:24 PM
Your error goes here
READ dataset lv_file_str INTO gt_rel_001. "here gt_rel_001 is a internal table, you are just moving it the header line and not appending
‎2010 Aug 10 3:33 PM
I tried it using a string and then appending but I still getting sy-subrc = 4.
Thanks
‎2010 Aug 10 3:35 PM
Hi Just go through this code, here the contents in the file are seperated by tab
*Field Symbols
FIELD-SYMBOLS:
<fs_line> TYPE string,
<fs_comp> TYPE ANY.
DATA:i_tab TYPE TABLE OF string,
la_mvke TYPE type_mvke_wa.
DO.
CLEAR:wf_string,
wa_matnr,
wa_vkorg,
wa_vtweg.
READ DATASET p_rep INTO wf_string.
IF sy-subrc NE 0.
IF sy-index EQ 1. "No data in the file
IF sy-batch IS INITIAL.
MESSAGE e904 WITH 'No records in file to reprocess'.
ELSE.
MESSAGE s904(zf) WITH text-006 DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSE. "End of File
CLOSE DATASET p_rep.
EXIT.
ENDIF.
ENDIF.
CLEAR : la_mvke,
i_tab[].
SPLIT wf_string AT
cl_abap_char_utilities=>horizontal_tab
INTO TABLE i_tab.
LOOP AT i_tab ASSIGNING <fs_line>.
ASSIGN COMPONENT sy-tabix OF STRUCTURE la_mvke TO <fs_comp>.
IF sy-subrc NE 0.
EXIT.
ELSE.
<fs_comp> = <fs_line>.
ENDIF.
ENDLOOP.
append la_mvke to i_mvke.
clear la_mvke.
enddo.
‎2010 Aug 10 3:12 PM
Hi Brightside,
You internal table work area gt_rel_001 in which you are reading the data is having three fieldds where as the lv_file_str will be on single string so in ur case work area should have a single field (a string) in which the read can insert the values.
Just for your reference attaching a code snippet
OPEN DATASET lv_filename FOR INPUT IN TEXT MODE.
IF sy-subrc NE c_zero.
PERFORM delete_dataset USING pv_filepath lwa_fnames-name.
MESSAGE e000(zcf) WITH text-058 lv_filename.
ELSE.
DO.
READ DATASET lv_filename INTO lwa_filedata-text.
IF sy-subrc NE c_zero.
EXIT.
ENDIF.
APPEND lwa_filedata TO li_filedata.Regards
Abhii
‎2010 Aug 10 3:14 PM
Where is your file? If it's on your PC then you need to use function module GUI_UPLOAD instead. OPEN DATASET is for files sitting on the operating system level of your application servers
‎2010 Aug 10 3:20 PM
Files are in application server .
Edited by: BrightSide on Aug 10, 2010 3:20 PM