Skip to Content
0
Apr 30, 2018 at 08:10 AM

modify dbtab from table transporting

9758 Views

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.

Attachments

s.png (33.9 kB)