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

METHOD DESTRUCTOR

Former Member
0 Likes
3,273

Hi,

I have a class in ABAP. My constructor is;

method CONSTRUCTOR.

...

CREATE OBJECT X_APP_EXCEL 'excel.application'.

...

endmethod.

I want to free X_APP_EXCEL object in destructor. And I wrote;

method DESTRUCTOR.

FREE OBJECT X_APP_EXCEL.

endmethod.

But, I am getting an error as;

"Within a destructor method, you can only use the system-call c-destructor." What is this? How can I free my object?

Thanks.

1 ACCEPTED SOLUTION
Read only

athavanraja
Active Contributor
0 Likes
1,848

when you created the method (destructor) its self the system would warn you that only c-destructor is supported.

its generally implemented using method FREE.

Regards

Raja

12 REPLIES 12
Read only

Former Member
0 Likes
1,848

Hi,

if you see the standard classes there you can see only clear , and refresh.

so i think you can use clear and refresh to destroy.

don't use free.

for reference see the class method <b>cl_gui_alv_grid</b> 's <b>FREE</b> method. this is a destructor.

in side destructor you use clear and refresh that will work.

regards

vijay

Read only

athavanraja
Active Contributor
0 Likes
1,849

when you created the method (destructor) its self the system would warn you that only c-destructor is supported.

its generally implemented using method FREE.

Regards

Raja

Read only

0 Likes
1,848

I can not write anything in destructor. When I write refresh and clear commands, the same error occured, and my X_APP_EXCEL is an ole object. I have to free this object. But I do not know how can I do? And what is c-destructor?

Read only

0 Likes
1,848

hi,

better change the name of the method and see .

change the name from destructor to free or some thing else.

regards

vijay

Read only

0 Likes
1,848

Yes that is alternative for solution. But, this class will be used by another users. Maybe at the end of they will not call the FREE method for free my X_APP_EXCEL. In this case, this is not good for object programming.

Read only

0 Likes
1,848

Hi,

you should ask them to use the FREE method. to free the object.

regards

vijay

Read only

0 Likes
1,848

Thanks

But, I want to ask that, why there is a destructor method in ABAP? When and why this method will be used? In another languages such as java, I am declaring destuctor method to free of class's resources. Is there any different concept for ABAP's destructor?

Thanks.

Read only

0 Likes
1,848

There are no destructors in ABAP. Read note 168703 to get details and explanations on this topic. In Java there is also no destructor only method 'Finalize' but you don't have guarantee when it will be called.

DESTRUCTOR statement in ABAP is for SAP intrnal use and can call kernel routines written in C.

From note 168703:

"<b>In light of all these problems, the designers of ABAP Objects decided no not provide an ABAP Destructor at this time. Instead, there is a provision for a 'C-destructor' that can however only be used by SAP kernel developers.</b>"

Message was edited by: Tomasz Mackowski

Message was edited by: Tomasz Mackowski

Read only

0 Likes
1,848

Hi,

i have no idea where it is used ABAP,

may be it is for internal use.

that is the reason it is throwing errors.,

regards

vijay

Read only

Former Member
0 Likes
1,848

Hi All,

Well I tried finding some documentation on this , but in vain .... so it doesnt seems this a reserved SAP method.

but it seems that the method destructor does not allow abap calls inside itself.

that means u can only use direct system call(kernel) to free memory.

As recommended by Vijay changing the name of method should solve your problem.

regards,

Sumeet Mishra

Read only

Former Member
0 Likes
1,848

Hi,

Well just to add to your understanding u can look for documentation on GARBAGE COLLECTOR.

ABAP uses GARBAGE COLLECTOR TO actually delete all object related resources.

During the FREE OBJECT command only the reference is lost , the memory is cleared only when the Garbage collector comes into picture.

regards,

Sumeet Mishra

Read only

0 Likes
1,848

Garbage Collector is used for managing ABAP Object objects, and FREE OBJECT is used to release OLE object referenced from ABAP code.

So I think you cannot guarantee freeing of Excel OLE object in your application after "destruction". You have two choices:

- free this object by yourself , but you must find a goood place where to do it, or

- leave this responsibility to clients of your class giving them some kind of 'free' or 'release' method which will call FREE OBJECT