Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a table or a structure dynamically if the value of the field is initial or space

priya_ramani
Participant
0 Kudos

Hi team,

i had one requirement where i need to compare two records.

Example , i need to compare VBAK table's record.
i have two vbelns , 123, 124
VBELN : 123 , 124.

Now , i'm giving the Table name, old 1st vbeln and second vbeln as input to a class method (Input to the method is dynamic , it can have any value), in which i'm dynamically selecting the data and comparing the field values and giving the output as below table format:

VBELN ERDAT ERNAM VKROG

123 XXY

124 XXX

ERDAT , VKORG displaying as space since between 123 and 124 vbelns, both have same value and i will consider only the fields which had the difference and hence displaying the same which have the differences.

Now i want to delete ERDAT column and VKORG column as these fields have no values hence want to avoid in the output table.

I want to have output as :

VBELN ERNAM

123 XXY

124 XXX

This above VBAK table can be anything , like VBRK , KONV etc...

Can you give your input thoughts how can i create that output table dynamically.

Regards,

Priya

1 ACCEPTED SOLUTION

mateuszadamus
Active Contributor
0 Kudos

Hello priya.ramani

You should first use the CL_ABAP_STRUCTDESCR class to read information about the table you provide as a parameter. The resulting object has a GET_COMPONENTS method, which will return information about each of the table's fields. Use this method to get the list of fields.

After you've compared the two records you can remove the fields that are not needed from the internal table received from the GET_COMPONENTS.

Then you should be able to create a new internal table with the use of CL_ABAP_TABLEDESCR class (method CREATE).

You can find a simple example here: https://answers.sap.com/answers/829685/view.html

Kind regards,
Mateusz
5 REPLIES 5

mateuszadamus
Active Contributor
0 Kudos

Hello priya.ramani

You should first use the CL_ABAP_STRUCTDESCR class to read information about the table you provide as a parameter. The resulting object has a GET_COMPONENTS method, which will return information about each of the table's fields. Use this method to get the list of fields.

After you've compared the two records you can remove the fields that are not needed from the internal table received from the GET_COMPONENTS.

Then you should be able to create a new internal table with the use of CL_ABAP_TABLEDESCR class (method CREATE).

You can find a simple example here: https://answers.sap.com/answers/829685/view.html

Kind regards,
Mateusz

0 Kudos
Hi mateuszadamus,Thanks for your quick reply.i followed your idea and got the expected results.Thanks,Priya Ramani.

Glad to hear that!

Kind regards,
Mateusz

Sandra_Rossi
Active Contributor
0 Kudos

Please read the Rules of Engagement: don't post your private information (email).

Sandra_Rossi
Active Contributor

Please use the button CODE when you post tables of data.

Input data:

VBELN ERDAT ERNAM VKROG
123         XXY
124         XXX

Expected output:

VBELN ERNAM
123   XXY
124   XXX