2017 Dec 12 3:12 AM
Hi Experts,
I have some problem that i'm already solve it, my problem is about CLEARING working area and REFRESHING internal table. i found out after the program execute the internal table and working area are still cointain the data when the program executed for the second time, the first execution data will combine with the second execution.
im already create form that i used to clear all working area and refresh the internal table. but i think thats still not efficient. is there any function or procedure i can use to clear or refresh all working area and internal table in single or couple lines?
note: im already browse in google i havent found any.
Thank you in advance and sorry for my bad english 🙂
here the example of my code that i think its not efficient:
2017 Dec 12 7:36 AM
Since you show only a subroutine, without telling anything about the environment (program type and execution, where is the subroutine called etc.), one can give only general hints:
You should make yourself knowledgable about
In order to understand your code better you should not use obsolete concepts. One of the reasons that they are obsolete is their strange behavior. REFRESH is obsolete too.
2017 Dec 12 7:36 AM
Since you show only a subroutine, without telling anything about the environment (program type and execution, where is the subroutine called etc.), one can give only general hints:
You should make yourself knowledgable about
In order to understand your code better you should not use obsolete concepts. One of the reasons that they are obsolete is their strange behavior. REFRESH is obsolete too.
2017 Dec 12 8:47 AM
For more information, my program type is Module Pool. The Subroutine will call first (in PBO) to Clear and Refresh all internal table and working area. after i read your reference i should change refresh into free but it still not efficient if i should write all working area and internal table i declare before in the subroutine. and there is a risk if the future enhancement to add more internal table and the programmer not add the internal table to the subroutine.
Thank you in advance.
2017 Dec 12 3:22 PM
You wouldn't have to bother if you used ABAP Objects, all these data objects as attributes of an object, and creating the object guarantees that these attributes have the initial value.
PS: using a module pool doesn't prevent using ABAP Objects on 99,99% of the code.
2017 Dec 12 3:47 PM
I liked the fact that the FORM name begins with f_. obviously just in case, you know, you mistook it for an object reference...
2017 Dec 12 4:34 PM
"and there is a risk if the future enhancement to add more internal table and the programmer not add the internal table to the subroutine."
If this is your concern, Sandra's answer is correct. Use ABAP Objects and let the garbage collector do the work for you.
2017 Dec 12 11:45 PM
Hello Hariyanto Hariyanto,
your central FORM for all initialization works, it is generally a best practice to initialize variables before they are used. The problem is not efficiency as your implementation is fast enough, but
So a lot discipline is required from the developer. In a complex design, it is difficult to gain confidence that all variables are properly initialized. Sandra and Horst already proposed the solution: use the Create Object pattern of ABAP Objects
In its simplest form, you make all variables public attributes of a class. You now must create an object using the CREATE OBJECT obj statement to access those attributes without a run-time error. The attributes are all initialized automatically.
You might implement a CONSTRUCTOR method for explicit initialization. For a complex design many objects are needed, each with its own initialization. A special factory method or a separate factory class will give you confidence that all objects are properly initialized. With this approach, the system helps you enforce the initialization of your data (attributes) before usage.
Further, you can make the data private and so control with routine (method) is allowed to change the data. Those are basic but significant advantage of objects.
regards,
JNN
2017 Dec 12 9:33 AM
Horst Keller is right about the concepts..
I think your subroutine is not getting called every time so not clearing workareas and internal tables.
If you want to get the root cause, better way would be put a breakpoint inside subroutine and then check if it is called or not?
Then yourself can find the issue, as this is clearly your program design issue.
And best way to clear workarea is 'Clear' and Internal table 'Free'(which you are already using).
2017 Dec 13 6:37 AM
Can you share more details about your problem like
-Where in your code this FORM is called
-Is it under some IF statement (so it is called based on some condition)
-Did you debug it and verified if the code in Form is ecxecuted