Application Development 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: 

internal table?

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

7 REPLIES 7

Former Member
0 Kudos

Select * from table into t_itab

for all entries in itab

where DELKZ = 'U1'.

Former Member
0 Kudos

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>

former_member181962
Active Contributor
0 Kudos
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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

former_member235056
Active Contributor
0 Kudos

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

hermanoclaro
Participant
0 Kudos

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