Automate invoice processing with the AWS SDK for SAP ABAP

Introduction: why are customers implementing Intelligent Document Processing?

Enterprises deal with large volumes of structured and unstructured data on a daily basis. Invoice processing, contract management, and financial reporting are just a few examples where businesses need to process a large number of documents efficiently. Manual processing of such documents can be tedious and error-prone. Hence, enterprises are looking for ways to automate their document processing workflow. Better document handling leads to more accurate collection, lowered capture costs, and the ability to retain and recall information electronically.

Many of our customers are running business-critical SAP workloads on AWS and are constantly looking at ways to build intelligent document processing workflows while reducing customization to their SAP applications. They are looking at simpler ways to integrate their SAP applications with AI/ML powered AWS services to modernize and reinvent their business workflows to drastically cut costs, increase agility, and improve productivity. While AWS services support integrations through open application programming interfaces (APIs),customers don’t want to be developing complex ABAP programs to consume these APIs. They are looking for simpler abstractions and access patterns for these APIs within their SAP modules.

Based on customer feedback, we recently announced the general availability of the AWS SDK for SAP ABAP, which allows customers to connect their SAP applications to 200+ AWS services with just a few lines of code. This removes the need for complex customizations, point-to-point integrations, and associated maintenance costs for customers.

In this blog, I will walk through how you can use the AWS SDK for SAP ABAP to combine SAP with AI/ML-powered AWS services like Amazon Textract, Amazon Translate, Amazon Comprehend, and Amazon SNS to automatically process and post invoices in SAP as they are received from your vendor. This solution supports formats including PDF, documents, and images.

Creating your Intelligent Document Processing workflow

Starting with the AWS SDK for SAP ABAP is easy. You can install the AWS SDK for SAP ABAP by downloading the SDK here and installing it in your SAP application stack using SAP transport management system. For additional details, please refer to the Getting Started with the AWS SDK for SAP ABAP Blog.

The AWS SDK for SAP ABAP abstracts the complexities of authentication, data formatting, performance, and encryption while providing simple-to-use functions for ABAP developers. The SDK API Reference Guide describes how each service can be accessed using the AWS SDK for SAP ABAP.


Before we dive into the implementation details, let’s first take a look at the prerequisites for this solution:

  1. An AWS account with appropriate IAM permissions to create and manage S3 buckets, SNS topics, and access the Amazon Textract, Amazon Translate, and Amazon Comprehend service.
  2. SAP ERP / S/4HANA system with SAP NetWeaver version 7.40 or higher.
  3. The AWS SDK for SAP ABAP is installed on the SAP ERP or S/4HANA system. For instructions on installing and configuring your SAP system with the AWS SDK for SAP ABAP, please refer to the guide here.
  4. Knowledge of SAP ABAP programming.

High-level invoice processing workflow

Many businesses receive a high volume of invoices from suppliers, which can be time consuming and error prone process to process manually. By using AWS SDK for SAP ABAP and Amazon Textract, businesses can seamlessly integrate the invoice processing workflow with their existing SAP ERP solutions, such as SAP S/4HANA or SAP ECC. This enables businesses to streamline their accounts payable/receivable processes and improve the overall efficiency of their finance operations.

To implement an invoice document processing workflow, we can leverage the following architecture.

Intelligent Document Processing with AWS SDK for SAP ABAP

  • Invoice documents that are received from suppliers in the form of PDFs are first uploaded to an Amazon S3 bucket using a custom ABAP application that leverages the AWS SDK for SAP ABAP to interact with AWS services natively. Then the custom ABAP application triggers the processing of the document.
  • The custom ABAP application uses the AWS SDK for SAP ABAP to call the Amazon Textract API and extracts the data from the document.
  • The extracted data is then sent to Amazon Translate to translate descriptions of the document into the desired target language.For language detection, Amazon Comprehend is used here to detect the source language before Amazon Translate translates it to the target language.
  • Using the extracted information, the custom ABAP application then performs invoice validation using the SAP ERP standard functions and posts the invoice documents in SAP.
  • If there are any errors found during the process, then the application would call the Amazon SNS API to trigger automated notification e-mails.
  • You can also optionally start an approval workflow using AWS Step functions to trigger review processes or orchestrations involving distributed applications.

Here are some code snippets to illustrate how to use the AWS SDK for SAP ABAP and Amazon Textract for intelligent document processing. To get the sample code of the entire solution, please refer to the git repo here.

First, lets’ see how to upload a file to S3 using the AWS SDK For SAP ABAP

*Create session object
Data(lo_session) = /aws1/cl_rt_session_aws=>create( Iv_profile_id = co_profile ).
*Create S3 client
Data(lo_s3) = /aws1/cl_s3_factory=>create( lo_session ).
*Perform action – upload to bucket
lo_s3->putobject( iv_bucket = p_bucket
                  iv_key    = p_key
                  iv_body   = lv_xstring ). 
CATCH /aws1/cx_s3_nosuchbucket.
* Handle exceptions

Next,let’s see how to call Amazon Textract API using the AWS SDK for SAP ABAP.Before we discuss how to use Amazon Textract in an Intelligent Document Processing workflow, it’s important to understand how the service processes documents.Textract uses advanced ML algorithms to detect and analyze text blocks,tables,and forms in a document.The service can identify text in various languages and even hand-written text.

*Create Textract client
  Data(lo_textract) = /aws1/cl_tex_factory=>create(lo_session ).
*S3 object 
  DATA(lo_s3object) = NEW /aws1/cl_texs3object( iv_bucket = p_bucket 
                                                iv_name   = p_key  ).                                                        
*Document location 
DATA(lo_documentlocation) = NEW /aws1/cl_texdocumentlocation( io_s3object = lo_s3object ).
Data(lv_jobid) = lo_textract->startdocumentanalysis(
         EXPORTING io_documentlocation  =  lo_documentlocation
                   it_featuretypes      =  lt_featuretypes ).
CATCH  /aws1/cx_rt_technical_generic.
* Handle exceptions

Textract processes a document in blocks, where each block represents a section of the document that contains text. For example, a block could represent a paragraph of text, a heading, or a table cell. Each block is analyzed for text, location, size, and other attributes. Textract also provides the confidence score for each block, indicating the likelihood that the block contains valid text.

Amazon Textract blocks

*Process Document blocks
Data(lt_blocks) = lo_textract->getdocumentanalysis( iv_jobid = pv_jobid )->get_blocks( ).

After extracting the data from the document, we can send it to Amazon Translate for translation using the following code:

*Create Translate client 
DATA(lo_xl8)     = /aws1/cl_xl8_factory=>create( lo_session ).
*Translate text
  CALL METHOD lo_xl8->translatetext
      iv_text               = pv_desc
      iv_sourcelanguagecode = 'auto'    " will use comprehend to do lang detection
      iv_targetlanguagecode = 'de'
      oo_output             = DATA(lo_output).

DATA(lv_trans_desc) = lo_output->get_translatedtext( ).

For notifying successful invoice postings or to notify exceptions during the process, you can publish to SNS.

* Create SNS client
DATA(lo_sns) = /aws1/cl_sns_factory=>create( lo_session ).
* Publish messaage
            iv_topicarn               =  lv_arn
            iv_message                = lv_msg
            iv_subject                 = lv_sub

Finally, we can use the standard SAP API like BAPI_ACC_DOCUMENT_POST to process the extracted information from the invoice document and post the vendor invoice transaction in SAP, as shown below. In the below example, we can see how the extracted invoice number maps back to the reference document number on the header section of the accounting document, and all the other details of the invoice map back to the relevant fields in the SAP vendor invoice transaction, including the translated texts.

Let’s take a look into some of the benefits of using AWS SDK for ABAP with Amazon Textract for Intelligent Document Processing:

  1. Integration: The AWS ABAP SDK provides seamless native integration with SAP systems and AWS services, allowing you to take advantage of purpose-built AWS services for your business transformation without having to make significant changes to your existing SAP landscape.
  2. Faster Processing: Amazon Textract can quickly and accurately process large volumes of documents, reducing manual effort and processing times. Large documents can be processed asynchronously for better scalability and performance.
  3. Increased Accuracy: Amazon Textract uses machine learning algorithms to extract data from documents, improving accuracy and reducing errors.
  4. Improved Efficiency: Automated document processing workflows free up resources and improve overall cost and operational efficiency
  5. Security: The AWS cloud provides a secure environment for storing and processing sensitive data, ensuring data privacy and compliance with industry regulations.

Overall, the use of the AWS ABAP SDK for business transformation in SAP can help you to improve efficiency, accuracy, and security while reducing costs.


The AWS SDK for SAP ABAP makes it easy for ABAP developers to extend and transform business processes by harnessing the power of AWS services natively using the SAP ABAP language. The SDK simplifies all of the architectural complexities in terms of connectivity, security, data formatting for interoperability, and the need for point-to-point integrations by eliminating the need to manually create complex integrations between SAP and AWS services. This capability paves the way for integrating SAP with more than 200+ AWS services. The AWS SDK for SAP ABAP fills a long-standing gap between the ABAP builder community and AWS Services.

To learn how install the SDK in your ABAP environment, visit the Getting Started Blog.