CORRESPONDING operator in ABAP 7.4


Working with CORRESPONDING operator in ABAP 7.4, examples of using CORRESPONDING in ABAP 7.4

A+ A-

In NetWeaver 7.4, SAP introduced a new operator called CORRESPONDING, this will be similar to and will replace MOVE-CORRESPONDING, this will work for both structures and internal tables, additionally you can also define own mapping rules and exclude some fields by using exclude

<RESULT_TAB> = CORRESPONDING type( [BASE ( <BASE> )] <STRUCTURE> [<MAPPING|EXCEPT>] ).

Example 1: Using plain CORRESPONDING

Below example will just act as MOVE or copying contents of internal table to other because both internal tables has same structure.

TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       END OF TY_MARA.
DATA: IT_MARA_1 TYPE TABLE OF TY_MARA,
      IT_MARA_2 TYPE TABLE OF TY_MARA.
   SELECT MATNR MTART
     FROM MARA INTO TABLE it_mara_1
     UP To 10 ROWS
     WHERE MTART = 'FERT'.
it_mara_2 = CORRESPONDING #( it_mara_1 ).
LOOP AT it_mara_2 INTO DATA(wa_mara).
  WRITE:/ wa_mara-matnr, wa_mara-mtart.
ENDLOOP.

Example 2: Using CORRESPONDING with different structures

If you use CORRESPONDING into existing internal table as result table, the matching fields will be overwritten and non-matching fields will be initialized (clear values).

*Declare ITAB 1
TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       END OF TY_MARA.
DATA: IT_MARA_1 TYPE TABLE OF TY_MARA.
*Declare ITAB 2
TYPES: BEGIN OF TY_MARA_1,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       MATKL TYPE MARA-MATKL,
       END OF TY_MARA_1.
DATA: IT_MARA_2 TYPE TABLE OF TY_MARA_1.

   SELECT MATNR MTART
     FROM MARA INTO TABLE it_mara_1
     UP To 10 ROWS
     WHERE MTART = 'FERT'.

   SELECT MATNR MTART MATKL
     FROM MARA INTO TABLE it_mara_2
     UP To 10 ROWS
     WHERE MTART = 'FERT'.
**Print output before CORRESPONDING
WRITE:/ 'Before CORRESPONDING'.
LOOP AT it_mara_2 INTO DATA(wa_mara).

  WRITE:/ wa_mara-matnr, wa_mara-mtart, wa_mara-matkl .

ENDLOOP.
ULINE.
it_mara_2 = CORRESPONDING #( it_mara_1 ).
**Print output After CORRESPONDING
WRITE:/ 'After CORRESPONDING'.
LOOP AT it_mara_2 INTO wa_mara.
  WRITE:/ wa_mara-matnr, wa_mara-mtart, wa_mara-matkl .
ENDLOOP.

Example 3: Using Mapping and Except with CORRESPONDING ABAP 7.4

MAPPING is useful when you wants to move a column values into similar column with different name, example If you have 2 internal tables, in table 1 you have column with name MATKL and in table 2 you have column with name MATL_GROUP, you can use MAPPING to move MATKL to MATL_GROUP.

EXCEPT is used when you wants to exclude some columns in moving to another itab/structure

*Declare ITAB 1
TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       END OF TY_MARA.
DATA: IT_MARA_1 TYPE TABLE OF TY_MARA.
*Declare ITAB 2
TYPES: BEGIN OF TY_MARA_1,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       MATKL TYPE MARA-MATKL,
       END OF TY_MARA_1.
DATA: IT_MARA_2 TYPE TABLE OF TY_MARA_1.
   SELECT MATNR MTART
     FROM MARA INTO TABLE it_mara_1
     UP To 10 ROWS
     WHERE MTART = 'FERT'.
   SELECT MATNR MTART MATKL
     FROM MARA INTO TABLE it_mara_2
     UP To 10 ROWS
     WHERE MTART = 'FERT'.
it_mara_2 = CORRESPONDING #( it_mara_1 EXCEPT matkl  ).

Example 4: Using MAPPING in CORRESPONDING ABAP 7.4

*Declare ITAB 1
TYPES: BEGIN OF TY_MARA,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       MATL_GROUP TYPE MARA-MATKL,
       END OF TY_MARA.
DATA: IT_MARA_1 TYPE TABLE OF TY_MARA.
*Declare ITAB 2
TYPES: BEGIN OF TY_MARA_1,
       MATNR TYPE MARA-MATNR,
       MTART TYPE MARA-MTART,
       MATKL TYPE MARA-MATKL,
       END OF TY_MARA_1.
DATA: IT_MARA_2 TYPE TABLE OF TY_MARA_1.

   SELECT MATNR MTART
     FROM MARA INTO TABLE it_mara_1
     UP To 10 ROWS
     WHERE MTART = 'FERT'.

   SELECT MATNR MTART MATKL
     FROM MARA INTO TABLE it_mara_2
     UP To 10 ROWS
     WHERE MTART = 'FERT'.

it_mara_2 = CORRESPONDING #( it_mara_1 MAPPING  matkl = matl_group  ).

Learner Questions

No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question


    Was this lesson helpful to you? Yes No 2 People out of 2 think this lesson helpful

    Lesson Navigation

    ←Previous Chapter
    Next Chapter →