Skip to Content
avatar image
Former Member

"LOOP ... WHERE ..." the line type of the table must be statically defined"

I am trying to Loop at a dynamic internal table (C_TH_DATA) using a WHERE clause.
(C_TH_DATA is being accessed in exit function - IF_RSPLFA_SRVTYPE_IMP_EXEC_REF~EXECUTE)

Error message:
"LOOP ... WHERE ..." the line type of the table must be statically defined"

I do NOT want to LOOP AT and use IF-condition inside the loop.

TYPES:<br>" contains exactly same fields as C_TH_DATA

" I just show LT_C_DATA to let you know which fields are inside of C_TH_DATA
 BEGIN OF LTY_C_TH_DATA,
      CALMONTH(6) TYPE N,
      CALYEAR(4) TYPE N,
      INFOPROV(30) TYPE C,
      YKYFD(6) TYPE C,
      YPOS(9) TYPE C,
      YVYTPE(3) TYPE C,
      YKYFA(9) TYPE P DECIMALS 3,
    END OF LTY_C_TH_DATA.

DATA: 
LTH_C_TH_DATA TYPE HASHED TABLE OF LTY_C_TH_DATA WITH UNIQUE KEY CALMONTH CALYEAR INFOPROV YKYFD YPOS YVYTPE,
LS_C_TH_DATA LIKE LINE OF LTH_C_TH_DATA.


* here is the problem:
 LOOP AT C_TH_DATA INTO LS_C_TH_DATA WHERE CALMONTH = '00000'.

* loop not processed because of error <br>* "LOOP ... WHERE ..." the line type of the table must be statically defined"
ENDLOOP<br>

This question has been asked several times in this forum before, but I did not see any answer:
https://archive.sap.com/discussions/thread/1800857

https://archive.sap.com/discussions/thread/1789437
https://archive.sap.com/discussions/thread/3354690

Add comment
10|10000 characters needed characters exceeded

  • Former Member Mike Pokraka

    It is a hashed table.

    It will be filled by the system if you do Integrated Planning, according to your filter.

  • Sorry, rephrase my question: How is the data type of your table defined? If it's dynamic then this would explain the message.

    I also note you use CALMONTH but the debugger shows 0CALMONTH.

  • Former Member Mike Pokraka

    Dear Mike, yes it is dynamic.

    No insult, but I wrote it in my first sentence: "I am trying to Loop at a dynamic internal table (C_TH_DATA) ..."
    And a maybe noobie question: can I control how the data type is defined in this case?

    You are right about CALMONTH / 0CALMONTH.
    I defined a hashed table as a work around, copied my C_TH_DATA into LTY_C_TH_DATA to be able to to on coding.

    But this is not the solution of the problem.

    I posted here to get help to solve my problem with C_TH_DATA.

    Any idea how to do that?

  • Get RSS Feed

3 Answers

  • Best Answer
    May 18, 2017 at 12:48 PM

    Sorry, missed the dynamic bit! Yes that's definitely the cause of the message. The compiler doesn't know the fields at compile time, therefore can't use a field in a WHERE.

    Some options: Try with a generic key table_line.

    Or use dynamic condition. Better still, combine with inline declaration:

    data(condition) = value string(`CALMONTH ='00000'`).
    LOOP at c_th_data into data(th_data_line) where (condition).
    Add comment
    10|10000 characters needed characters exceeded

  • May 18, 2017 at 12:45 PM

    Edit: And of course if you are on a newer release, simply don't declare a workarea anymore. Use inline declarations instead. Example:

    LOOP AT C_TH_DATA REFERENCE INTO DATA(LS_C_TH_DATA) WHERE CALMONTH = '00000'.

    Edit 2:

    I also missed the dynamic part ;)

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 18, 2017 at 04:12 PM

    The anwer of Mike did the trick:

    data(condition) = value string(`CALMONTH ='00000'`).
    
    LOOP at c_th_data into data(th_data_line) where (condition).
    Add comment
    10|10000 characters needed characters exceeded