Skip to Content
Technical Articles
Author's profile photo Kallol Chakraborty

Easy way to populate/fetch column names from internal table

Introduction

Sometimes, there is a need to fetch the headers of an internal table for multiple purposes. I have come across a similar situation multiple times. But, I tried different ways to achieve that.

So, I am writing this blog post for easy reference.

Solution

In this blog post, I am going to show 2 ways to populate the headers.

  1. Static way: Hardcoding: Here, the column names are hardcoded. This approach can be taken if the number of columns is less and there is less chance of changing the structure. Kindly check the below code for further details.Populating%20headers%20by%20hardcoding.
    2. Dynamic way: This method will help you fetch the column names directly from data elements. Whenever you will add any new columns, the data will be fetched automatically. No need to manipulate the code again and again. This can be achieved in 2 ways.

    1. Using the FM: DDIF_FIELDINFO_GET. Please check the below code below.Using%20FM%3A%20DDIF_FIELDINFO_GET Once you get the column names you can use them according to your need.
    2. Using Standard SAP Object Class. Please check the below code.Using%20SAP%20Standard%20Object%20Class

 

If I have missed something, please feel free to add it in the comment section so that, this post can be useful to others.

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matthew Billingham
      Matthew Billingham

      If you're going to post code, don't do it as a picture. Use the code button in the blog editor. It looks like thisย {;}

      Author's profile photo Kallol Chakraborty
      Kallol Chakraborty
      Blog Post Author

      Dear Billingham,

      Thanks for the suggestion. I will keep this in mind.

      Actually, I put the picture intentionally, so that the person who is referring should write the code by himself. This will help him/her not to refer to this blogpost the 2nd time. ๐Ÿ™‚

      Regards,

      Kallol

      Author's profile photo Matthew Billingham
      Matthew Billingham

      I think that should be left to the reader.