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 dbtab from table transporting

Former Member
22,367

There seems to be no way to MODIFY a DB table from an internal table TRANSPORTING only certain fields.

It seems a pity to loop through the internal table and do thousands of MODIFY commands. Or, as show below, loop through the itab and load from the DB the data (e.g. field "hash") we want to retain.

Is there a more elegant solution?

" Load parts from external system
DATA(lt_part) = ycl_hybris_api=>part_list(
  attributes = 'galleryImages,code,creationtime,modifiedtime'
  sort       = 'code'
).
CHECK lt_part IS NOT INITIAL.

" Set all timestamps to now
DATA ls_part TYPE y00_hyb_parts.
ls_part-loaded = ycl_date=>timestamp( ).
MODIFY lt_part FROM ls_part TRANSPORTING loaded WHERE loaded IS INITIAL.

" We need to retain the old HASH value
LOOP AT lt_part ASSIGNING FIELD-SYMBOL(<ls_part>).
  SELECT SINGLE hash FROM y00_hyb_parts INTO CORRESPONDING FIELDS OF <ls_part> WHERE matnr = ls_part-matnr.
ENDLOOP.

" Cache the result
MODIFY y00_hyb_parts FROM TABLE lt_part transporting.
COMMIT WORK AND WAIT.

1 ACCEPTED SOLUTION
Read only

pokrakam
Active Contributor
10,386
UPDATE y00_hyb_parts SET loaded = whatever WHERE ...
4 REPLIES 4
Read only

pokrakam
Active Contributor
10,387
UPDATE y00_hyb_parts SET loaded = whatever WHERE ...
Read only

Former Member
0 Likes
10,386

The real question is how I update the DB Table from the internal table lt_part. There are various fields there that need to be updated FROM the external system.

The field loaded should only be set in the DB for those parts in lt_part which were currently loaded.

The field hash should not be changed in the DB table at all.

Read only

pokrakam
Active Contributor
0 Likes
10,386

The only way I know is to pull the existing data into an itab, update the needed info and then do an update. You could probably do something really fancy with UPDATE ... FROM TABLE VALUE #( ... )..., but at it's simplest:

SELECT * FROM y00_hyb_parts INTO TABLE @data(staging_table) WHERE ... .
   ... "merge updates onto staging_table
UPDATE y00_hyb_parts FROM TABLE staging_table.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
10,386

Since MODIFY can work as INSERT, it makes no sense to transport only part of the fields

Mike's answer is correct.