This is my requirement to update Header Note PO with Decision Note from FIORI App when processing PO Approval. when user fill decision note when PO Reject or Approve, thats decision note must send and update particular Header Note PO.
We can use BAdI /IWWRK/BADI_WF_BEFORE_UPD_IB. Go to tcode SE18 and create new implementation.
After you create New Implementation, then fill Filter Value with PO Workflow Approval = WS20000075.
Go to Implementing Class. and double click on it to start write your ABAP Code.
We use TDOBJECT code in Header Note F04 ( For Rejection Note ) and F03 ( For Approval Note ).
1 2 |
CONSTANTS : co_rej TYPE char10 VALUE 'F04', co_app TYPE char10 VALUE 'F03'. |
Get PO Object ID and Item Number from Workflow.
1 2 3 |
lo_wf_api = cl_mm_pur_util_apv_wf_api=>get_instance( ). lv_user_id = sy-uname. ls_wfl_inb-workitem_id = is_wi_details-wi_id. |
Get Object Information from Workflow Workitem and get PO Number and PO Item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
IF lo_wf_api IS NOT INITIAL. * Get the Object Information from WorkItem. CALL METHOD lo_wf_api->get_boident_for_workitem EXPORTING iv_user_id = lv_user_id is_workflow_inbox = ls_wfl_inb IMPORTING es_wiid_boident = ls_wiid_boident. * Check, that the PR is found for the given Workitem ID IF ls_wiid_boident IS NOT INITIAL. lv_po_num = ls_wiid_boident-object_id. lv_po_itm = ls_wiid_boident-object_line. ELSE. * Handle error RETURN. ENDIF. ENDIF. "Access the workflow data CALL FUNCTION 'SAP_WAPI_GET_OBJECTS' EXPORTING workitem_id = is_wi_details-wi_id IMPORTING leading_object_2 = ls_object. IF lv_po_num IS INITIAL. lv_po_num = ls_object-instid(10). ENDIF. |
We use Decision Key to find out whether Approve or Reject. Decision Key 0001 ( Yes / Approve ) and 0002 ( No/Reject ).
1 2 3 4 5 6 7 8 |
CASE iv_decision_key. WHEN 0001. "Approve ...... WHEN 0002. "Reject ..... ENDCASE. |
Looping internal table IT_WF_CONTAINER_TAB to get decision note and populate lt_lines internal table then run function module SAVE_TEXT to save to header note PO.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
LOOP AT it_wf_container_tab INTO ls_comments_line. lw_lines-tdformat = '*'. lw_lines-tdline = ls_comments_line-value. APPEND lw_lines TO lt_lines. ENDLOOP. CALL FUNCTION 'SAVE_TEXT' EXPORTING client = sy-mandt header = ls_header savemode_direct = 'X' TABLES lines = lt_lines EXCEPTIONS id = 1 language = 2 name = 3 object = 4 OTHERS = 5. |
This is the full ABAP Code :
badi to update decision note fiori abap code