Skip to Content

Memory consumption of ABAP programs even though a benchmark parameter to evaluate the performance and quality of the code, was never the prime object of interest during a code review activity. But over the period of time this same piece of code comes back as either a potential performance bottleneck to be resolved or a production issue or a memory overrun issue.

I came across a new an interesting improvement in the ABAP Language construct and it is quite intriguing to me. As a matter of fact, it takes only 30 lines of code to show its fascinating results. Let us take an hypothetical example of material master data wherein we select data from the table MARA.

Problem Statement:

Not all materials have an Old Material Number (BISMT) present. Typically during data migration / cutover activity new materials are created in SAP and also an old material number is also added to these. Over a period of time tens and thousands of new materials are created and these will not have the Old Material number information. And now if we have a select query and populate these in an internal table, large amount of memory is allocated just to maintain the initial values. As an ABAP developer, I never cared about this because never had any control on this memory allocation. If the internal table grows dramatically, so is the memory wastage. This is a linear growth of memory wastage and something had to be done.

BOXED Components.jpg

This is exactly the point of concern and also the source of opportunity to conserve the program memory. And SAP has answered to this issue by the introduction of a new keyword “BOXED”.

Solution : This keyword has been kept really simple and developer friendly, you just need to add the keyword addition to the internal table definition.

TYPES:BEGIN OF address,

            …

END OF address.

           Fig 1: Regular Internal Table Definition

TYPES:BEGIN OF address,

            …

  alt_post_addr1   TYPE address BOXED,

  alt_post_addr2   TYPE REF TO  address, “alternative address

END OF address.

     Fig 2: Internal Table Definition with BOXED components

The actual code implementation and runtime analysis coming soon…

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Matthew Billingham

    From what Basis version is this command available?

    (Moderator note: don’t use “b’coz” or similar abbreviations – especially in articles – spell words out in full).

    (0) 
    1. Clemens Li

      Hi Subrahmanya Pindiproli,

      thank you for this helpful and informative blog. Unfortunately I’m not yet working on Netweaver 7.0 Ehp 2 right now.

      I’d like to know what happens when displaying a table with boxed components in ALV, does it even work?

      The BOXED COMPONENT is comparable to INITIAL in the SQL database. As we can query a database for <field> IS INITIAL, what is the equivalent here.

      Is this an allowed way:

      LOOP AT itab REFERENCE INTO <dref>.

        CHECK <dref>->component IS BOUND.

      Although memory is much less critical than it used to be, it may allow use of huge database structures (like BSEG…) if we just declare all components as BOXED – I want a syntax to declare a structure as ALL COMPONENTS BOXED.

      Best regards

      Clemens

      (0) 
      1. Naimesh Patel

        Hello Clemens,

        Please allow me to answer your question, even thought they were to author.

        Structure declared with BOXED TYPE would be a deep structure. Since ALV’s can’t handle deep structure, I suppose we wont be able to use them for output purpose.

        Initial value sharing is controlled and managed by internal memory management. So, we can’t LOOP using what you have shown. But your ITAB is still an ITAB, so you can do the WHERE field is initial.

        You can definitely declare your TYPE as BOXED and include that within your table.

        Regards,
        Naimesh Patel

        (0) 
  2. Naimesh Patel

    Thanks for your post.

    You also want to include a fact that this is referred as the Static Box.

    Also, it would be beneficial to know when the initial value sharing is rewoked and system assign its own memory to these variables:

    • Write Access to the variable
    • When Variable is assigned to a Field-Symbol
    • When Variable is passed as a parameter to any subroutine
    • Accessing Variable using the Data reference

    I recently published a post – What is New TYPE Category TYPE … BOXED in ABAP? to cover few points on BOXED type.

    Regards,
    Naimesh Patel

    (0) 

Leave a Reply