‎2007 Jul 19 11:53 AM
Hi all,
I have an internal table with field DELKZ...and it contains values WB,U1,SP,KD...etc.
IF itab-delkz = 'U1'.
i need to get data from a database table.
My question is i dont want to write the SELECT statement in LOOP?
plz advise me regarding this.
regards.
kr.
‎2007 Jul 19 11:57 AM
Hi,
You can use the for all entries to avoid looping,
Please look the example code below.
<b>Reward all helpfull answers.</b>
select SERVICEPO from ymminward into table it_std_SERVICEPO
where gedocno = wrk_gedocno.
sort it_std_servicepo by servicepo.
delete adjacent duplicates from it_std_servicepo.
*Getting the vendor to be supplied
if it_std_servicepo is not initial.
select emlif from ekpo into table it_std_emlif
for all entries in it_std_servicepo
where ebeln = it_std_servicepo-servicepo.
sort it_std_emlif by emlif.
delete adjacent duplicates from it_std_emlif.
endif.
*Getting the addressnumber
if it_std_emlif is not initial.
select adrnr from lfa1 into table it_std_adrnr
for all entries in it_std_emlif
where lifnr = it_std_emlif-emlif.
sort it_std_adrnr by adrnr.
delete adjacent duplicates from it_std_adrnr.
endif.
Regards,
rakesh.
‎2007 Jul 19 11:55 AM
Select * from table into t_itab
for all entries in itab
where DELKZ = 'U1'.
‎2007 Jul 19 11:56 AM
hi
<b>select * from ztable into itab2 for all entries in itab where delkz = 'U1'.</b>
regards
ravish
<b>plz dont forget to reward points if helpful</b>
‎2007 Jul 19 11:56 AM
loop at itab where delkz = 'U1'.
itab2 = itab.
append itab2.
clear itab2.
endloop.
if not itab2[] is initial.
select * from <database table> into table itab_new
for all entries in itab2
where <condition>.
endif.Regards,
Ravi
‎2007 Jul 19 11:57 AM
Hi,
You can use the for all entries to avoid looping,
Please look the example code below.
<b>Reward all helpfull answers.</b>
select SERVICEPO from ymminward into table it_std_SERVICEPO
where gedocno = wrk_gedocno.
sort it_std_servicepo by servicepo.
delete adjacent duplicates from it_std_servicepo.
*Getting the vendor to be supplied
if it_std_servicepo is not initial.
select emlif from ekpo into table it_std_emlif
for all entries in it_std_servicepo
where ebeln = it_std_servicepo-servicepo.
sort it_std_emlif by emlif.
delete adjacent duplicates from it_std_emlif.
endif.
*Getting the addressnumber
if it_std_emlif is not initial.
select adrnr from lfa1 into table it_std_adrnr
for all entries in it_std_emlif
where lifnr = it_std_emlif-emlif.
sort it_std_adrnr by adrnr.
delete adjacent duplicates from it_std_adrnr.
endif.
Regards,
rakesh.
‎2007 Jul 19 11:58 AM
Hi,
If only one entry existing in the internal table then..
Read the data into workarea where delkz = 'U1'.
if sy-subrc eq 0.
select.......
endif.
if multiple entries are existing in itab then..
append lines of itab into itab2.
delete itab2 where delkz ne UI.
if itab2[] is not initial.
select .....for all entries in itab2.
endif.
Reward points if it helps..
regards,
Omkar.
‎2007 Jul 19 12:03 PM
Hi,
The way to skip loop statement is only to use,
SELECT * FROM <DATABASE TABLENAME> INTO CORRESPONDING FIELDS OF TABLE <UR TABLENAME> WHERE DELKZ = 'U1'.
But its better to use loop statement for better performance of program.
Pls reward points.
Regards,
Ameet
‎2007 Jul 19 12:23 PM
Hi,
For this, you would need to create a second internal table, to contain the data that fulfill your requeriments, or you could delete from the internal table all the entries that does not fulfill the requeriments.
Like this (for create another itab):
LOOP AT itab1 WHERE delkz = 'U1'.
CLEAR: itab2.
itab2 = itab1.
APPEND itab2.
ENDLOOP.
Or this (Deleting):
DELETE itab1 WHERE delkz <> 'U1'.
Then, you can select the data you need, either from the itab2 or, if you choose to delete from the original internal table, the itab1, like as follows:
SELECT * FROM dbtab FOR ALL ENTRIES IN itab1 (or itab2) WHERE log_exp.
Best Regards,
-h