Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8430

Re: How to get values from workflow to program

$
0
0

Hello,

 

With some help here and there, we have been able to set up the workflow. Special thanks to Modak Gupta.

 

I'm sharing the steps below. I would be grateful if someone could explain the different binding, what are their purposes depending on the place they are done, etc. I am still not very at ease with the binding. Thanks.

 

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.

 

Steps:

 

1. 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.

 

 

2. 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.

 

 

1.png

 

 

 

Modify the program by clicking on Program above:

 

 

 

2.png

 

 

3.png

 

 

 

Add the parameters in the new method (BAPI)

 

4.png

 

 

5.png

 

 

Add the parameters in the new Event.

 

6.png

 

 

 

3. 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.

  1. endmethod.

 

 

 

4. Create the workflow in SWDD

 

Add the Business Object in the container and tick Import.

 

 

7.png

 

 

Create a task with the following details.

 

8.png

 

Click on Binding in the above screen:

 

9.png

 

10.png

 

 

 

Create an Activity and attach the task to it.

 

 

11.png

 

 

12.png

 

 

Affect Agents

 

13.png

 

 

Add a starting event in Basic Data.

 

15.png

 

 

16.png

 

Add a Process Control to end the workflow.

 

 

17.png

 

 

Workflow Final should look like this:

 

16.jpg

 

 

I hope it would be helpful to some of you. Sorry about the binding, there might be some issues not correct. But normally, if you follow the steps as they are, and for binding, you do Automatic Binding, it should be ok.

 

Thanks


Viewing all articles
Browse latest Browse all 8430

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>