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 table to DB Table

danielpray805
Explorer
0 Likes
2,727

Hello folks,

I'm currently working on to update the table in SAP db from the internal table.

First, I made an internal table from three different db tables.

TYPES: BEGIN OF GT_FINAL,
         LFGJA TYPE MBEWH-LFGJA,
         LFMON TYPE MBEWH-LFMON,
         LBKUM TYPE MBEWH-LBKUM,
         SALK3 TYPE MBEWH-SALK3,
         VERPR TYPE MBEWH-VERPR,
         STPRS TYPE MBEWH-STPRS,
         PEINH TYPE MBEWH-PEINH,
         MATNR TYPE MARA-MATNR,
         MTART TYPE MARA-MTART,
         MAKTX TYPE MAKT-MAKTX,
       END OF GT_FINAL.

DATA: IT_FINAL TYPE TABLE OF GT_FINAL,
      WA_FINAL TYPE          GT_FINAL.

SELECT A~LFGJA
         A~LFMON
         A~LBKUM
         A~SALK3
         A~VERPR
         A~STPRS
         A~PEINH
         B~MATNR
         B~MTART
         C~MAKTX
    APPENDING CORRESPONDING FIELDS OF TABLE IT_FINAL
    FROM MBEWH AS A
    INNER JOIN MARA AS B
    ON A~MATNR = B~MATNR
    INNER JOIN MAKT AS C
    ON A~MATNR = C~MATNR
    WHERE A~LFGJA EQ P_LFGJA
          A~LFMON IN P_LFMON
          B~MATNR IN P_MATNR.

DELETE FROM ZREPORT01_TABLE
      WHERE LFGJA EQ P_LFGJA
        AND LFMON IN P_LFMON
        AND MATNR IN P_MATNR.



INSERT ZTABLE FROM IT_FINAL

And here is my problem comes.

First, I was trying to delete current db table.

Then, I was trying to update the db table from internal table in someway.

I got stuck because everytime I was trying to use,

INSERT ZTABLE FROM IT_FINAL.

I got error.

Overall, my question is.

how to update db table from internal table?

Thanks.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
2,535

Basically the record of the internal table must match those of the database table

usually (easy way) the internal table is defined from the database table ddic definition

DATA: IT_FINAL TYPE TABLE OF ZTABLE.

Read the documentation of Insert dbtab in SQL Abap and look for ABAP SQL - Work Areas in Statements.

Then either use the ddic table definition or adapt your internal table type to make it compliant with the database table

Basically the record of the internal table must match those of the database table

usually (easy way) the internal table is defined from the database table ddic definition

DATA: IT_FINAL TYPE TABLE OF ZTABLE.

Read the documentation of Insert dbtab in SQL Abap and look for ABAP SQL - Work Areas in Statements.

Then either use the ddic table definition or adapt your internal table type to make it compliant with the database table

8 REPLIES 8
Read only

former_member763929
Participant
0 Likes
2,535

Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with Community Q&A , as the overview provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a picture to your Profile you encourage readers to respond.

Read only

FredericGirod
Active Contributor
0 Likes
2,535

... ACCEPTING DUPLICATE KEYS maybe help.

Read only

hrmanagerde
Active Participant
0 Likes
2,535

ZTABLE and IT_FINAL must be compatible. Is that the case?

Read only

RaymondGiuseppi
Active Contributor
2,536

Basically the record of the internal table must match those of the database table

usually (easy way) the internal table is defined from the database table ddic definition

DATA: IT_FINAL TYPE TABLE OF ZTABLE.

Read the documentation of Insert dbtab in SQL Abap and look for ABAP SQL - Work Areas in Statements.

Then either use the ddic table definition or adapt your internal table type to make it compliant with the database table

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,535

What "error" do you get?

Read only

matt
Active Contributor
2,535

"Got an error" is not a recognisable message. For all I know it means your computer explodes each time you try to run it.

Read only

danielpray805
Explorer
0 Likes
2,535

I believe they are compatible.

Read only

danielpray805
Explorer
0 Likes
2,535

I guess ZTABLE AND IT_FINAL internal table doesn't match.

In that case, then, I guess I should define this

DATA: IT_FINAL TYPE TABLE OF GT_FINAL,
      WA_FINAL TYPE          GT_FINAL.

to this.

DATA: IT_FINAL TYPE TABLE OF ZTABLE,
      WA_FINAL TYPE        ZTABLE.

But, then what about the GT_FINAL? It seems like that GT_FINAL is useless then.