Skip to Content
author's profile photo Former Member
Former Member

Comparison of two tables based on a dynamic field.

Hello Everyone,

I have three internal tables with me.

HEADER_T : Contains Header level data.

DETAILED_T : Contains the Detailed Data.

FIELDS_T : Contains the field names with which mapping is to be done for the above two levels.

What I need to do is for each entry of HEADER_T , I need to fetch corresponding entries in DETAILED_T comparing on fields mentioned in FIELDS_T.

For Example:

HEADER_T

A P AT

A1 P1 20

A1 P2 10

A2 P1 30

DETAILED_T.

A P E T

A1 P1 E1 5

A1 P1 E2 5

A1 P1 E3 5

A1 P1 E4 5

A1 P2 E1 5

A1 P2 E2 5

A2 P2 E1 20

A2 P2 E2 10

FIELDS_T

FNAME:

A

P

So here for 1st entry in HEADER_T we get 4 entries in DETAILED_T using the fields of table FIELDS_T

Kindly give your inputs.

Thanks & Regards,

Rohit.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 11:21 AM

    Hello Rohit,

    One way to do this would be by using ASSIGN & dynamic where clause:

    LOOP at header_t ASSIGNING <header>.
    
         WRITE: / <header>-a, <header>-p. SKIP.
    
         LOOP at fields_t ASSIGNING <fields>.
              ASSIGN COMPONENT fname OF STRUCTURE <header> to <comp>.
              IF sy-subrc = 0.
                   IF sy-tabix = 1.
                        l_where = <fields>-fname && ` = ` && '''' && <comp> && ''''.
                   ELSE.
                        l_where = l_where && ` AND ` && <fields>-fname && ` = ` && '''' && <comp> && ''''.
                   ENDIF.
              ENDIF.
         ENDLOOP.
    
         LOOP at detailed_t ASSIGNING <detail> WHERE (l_where).
              WRITE: `     `, <detail>-a, <detail>-p, <detail>-e.
         ENDLOOP.
         SKIP 2.
    
    ENDLOOP.
    

    Cheers,

    Manu.

    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.