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

Internal Tables comparison

Former Member
0 Likes
1,224

Hi,

I have a two internal tables, one is master internal table and the other is duplicate of that master table.I want to compare first internal table fields with other internal table fields If matches i want to delete that entry in the master internal table.

I don't want to use LOOP... ENDLOOP.

Is there any other possibility?

Thanks in advance,

fractal

Hi,

I have a two internal tables, one is master internal table and the other is duplicate of that master table.I want to compare first internal table fields with other internal table fields If matches i want to delete that entry in the master internal table.

I don't want to use LOOP... ENDLOOP.

Is there any other possibility?

Thanks in advance,

fractal

8 REPLIES 8
Read only

Former Member
0 Likes
974

Hi,

I believe it is not possible to do that without LOOP AT..ENDLOOP...

THanks,

Naren

Read only

Former Member
0 Likes
974

Hi,

look at the below SAP help link for Comparing Internal Tables:-

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3841358411d1829f0000e829fbfe/content.htm

Regards

Sudheer

Read only

0 Likes
974

It is not possible to compare individual records of an ITAB without looping at it.. you could loop at one & read the other.. you can use the assignh component option in filed-symbols to make the code efficient..

~Suresh

Read only

uwe_schieferstein
Active Contributor
0 Likes
974

Hello Fractal

I recommend to use the same approach as SAP standard uses for creating change documents. In order to do so you need to define two additional itab having a change indicator as shown below:

TYPES: BEGIN OF ty_s_itab_di.  
INCLUDE TYPE struc_a.
TYPES: CHIND  TYPE bu_chind.
TYPES: END OF ty_s_itab_di.
TYPES: ty_t_itab_di  TYPE STANDARD TABLE OF ty_s_itab_di 
                     WITH DEFAULT KEY.
DATA:  
  gt_itab_old  TYPE ty_t_itab_di,


gt_itab_new TYPE ty_t_itab_di.

  • Fill itabs gt_Itab_old with the corresponding data of itab1 and gt_itab_new with the corresponding data of itab2.

*

  • Very important: sort you itabs either by all key fields or by all fields.

*

  • Call function CHANGEDOCUMENT_PREPARE_TABLES with the following parameters:

- CHECK_INDICATOR = ' '

- TABLE_NEW = gt_Itab_new

- TABLE_OLD = gt_itab_old

The function module will remove identical lines from both itabs. New entries in gt_itab_New will have CHIND = 'I' and deleted entries in gt_itab_old will have CHIND = 'D'. If there is a delta between entries having the same keys then CHIND = 'U' (update).

Here is an extract of the function module's documentation for the TABLES parameter:

 Table contains the changed data
 
     The table structure must begin with the structure specified under
     TABLENAME and an additional processing flag (TYPE C, length 1).
 
     The table must be passed sorted by key.
 
     During compression, identical lines in TABLE_OLD and TABLE_NEW are
     deleted and the processing flag set. The following cases are
     distinguished:
 
     o   Lines which exist with table key in TABLE_NEW, but not in TABLE_OLD:
         Processing flag = "I" for INSERT.
 
     o   Lines which exist with table key in TABLE_NEW and in TABLE_OLD, the
         contents of the TABLENAME structure fields in TABLE_NEW is not the
         same as in TABLE_OLD: Processing flag = "U" for UPDATE.
 
     o   Lines which exist with table key in TABLE_NEW and in TABLE_OLD, the
         contents of the TABLENAME structure fields in TABLE_NEW is the same
         as in TABLE_OLD: Delete the line in TABLE_NEW, Delete the line in
         TABLE_OLD.

Regards

Uwe

Read only

Former Member
0 Likes
974

You will have to LOOP at one table, but you can then READ the other table. See:

/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops

Rob

Read only

0 Likes
974

Hello Rob

As I said before you don't need loop at all. All that is required are the two additional itabs which have to be sorted prior to calling the function module.

Regards

Uwe

Read only

0 Likes
974

Yes, but I took this to be a performance question. If you look at the FM, you'll see that it's doing some looping at the tables.

Rob

Read only

0 Likes
974

Hello Bob

You are definitely right. Looping must be done, yet at least it's not us who has to do the coding.

Regards

Uwe