custom approval workflow for mass invoices

36
7/24/2019 Custom Approval Workflow for Mass Invoices http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 1/36 Generated by Jive on 2015-11-26+01:00 1 Custom Approval Workflow for Mass Invoices Business Scenario: There are thousands of low-value, yet high-volume vendor invoices that need to be posted and paid in an efficient and timely manner. Any effort to manually POST these within SAP using Enjoy transaction is very time consuming and labor intensive. In addition to this, it is required that all these invoices obtain Approval through workflow before Posting.  So end users should be able to manually upload invoices in an Excel format using a custom program. The invoice data should be validated and then sent for Approval. Managers should be able to review and approve/ reject these invoices. The invoices should be posted in SAP after Approval. In case of Error or rejection, SAP email notifications should be generated to the End user.  This document provides a custom solution for developing Approval Workflow for Mass Invoices.  Benefits: Approval and Audit trail Timey payout to Vendors No dependency on any external interfaces  Create a custom program for uploading an Excel/CSV file containing Vendor Invoice records Excel file can be saved as CSV (Comma Delimited) file. Invoice Data from CSV file upload can either be staged in Data tables for tracking and auditing purposes. This solution directly processes the Invoice upload and sends it for Approval.  Sample template for Excel/CSV file (more fields can be included based on requirement)  Call transaction SE38 and create a sample program - Z_MASS_INV_UPLOAD with following options:  

Upload: vbak24

Post on 23-Feb-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 1/36

Generated by Jive on 2015-11-26+01:00

1

Custom Approval Workflow for Mass Invoices

Business Scenario:

There are thousands of low-value, yet high-volume vendor invoices that need to be posted and paid in an

efficient and timely manner. Any effort to manually POST these within SAP using Enjoy transaction is very timeconsuming and labor intensive. In addition to this, it is required that all these invoices obtain Approval through

workflow before Posting.

 

So end users should be able to manually upload invoices in an Excel format using a custom program. The

invoice data should be validated and then sent for Approval. Managers should be able to review and approve/ 

reject these invoices. The invoices should be posted in SAP after Approval. In case of Error or rejection, SAP

email notifications should be generated to the End user.

 

This document provides a custom solution for developing Approval Workflow for Mass Invoices.

 Benefits:

• Approval and Audit trail• Timey payout to Vendors

• No dependency on any external interfaces

 

Create a custom program for uploading an Excel/CSV file containing Vendor Invoice records

Excel file can be saved as CSV (Comma Delimited) file. Invoice Data from CSV file upload can either be

staged in Data tables for tracking and auditing purposes. This solution directly processes the Invoice upload

and sends it for Approval.

 Sample template for Excel/CSV file (more fields can be included based on requirement)

 

• Call transaction SE38 and create a sample program - Z_MASS_INV_UPLOAD with following options:

 

Page 2: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 2/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

2

 

• Sample Code for file Upload.

 This action opens a Browse window for selecting a File stored on local hard drive and saves it as a

SAP office document. The Document ID is available within ‘documents’ table.

 

* Data declaration  data:

  documents TYPE STANDARD TABLE OF sood4,

  document TYPE sood4,

  folder_id TYPE sofdk.

 

free documents.

  CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

  EXPORTING

  region = 'B'

  IMPORTING

  folder_id = folder_id

  EXCEPTIONS

  OTHERS = 0.

 

document-foltp = folder_id-foltp.

  document-folyr = folder_id-folyr.

  document-folno = folder_id-folno.

  APPEND document TO documents.

 

* Upload file as SAP Office doc

  CALL FUNCTION 'SO_DOCUMENTS_MANAGER'

  EXPORTING

  activity = 'IMPO'

  TABLES

  documents = documents.

 

Page 3: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 3/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

3

 

• Sample Code for viewing Uploaded file.

 This action retrieves the document by instantiating business object of type ‘MESSAGE’ and calling

its ‘DISPLAY’ method.

 

TYPES: BEGIN OF typ_message_key

  foltp TYPE so_fol_tp, "Object folder: Object type from ID

  folyr TYPE so_fol_yr, "Object folder: Year from ID

  folno TYPE so_fol_no, "Object folder: Number from ID

  doctp TYPE so_doc_tp, "Object: Object Type From ID

  docyr TYPE so_doc_yr, "Object: Year from ID

  docno TYPE so_doc_no, "Object: Number from ID

  fortp TYPE so_for_tp, "Forwarder: Object type from ID

  foryr TYPE so_for_yr, "Forwarder: year from the ID

  forno TYPE so_for_no, "Forwarder: number from the ID

  END OF typ_message_key.

 

DATA :

  l_message_key TYPE typ_message_key,

Page 4: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 4/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

4

  l_object_key TYPE swotobjid-objkey,

  l_message TYPE swc_object,

 

READ TABLE documents INDEX 1 INTO document.

 

l_message_key-foltp = document-foltp.l_message_key-folyr = document-folyr.

l_message_key-folno = document-folno.

l_message_key-doctp = document-objtp.

l_message_key-docyr = document-objyr.

l_message_key-docno = document-objno.

 

swc_container l_message_container.

 

l_object_key = l_message_key.

 swc_create_object l_message 'MESSAGE' l_object_key.

swc_call_method l_message 'Display' l_message_container.

 

• Sample Code for triggering workflow

 This action raises ‘MassApprovalRequested’ event of Business object ‘ZMASSINV’ (created in next

step)

 

• • Create number range ZBATCHNO for Batch Number.

 

Page 5: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 5/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

5

 

• • Generate new Batch number and trigger approval workflow

 

DATA :

  l_bo_objkey LIKE sweinstcou-objkey,

  l_bo_obj_type TYPE swotobjid-objtype,

  l_event TYPE swetypecou-event,

  l_batch_no TYPE numc10.

 

DATA :

  it_swcont TYPE STANDARD TABLE OF swcont INITIAL SIZE 0.

 

* Generate New Batch number

  CALL FUNCTION 'NUMBER_GET_NEXT'

  EXPORTING

  nr_range_nr = '01'

  object = 'ZBATCHNO'

  IMPORTING

  number = l_batch_no

  EXCEPTIONS

  interval_not_found = 1

  number_range_not_intern = 2

  object_not_found = 3

  quantity_is_0 = 4

  quantity_is_not_1 = 5

  interval_overflow = 6

  OTHERS = 7.

 

Page 6: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 6/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

6

  l_bo_objkey = l_batch_no.

  l_bo_obj_type = 'ZMASSINV'.

  l_event = 'MassApprovalRequested'.

 

* Pass document details to the workflow as Event parameter

  READ TABLE documents INDEX 1 INTO document. 

l_message_key-foltp = document-foltp.

  l_message_key-folyr = document-folyr.

  l_message_key-folno = document-folno.

  l_message_key-doctp = document-objtp.

  l_message_key-docyr = document-objyr.

  l_message_key-docno = document-objno.

 

* Instantiate Object of type Message

  swc_container l_message_container.  l_object_key = l_message_key.

swc_create_object l_message 'MESSAGE' l_object_key.

 

* Transfer Message object to Workflow

swc_set_element it_swcont 'UploadedDoc' l_message.

 

* Raise Event to trigger workflow.

  CALL FUNCTION 'SWE_EVENT_CREATE'

  EXPORTING

  objtype = l_bo_obj_type  objkey = l_bo_objkey

  event = l_event

  TABLES

  event_container = it_swcont

  EXCEPTIONS

  objtype_not_found = 1

  OTHERS = 2.

 

IF sy-subrc EQ 0.

  COMMIT WORK.

  ENDIF.

 

Create a Custom Business Object - ZMASSINV

• Call transaction SWO1 (Business Object Builder) and create object type ‘ZMASSINV’

 

Page 7: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 7/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

7

 

• Provide Object name, Description and underlying program name. Supertype field is blank since thisobject type is not inherited from any standard SAP business object type

 

• Change Object Release status to ‘Implemented’

 

Page 8: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 8/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

8

 

• Save and Generate object type ‘ZMASSINV’

 

Create Key field

For the purpose of demo, we can use a numerical field – Batch number as key field. This number

uniquely identifies each upload attempt.

 

• Place cursor on ‘Key Fields’ and click ‘Create’. On the subsequent popup screen – choose‘No’ , since this field does not reference any Database table.

 

Page 9: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 9/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

9

 

• Choose any numerical field e.g. – SYST-SPONO as data type reference

 

Page 10: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 10/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

10

 

Create Custom Event

• Place cursor on ‘Events’ and click ‘Create’. On the subsequent popup screen – provideevent name ‘MassApprovalRequested’. This event will serve as Triggering event for theMass Invoice Approval Workflow.

 

• Place cursor on event and change its release status to implemented

 

Page 11: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 11/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

11

 

• Create Event Parameters

Place cursor on event and choose ‘Parameters’.

 

Next click ‘Create’ and specify parameter name as ‘UploadedDoc’ of object type MESSAGE. This

event parameter represents the Uploaded excel file that is stored as SAP office document. 

Page 12: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 12/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

12

 

Create Custom Method

• Post Invoices after Approval

Place cursor on ‘Method and click ‘Create’. On the subsequent popup screen – provide methodname ‘PostMassUpldInv’. This is a background method.

 

Page 13: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 13/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

13

 

Create the same import parameter ‘UploadedDoc’ for this method

 

Page 14: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 14/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

14

 

Place cursor on Method and Click on Program

 

Sample method code

Page 15: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 15/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

15

 

begin_method postmassupldinv changing container.

DATA:

  uploadeddoc TYPE swc_object,

  lt_content_hex LIKE solix OCCURS 0 WITH HEADER LINE,

  lt_text_data TYPE STANDARD TABLE OF soli,  l_doc_size TYPE i,

  l_obj_len TYPE so_obj_len,

  l_obj_key TYPE swotobjid-objkey,

 

BEGIN OF l_key,

  objtp TYPE so_obj_tp,

  objyr TYPE so_obj_yr,

  objno TYPE so_obj_no,

  END OF l_key.

 swc_get_element container 'UploadedDoc' uploadeddoc.

 

*Retrieve Contents of the document

swc_call_method uploadeddoc 'ReadDocumentAttributes' container.

swc_get_table container 'Content_Hex' lt_content_hex .

 

*Retrieve second half of Object key

swc_get_object_key uploadeddoc l_obj_key.

l_key = l_obj_key+17(17).

 *Determine Document size

SELECT SINGLE objlen

  INTO l_obj_len

  FROM sood

WHERE objtp = l_key-objtp

  AND objyr = l_key-objyr

  AND objno = l_key-objno.

 

l_doc_size = l_obj_len.

 

* Conver to Text

CALL FUNCTION 'SCMS_BINARY_TO_TEXT'

  EXPORTING

  input_length = l_doc_size

  TABLES

  binary_tab = lt_content_hex

  text_tab = lt_text_data

Page 16: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 16/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

16

  EXCEPTIONS

  failed = 1

  OTHERS = 2.

 

* At this point - lt_text_data contains Invoice data in a tab delimited format. This

data can be processed and individual invoices can be posted using function

‘BAPI_ACC_INVOICE_RECEIPT_POST’

 

end_method.

 

Create Custom Approval Workflow

• Call transaction SWDD – Workflow Builder. Click Save and provide name for the Workflowtemplate

 

Page 17: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 17/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

17

 

• Create Workflow Container variable – ‘UploadedDoc’ of type MESSAGE.

 

Page 18: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 18/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

18

 

• Create another Container Variable ‘MassUpload’ of type ZMASSINV

 

Page 19: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 19/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

19

 

Set both these variables as ‘Import’ parameters for the Workflow container.

 

• Click on the Red-hat icon.

 

Page 20: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 20/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

20

 

• Set up triggering event for this workflow as ZMASSINV- MASSAPPROVALREQUESTED

 

Page 21: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 21/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

21

• Setup Data Binding from Event container to Workflow Container. The Event object of type ‘ZMASSINV’ and Uploaded Document of type ‘MESSAGE’ must be transferred to theWorkflow Container. The Event Creator is the SAP User name of the person who submitsMass invoices for approval.

 

• Activate the event linkage.

This will cause a workflow instance to be triggered every time a Batch of invoices is Uploaded.

 

Page 22: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 22/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

22

 

• Add ‘Uploaded Document’ object to Workflow Attachments

Double Click on ‘Undefined Step’ and choose step type as ‘Container Operation’

 

Page 23: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 23/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

23

 

Append Uploaded document to Attachments table. This will cause the Document to appear within the Approval

Decision step.

 

Page 24: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 24/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

24

 

• Right click on the outcome branch ‘Doc Attached’ and select ‘Create’ – User DecisionStep.

 

Page 25: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 25/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

25

 

Set Work item text as ‘Review Mass Invoice Upload Batch’. Use standard agent determination

Rule (get superior) to route approval workflow to Manager of the User who uploads the Batch of 

Invoice. Set two outcomes of review process – Approve and Reject

 

Page 26: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 26/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

26

 

Create 2 new variables within Workflow Container – ‘Rejection reason’ and ‘Reviewer’

 

Click on User Decision –> Control tab -> Binding and retrieve the User name of the Reviewer

(Manager) and the Rejection Reason from Task container back to Workflow Container

Page 27: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 27/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

27

 

• Right click on the outcome branch ‘Approved’ and select ‘Create’ – Activity Step

 

Page 28: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 28/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

28

 

Choose Create task

 

Page 29: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 29/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

29

 

Page 30: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 30/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

30

 

 The ‘Uploaded Document’ object must be passed to the Task Container from Workflow Container.

 

Page 31: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 31/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

31

 

• Right click on the outcome branch ‘Rejected’ and select ‘Create’ – Send mail Step

 

Page 32: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 32/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

32

 

Insert variables from Workflow container to make the Email text more meaningful.

 

Page 33: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 33/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

33

 

Go to ‘Control’ tab -> Binding within Email step and pass Attachments from Workflow Container

to Email step – task container so these attachments can be viewed from the Email notification.

 

Page 34: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 34/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

34

 

Working DEMO

• User executes custom demo program Z_MASS_INV_UPLOAD, uploads a CSV filecontaining invoice records and hits ‘Submit for Approval’

 

• The Workflow gets triggered and Approval item is routed to the Manager of the User who uploadedthe document.

 

Page 35: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 35/36

Custom Approval Workflow for Mass Invoices

Generated by Jive on 2015-11-26+01:00

35

 

• The Manager can view the following Decision step by executing this Work item. The uploaded file is

available to review as an attachment.

 

• If the Manager chooses to Reject, a pop up screen prompts for a Rejection reason.

 

Page 36: Custom Approval Workflow for Mass Invoices

7/24/2019 Custom Approval Workflow for Mass Invoices

http://slidepdf.com/reader/full/custom-approval-workflow-for-mass-invoices 36/36

Custom Approval Workflow for Mass Invoices

 

• Following Email is sent back to the User who submitted the Batch of Mass invoices for Approval. Theoriginal Uploaded file and the Rejection reason are both available as Email Attachments.