Skip to Content

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

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jul 28, 2020 at 08: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,
    Mateusz
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.