Creating Dynamic Internal Table

Share on Facebook24Share on LinkedIn1Tweet about this on TwitterShare on Google+0
Please Share!!

In one of our post, we showed the usage of Dynamic Where Condition . In this article, we would show one out of the many ways to generate Dynamic Internal Table and display it in ALV output.

Say you have a requirement where you want to show a report to indicate one Material is present in how many Plants. Say your input material ‘M1’ is present in two plants say ‘P1’ and ‘P2’. So the output ALV report should show only two three columns, M1, P1 and P2. Say you have another material ‘M2’ which is present in 5 plants ‘P1’, ‘P2’, ‘P3’, ‘P4’ and ‘P5’. Then the output table would have six columns. M1, P1, P2, P3, P4 and P5.

Make a note, the number of columns are changing based on the input. Let us see a real example.

Check the MARC table.


Above screenshot shows that Material ‘100522’ is present in two plants. Our ALV would show as below.


Dynamic Internal Table

Check the MARC screenshot, Material ‘100567’ is present in four plants. Our ALV would show as below.



Did you notice, the number of columns are changing dynamically as per the data? This can be done in many ways, but the most convenient way is to create  dynamic structure/internal table and display it.


Function Module ‘DDIF_FIELDINFO_GET‘ would help us to fetch table field information. Check the code below, we are replacing ‘MARC-WERKS’ field label, with the actual Plant number. This was just a specific project requirement. You might have some other requirement.

Dynamic Internal Table

Material is a fixed column but Plants are dynamic based on data from MARC. Check we are looping through the internal table and using FM ‘DDIF_FIELDINFO_GET‘ to determine and populate field catalog information.

Once we have the field catalog (i_fcat), we need to build the dynamic internal table with the required columns determined by i_fcat. For this example, we are using method ‘CREATE_DYNAMIC_TABLE‘ of class CL_ALV_TABLE_CREATE.


The below two steps are the most important ones. Here we are assigning the dynamic structure to the <field-symbol> table and <field-symbol> work area which would be used later to display the ALV.

Also Read: ‘SAP  HANA from space level’.

There is some mathematic done to mark ‘X’ for the column where the material is present. So do not be confused. In debugging, it shows that although MATNR has 18 characters, the dynamic table show 36 (just the double). Same with Plant, it shows 8 instead of 4. So, this is something you want to check before you put your data.

Once you have populated the data in the dynamic internal table, displaying data in ALV is a cake walk. Just use the FM ‘REUSE_ALV_GRID_DISPLAY‘.

Check the code behaviour in Debugging mode”

Dynamic Internal Table

Check I_FCAT table, it has 4 rows of fields. This means, the dynamic internal table would have 4 columns. One fixed for Material and 3 dynamic for plants.


This is the class and method which actually creates the dynamic internal table.

Dynamic Internal Table

Check I_DYNAMIC_TABLE, it has now 3 columns for plants. This is the structure you need. Now just create the internal table and work area and populate your final data and display it.


Let us see, how the output would look like when we input 3 materials which are available in multiple plants.


Check, the number of plant columns are the union of all the three materials. Isn’t it dynamic? 


Please find the working program for the above requirement here.

If you want to get such practical tweaks and tricks straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.

If you liked this post, please hit the share buttons. Please like us at facebook and encourage us. If you have any suggestions, criticism, comments or questions, please comment or reach out to us.

Thank you very much for your time!!


Image source: (modified)

Share on Facebook24Share on LinkedIn1Tweet about this on TwitterShare on Google+0
Please Share!!

2 Comments on "Creating Dynamic Internal Table"

  1. Sharath Yaralkattimath | January 15, 2016 at 5:00 am |

    Hi Raju,

    Why do we use END-OF-SELECTION, what benefits it gives than writing the same code in START-OF-SELECTION? END-OF-SELECTION was used with LDB earlier.

  2. Hello Sharath

    As mentioned in your question, it is/was used with LDB and in executable program with no LDB, it serves no purpose. As a result, it is entirely upto you or your project standard to use it or ditch it. However, one benefit which comes to my mind is – improved readability. End of Statement, gives me an indication that program processing has completed and subsequent steps involved summation…. which may make it nice to have feature for big executable reports.

Comments are closed.