Skip to Content
-1

How to Update Database Table with an Dynamic Internal Table of type ANY TABLE

I am trying to update a transparent Table using Dynamic Table. But everytime i try to update it i recieve a dump stating Move to SRC to DEST.

data : itab type standard table of ZCUSTOM_TABLE.

CREATE DATA dref TYPE ('ZCUSTOM_TABLE').
ASSIGN dref->* TO <wa>.

LOOP AT it_final ASSIGNING <wa>.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <val>.
IF sy-subrc = 0.
APPEND <val> TO itab.
CLEAR : <val>,<wa>.
ELSE.
EXIT.
ENDIF.
ENDLOOP.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 30, 2016 at 01:18 AM

    Thanks Sandra for the response.

    Your Queries :

    1) IT_FINAL : is the dynamic Internal Table (Data Type : TYPE TABLE)
    2) Yes Create DATA only creates Work Area . In the sample code above <WA> is work Area to access data from IT_FINAL.

    3) the Data record by record gets stored in ITAB which is of the Custom Table TYPE. As while Updating Database Custom Table using Statement MODIFY CUSTOM_TABLE FROM TABLE ITAB , Table ITAB should be of same structure .

    I hope i have clarified your queries, Please guide me in resolving this issue, thanks

    Add comment
    10|10000 characters needed characters exceeded

    • Are you looking for something like that (which in fact corresponds to MOVE-CORRESPONDING it_final TO <it_dbtab> in ABAP 7.40):

      FORM process_dyn_itab 
            USING 
              it_final   TYPE ANY TABLE 
              i_dbtab    TYPE tabname.
      
        DATA: dref TYPE REF TO data.
        FIELD-SYMBOLS: <wa_final> TYPE any,
                       <wa_dbtab> TYPE any,
                       <itab>     TYPE ANY TABLE.
      
        CREATE DATA dref TYPE (i_dbtab).
        ASSIGN dref->* TO <wa_dbtab>.
        CREATE DATA dref TYPE TABLE OF (i_dbtab).
        ASSIGN dref->* TO <itab>.
      
        LOOP AT it_final ASSIGNING <wa_final>.
          MOVE-CORRESPONDING <wa_final> TO <wa_dbtab>.
          INSERT <wa_dbtab> INTO TABLE <itab>.
        ENDLOOP.

      MODIFY (i_dbtab) FROM TABLE <itab>. ENDFORM.
  • Dec 29, 2016 at 07:14 PM

    You should use the debugger to see the contents of variables, that would help you understand where the issues are.

    Especially sy-index : it's initialized only if DO or WHILE are used. In your case, you're using LOOP AT, so only SY-TABIX is initialized.

    What is IT_FINAL?

    Do you know CREATE DATA dref TYPE ('ZCUSTOM_TABLE') only creates a structure, not an internal table? Use TYPE TABLE OF ('ZCUSTOM_TABLE') to create an internal table.

    Add comment
    10|10000 characters needed characters exceeded