批量修改product description

187 阅读1分钟

Created by Jerry Wang on May 29, 2014

下列report使用Function module COM_PRODUCT_MAINTAIN_MULT_API批量修改一系列product的description。可以使用同样原理修改其他settype.
将待批量修改的product id放入internal table:
clipboard1

指定待修改description的value和修改类型"U" ( Update ):
clipboard2
执行完report后可到UI上检查修改情况:
clipboard3
clipboard4

REPORT zprod_multiple_change.
DATA:   lt_productm    TYPE  comt_product_maintain_api_extt,
        ls_productm    TYPE  comt_product_maintain_api_ext,
        et_bapireturnh TYPE bapiret2_tab,
        lt_product     TYPE comt_product_s_tab,
        lt_prod_out    TYPE comt_product_tab_guid,
        lt_shorttext   TYPE comt_pr_shtext_maintain_tab,
        ls_shorttext   LIKE LINE OF lt_shorttext,
        lt_prod_id     TYPE STANDARD TABLE OF comm_product-product_id,
        lt_prod_db     TYPE STANDARD TABLE OF comm_product-product_guid.
START-OF-SELECTION.
  APPEND '1002029' TO lt_prod_id.
  APPEND '1002030' TO lt_prod_id.
  LOOP AT lt_prod_id ASSIGNING FIELD-SYMBOL(<id>).
    CALL FUNCTION 'CONVERSION_EXIT_PRID1_INPUT'
      EXPORTING
        input  = <id>
      IMPORTING
        output = <id>.
  ENDLOOP.
  SELECT product_guid INTO TABLE lt_prod_db FROM comm_product FOR ALL ENTRIES IN lt_prod_id
     WHERE product_id = lt_prod_id-table_line.
  ASSERT sy-subrc = 0.
  LOOP AT lt_prod_db ASSIGNING FIELD-SYMBOL(<guid>).
    DATA(ls_product) = VALUE comt_product_s( product_guid = <guid> ).
    APPEND ls_product TO lt_product.
  ENDLOOP.
  CALL FUNCTION 'COM_PRODUCT_READ_MULTIPLE'
    EXPORTING
      it_product = lt_product
    IMPORTING
      et_product = lt_prod_out.
  LOOP AT lt_prod_out ASSIGNING FIELD-SYMBOL(<result>).
    MOVE-CORRESPONDING <result> TO ls_productm-header-com_product.
    ls_productm-header-pr_number = sy-tabix.
    ls_shorttext-data-langu = sy-langu.
    ls_shorttext-data-short_text = 'inserted by program code'.
    ls_shorttext-update_type = 'U'.
    ls_shorttext-data-logsys = <result>-logsys.
    APPEND ls_shorttext TO lt_shorttext.
    ls_productm-header-short_texts = lt_shorttext.
    APPEND ls_productm TO lt_productm.
  ENDLOOP.
  CALL FUNCTION 'COM_PRODUCT_MAINTAIN_MULT_API'
    EXPORTING
      iv_check_only                 = ' '
      iv_suppress_inactive          = 'X'
      iv_activate_inactive_products = 'X'
    IMPORTING
      et_bapireturn                 = et_bapireturnh
    CHANGING
      ct_product                    = lt_productm
    EXCEPTIONS
      internal_error                = 1
      OTHERS                        = 2.
  LOOP AT et_bapireturnh ASSIGNING FIELD-SYMBOL(<error>).
    WRITE: / 'Error: ', <error>-message COLOR COL_NEGATIVE.
  ENDLOOP.
  CHECK et_bapireturnh IS INITIAL.
  CALL FUNCTION 'CRM_PRODUCT_UI_SAVE'
    EXPORTING
      iv_update_task = abap_false.
  ASSERT sy-subrc = 0.
  COMMIT WORK AND WAIT.
  WRITE: / 'Mass change finished successfully' COLOR COL_POSITIVE.