Technical Articles
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.
- 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.
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.- Using the FM: ‘DDIF_FIELDINFO_GET‘. Please check the below code below.
Once you get the column names you can use them according to your need.
- Using Standard SAP Object Class. Please check the below code.
- Using the FM: ‘DDIF_FIELDINFO_GET‘. Please check the below code below.
If I have missed something, please feel free to add it in the comment section so that, this post can be useful to others.
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ย {;}
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
I think that should be left to the reader.