Skip to Content
Technical Articles
Author's profile photo Masayuki Sekihara

Fiori My Inbox – Step 6. Implement the BADI for updating the decision

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

/wp-content/uploads/2015/06/inbox6_719671.png

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

/wp-content/uploads/2015/06/inbox6_2_719717.png

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

/wp-content/uploads/2015/06/inbox6_3_719718.png

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

/wp-content/uploads/2015/06/inbox6_4_719719.png

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.

/wp-content/uploads/2015/06/inbox6_5_719723.png

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

/wp-content/uploads/2015/06/inbox6_6_719724.png

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

Drill into the BAdI implementation you just created:

/wp-content/uploads/2015/06/inbox6_7_719725.png 

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:

/wp-content/uploads/2015/06/inbox6_8_719730.png 

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:

/wp-content/uploads/2015/06/inbox6_9_719731.png

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:

/wp-content/uploads/2015/06/inbox6_10_719741.png

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:

/wp-content/uploads/2015/06/inbox6_11_719742.png

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

/wp-content/uploads/2015/06/inbox6_12_719743.png

——————

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.

—————–

 

 

Assigned Tags

      18 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sheetal Deshmukh
      Sheetal Deshmukh

      hi Masa,

      Thaks for the blog !

      I implemented this BADi., as I do not have user decision step in workflow. rather my scenario is currently approval happens through portal ( UWL). on click of portal the web gui with ztransaction opens. There are Approve reject buttons within the screen that call respective abap methods.

      How can I implement this in my inbox?

      Regards,

      Sheetal

      Author's profile photo Masayuki Sekihara
      Masayuki Sekihara
      Blog Post Author

      Please create a new discussion and share your BADI code. SCN members can check it and give some support. Discussion

      Author's profile photo Former Member
      Former Member

      Nice guide, but are there more detailed explanations how to implement other BADis? E.g. What should be put in every step - is it predetermined somewhere or a free user's choice?

      Author's profile photo Jocelyn Dart
      Jocelyn Dart

      Hi Diana,

      Do you mean what is the step value? The step value is the node number in the workflow flowchart that links to the task. 

      Rgds,

      Jocelyn

      Author's profile photo Abhishek Sharma
      Abhishek Sharma

      Hi Masayuki,

      I've implemented the same badi in the MYINBOX application.

      I'm able to approve/reject on the application but the same is not updated on the back end.

      I'm getting sysubrc 4  on the step "select single * from swxformabs into ls_formabs where formnumber = formnumber."

      Author's profile photo Abhishek Kumar
      Abhishek Kumar

      Hi,

       

      I am facing the same issue , Can you please suggest, How you overcome with this issue ?

       

      Author's profile photo Alan Rickayzen
      Alan Rickayzen

      Whether or not this technique can be used depends on the task. In nearly all cases this technique can be used, but when the application has implemented its own logic for handling the communication between the approval task and the application this technique may not succeed.

      This technique cannot be used for the workflow (WS21000098 FI-CA Dual Control: Approve Request), which follows a unique integration embedded in the application. Note 2378748

      Author's profile photo Kapil Changrani
      Kapil Changrani

      Hi,

      I implemented Above BADI for PO approval and approval works fine , now I am facing a strange issue.

      Below notification of - "Purchase Order XXX Released" - this comes only if I am in the debugging mode in above BADI. If I run the whole process without debugging mode - PO gets released successfully, however I do not get the below notification after its released.

      Is there a way to resolve this issue? Like do I need to put a wait in the BADI implementation or something like that?

      Thanks,

       

       

       

      Author's profile photo Masayuki Sekihara
      Masayuki Sekihara
      Blog Post Author

      Hi Kapil,

      Please create a new question. https://answers.sap.com/index.html

      Probably some issue is in your workfow temlate side.

      Regards,

      Masa /SAP Technology RIG

       

      Author's profile photo Kapil Changrani
      Kapil Changrani

      Hi Masayuki,

      WF template is just copy of original Purchase Order Release WF. I am on  S/4 1610 .

      All is working fine in debug mode, but not in actual run.

      PO gets released - both debug and non debug mode - from FIORI App MY Inbox

      Notification of PO release only received in Debug Mode of this BADI.

      If I run it all the way thru, without debugging, I do not get notification of PO release.

       

      Question opened at -

      https://answers.sap.com/questions/168350/index.html

      Author's profile photo Itelligence Application Support
      Itelligence Application Support

      Hello Masayuke,

      great post!!!

       

      We managed to get PO WF and FI parked documents WF action buttons following your instructions here!

      For our custom PO release WF we could copy the existing implementation MM_PUR_PO_APPROVE_ACTIONS into a Z one implemented by the same class and apply the filter pointing to our workflow and step and it Works fine

       

      For Parked documents it is more tricky since we could not find any simple implementation by SAP. Just used your approach removing the absence related coding and using the WF outcome values to update the container

      ls_container_line-value = <code of outcome in WF>

      And it Works!!!

      Can you confirm this approach is correct?

       

      Another side issue we are still facing for FI parked documents workflow is the fact description of the workitem in myinbox does not show any information about the parked document to reléase/reject. Is this the normal behaviour? Users can open sapguihtml but it makes very little sense to me

      Can you provide some guidance?

      Author's profile photo Masayuki Sekihara
      Masayuki Sekihara
      Blog Post Author

      Please post questions in https://answers.sap.com/index.html

      Author's profile photo Tanweer Zaki
      Tanweer Zaki

      Dear Masayuki,

      If we don't have any outcome in the dialog work item and instead BO is updating workflow container which is later being checked using decision step to create Approve/Rejected outcome (Example TS21500003 in Leave Request Workflow) then how to handle such scenarios.

      I tried to use above BADI but in this case it is not stopping at the break point in the BADI method. Please suggest.

       

      Regards,

      Tanweer

      Author's profile photo Tanweer Zaki
      Tanweer Zaki

      Dear Masayuki,

      For above issue, I also raised below question but so far no replies.

      https://answers.sap.com/questions/387623/workflow-task-in-fiori-with-no-outcome.html

       

      Regards,

      Tanweer

      Author's profile photo Kapil Changrani
      Kapil Changrani

      Hi Masayuki,

      Is this BADI common for any type of approval, I am trying to use custom PR workflow(at header level) in MYINBOX in S4 1610 , I am sure I am not the first one with this requirement,

      Right now the custom workflow is not even showing up in My Inbox.

      Any guidance will be appreciated.

      Author's profile photo Mat Beerkens
      Mat Beerkens

      For all looking to find an answer on a user-decision, please look at FM SAP_WAPI_DECISION_COMPLETE.

      Author's profile photo Prerna Ambastha
      Prerna Ambastha

      Will I have to implement the Badi, even if my step is a User Decision step?
      Because I created a user-decision step and till now i haven't implemented the Badi, and my submit button is not working in Fiori. On Approve/Reject, nothing is happening.

      Author's profile photo Gianni Solomita
      Gianni Solomita

      Did you find a solution for the problem that nothing happens on approve/reject?