头图

Suppose we have two ABAP internal tables, each of which contains a, b and a', b'fields.

We hope to assign the a and b fields of inner table 1 to the a'and b'fields of inner table 2 respectively. Because the field names are different, MOVE-CORRESPONDING cannot be used.

The traditional method is to write a LOOP, in the loop body, manually assign the field a of each row of Table 1 to the field a'of each row of Table 2:

In fact, there is a simpler and more efficient method.

Use cl_abap_corresponding to create a mapping table, this mapping table, specify the following rules:

  • Assign the field value focus_language of the inner table to the focus_area field of another inner table.
  • Assign the field value salary of the inner table to salary_plus_bonous of another inner table.

The create method passes in this mapping table and returns an executor. Call the execute method of the executor to specify the source internal table and the target internal table that need to be field assigned, and the assignment operation is automatically completed, without the developer manually using LOOP assignment.

The Execute method is completed in the ABAP kernel, which is more efficient than using LOOP in ABAP applications.

For more details about this class, please refer to my article: introduces a method for efficient copying of internal tables in ABAP kernel state, and the corresponding pseudo implementation of Java and JavaScript versions )

More original articles by Jerry, all in: "Wang Zixi":


注销
1k 声望1.6k 粉丝

invalid