07-07-2017 12:54 PM
When trying to execute the following code I am getting the error:
The variable "WA-EBELN" cannot be used here.
DATA: gt_tab1_tmp TYPE TABLE OF ekpo.
SELECT * FROM ekpo INTO TABLE gt_tab1_tmp.
DATA(lv_sum) = REDUCE i( INIT x = 0 FOR wa IN gt_tab1_tmp NEXT x = x + 1 ).
WRITE: wa-ebeln.
How to access the work-area that is being created dynamically?
Please help!!
07-08-2017 7:46 AM
Why do you want to? What value are you after? If it's the last entry, then
gt_tab1_tmp[ lines( gt_tab1_tmp) ]-ebeln should do it.
By the way - that's a terrible name for a variable. What's wrong with items or po_items? Meaningful names are an important part of decent programming. But I guess this is just some kind of proof of concept, since no-one would really select everything from EKPO, nor rely on the last record being read having any significance whatsoever.
07-07-2017 1:03 PM
Your variable wa is declared inline in your REDUCE statement and just like LET it is only visible within the inline statement. So you cannot use it outside.
07-07-2017 1:18 PM
But in the debugging mode, I am seeing that after executing the reduce statement, the wa visibility still there in write line also!! So, isn't there a way by which we can access that runtime variable?
See the screenshots below. I have changed the last line of the code to check the visibility.
07-07-2017 1:56 PM
It is "visible" but not usable. There is a simple trick (implicitly mentioned in the docu), but I don't tell it, because you should not use it.
07-08-2017 7:46 AM
Why do you want to? What value are you after? If it's the last entry, then
gt_tab1_tmp[ lines( gt_tab1_tmp) ]-ebeln should do it.
By the way - that's a terrible name for a variable. What's wrong with items or po_items? Meaningful names are an important part of decent programming. But I guess this is just some kind of proof of concept, since no-one would really select everything from EKPO, nor rely on the last record being read having any significance whatsoever.
07-10-2017 7:41 AM
07-10-2017 10:41 AM
I've heard that excuse before. I don't buy it. It takes exactly as long to use a meaningful name as a meaningless one, even for a test program. Why not get into the habit immediately of using meaningful names?
But you haven't answered my other question:
Why do you want to? What value are you after? If it's the last entry, then
gt_tab1_tmp[ lines( gt_tab1_tmp) ]-ebeln should do it.