‎2006 Oct 30 2:26 PM
Hello, I am new to ABAP so please bear with me if my question is a little stupid...
I am creating a program to dataload information into a transaction from a text file. I am checking the file exists by doing the following:
OPEN DATASET file IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE s001(zt) WITH 'Unable to locate specified file'.
STOP.
ENDIF.But I would also like to be able to check the contents of the file and stop the program creating a batch input session if an empty file is being loaded.
Is there a way this can be done?
Kind Regards
Carly
‎2006 Oct 30 2:30 PM
Hi, after you open it you can simply read it, into your ITAB, then check ITAB afterwards, if not initial, then create your BI SESSION.
report zrich_0001.
Parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt'.
data: itab type table of string.
data: wa type string.
start-of-selection.
* Read file
open dataset d1 for input in text mode.
if sy-subrc = 0.
do.
read dataset d1 into wa.
if sy-subrc <> 0.
exit.
endif.
append wa to itab.
enddo.
endif.
close dataset d1.
<b>
if not itab[] is initial.
* then create your BI session.
endif.</b>
Regards,
Rich Heilman
‎2006 Oct 30 2:30 PM
Hi, after you open it you can simply read it, into your ITAB, then check ITAB afterwards, if not initial, then create your BI SESSION.
report zrich_0001.
Parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt'.
data: itab type table of string.
data: wa type string.
start-of-selection.
* Read file
open dataset d1 for input in text mode.
if sy-subrc = 0.
do.
read dataset d1 into wa.
if sy-subrc <> 0.
exit.
endif.
append wa to itab.
enddo.
endif.
close dataset d1.
<b>
if not itab[] is initial.
* then create your BI session.
endif.</b>
Regards,
Rich Heilman
‎2006 Oct 30 2:31 PM
OPEN DATASET file for input IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE s001(zt) WITH 'Unable to locate specified file'.
STOP.
ENDIF.
do.
read dataset file into jtab.
if sy-subrc <> 0.
exit.
endif.
close dataset file.
if jtab is not initial.
loop at jtab.
---
---
write ur bdc code here
endloop
Message was edited by: Kaluvala Santhosh
‎2006 Oct 30 2:38 PM
Hi Carly,
try this:
data: lines type sy-tabix.
OPEN DATASET DATEI_AC FOR INPUT IN TEXT MODE.
*
IF SY-SUBRC NE 0. MESSAGE E001. EXIT. ENDIF.
*
DO.
READ DATASET DATEI_AC INTO ITAB_AC.
IF SY-SUBRC <> 0. EXIT. ENDIF. "EOF reached
APPEND ITAB_AC.
ENDDO.
*
CLOSE DATASET DATEI_AC.
*
describe table itab_AC lines lines.
*
if lines = 0. "than are no lines in the external file.
write: / 'Nolines in external file'.
else.
do what you want.
...
endif.
Regards, Dieter
‎2006 Oct 30 3:26 PM
Hi,
if itab[] is initial.
message 'No data to transfer'
else.
loop at itab.
transfer itab to gv_file.
endloop.
endif.
Regards
amole