Skip to Content
avatar image
-1
Former Member

Clear Work Area and Internal Table in entire program

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:

clear-it.png (26.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • 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

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 12, 2017 at 07: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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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

      • others might not know about this policy and declare variables elsewhere
      • it is easy to miss some variables when you recheck after each change
      • there are no limit on how any other FORM/function may change the data

      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

  • avatar image
    Former Member
    Dec 12, 2017 at 09: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).

    Add comment
    10|10000 characters needed characters exceeded