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: 

comparing two internal tables.

Former Member
0 Kudos

i am using CO_BO_OPR_OF_ORDER_GET function module to get the operation details corresponding to an order number. it imports two internal tables, a new one and an old one.

suppose if i have updated a date of an operation and i want to check which particular operation's date has been updated, how do i do this? the internal tables imported have the old structure and the new structure, so i have to compare them and find out the operations whose dates differ..? is there any specific compare statement?

having a loop inside another would take up processing time.

4 REPLIES 4

Former Member
0 Kudos

Hi

<b>Comparing Internal Tables </b>

Like other data objects, you can use internal tables as operands in logical expressions.

.... <itab1> <operator> <itab2> ...

For <operator>, all operators listed in the table in Comparisons Between Data Types can be used (EQ, =, NE, <>, ><, GE, >=, LE, <=, GT, >, LT, <).

If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets ([ ]) after the table name.

The first criterion for comparing internal tables is the number of lines they contain. The more lines an internal table contains, the larger it is. If two internal tables contain the same number of lines, they are compared line by line, component by component. If components of the table lines are themselves internal tables, they are compared recursively. If you are testing internal tables for anything other than equality, the comparison stops when it reaches the first pair of components that are unequal, and returns the corresponding result.


DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.

DATA: ITAB LIKE TABLE OF LINE,
JTAB LIKE TABLE OF LINE.

DO 3 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
  APPEND LINE TO ITAB.
ENDDO.

MOVE ITAB TO JTAB.

LINE-COL1 = 10. LINE-COL2 = 20.
APPEND LINE TO ITAB.

IF ITAB GT JTAB.
WRITE / 'ITAB GT JTAB'.
ENDIF.

APPEND LINE TO JTAB.

IF ITAB EQ JTAB.
WRITE / 'ITAB EQ JTAB'.
ENDIF.

LINE-COL1 = 30. LINE-COL2 = 80.
APPEND LINE TO ITAB.

IF JTAB LE ITAB.
WRITE / 'JTAB LE ITAB'.
ENDIF.

LINE-COL1 = 50. LINE-COL2 = 60.
APPEND LINE TO JTAB.

IF ITAB NE JTAB.
WRITE / 'ITAB NE JTAB'.
ENDIF.

IF ITAB LT JTAB.
WRITE / 'ITAB LT JTAB'.
ENDIF.

The output is: 

ITAB GT JTAB

ITAB EQ JTAB

JTAB LE ITAB

ITAB NE JTAB

ITAB LT JTAB

This example creates two standard tables, ITAB and JTAB. ITAB is filled with 3 lines and copied to JTAB. Then, another line is appended to ITAB and the first logical expression tests whether ITAB is greater than JTAB. After appending the same line to JTAB, the second logical expression tests whether both tables are equal. Then, another line is appended to ITAB and the third logical expressions tests whether JTAB is less than or equal to ITAB. Next, another line is appended to JTAB. Its contents are unequal to the contents of the last line of ITAB. The next logical expressions test whether ITAB is not equal to JTAB. The first table field whose contents are different in ITAB and JTAB is COL1 in the last line of the table: 30 in ITAB and 50 in JTAB. Therefore, in the last logical expression, ITAB is less than JTAB.

Regards Rk

Former Member
0 Kudos

Hi,

Look at the below sample to code to compare the Internal tables

REPORT demo_int_tables_compare.

DATA: BEGIN OF line,
        col1 TYPE i,
        col2 TYPE i,
      END OF line.

DATA: itab LIKE TABLE OF line,
      jtab LIKE TABLE OF line.

DO 3 TIMES.
  line-col1 = sy-index.
  line-col2 = sy-index ** 2.
  APPEND line TO itab.
ENDDO.

MOVE itab TO jtab.

line-col1 = 10. line-col2 = 20.
APPEND line TO itab.

IF itab GT jtab.
  WRITE / 'ITAB GT JTAB'.
ENDIF.

APPEND line TO jtab.

IF itab EQ jtab.
  WRITE / 'ITAB EQ JTAB'.
ENDIF.

line-col1 = 30. line-col2 = 80.
APPEND line TO itab.

IF jtab LE itab.
  WRITE / 'JTAB LE ITAB'.
ENDIF.

line-col1 = 50. line-col2 = 60.
APPEND line TO jtab.

IF itab NE jtab.
  WRITE / 'ITAB NE JTAB'.
ENDIF.

IF itab LT jtab.
  WRITE / 'ITAB LT JTAB'.
ENDIF.

Regards

Sudheer

Former Member
0 Kudos

hi,

i think u have to do field comparison .

if ( itab1-field1 = itab2-field1 ).

... do somehting....

like this u have to ...

reward if helpful

ravi

former_member181962
Active Contributor
0 Kudos

HI Maouli,

YOu have no other go.

YOu have to loop one internal table reading the other.

To make things a little better, you have to sort the tables by theor key fields and read using binary search.

Regards,

Ravi

loop at itab1.

read table itab2 with key field1 = itab1-field2.

if sy-subrc = 0.

if itab1-date <> itab2-date.

  • Diferent dates

endif.

endif.

endloop.