Application Development and Automation 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: 
Read only

Compare data between a Database table and an internal table

ejas_nazeerutheen87
Discoverer
0 Likes
1,238

Hi guys,

I want to compare two columns from an internal table (Specification number and Material Number) to the same two columns in a database table (ESTMJ). The specification number and material number assignment in the internal table should be the same as the specification number and material number assignment in the database table. I am pretty new to ABAP. How do i go about this comparison?

Should I pull the data from the db table and then compare it with the internal table? or can i directly compare the two columns of both tables?

Thanks in advance 🙂

Best regards

Ejas.

1 ACCEPTED SOLUTION
Read only

Alterman
Participant
1,108

Version 1:

Your internal table is ITAB1.

//declare a 2nd internal table

table I_ESTMJ_2 like ESTMJ.

//load this 2nd internal table

select * from ESTMJ into table i_ESTMJ_2.

//compare

loop at ITAB1.

read table i_ESTMJ_2 where/with {material number assignment, aka, whatever you specifically looking for}

if sy-subrc <> 0.

/*do whatever you wanted if records don't match or don't exist*/

endif.

endloop.


Version 2, delete what's extra:

loop at ITAB1.
delete i_ESTMJ_2 where {I_STMJ_2 material number assignment} ne {ITAB1-material number assignment}.
endloop.

3 REPLIES 3
Read only

Alterman
Participant
1,109

Version 1:

Your internal table is ITAB1.

//declare a 2nd internal table

table I_ESTMJ_2 like ESTMJ.

//load this 2nd internal table

select * from ESTMJ into table i_ESTMJ_2.

//compare

loop at ITAB1.

read table i_ESTMJ_2 where/with {material number assignment, aka, whatever you specifically looking for}

if sy-subrc <> 0.

/*do whatever you wanted if records don't match or don't exist*/

endif.

endloop.


Version 2, delete what's extra:

loop at ITAB1.
delete i_ESTMJ_2 where {I_STMJ_2 material number assignment} ne {ITAB1-material number assignment}.
endloop.

Read only

ejas_nazeerutheen87
Discoverer
0 Likes
1,108

Thanks a lot Mikhail. Much appreciated 🙂

Read only

former_member808116
Participant
0 Likes
1,108

You can: Select Inner join two data table.