cancel
Showing results for 
Search instead for 
Did you mean: 

create inline a filter table with new abap syntax

sebastian_wilhelm1
Participant
0 Kudos

Hi experts!

I have a table productions containing, among others, article ids. Now I want to loop over all entries for which no Article ID exists in the articleIs table. Can I do this inline with the new abap syntax. 

Something like this

 

LOOP AT filter #( productions IN articles where ArticleId not in articles-ArticleId ) INTO DATA(production).

 

Does anyone know if this is possible.

Thanks and regards,

Sebastian

Sandra_Rossi
Active Contributor
0 Kudos
EXCEPT IN
sebastian_wilhelm1
Participant
0 Kudos

Hi Sandra! Thanks for you answer but it seems that it is not working.

I tried 

filter #( productions EXCEPT IN articles where ArticleId = ArticleId )

and got an error "The operation requires a key (SORTED or HASHED) on table column(s)". None of the table is a sorted or hashed table.

Sandra_Rossi
Active Contributor
With FILTER, articles MUST BE a sorted or hashed table, whatever it's IN or EXCEPT IN. See ABAP documentation for more information.
sebastian_wilhelm1
Participant
0 Kudos
Okay thanks. Then filter doesn't help. In most cases I don't have a sorted or hashed table. When I have to create one and map the data, the implementation effort is higher than doing a nested loop. Do you know if there is another inline syntax achiving the desired result?
Sandra_Rossi
Active Contributor

It's a problem if you don't use sorted/hashed tables for the kind of operation you want to do, you'll get bad performance.

Can't you simply define a secondary key for your standard table articles?

I REALLY DON'T recommend this solution if articles is a standard table, but you can do it this way (VALUE, REDUCE, NEW):

VALUE #( FOR <production> IN productions
         LET article = REF #( articles[ ArticleId = <production>-ArticleId ] OPTIONAL )
         IN
         ( LINES OF COND #( WHEN article IS BOUND THEN ... ) ) )

 

sebastian_wilhelm1
Participant
0 Kudos
Thanks for you help. I'm wokring on BTP and the tables are all SAP Standard Tables, so creating a secondary key is no usefull option. How can I mark your comment as a correct answer?
Sandra_Rossi
Active Contributor
0 Kudos
Do you mean S/4HANA Public Cloud? I don't understand why you are limited to use only standard internal tables. At worst, you can copy to a sorted table and free immediately the memory of the standard table, the copy is very fast compared to repeated linear search.
sebastian_wilhelm1
Participant
0 Kudos
Hi Sandra! I'm not limited to standard tables. The intention of my question was to find a short way to create a filter like described - without creating extra tables with secondary keys and doing some mapping. The mentioned tables articles and productions will only contain 1-5 entries, so I shouldn't get a performance issue.

Accepted Solutions (1)

Accepted Solutions (1)

patrick_winkler
Product and Topic Expert
Product and Topic Expert
0 Kudos
    TYPES: BEGIN OF ty_production,
             prod_id    TYPE string,
             article_id TYPE string,
           END OF ty_production,
           BEGIN OF ty_article,
             article_id TYPE string,
           END OF ty_article,
           tt_productions TYPE SORTED TABLE OF ty_production WITH UNIQUE KEY prod_id,
           tt_articles    TYPE SORTED TABLE OF ty_article    WITH UNIQUE KEY article_id.

    DATA(productions) = VALUE tt_productions( ( prod_id = 'P1' article_id = 'A1' )
                                              ( prod_id = 'P2' article_id = 'A2' )
                                              ( prod_id = 'P3' article_id = 'A3' ) ).
    DATA(articles) = VALUE tt_articles( ( article_id = 'A1' )
                                        ( article_id = 'A3' )
                                        ( article_id = 'A4' ) ).

    LOOP AT FILTER #(  productions EXCEPT IN articles WHERE article_id = article_id )
      ASSIGNING FIELD-SYMBOL(<prod_with_not_exst_art>).
      out->write( <prod_with_not_exst_art>-prod_id ).
    ENDLOOP.

Answers (0)