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

Update or append data from internal table to transparent table .

carlos_zhang3
Participant
0 Likes
6,116

Dear Guru ,

I need a program which can compare the records between internal table and transparent table .

If the transparent table already have the record (check with PK) , it only update the record from internal table .

If not , append the record from my internal table to the transparent table ...

My solution is a stupid way that is to check the transparent table before we take the decision ... if it has , update , if not , append ...

Does any fast way can do this ?

Thanks .

Best Regards,

Carlos Zhang

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,463

Use MODIFY <database table> FROM TABLE <internal table>

If the record avaialble for primary key condition in database table, record will be updated, otherwise record will be inserted.

Regards

Vinod

Dear Guru ,

I need a program which can compare the records between internal table and transparent table .

If the transparent table already have the record (check with PK) , it only update the record from internal table .

If not , append the record from my internal table to the transparent table ...

My solution is a stupid way that is to check the transparent table before we take the decision ... if it has , update , if not , append ...

Does any fast way can do this ?

Thanks .

Best Regards,

Carlos Zhang

4 REPLIES 4
Read only

Former Member
0 Likes
2,463

Hi,

You can use MODIFY key word to update the database. This serves 2 purposes.

1) if the Records with Primary Key already there it UPDATEs the Records

2) Otherwise it APPENDs the Records to the Transperant Table.

loop at itab into wa.
" do whatever you want to process
endloop.

modify <DBTAB> FROM TABLE <ITAB> " Instead of modifying within a loop you can do it FROM TABLE addition

For more infor Take F1 help on this MODIFY key word

Hope this would serve your purpose.

Cheerz

Ram

Read only

Former Member
0 Likes
2,463

Good day Carlos Zhang,

Here is the code i used.


data: fs_spfli like line of t_spfli,
      fs_spfli1 like line of t_spfli.
 
Loop at t_spfli into fs_spfli.

MODIFY zspfli from fs_spfli.
clear fs_spfli.
  IF sy-subrc EQ 0.
        COMMIT WORK.
      ELSE.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
 Endloop.

HERE ZSPFLI IS MY TRANSPERANT TABLE I CREATED.
T_SPFLI CONTAINS RECORDS SOME MAY BE EXTRA RECORDS.

Regards and Best wishes.

Read only

Former Member
0 Likes
2,464

Use MODIFY <database table> FROM TABLE <internal table>

If the record avaialble for primary key condition in database table, record will be updated, otherwise record will be inserted.

Regards

Vinod

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,463

May i know how does your solution differ from Ramchander's post ? Does it add any value ?