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.
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.
If you find this post useful, please like, share & comment.
Also, please don’t forget to endorse me on LinkedIn. 🙂