Skip to Content
author's profile photo Former Member
Former Member

difference between move and move corresponding...with simple easy example

thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 02, 2007 at 05:07 PM

    Hi Balaji,

    The difference is as below:

    MOVE : This statement is used to move the contents of one field or structure to another field or structure... If you are moving the contents of a structure to another structure, then it is necessary that both structures have the same fields, with same name, and same sequence..

    Ex. DATA : w_a(1) TYPE c ,

    w_b(1) TYPE c.

    MOVE 'A' to w_a. ( w_a contents become 'A' )

    MOVE w_a to w_b. ( w_b contents become 'B' ).

    Ex. DATA : Begin of e_a,

    field1 TYPE c,

    field2 TYPE c,

    End of e_a.

    DATA : Begin of e_b,

    field2 TYPE c,

    field3 TYPE c,

    field1 TYPE c,

    END of e_b.

    DATA : Begin of e_c,

    field1 TYPE c,

    field2 TYPE c,

    End of e_c.

    Here, e_a and e_c have same structure and same sequence of fields..

    So, you can use MOVE e_a To e_c.

    But, e_b have different sequence of fields..

    So, you need to use MOVE-CORRESPONDING e_a TO e_b.

    When you use MOVE-CPORRESPONDING, the system compares the field names of the source structure with the destination and assigns the source fields to the destination fields with the same name..

    Thanks and Best Regards,

    Vikas Bittera.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 02, 2007 at 05:20 PM

    Hello Balaji,

    consider that you have 3 structures or table

    eg :

    structure1 contains fields company code,plant,date,year

    structure2 contains fields company code,plant,date,year

    structure3 contains fields company code,plant,date,month,year.

    you are declaring all fields in the structure with the same name

    ie, companycode like bseg-bukrs for all 3 structures..etc

    assume structure1 contains the data and you are passing it

    if you are using

    move structure1 to structure2.

    what happens::::::::

    company code from structure1 passed to company code of structure2

    plant from structure1 passed to plant of structure2

    date from structure1 passed to date of structure2

    year from structure1 moved to year of structure2

    all data from structure1 are correctly moved to correct fields of structure2

    if you are using

    move structure1 to structure3.

    what happens::::::::::::::::

    data will become corrupt because the structure1 and structure3 have different number of fields and possibly different types of field too

    in the above statement what happens is

    company code from structure1 passed to company code of structure3

    plant from structure1 passed to plant of structure3

    date from structure1 passed to date of structure3

    year from structure1 will be tried to moved to month of structure3

    "this is wrong..year should be passed to year..this statement may corrupt the "data or possibly give a syntax error while programming

    in this case where the 2 structures are different ad you need to pass date we use

    Move-corresponding structure1 to structure3

    then what happens::::::::::::::::

    company code from structure1 passed to company code of structure3

    plant from structure1 passed to plant of structure3

    date from structure1 passed to date of structure3

    month date in strucure 3 will be left empty since there is no corresponding

    field with that name in structure1

    year from structure1 will be tried to moved to month of structure3

    hope it proved useful

    reward if helpful 😊

    regards

    Byju

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 03, 2007 at 04:33 AM

    Please find the diffrence between Move and Move corresponding

    1) Ex - MOVE f TO g.

    In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Assignments and Dynamic Field Assignments.

    Effect

    Moves the contents of field f to field g. Field f remains unchanged.

    This statement is equivalent to:

    g = f.

    Example

    DATA: NUMBER TYPE I,

    FIVE TYPE I.

    MOVE 5 TO FIVE.

    MOVE FIVE TO NUMBER.

    The fields NUMBER and FIVE now both have the value 5.

    Notes

    1) Multiple assignments like

    NUMBER = FIVE = 5.

    are also possible. ABAP executes them from right to left (as in the above example).

    2)If the field types or lengths differ, the system automatically carries out type conversion. Type I fields are handled like type P fields. If you select the fixed point arithmetic attribute for an ABAP program, type P fields are either rounded according to the number of decimal places or filled with zeros.

    3)If the assignment is allowed but the source field type cannot be converted to the target field type, the contents of the target field are undefined. This would be the case, if you were to assign a C field containing 'ABCD' to a type D or T field.

    The operation is terminated only if the target field is a numeric type ( I, P or F).

    Now Check

    2) MOVE-CORRESPONDING struc1 TO struc2.

    Effect

    struc1 and struc2 must be structures.

    Searches for all names of subfields that occur both in struc1 and struc2. Generates for all relevant field pairs which correspond to the subfields ni, statements of the form

    MOVE struc1-ni TO struc2-ni.

    The other fields remain unchanged.

    Notes

    1)If untyped field symbols or parameters are used for struc1 or struc2 in procedures, the corresponding type is determined at runtime. If struc1 or struc2 are no structures then, a runtime error occurs. If you use untyped operands, in particular, with large structures, the statement executes much more slowly than if you use structures that can be recognized statically.

    2)With deep structures, the complete (path) names of the corresponding field pairs must be textually identical.

    3)The command performs the assignments based on the name identity of the fields. To avoid unintended assignments, you should consider all fields of the source and the target structure. If the source or the target structure has been defined with reference to a type from the ABAP Dictionary (for example, a database table), new fields are subsequently added to that structure by enhancing the ABAPDictionary type. Besides the intended name identities, accidental identies may occur which may result in a wrong program logic.

    Example

    DATA: BEGIN OF INT_TABLE OCCURS 10,

    WORD(10),

    NUMBER TYPE I,

    INDEX LIKE SY-INDEX,

    END OF INT_TABLE,

    BEGIN OF RECORD,

    NAME(10) VALUE 'not WORD',

    NUMBER TYPE I,

    INDEX(20),

    END OF RECORD.

    ...

    MOVE-CORRESPONDING INT_TABLE TO RECORD.

    This MOVE-CORRESPONDING statement is equivalent to both the following statements:

    MOVE INT_TABLE-NUMBER TO RECORD-NUMBER.

    MOVE INT_TABLE-INDEX TO RECORD-INDEX.

    Example

    TYPES: BEGIN OF ROW1_3,

    CO1 TYPE I,

    CO2 TYPE I,

    CO3 TYPE I,

    END OF ROW1_3.

    TYPES: BEGIN OF ROW2_4,

    CO2 TYPE I,

    CO3 TYPE I,

    CO4 TYPE I,

    END OF ROW2_4.

    TYPES: BEGIN OF MATRIX1,

    R1 TYPE ROW1_3,

    R2 TYPE ROW1_3,

    R3 TYPE ROW1_3,

    END OF MATRIX1.

    TYPES: BEGIN OF MATRIX2,

    R2 TYPE ROW2_4,

    R3 TYPE ROW2_4,

    R4 TYPE ROW2_4,

    END OF MATRIX2.

    DATA: ROW TYPE ROW1_3,

    M1 TYPE MATRIX1,

    M2 TYPE MATRIX2.

    ROW-CO1 = 1. ROW-CO2 = 2. ROW-CO3 = 3.

    MOVE: ROW TO M1-R1, ROW TO M1-R2, ROW TO M1-R3.

    MOVE-CORRESPONDING M1 TO M2.

    The last MOVE-CORRESPONDING statement is equivalent to the statements:

    MOVE: M1-R2-CO2 TO M2-R2-CO2,

    M1-R2-CO3 TO M2-R2-CO3,

    M1-R3-CO2 TO M2-R3-CO2,

    M1-R3-CO3 TO M2-R3-CO3.

    Reward points if you find helpful....

    Regards,

    Minal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 03, 2007 at 04:40 AM

    hi,

    <u>MOVE</u>

    If source structure = destination structure

    <u>MOVE-Corresponding</u>

    If source structure <> destination structure, but some fields are common.

    reward if helpful...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 03, 2007 at 05:08 AM

    DATA: BEGIN OF wa_tab1,

    fld1(4) VALUE ’FLD1’,

    fld2(4) VALUE ’FLD2’,

    fld3(4) VALUE ’FLD3’,

    fld4(4) VALUE ’FLD4’,

    fld5(4) VALUE ’FLD5’,

    END OF wa_tab1,

    BEGIN OF wa_tab2,

    fld1(4),

    fld2(4),

    fld3(4),

    fld4(4),

    END OF wa_tab2.

    • Move Corresponding *************

    MOVE-CORRESPONDING wa_tab1 to wa_tab2.

    • End Move Corresponding ************

    • Move ********************

    MOVE: wa_tab1-fld1 to wa_tab2-fld1,

    wa_tab1-fld2 to wa_tab2-fld2,

    wa_tab1-fld3 to wa_tab2-fld3,

    wa_tab1-fld4 to wa_tab2-fld4.

    • End Move ******************

    In above example, the result of MOVE and MOVE-CORRESPONDING is same. MOVE-CORRESPONDING is look like easy to coding but MOVE statement have performance better than MOVE-CORRESPONDING because when you apply MOVE-CORRESPONDING CPU usage of system will be increased.

    Reward if useful.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 03, 2007 at 05:24 AM

    Hi,

    Please take a look at my example below:

    REPORT  z_aris_test_18.
    
    TABLES: vbak.
    
    TYPES: BEGIN OF t_vbak,
            vbeln TYPE vbak-vbeln,
            vbtyp TYPE vbak-vbtyp,
           END OF t_vbak.
    
    TYPES: BEGIN OF t_vbap,
            vbeln TYPE vbap-vbeln,
            posnr TYPE vbap-posnr,
           END OF t_vbap.
    
    TYPES: BEGIN OF t_output,
            vbeln TYPE vbak-vbeln,
            posnr TYPE vbap-posnr,
            vbtyp TYPE vbak-vbtyp,
           END OF t_output.
    
    DATA: gt_vbak   TYPE STANDARD TABLE OF t_vbak,
          gt_vbap   TYPE STANDARD TABLE OF t_vbap,
          gt_output TYPE STANDARD TABLE OF t_output,
          wa_output LIKE LINE OF gt_output.
    
    FIELD-SYMBOLS: <fs_vbak> LIKE LINE OF gt_vbak,
                   <fs_vbap> LIKE LINE OF gt_vbap.
    
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_vbeln FOR vbak-vbeln,
                    s_vbtyp FOR vbak-vbtyp.
    SELECTION-SCREEN END OF BLOCK b1.
    
    START-OF-SELECTION.
      SELECT vbeln vbtyp
        FROM vbak
        INTO TABLE gt_vbak
       WHERE vbeln IN s_vbeln
         AND vbtyp IN s_vbtyp.
    
      IF NOT gt_vbak[] IS INITIAL.
        SELECT vbeln posnr
          FROM vbap
          INTO TABLE gt_vbap
           FOR ALL ENTRIES IN gt_vbak
         WHERE vbeln = gt_vbak-vbeln.
      ENDIF.
    
      SORT gt_vbak BY vbeln.
      SORT gt_vbap BY vbeln posnr.
    
      LOOP AT gt_vbak ASSIGNING <fs_vbak>.
        LOOP AT gt_vbap ASSIGNING <fs_vbap>
                        WHERE vbeln = <fs_vbak>-vbeln.
    *     Using MOVE-CORRESPONDING statement
          MOVE-CORRESPONDING <fs_vbap> TO wa_output.
    
    *     Using MOVE statement
          MOVE <fs_vbak>-vbtyp TO wa_output-vbtyp.
          APPEND wa_output TO gt_output.
          CLEAR wa_output.
        ENDLOOP.
      ENDLOOP.
    
    END-OF-SELECTION.
      LOOP AT gt_output INTO wa_output.
        WRITE: / wa_output-vbeln,
                 wa_output-posnr,
                 wa_output-vbtyp.
      ENDLOOP.
    

    Hope it helps...

    P.S. Please award points if it helps...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 03, 2007 at 05:29 AM

    Balaji

    its very simple boss.

    when the datatype of both the variable is same we use move statement

    and when the datatype is diffent and the structure of both the variables are different we use move-corresponding.

    REWARD ME IF U ARE HAPPY WITH THE ANSWER.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.