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:
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)
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.
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,
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.
This action raises ‘MassApprovalRequested’ event of Business object ‘ZMASSINV’ (created in next step)
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.
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
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.
Create Custom Event
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.
Create Custom Method
Place cursor on ‘Method and click ‘Create’. On the subsequent popup screen – provide method name ‘PostMassUpldInv’. This is a background method.
Create the same import parameter ‘UploadedDoc’ for this method
Place cursor on Method and Click on Program
Sample method code
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
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
Set both these variables as ‘Import’ parameters for the Workflow container.
This will cause a workflow instance to be triggered every time a Batch of invoices is Uploaded.
Double Click on ‘Undefined Step’ and choose step type as ‘Container Operation’
Append Uploaded document to Attachments table. This will cause the Document to appear within the Approval Decision step.
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
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
Choose Create task
The ‘Uploaded Document’ object must be passed to the Task Container from Workflow Container.
Insert variables from Workflow container to make the Email text more meaningful.
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.
Working DEMO
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |