Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

This document explains how to get values from a program (BADI in our case), pass the values from the program to the workflow and then pass the values from the workflow to a program (BAPI in our case).

I am myself a beginner in workflow. With some help in SCN, we have been able to set up a workflow to meet the requirements.

Special thanks tomodak.gupta.

Original Discussion thread: Re: How to get values from workflow to program

1. Creation of a workflow to execute MIGO

This document explains how to get values from a program (BADI in our case), pass the values from the program to the workflow and then pass the values from the workflow to a program (BAPI in our case).

1.1 Requirement:

Once MIGO is done, the client wishes to do another MIGO. For him to know that the first MIGO has been done, he needs to get it in his SAP Inbox (Workflow). From there, he can just execute the workflow and he will do the second MIGO.


1.1 Steps

1.1.1 BAPI

Create a BAPI in SE37 to get the purchase order (we need it because we will open the second MIGO with the purchase order of the first MIGO). We will also call the transaction MIGO in the BAPI (For our requirement, it is ZMIGO, but very similar to MIGO, just some different customizing).

In the BAPI, use the function module BAPI_GOODSMVT_GETDETAIL to get the purchase order.

A BDC is also done in the BAPI to open ZMIGO with the purchase order.

Code:

FUNCTION zbapi_call_transaction.
*"----------------------------------------------------------------------
*"*"Interface locale :
*"  IMPORTING
*"     VALUE(MATERIALDOCUMENT) TYPE  MBLNR
*"     VALUE(MATDOCUMENTYEAR) TYPE  MJAHR
*"  EXPORTING
*"     VALUE(RETURN) TYPE  BAPIRETURN
*"----------------------------------------------------------------------


DATA: gt_items TYPE STANDARD TABLE OF bapi2017_gm_item_show,
gs_items
TYPE bapi2017_gm_item_show,
gt_return
TYPE STANDARD TABLE OF bapiret2,
gs_header
TYPE bapi2017_gm_head_02,
l_materialdocument 
TYPE  bapi2017_gm_head_02-mat_doc,
l_matdocumentyear
TYPE  bapi2017_gm_head_02-doc_year.

DATA: gs_bdcdata  TYPE bdcdata,
gt_bdcdata 
TYPE TABLE OF bdcdata,
l_opt
TYPE ctu_params.

l_materialdocument      
= materialdocument.
l_matdocumentyear       
= matdocumentyear.

CALL FUNCTION 'BAPI_GOODSMVT_GETDETAIL'
EXPORTING
materialdocument
= l_materialdocument
matdocumentyear 
= l_matdocumentyear
IMPORTING
goodsmvt_header 
= gs_header
TABLES
goodsmvt_items  
= gt_items
return           = gt_return.

READ TABLE gt_items INTO gs_items INDEX 1.
IF sy-subrc EQ 0.

CLEAR gs_bdcdata.
gs_bdcdata
-program  = 'SAPLMIGO'.
gs_bdcdata
-dynpro   = '0001'.
gs_bdcdata
-dynbegin = 'X'.
APPEND gs_bdcdata TO gt_bdcdata.

CLEAR gs_bdcdata.
gs_bdcdata
-fnam = 'BDC_CURSOR'.
gs_bdcdata
-fval = 'GODYNPRO-PO_NUMBER'.
APPEND gs_bdcdata TO gt_bdcdata.

CLEAR gs_bdcdata.
gs_bdcdata
-fnam = 'GODYNPRO-PO_NUMBER'.
gs_bdcdata
-fval = gs_items-po_number.
APPEND gs_bdcdata TO gt_bdcdata.

CLEAR gs_bdcdata.
gs_bdcdata
-fnam = 'BDC_CURSOR'.
gs_bdcdata
-fval = 'GODEFAULT_TV-BWART'.
APPEND gs_bdcdata TO gt_bdcdata.

CLEAR gs_bdcdata.
gs_bdcdata
-fnam = 'GODEFAULT_TV-BWART'.
gs_bdcdata
-fval = '101'.
APPEND gs_bdcdata TO gt_bdcdata.

CLEAR gs_bdcdata.
gs_bdcdata
-fnam = 'BDC_CURSOR'.
gs_bdcdata
-fval = 'GODYNPRO-PO_NUMBER'.
APPEND gs_bdcdata TO gt_bdcdata.

CLEAR gs_bdcdata.
gs_bdcdata
-fnam = 'BDC_OKCODE'.
gs_bdcdata
-fval = '=OK_GO'.
APPEND gs_bdcdata TO gt_bdcdata.

l_opt
-dismode = 'E'.
l_opt
-defsize = 'X'.

CALL TRANSACTION 'ZMIGO' USING gt_bdcdata OPTIONS FROM l_opt.

ENDIF.

ENDFUNCTION.

 

1.1.2 Business Object

Create a Business Object in SWO1.

It is a copy of BUS2017, we have added our BAPI and an event. We also modified the program.




Modify the program by clicking on Program above:





Add the parameters in the new method (BAPI)





Add the parameters in the new Event.





1.1.3 BADI

Implement the BADI in SE18 / SE19

BADI: MB_DOCUMENT_BADI -

Method: MB_DOCUMENT_BEFORE_UPDATE

Get the purchase order

Use the function module SAP_WAPI_CREATE_EVENT to pass values from program to workflow.

Code:

method IF_EX_MB_DOCUMENT_BADI~MB_DOCUMENT_BEFORE_UPDATE.

DATA : BEGIN OF key,
mblnr
TYPE mkpf-mblnr,
mjahr
TYPE mkpf-mjahr,
END OF key.
DATA : event_container TYPE TABLE OF swcont.
DATA : objkey TYPE sweinstcou-objkey.
DATA : s_xmkpf TYPE mkpf.
DATA: l_RETURN_CODE TYPE sy-subrc,
l_event_id
TYPE SWR_STRUCT-EVENT_ID,
lt_container
TYPE STANDARD TABLE OF SWR_CONT,
ls_container
TYPE SWR_CONT.

data :INPUT_CONTAINE type table of SWR_CONT ,
x_cont
type swr_cont.

" numéro commande d'achat
DATA ls_xmseg TYPE mseg.
CLEAR ls_xmseg.
READ TABLE xmseg INTO ls_xmseg INDEX 1.

x_cont
-ELEMENT = 'MATERIALDOCUMENT'.
x_cont
-VALUE = ls_xmseg-mblnr.
APPEND x_cont to INPUT_CONTAINE.

x_cont
-ELEMENT = 'MATERIALDOCYEAR'.
x_cont
-VALUE = ls_xmseg-mjahr.
APPEND x_cont to INPUT_CONTAINE.

CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
object_type            
= 'ZYBI'
object_key             
= objkey
event                   = 'EVENT2'
COMMIT_WORK            
= space

IMPORTING
RETURN_CODE            
= l_RETURN_CODE
EVENT_ID               
= l_event_id
TABLES
INPUT_CONTAINER        
= INPUT_CONTAINE.

endmethod.

 

1.1.4 Workflow

Create the workflow in SWDD

Add the Business Object in the container and tick Import.



Create a task with the following details.





Click on Binding in the above screen:





Create an Activity and attach the task to it.






Affect Agents




Add a starting event in Basic Data.




Add a Process Control to end the workflow.



Workflow Final should look like this:



1.2         Tests

MIGO:





Verify in SAP Inbox (Transaction SBWP)



Execute the workflow by double-clicking





Tick OK and Save.




Best Regards,

Feenaz

3 Comments
Labels in this area