Skip to Content
avatar image
Former Member

modify dbtab from table transporting

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.

s.png (33.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Apr 30 at 08:33 AM
    UPDATE y00_hyb_parts SET loaded = whatever WHERE ...
    Add comment
    10|10000 characters needed characters exceeded

    • 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.
      

  • Apr 30 at 09:37 AM

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

    Mike's answer is correct.

    Add comment
    10|10000 characters needed characters exceeded