Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to access dynamically created work area in ABAP 7.4?

0 Kudos

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!!

1 ACCEPTED SOLUTION

matt
Active Contributor

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.

6 REPLIES 6

fabianlupa
Contributor

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.

0 Kudos

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.

horst_keller
Product and Topic Expert
Product and Topic Expert

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.

matt
Active Contributor

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.

0 Kudos

Its just a test program to clear a concept.

matt
Active Contributor
0 Kudos

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.