Skip to Content
1

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

May 18, 2017 at 09:48 AM

600

avatar image

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

10 |10000 characters needed characters left characters exceeded

What is the data type of C_TH_DATA? That's what it seems to be complaining about.

0

It is a hashed table.

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

0

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.

0

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?

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Mike Pokraka May 18, 2017 at 12:48 PM
1

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).
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Thank you Mike, I can cancel anger management courses :-p

Just a question: can you use "value" to generate a string?

0

Yes you can use value <type>( ) to generate anything. Particularly useful for assigning structures or to avoid helper variables in function module calls.

Alternative would be:

data x type <type> value 'abc'.

See the excellent blogs from Horst:

https://blogs.sap.com/2013/05/27/abap-news-for-release-740-constructor-operator-value/

Summary blog here:

https://blogs.sap.com/2013/07/22/abap-news-for-release-740/

0
Uwe Fetzer May 18, 2017 at 12:45 PM
0

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 ;)

Share
10 |10000 characters needed characters left characters exceeded
Oliver Söder May 18, 2017 at 04:12 PM
0

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).
Share
10 |10000 characters needed characters left characters exceeded