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

Filter on internal table with multiple Fields

former_member664730
Participant
0 Likes
4,631

Hi All,

My requirement is to filter internal table using multiple fields.

CONTANTS:lc_star TYPE C VALUE '*'.

DATA:LIT_X_all TYPE STANDARD TABLE OF ZTT WITH NON-UNIQUE KEY EXTSYSTEM CCODE EKORG WERKS MATKL .
DATA: LIT_FILTER_E TYPE SORTED TABLE OF ZTT-EXTSYSTEM WITH NON-UNIQUE KEY TABLE_LINE ,
      LIT_FILTER_o TYPE SORTED TABLE OF ZTT-EKORG WITH NON-UNIQUE KEY TABLE_LINE ,
      LIT_FILTER_c TYPE SORTED TABLE OF ZTT-ccode WITH NON-UNIQUE KEY TABLE_LINE ,
      LIT_FILTER_w TYPE SORTED TABLE OF ZTT-werks WITH NON-UNIQUE KEY TABLE_LINE .
	  
 SELECT * FROM ZTT WHERE A = @i_A<br> INTO TABLE @LIT_X_ALL.

 LOOP AT i_pit_input INTO DATA(lwa_input).
 "filter to avoid select statement in loop
 lit_filter_e = VALUE #( ( CONV #( lc_star ) ) ( lwa_input-extsystem ) ).
 DATA(lit_final_e) = FILTER #( LIT_APPROVER_ALL IN lit_filter_e WHERE extsystem = table_line ).
 
 lit_filter_o = VALUE #( ( CONV #( lc_star ) ) ( lwa_input-ekorg ) ).
 DATA(lit_final_o) = FILTER #( lit_final_e IN lit_filter_O WHERE ekorg = table_line ).
 
 lit_filter_c = VALUE #( ( CONV #( lc_star ) ) ( lwa_input-ccode ) ).
 DATA(lit_final_c) = FILTER #( lit_final_o IN lit_filter_c WHERE ccode = table_line ).
 
 lit_filter_w = VALUE #( ( CONV #( lc_star ) ) ( lwa_input-werks ) ).
 DATA(lit_final_w) = FILTER #( lit_final_c IN lit_filter_w WHERE werks = table_line ).

 APPEND LINES OF lit_filter_w TO lit_FINAL.
 ENDLOOP.<br>

currently i am using above code with filter for each field . can we achieve same requirement with single filter instead of multiple filters.ThanksPhani

8 REPLIES 8
Read only

Sandra_Rossi
Active Contributor
0 Likes
3,537

Please edit your question, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!

Read only

ThorstenHoefer
Active Contributor
0 Likes
3,537

Hi phanikumar_y,

do you mean something like this:

select a~*
from @LIT_APPROVER_ALL as a 
where exists(
select @abap_true
from ztt as b
  where b~extsys = a~extsys
    and b~ekorg = a~ekorg
    and ...
)
into table @data(lt_result)

or 

select a~*
from @LIT_APPROVER_ALL as a 
inner join ztt as b
   on b~extsys = a~extsys
  and b~ekorg = a~ekorg
  and ....
into table @data(lt_result)
Read only

0 Likes
3,537

No. My requirement is check particular combination exists or not .

Read only

Sandra_Rossi
Active Contributor
3,537

It seems your code is incomplete as I don't understand the goal: why do you loop at I_PIT_INPUT, because final result will only consider last line of I_PIT_INPUT...

Read only

former_member664730
Participant
0 Likes
3,537

My bad . i missed append staement in end . edited code now.

Read only

stanislaslemaire
Participant
0 Likes
3,537

Hello,

perhape can you use standard function LVC_FILTER_APPLY ...
Check it !
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }

Read only

FredericGirod
Active Contributor
0 Likes
3,537

and why didn't you use directly the i_pit_input to filter the value of your table ?

FILTER #( lit_x_all IN i_pit_input
WHERE extsystem = extsystem
AND ekorg = ekor ....

(and I don't understand the usage of the * )

Read only

former_member664730
Participant
0 Likes
3,537

Hi Fredric,

i cannot use directly because i have use OR operation . check value or '*' exits or not ?

Thanks,

Phani