Open text file with ABAP :
1. open with "open dataset ". can run in background mode
You can open up to 100 files per internal session. The actual maximum number of simultaneously open files may be less, depending on the platform.
Example :
report zopenfile.
*------------------------------------------------
* www.developerpages.gr
*------------------------------------------------
data : rec(255).
parameters : fname(255).
open dataset fname for input in legacy text mode.
do.
read dataset fname into rec.
if sy-subrc <> 0.
exit.
else.
write :/ rec.
endif.
enddo.
close dataset fname.
2. open with GUI services .
cannot run in background mode
Example :
report zopenfile.
*--------------------------------------------------
* www.developerpages.gr
*--------------------------------------------------
TYPES: BEGIN OF itab_file,
rec(500) TYPE C,
END OF itab_file.
data: l_input_file type string.
data : rec_line(500).
data : f_TAB type table of itab_file.
l_input_file = 'c:\test.txt'.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = l_input_file
CHANGING
DATA_TAB = f_TAB
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
RAISE EXPORT_ERROR.
ENDIF.
loop at f_tab into rec_line.
write :/ rec_line.
endloop.
Original Article : http://developerpages.gr/index.php/el/desktop-development-2/abap/66-open-text-file-with-abap
1. open with "open dataset ". can run in background mode
You can open up to 100 files per internal session. The actual maximum number of simultaneously open files may be less, depending on the platform.
Example :
report zopenfile.
*------------------------------------------------
* www.developerpages.gr
*------------------------------------------------
data : rec(255).
parameters : fname(255).
open dataset fname for input in legacy text mode.
do.
read dataset fname into rec.
if sy-subrc <> 0.
exit.
else.
write :/ rec.
endif.
enddo.
close dataset fname.
2. open with GUI services .
cannot run in background mode
Example :
report zopenfile.
*--------------------------------------------------
* www.developerpages.gr
*--------------------------------------------------
TYPES: BEGIN OF itab_file,
rec(500) TYPE C,
END OF itab_file.
data: l_input_file type string.
data : rec_line(500).
data : f_TAB type table of itab_file.
l_input_file = 'c:\test.txt'.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = l_input_file
CHANGING
DATA_TAB = f_TAB
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
RAISE EXPORT_ERROR.
ENDIF.
loop at f_tab into rec_line.
write :/ rec_line.
endloop.
Original Article : http://developerpages.gr/index.php/el/desktop-development-2/abap/66-open-text-file-with-abap
No comments:
Post a Comment