Friday, August 16, 2019

Pass values from program to workflow BUS2017 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).


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.


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_02mat_doc,
l_matdocumentyear
TYPE  bapi2017_gm_head_02doc_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 sysubrc 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_itemspo_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_optdismode = ‘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.


/wp-content/uploads/2014/04/1_446669.png

Modify the program by clicking on Program above:

/wp-content/uploads/2014/04/2_446670.png

/wp-content/uploads/2014/04/3_446739.png


Add the parameters in the new method (BAPI)

/wp-content/uploads/2014/04/4_446740.png

/wp-content/uploads/2014/04/5_446747.png


Add the parameters in the new Event.

/wp-content/uploads/2014/04/6_446748.png



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 mkpfmblnr,
mjahr
TYPE mkpfmjahr,
END OF key.
DATA : event_container TYPE TABLE OF swcont.
DATA : objkey TYPE sweinstcouobjkey.
DATA : s_xmkpf TYPE mkpf.
DATA: l_RETURN_CODE TYPE sysubrc,
l_event_id
TYPE SWR_STRUCTEVENT_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_contELEMENT = ‘MATERIALDOCUMENT’.
x_cont
VALUE = ls_xmsegmblnr.
APPEND x_cont to INPUT_CONTAINE.
x_contELEMENT = ‘MATERIALDOCYEAR’.
x_cont
VALUE = ls_xmsegmjahr.
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.
/wp-content/uploads/2014/04/7_446749.png


Create a task with the following details.

/wp-content/uploads/2014/04/8_446750.png



Click on Binding in the above screen:

/wp-content/uploads/2014/04/9_446751.png

/wp-content/uploads/2014/04/10_446752.png


Create an Activity and attach the task to it.


/wp-content/uploads/2014/04/11_446753.png


/wp-content/uploads/2014/04/12_446754.png

Affect Agents

/wp-content/uploads/2014/04/13_446755.png


Add a starting event in Basic Data.

/wp-content/uploads/2014/04/14_446756.png

/wp-content/uploads/2014/04/15_446757.png

Add a Process Control to end the workflow.
/wp-content/uploads/2014/04/1_446669.png


Workflow Final should look like this:

/wp-content/uploads/2014/04/17_446758.jpg

1.2         Tests

MIGO:

/wp-content/uploads/2014/04/5_446747.png

/wp-content/uploads/2014/04/6_446748.png

Verify in SAP Inbox (Transaction SBWP)

/wp-content/uploads/2014/04/7_446749.png

Execute the workflow by double-clicking

/wp-content/uploads/2014/04/21_446760.png



Tick OK and Save.

/wp-content/uploads/2014/04/9_446751.png

No comments:

Post a Comment