Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
masa_139
Product and Topic Expert
Product and Topic Expert

Please find the series of documents in the SAP Fiori - My Inbox.


 


The final step is BADI implementation for updating the decision in the backend.


You can find the BADI information in the App Extensibility: My Inbox - SAP Fiori Apps - SAP Library.



BADI Implementation:


 

Server: ERP


Transaction: SE18

BADI: /IWWRK/BADI_WF_BEFORE_UPD_IB



Drill into the BAdI Definition. Right click on the Implementations node and select Create BAdI Implementation in the context menu:


In the popup window click the create icon in the bottom right hand corner:



In the Create Enhancement Implementation enter the details as shown below:


You will be navigated back to the Select or Create Enhancement Implementation popup window. Make sure your newly created Enhancement Implementation is selected as shown below and click the Enter button on this popup window.



The Create BAdI Implementation popup window will now be displayed: Enter in the details as shown below:



Click the Enter button. Go into Change mode by click the Display/Change button.

Drill into the BAdI implementation you just created:

 


Switch to Change mode and double click on the Filter Val. Node…on the right hand side you will see the filter details view displayed:


Click the Create Combination button.

In the popup window, select both WORKFLOW_ID and STEP_ID:

Click the Enter button. You should now see the following:


 


Double click on the ‘????’ in the Value 1 column for the STEP_ID row. You should see the following popup window:

Your filters should now be set as shown below:



Activate your BAdI by clicking the Activate button. Make sure to activate all objects that make up the BAdI.

 

Note: you will see a warning telling you that the method that holds the actual implementation code has not been implemented…this will be done in the following step.

 

Implement the method coding:


 

In your Enhancement Implementation switch to the Enh. Implementation Elements tab:


Double click on the Implementing Class node.


Double click on the Method /IWWRK/IF_WF_WI_BEFORE_UPD_IB~BEFORE_UPDATE (it’s the only method in the list). This will take you to the editor for this method:



Switch to change mode and add the follow code between the method and endmethod lines.



------------------

method /IWWRK/IF_WF_WI_BEFORE_UPD_IB~BEFORE_UPDATE.

"1. data definition

DATA ls_object TYPE swr_obj_2.

DATA lv_objtype TYPE swr_struct-object_typ.

DATA lv_objkey TYPE SWR_STRUCT-OBJECT_KEY.

DATA lv_retcode TYPE sy-subrc.

DATA lt_container TYPE TABLE OF swr_cont.

DATA ls_container_line TYPE swr_cont.

DATA lt_msg_lines type sapi_msg_lines.

DATA lt_msg_struc type sapi_msg_struc.

DATA FORMNUMBER TYPE SWXFORMABS-FORMNUMBER.

DATA ls_formabs TYPE swxformabs.

"2. get workitem ID

CALL FUNCTION 'SAP_WAPI_GET_OBJECTS'

EXPORTING

WORKITEM_ID            = is_wi_details-wi_id

*   LANGUAGE               = SY-LANGU

*   USER                   = SY-UNAME

*   BUFFERED_ACCESS        = 'X'

IMPORTING

*   LEADING_OBJECT         =

RETURN_CODE            = lv_retcode

LEADING_OBJECT_2       = ls_object

TABLES

*   OBJECTS                =

MESSAGE_LINES          = lt_msg_lines

MESSAGE_STRUCT         = lt_msg_struc

*   OBJECTS_2              =

.

"3. Get document number

MOVE ls_object-instid TO formnumber.

*4. Get decision result

CLEAR lt_container.

CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'

EXPORTING

WORKITEM_ID                    = is_wi_details-wi_id

*   LANGUAGE                       = SY-LANGU

*   USER                           = SY-UNAME

*   BUFFERED_ACCESS                = 'X'

IMPORTING

RETURN_CODE                    = lv_retcode

*   IFS_XML_CONTAINER              =

*   IFS_XML_CONTAINER_SCHEMA       =

TABLES

SIMPLE_CONTAINER               = lt_container

MESSAGE_LINES          = lt_msg_lines

MESSAGE_STRUCT         = lt_msg_struc

*   SUBCONTAINER_BOR_OBJECTS       =

*   SUBCONTAINER_ALL_OBJECTS       =

.

"5. Get application data

select single * from swxformabs into ls_formabs where formnumber = formnumber.

"6. set decision value to the container.

CASE iv_decision_key.

WHEN 0001. "Approved

ls_container_line-value = 'A'.

ls_formabs-procstate = 'A'.

WHEN 0002. "Rejected

ls_container_line-value = 'R'.

ls_formabs-procstate = 'R'.

ENDCASE.

"7. Set result

"_WI_RESULT is what the workflow keys off to determine

"which path to follow - Approve or Reject path

ls_container_line-element = '_WI_RESULT'.

"Modify the workflow's container data - we are updating the row that

"holds _WI_RESULT which will be in the second row of the table

MODIFY lt_container INDEX 3 FROM ls_container_line TRANSPORTING value.

"8. update container

CALL FUNCTION 'SAP_WAPI_WRITE_CONTAINER'

EXPORTING

WORKITEM_ID                        = is_wi_details-wi_id

*   LANGUAGE                           = SY-LANGU

*   ACTUAL_AGENT                       = SY-UNAME

DO_COMMIT                          = 'X'

*   IFS_XML_CONTAINER                  =

*   OVERWRITE_TABLES_SIMPLE_CONT       = ' '

*   CHECK_INBOX_RESTRICTION            = ' '

IMPORTING

RETURN_CODE                        = lv_retcode

TABLES

SIMPLE_CONTAINER                   = lt_container

MESSAGE_LINES          = lt_msg_lines

MESSAGE_STRUCT         = lt_msg_struc

.

"9. Update the application data

ls_formabs-approvdate = sy-datum.

ls_formabs-approvby = sy-uname.

update swxformabs from ls_formabs.

*10. Complete the task

CALL FUNCTION 'SAP_WAPI_WORKITEM_COMPLETE'

EXPORTING

WORKITEM_ID                     = is_wi_details-wi_id

*   ACTUAL_AGENT                    = SY-UNAME

*   LANGUAGE                        = SY-LANGU

*   SET_OBSOLET                     = ' '

DO_COMMIT                       = 'X'

*   DO_CALLBACK_IN_BACKGROUND       = 'X'

*   IFS_XML_CONTAINER               =

*   CHECK_INBOX_RESTRICTION         = ' '

IMPORTING

RETURN_CODE                     = lv_retcode

*   NEW_STATUS                      =

TABLES

*   SIMPLE_CONTAINER                = lt_container

MESSAGE_LINES          = lt_msg_lines

MESSAGE_STRUCT         = lt_msg_struc

.

*11. Set confirm

CALL FUNCTION 'SAP_WAPI_WORKITEM_CONFIRM'

EXPORTING

WORKITEM_ID                   = is_wi_details-wi_id

*   ACTUAL_AGENT                  = SY-UNAME

*   LANGUAGE                      = SY-LANGU

DO_COMMIT                     = 'X'

*   CHECK_INBOX_RESTRICTION       = ' '

IMPORTING

RETURN_CODE                   = lv_retcode

*   NEW_STATUS                    =

TABLES

MESSAGE_LINES          = lt_msg_lines

MESSAGE_STRUCT         = lt_msg_struc

.

endmethod.

-----------------

 

 

18 Comments