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

Modify DBTable

Former Member
0 Likes
994

Hi All,

I try to modify or insert data to database table but the code just modify only 1 row.

I just added only 1 data to ztable.

Do you know why i cant add data to ztable.

Thanks for help.

LOOP AT IT_REPORT INTO WA_REPORT WHERE TEDARIK IS NOT INITIAL.

         READ TABLE GT_TEDRK_TESM WITH KEY KUNET    = WA_REPORT-KUNET

                                                                              KUNWE    = WA_REPORT-KUNWE

                                                                              RMATNR   = WA_REPORT-RMATNR

                                                                              NAMET    = WA_REPORT-NAMET

                                                                              TARIH    = WA_REPORT-TARIH

                                                                              SFRTR_TX = WA_REPORT-SFRTR_TX.

         IF SY-SUBRC IS NOT INITIAL.

           MOVE-CORRESPONDING WA_REPORT TO WA_TEDRK_TESM.

           INSERT ZPP_T_TEDRK_TESM FROM WA_TEDRK_TESM.

         ENDIF.

       ENDLOOP.


LOOP AT IT_REPORT INTO WA_REPORT WHERE TEDARIK IS NOT INITIAL.

         READ TABLE GT_TEDRK_TESM WITH KEY KUNET    = WA_REPORT-KUNET

                                                                              KUNWE    = WA_REPORT-KUNWE

                                                                              RMATNR   = WA_REPORT-RMATNR

                                                                              NAMET    = WA_REPORT-NAMET

                                                                              TARIH    = WA_REPORT-TARIH

                                                                              SFRTR_TX = WA_REPORT-SFRTR_TX.

         IF SY-SUBRC IS NOT INITIAL.

           MOVE-CORRESPONDING WA_REPORT TO WA_TEDRK_TESM.

           MODIFY ZPP_T_TEDRK_TESM FROM WA_TEDRK_TESM.

         ENDIF.

       ENDLOOP.



LOOP AT IT_REPORT INTO WA_REPORT WHERE TEDARIK IS NOT INITIAL.

         READ TABLE GT_TEDRK_TESM WITH KEY KUNET    = WA_REPORT-KUNET

                                                                              KUNWE    = WA_REPORT-KUNWE

                                                                              RMATNR   = WA_REPORT-RMATNR

                                                                              NAMET    = WA_REPORT-NAMET

                                                                              TARIH    = WA_REPORT-TARIH

                                                                              SFRTR_TX = WA_REPORT-SFRTR_TX.

         IF SY-SUBRC IS NOT INITIAL.

           MOVE-CORRESPONDING WA_REPORT TO WA_TEDRK_TESM.

            APPEND GT_TEDRK_TESM.

    

         ENDIF.

       ENDLOOP.


           MODIFY ZPP_T_TEDRK_TESM FROM WA_TEDRK_TESM.

THANKS FOR YOUR HELP


1 ACCEPTED SOLUTION
Read only

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Likes
920

Hi Erm,

The data will be modified based on key fields. It check with the key fields of structure to the database table and modifies accordingly. Please check the key fields.

And also Your question is not clear. If it doesnot help, make sure you give enough clarification or detail to understand your issue.

Regards,

Ajit

6 REPLIES 6
Read only

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Likes
921

Hi Erm,

The data will be modified based on key fields. It check with the key fields of structure to the database table and modifies accordingly. Please check the key fields.

And also Your question is not clear. If it doesnot help, make sure you give enough clarification or detail to understand your issue.

Regards,

Ajit

Read only

shadab_maldar
Active Participant
0 Likes
920

Hi Erm,

What are the key fields in ztable.?

Regards,

Shadab.

Read only

Private_Member_5521
Participant
0 Likes
920

The INSERT command adds lines to the DB table as long as there are no duplicate keys present, if there are it will throw an ABAP DUMP.

The MODIFY command changes behavior depending on the existence or not of the record when comparing key fields:

  1. If the key field values are already present in the table, it will change the record that exists in the table
  2. If the key field values are new, then it will add that new record to the table.

In your code, you only do a straight insert in the first loop, the other two will most likely change the same existing DB record when finding the same key values.

Read only

bauert
Explorer
0 Likes
920

The last MODIFY statement is outside of the LOOP. Is that correct? This will Change the DB Data only with the last valid data from the LOOP.

Did you check already the sy-dbcnt?

Read only

VenkatRamesh_V
Active Contributor
0 Likes
920

Hi Erm,

Try,

Declare a internal table as like ztable.

Append the internal tables instead of updating ztable in  loop.

Ater endloop.

MODIFY ZTABLE FROM TABLE  it_upd. ( new internal table).

COMMIT WORK.

Hope it helpful,

Regards,

Venkat.

Read only

Former Member
0 Likes
920

If inside the loop, Use MODIFY ztable from work_area TRANSPORTING field1 field2.

Outside loop, use MODIFY ztable From table it_table WHERE <condition>.