SAP ABAP Workflow
SAP ABAP Workflow
com
Scenario:
The scenario is when a Purchase Order Document creates a workflow will send an approval
request email to the approver. That email will be received in Gmail Inbox or any other email
server.
The approver will open that email in any device by using Gmail or mail server app or website.
He will have two options Approve or Reject the purchase order.
He will just click on approve/reject button in email and the effect will happen in SAP Inbox.
Page | 1
SAP Technical Consultant [email protected]
Go to SW01:
Create a business object by follow these the steps.
Step 1:
Page | 2
SAP Technical Consultant [email protected]
The Business Object is created. Now we have to arrange it according to the need.
Step 2:
Must Implement and Release the Business object to make it available for use.
Page | 3
SAP Technical Consultant [email protected]
Page | 4
SAP Technical Consultant [email protected]
Step 3:
We must create Key Field that is Purchase Order Number in Our case.
Page | 5
SAP Technical Consultant [email protected]
Page | 6
SAP Technical Consultant [email protected]
Step 4:
We have to create a method in this Business Object to send Email to the recipient.
Page | 7
SAP Technical Consultant [email protected]
Page | 8
SAP Technical Consultant [email protected]
We must need to Implement and Release the Method to make it available for use in Workflow
Tasks.
Page | 9
SAP Technical Consultant [email protected]
Page | 10
SAP Technical Consultant [email protected]
Step 5:
Create the parameters for the method that should be passed to that method during workflow
running.
Page | 11
SAP Technical Consultant [email protected]
Page | 12
SAP Technical Consultant [email protected]
Step 6:
Now we have to write code in the created method to send Email.
Note: The code is written for practice only. You can write by your own way with the new
ABAP syntax as well.
CONSTANTS:
Page | 13
SAP Technical Consultant [email protected]
TRY.
SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
EXPORTING
EBELN = PURCHASINGDOCUMENT
TABLES
GT_CONT = GT_CONT.
DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = C_HTM
I_TEXT = GT_CONT
I_LANGUAGE = SY-LANGU
I_SUBJECT = MAILSUBJECT ).
SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
SEND_REQUEST->SET_SENDER( SENDER ).
Page | 14
SAP Technical Consultant [email protected]
I_COPY = 'X' ).
I_BLIND_COPY = 'X' ).
DATA(LV_SENT_TO_ALL) = SEND_REQUEST->SEND( ).
IF LV_SENT_TO_ALL = 'X'.
ELSE.
ENDIF.
COMMIT WORK.
ENDTRY.
END_METHOD.
Page | 15
SAP Technical Consultant [email protected]
CONSTANTS:
*-- Constants used in the body of the Email (HTML)
C_HTM TYPE CHAR3 VALUE 'HTM',
C_STYLE_START TYPE CHAR255 VALUE '<FONT face=Arial size=2>',
C_NEW_LINE TYPE CHAR255 VALUE '<br>',
C_LINK_START TYPE CHAR128 VALUE '<A href="www.w3schools.com">',
C_LINK_TEXT TYPE CHAR32 VALUE 'Link for learning HTML',
C_LINK_END TYPE CHAR4 VALUE '</A>',
C_SPACE(6) TYPE C VALUE ' '.
CLEAR GW_CONT.
MOVE '<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">' TO GW_CONT-LINE.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
MOVE '<head>' TO GW_CONT-LINE.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
GW_CONT-LINE = '<em><font ' .
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
GW_CONT-LINE = 'color="#0000FF" size="+7" face="Arial,'.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
GW_CONT-LINE = 'Helvetica, sans-serif"> </font></em>'.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
MOVE '</head>' TO GW_CONT-LINE.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
GW_CONT-LINE = '<br>'.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
CLEAR GW_CONT.
GW_CONT-LINE = '<br>'.
APPEND GW_CONT TO GT_CONT.
Page | 16
SAP Technical Consultant [email protected]
GW_CONT-LINE = '<body>'.
"Option 1
CONCATENATE '<li>'
'<a href="'
G_URL_FIOR1
'">'
'Approve</a>'
'</li>'
INTO GW_CONT-LINE.
APPEND GW_CONT TO GT_CONT.
"Option 2
CONCATENATE '<li>'
'<a href="'
G_URL_FIOR2
'">'
'Reject</a>'
'</li>'
INTO GW_CONT-LINE.
APPEND GW_CONT TO GT_CONT.
GW_CONT-LINE = '</ul>'.
APPEND GW_CONT TO GT_CONT.
GW_CONT-LINE = '</body>'.
APPEND GW_CONT TO GT_CONT.
GW_CONT-LINE = '<br><p>Regards</P>'.
APPEND GW_CONT TO GT_CONT.
GW_CONT-LINE = '</body></html>'.
APPEND GW_CONT TO GT_CONT.
CLEAR GW_CONT.
GW_CONT-LINE = '<br>'.
APPEND GW_CONT TO GT_CONT.
Page | 17
SAP Technical Consultant [email protected]
Note: After writing code in the BO Method must need to click on generate button to
make it available.
Step 7:
Now we have to create event to use in Workflow.
Page | 18
SAP Technical Consultant [email protected]
Same as before, must need to implement and release it to make it available for use.
Page | 19
SAP Technical Consultant [email protected]
Step 8:
We need an API that will send a request of approve or reject case selected by approver from
email.
Go To Transaction Code SEGW and create a project with the following objects:
Note: I am not telling ODATA Creation in Detail here. Also change length of Ebeln to 25.
After Creating and Generating the ODATA Project we have to redefine the Get Entity Method.
Page | 20
SAP Technical Consultant [email protected]
IF SY-SUBRC EQ 0.
IF LV_VAR2 EQ 'A'.
ENDIF.
ENDIF.
MOVE LV_VAR1 TO LV_EBELN.
SELECT SINGLE * FROM EKKO INTO ER_ENTITY WHERE EBELN EQ LV_EBELN.
Page | 21
SAP Technical Consultant [email protected]
Step 9:
Create Workflow and Workflow Task:
Go to PFTC:
Page | 22
SAP Technical Consultant [email protected]
Page | 23
SAP Technical Consultant [email protected]
Step 10:
Create workflow.
Page | 24
SAP Technical Consultant [email protected]
Activity 1:
We have to create this Task in PFTC T-Code.
Page | 25
SAP Technical Consultant [email protected]
Activity 2:
We have to use standard task here for sending notification in Inbox.
Page | 26
SAP Technical Consultant [email protected]
Step 11:
Let’s Run the Workflow and Test it.
Page | 27
SAP Technical Consultant [email protected]
Page | 28
SAP Technical Consultant [email protected]
We can see our inbox the notification arrived to approve Purchase Order.
Page | 29
SAP Technical Consultant [email protected]
Page | 30
SAP Technical Consultant [email protected]
Page | 31