To delete BOM component from production order

REPORT zsample.
PARAMETERS : p_aufnr like afko-aufnr DEFAULT '318233000039'.
START-OF-SELECTION.
  PERFORM f_delete_bom USING p_aufnr.
END-OF-SELECTION.

FORM f_delete_bom USING p_aufnr.
* -- Type --
  TYPES:  BEGIN OF ty_afko_resb,
           aufnr TYPE afko-aufnr,
           rsnum TYPE resb-rsnum,
           rspos TYPE resb-rspos,
          END   OF ty_afko_resb.
* Data declration
  DATA:   lt_resbd_to_delete TYPE coxt_t_resbdel,
          ls_resbd_to_delete TYPE coxt_s_resbdel,
          ct_return          TYPE coxt_t_bapireturn,
          wa_return          TYPE LINE OF coxt_t_bapireturn,
          ct_return2         TYPE coxt_bapireturn,
          l_error_occured(1) TYPE c,
          l_temp_order_key   LIKE cif_r3ord-aufnr.
  DATA :  lt_afko_resb TYPE TABLE OF ty_afko_resb,
          wa_afko_resb LIKE LINE OF  lt_afko_resb.
* Initialized
  CLEAR   l_temp_order_key.
  REFRESH lt_afko_resb.
* Get Data using the Production order number
  SELECT      a~aufnr r~rsnum r~rspos
    FROM      afko AS a
  INNER JOIN  resb AS r ON a~rsnum = r~rsnum
    INTO CORRESPONDING FIELDS OF TABLE lt_afko_resb
    WHERE     a~aufnr = p_aufnr.
*      AND     r~xloek <> 'X'.
  IF sy-subrc EQ 0.
   "--Append the component to delete--
*  clear ls_resbd_to_delete.
*  ls_resbd_to_delete-rsnum = '8088014'.
*  ls_resbd_to_delete-rspos = '3'.
*  APPEND ls_resbd_to_delete to lt_resbd_to_delete.
    LOOP AT lt_afko_resb INTO wa_afko_resb.
      CLEAR ls_resbd_to_delete.
      ls_resbd_to_delete-rsnum = wa_afko_resb-rsnum.
      ls_resbd_to_delete-rspos = wa_afko_resb-rspos.
      APPEND ls_resbd_to_delete TO lt_resbd_to_delete.
    ENDLOOP.
    "--Function module to delete the component--
    CALL FUNCTION 'CO_XT_COMPONENTS_DELETE'
      EXPORTING
        it_resbkeys_to_delete = lt_resbd_to_delete
      IMPORTING
        e_error_occurred      = l_error_occured
      TABLES
        ct_bapireturn         = ct_return
      EXCEPTIONS
        delete_failed         = 1
        OTHERS                = 2.
    IF sy-subrc = 0 AND ct_return[] IS INITIAL.
      PERFORM change_flag_set(saplcozv).
      REFRESH ct_return.
      l_temp_order_key = p_aufnr.
      CALL FUNCTION 'CO_XT_ORDER_PREPARE_COMMIT'
        IMPORTING
          e_order_key      = l_temp_order_key
          es_bapireturn    = ct_return2
          e_error_occurred = l_error_occured.
      COMMIT WORK AND WAIT.
      IF l_error_occured IS NOT INITIAL.
          WRITE:/ 'Deleted : ' , p_aufnr.
        ELSE.
          WRITE:/ 'Error in deleting : ' , p_aufnr.
      ENDIF.
    ELSE.
      WRITE:/ 'Delete failed : ' , p_aufnr.
      data lv_message type string.
      LOOP AT ct_return into wa_return.
          call function 'MESSAGE_TEXT_BUILD'
             exporting
               msgid               = wa_return-id          "Messg class
               msgnr               = wa_return-number          "Messg No.
               msgv1               = wa_return-message_v1
               msgv2               = wa_return-message_v2
               msgv3               = wa_return-message_v3
               msgv4               = wa_return-message_v4
             importing
               message_text_output = lv_message.
               .
              WRITE:/ 'Delete failed : ' , p_aufnr, lv_message.
      ENDLOOP.
    ENDIF.
   ELSE.
      WRITE:/ 'Nothing to delete : ' , p_aufnr.
  ENDIF.
ENDFORM.                    "f_delete_bom
0 comments:

Post a Comment

message

Labels

NuffNang

Search google

Blog Archive

My Blog List

Twitter

Message

Followers