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: 

Comparison of two tables based on a dynamic field.

Former Member
0 Kudos

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.

4 REPLIES 4

Former Member
0 Kudos

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.

0 Kudos

line 09 is trucated... This editor sucks really

so 09 should ends with && ''''.

Br,

Manu.

0 Kudos

Thank you Manu,

Seems like the solution should work.

I will try and get back

Thanks

0 Kudos

Hope this would work.

In case of any issues, do revert. I have a backup solution.