Problem/Scenario: I did not want to make organizational plan or my client want to run workflow from Z table.
I had a custom table ZWORKFLOW:
Design of table will depend on your requirement that how you want, for example I am taking development id, workflow id, Authorization and creator and relative manager.
Entries are like:
After having this I created a Z method in BOR:
In this method I will take the initiator SAP user id value and will get respective manager SAP id. Second I will call 'Z_SD_WORKFLOW_GET_USER_EMAIL' FM to pass the Manager SAP user id and will get the e@mail id.
Scratch Code can be:
data :
wf_initiator type user,
ZAGENT type user,
lv_zwf_initiator TYPE user,
ZBILLING_MAIL_MANAGER TYPE AD_SMTPADR,
c_us(2) type c value 'US'.
*Set initiator value without 'US'
swc_get_element container 'z_Wf_Initiator' WF_INITIATOR.
*Get initiator value without 'US'
lv_zwf_initiator = WF_INITIATOR.
lv_zwf_initiator = lv_zwf_initiator+2(10). *Select the agent user id
select single ZMANAGERID from ZWORKFLOW into ZAGENT
where ZDEVID = 'DEV110'
AND ZWORKFLOWID = 'BILLING'
AND ZAUTH_ID = 'DELETE'
AND ZUSERID = lv_zwf_initiator. CALL FUNCTION 'Z_SD_WORKFLOW_GET_USER_EMAIL'
EXPORTING
zuserid = ZAGENT
IMPORTING
EMAIL = ZBILLING_MAIL_MANAGER.
SWC_SET_ELEMENT CONTAINER RESULT ZBILLING_MAIL_MANAGER.
END_METHOD.
And the used FM(I will pass the user id and will get email id*) is:
*It should be maintained in user file.
FUNCTION z_sd_workflow_get_user_email.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(ZUSERID) TYPE ZUSERID
*" EXPORTING
*" REFERENCE(EMAIL) TYPE AD_SMTPADR
*"----------------------------------------------------------------------
* Type declaration
TYPES :
BEGIN OF email,
persnumber TYPE ad_persnum, "Personal number
addrnumber TYPE ad_addrnum, "Addess Number
END OF email.
* data declaration
DATA : wa_email TYPE email. "work area for getting the key parameter
*Selection for personal and address number
SELECT SINGLE
persnumber
addrnumber
INTO CORRESPONDING FIELDS OF wa_email
FROM usr21
WHERE bname = zuserid.
* Check sy-subrc = 0
IF sy-subrc = 0.
*Selection for getting email address
SELECT SINGLE
smtp_addr
INTO email
FROM adr6
WHERE addrnumber = wa_email-addrnumber AND
persnumber = wa_email-persnumber.
ENDIF.
Note:
You can also define error code/error handling here if SY-SUBRC not return to zero. You can push same in ‘ZBILLING_MAIL_MANAGER.” .Later on in workflow as next step you can check it in condition, you can handle this situation and you can send mail to SUPERUSER (I maintained in ZWORKFLOW table, I made this super user concept for it) describing the error code.
Make a task for it:
Define a local container element :
Before binding, declare a global element in your workflow to get the email address:
"
Do the proper binding:
"
Later on you can attach in your workflow.