07-28-2020 9:42 AM
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
07-28-2020 9:54 AM
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,07-28-2020 9:54 AM
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,07-28-2020 2:00 PM
07-28-2020 2:03 PM
07-28-2020 1:41 PM
Please read the Rules of Engagement: don't post your private information (email).
07-28-2020 1:42 PM
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