Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Checking a file for data

Former Member
0 Likes
770

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

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
644

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

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
645

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

Read only

Former Member
0 Likes
644

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

Read only

Former Member
0 Likes
644

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

Read only

Former Member
0 Likes
644

Hi,

if itab[] is initial.

message 'No data to transfer'

else.

loop at itab.

transfer itab to gv_file.

endloop.

endif.

Regards

amole