Skip to Content

ATC Check: Explicit SORT statement required

Hi,

I have noticed that when we select data from second table(say ITAB2) based on first table(say ITAB1) using FOR ALL ENTRIES, without explicitly specifying the SORT statement on the first table (eg: SORT itab1 by key fields), the ATC check gives error that the two tables can be JOINED instead of individual selects. If I write an explicit SORT statement on ITAB1, the error goes away.

This happens if we define the ITAB1 as SORTED TABLE OF or apply the ORDER BY clause based on the primary key while fetching data.

Does it mean that ATC looks for an explicit SORT statement and does not consider that table is SORTED using a different technique?

Regards,

Manish

Add a comment
10|10000 characters needed characters exceeded

  • Is it a sorted table on the primary key? Do you use ORDER BY with FOR ALL ENTRIES? (there used to be lots of issues until recently, cf SAP notes)

    Either it's not exactly what you said, or ATC prioritizes the recommendation of joining the two database tables before checking the primary index, or it's a bug in ATC.

    But without the exact code concerned, and without the exact message, it's difficult to say.

Related questions

2 Answers

  • Posted on Jul 16, 2020 at 05:47 AM

    Hi Sandra,

    Here is the code for various scenarios:

    1. No SORT statement anywhere:
    If I do not use the SORT statement on lt_A501, in ATC check, it says that I should be joining these two tables (A501 and KONP). As A501 is a buffered table, I am not joining it with KONP, even if I do, the current ATC error goes away, but another one comes up which says" Buffered table in a JOIN".

    SELECT matnr, knumh

            FROM  a501
           WHERE  kappl =  'V'
            AND   kschl = 'ZMGC'
             AND  zzbuy =  'G0050'
             AND  matnr IN @lt_product_range
              AND datab LE @sy-datum
              AND datbi GE @sy-datum
            INTO TABLE @DATA(lt_a501).
    
          IF lt_a501 IS NOT INITIAL.
            " Get only the active condition records
            SELECT knumh, kbetr
             FROM konp
             FOR ALL ENTRIES IN @lt_a501
             WHERE knumh = @lt_a501-knumh
              AND  loevm_ko = ' '
             INTO TABLE @DATA(lt_konp).

    2. Explicit SORT statement added :
    if I add the explicit SORT statement on lt_A501 based on KNUMH, the ATC error goes away.

          SELECT matnr, knumh
            FROM  a501
           WHERE  kappl =  'V'
            AND   kschl = 'ZMGC'
             AND  zzbuy =  'G0050'
             AND  matnr IN @lt_product_range
              AND datab LE @sy-datum
              AND datbi GE @sy-datum
            INTO TABLE @DATA(lt_a501).
    
          IF lt_a501 IS NOT INITIAL.
            SORT lt_a501 BY knumh.
            " Get only the active condition records
            SELECT knumh, kbetr
             FROM konp
             FOR ALL ENTRIES IN @lt_a501
             WHERE knumh = @lt_a501-knumh
              AND  loevm_ko = ' '
             INTO TABLE @DATA(lt_konp).

    3. SORT using ORDER BY:
    And if I specify ORDER by KNUMH in the first query itself, ATC error again comes back

          " get data from condition table for the govt price buying grp
          SELECT matnr, knumh
            FROM  a501
           WHERE  kappl =  'V'
            AND   kschl = 'ZMGC'
             AND  zzbuy =  'G0050'
             AND  matnr IN @lt_product_range
              AND datab LE @sy-datum
              AND datbi GE @sy-datum
            ORDER BY knumh
            INTO TABLE @DATA(lt_a501).
    
          IF lt_a501 IS NOT INITIAL.
            " Get only the active condition records
            SELECT knumh, kbetr
             FROM konp
             FOR ALL ENTRIES IN @lt_a501
             WHERE knumh = @lt_a501-knumh
              AND  loevm_ko = ' '
             INTO TABLE @DATA(lt_konp).

    qw6bf.png (21.1 kB)
    d54ck.png (21.1 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 20, 2020 at 08:28 AM

    Hello Manish,

    ATC is a static code analysis tool. It works solely on source code, not in runtime and focuses on the most common weaknesses of the code. Hence it has a limited power to unfold complexity of the code. It is also not welcome to have tons of false positive findings..

    I would assume that an explicit SORT means for ATC something like the following: too complex scenario, does not worth to investigate any more, the developer must know what she or he is doing...

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.