Application Development and Automation 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: 
Read only

How to return REF TO ITAB from Static Method?

mithun1950
Discoverer
0 Likes
1,735

Good day to you, All!

is it possible to return (or exporting/changing) an internal table from STATIC method as a ref to?

At the moment I creating an instance of the class, copying itab to a class attribitute and getting this gt_itab via class instance in my program.

All previous attepmtions to get reference to returnings itab ended up with a freed stack message (so I worked with a local variable).

Any tips will be appreciated.

Thank you.

3 REPLIES 3
Read only

former_member751591
Participant
0 Likes
1,498

Thank you for visiting SAP Community to get answers to your questions. Since you are new, I recommend that you familiarize yourself with our Q&A Tutorial. It provides tips for preparing questions that draw responses from our members. Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a Pictureto your profile you encourage readers to respond.

Thank you!

Read only

FredericGirod
Active Contributor
0 Likes
1,498

I think you cannot, as you do not have instance, you do not have memory area allocated for your class. So when you finished to use it, the memory is free and everything is lost.

Why do you need absolutly a static method ?

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,498

All local variables are freed from memory when the procedure ends. If you get its Data Reference while the method is running and you return the Data Reference (whatever you use an exporting, changing or returning parameter, and even through an importing parameter if it's itself a reference), accessing it after the method has ended will produce a "freed" error.

The only solution is to create an Independent Data Reference which points to an Anonymous Data Object (CREATE DATA).

NB: note that you can also return a reference to a data object which exists outside of the procedure, like an instance attribute (as long as its instance keeps existing), static attribute, global variable, etc.