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

Select loop

joerg_arndt
Participant
0 Likes
902

Hi Folks,

I try to download all the Reports to a file with the following code.

But it selects only 1 record and then it stops with a runtime error.

REPORT Z_DOWNLOAD_REPORTS .

tables trdir.

DATA : BEGIN OF ITAB OCCURS 0,

F(72) TYPE C,

END OF ITAB.

select *

from trdir

where name like 'BA%'.

READ REPORT trdir-name INTO ITAB.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\PRG.TXT'

TABLES

DATA_TAB = ITAB.

endselect.

Thank you very much for the help.

Joerg

1 ACCEPTED SOLUTION
Read only

kostas_tsioubris
Contributor
0 Likes
858

Hi,

your code has 2 errors. First of all the GUI_DOWNLOAD probably performs a commit work or something which in turn crash your program. Second since you are giving the same file name your file will be overwriten.

Do something like this.

data : begin of lt_name occurs 0,

name like trdir-name,

end of lt_name.

data: filename type string.

select name

from trdir into table lt_name

where name like 'BA%'.

loop at lt_name.

READ REPORT lt_name-name INTO ITAB.

filename = lt_name-name.

condense filename no-gaps.

concatenate ''C:\' filename '.txt' into filename.

condense filename no-gaps.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = filename

TABLES

DATA_TAB = ITAB.

endloop.

Regards

Kostas

Message was edited by:

Kostas Tsioubris

8 REPLIES 8
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
858

Hi,

Dont put any FM call between SELECT and ENDSELECT.

What you can do instead use SELECT INTO TABLE and then

data: it_trdir type table trdir.

SELECT * FROM TRDIR INTO TABLE it_trdir where name like 'BA%'.

call the FM

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\PRG.TXT'

TABLES

DATA_TAB = ITAB.

Regards,

Sesh

Read only

Former Member
0 Likes
858

try removing the select end select loop. Instead, take all programs in to another internal table and loop at that internal table to read the program and download.

reward if it helps

krishna

Read only

Former Member
0 Likes
858

Your GUI_DOWNLOAD statement is inside the select statement thats y , for each record it will excecute the GUI_DOWNLOAD fm. thts y one record is coming, the error is because of callin the fm in side the select statement.

regards

prabhu

Read only

Former Member
0 Likes
858

Your GUI_DOWNLOAD statement is inside the select statement thats y , for each record it will excecute the GUI_DOWNLOAD fm. thts y one record is coming, the error is because of callin the fm in side the select statement.

regards

prabhu

reward if it is helpful

Read only

kostas_tsioubris
Contributor
0 Likes
859

Hi,

your code has 2 errors. First of all the GUI_DOWNLOAD probably performs a commit work or something which in turn crash your program. Second since you are giving the same file name your file will be overwriten.

Do something like this.

data : begin of lt_name occurs 0,

name like trdir-name,

end of lt_name.

data: filename type string.

select name

from trdir into table lt_name

where name like 'BA%'.

loop at lt_name.

READ REPORT lt_name-name INTO ITAB.

filename = lt_name-name.

condense filename no-gaps.

concatenate ''C:\' filename '.txt' into filename.

condense filename no-gaps.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = filename

TABLES

DATA_TAB = ITAB.

endloop.

Regards

Kostas

Message was edited by:

Kostas Tsioubris

Read only

0 Likes
858

since you put the same program in select loop. you ll get the last output of the FM in last pass of the loop.

so your approach shud be like this

1. make a select on table and populate the data in internal table

2. loop at itab into wa.

use FM using WA

Endloop.

3. Cheers.

Read only

Former Member
0 Likes
858

Hi,

Remove the FM from Select... EndSelect.

Instead use

REPORT Z_DOWNLOAD_REPORTS .

tables trdir.

DATA : BEGIN OF ITAB OCCURS 0,

F(72) TYPE C,

END OF ITAB.

SELECT *

FROM TRDIR INTO TABLE ITAB

WHERE NAME LIKE 'BA%'.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\PRG.TXT'

TABLES

DATA_TAB = ITAB.

Reward points if useful,

Kiran

Read only

joerg_arndt
Participant
0 Likes
858

Thank you very much.