Your Order to Cash - Billing & Invoicing Data Template
Your Order to Cash - Billing & Invoicing Data Template
- Recommended attributes to collect
- Key activities to track
- Extraction guidance for SAP S/4HANA
Order to Cash - Billing & Invoicing Attributes
| Name | Description | ||
|---|---|---|---|
| Invoice Number InvoiceNumber | The unique identifier for a billing document, serving as the primary case identifier for the invoicing process. | ||
| Description The Invoice Number, known as the Billing Document Number in SAP, uniquely identifies each billing transaction. It acts as the central key that links all related activities, from invoice creation and posting to payment receipt and reconciliation. In process mining, this attribute is essential for case correlation. All events sharing the same Invoice Number are grouped into a single process instance, allowing for a complete, end-to-end analysis of the billing lifecycle for each individual invoice. This enables tracking of cycle times, identifying deviations, and analyzing the journey of each invoice. Why it matters It is the fundamental identifier that connects all related billing activities into a single case, making end-to-end process analysis possible. Where to get SAP Table: VBRK, Field: VBELN Examples 900012349000567890009012 | |||
| Activity Name ActivityName | The name of the business activity or event that occurred within the billing process, such as 'Invoice Generated' or 'Payment Received'. | ||
| Description The Activity Name describes a specific step or milestone in the billing lifecycle. These activities are derived from various data points in SAP, such as transaction codes, document status changes, or specific log entries, to create a sequential process flow. Analyzing the sequence and frequency of these activities is the core of process mining. It helps visualize the process map, discover common and rare process variants, identify bottlenecks between steps, and measure the frequency of non-value-added activities like rework or cancellations. Why it matters This attribute defines the steps in the process, enabling the visualization of process maps and the analysis of process flow, variations, and bottlenecks. Where to get Derived from various sources including transaction codes (SY-TCODE), change document statuses (tables CDHDR/CDPOS), or business workflow logs (e.g., SWW_WI2OBJ). Examples Invoice GeneratedInvoice Posted To AccountingCustomer Payment ReceivedInvoice Cancelled | |||
| Event Time EventTime | The precise timestamp indicating when an activity or event occurred. | ||
| Description Event Time provides the date and time for each activity, forming the chronological backbone of the process. This timestamp is crucial for calculating durations, cycle times, and waiting times between different steps in the billing process. In analysis, Event Time is used to order activities sequentially, calculate key performance indicators like Days Sales Outstanding and Invoice Generation Cycle Time, and identify time-based bottlenecks. It enables a dynamic view of the process, showing how performance changes over time and how long each stage of the billing cycle takes. Why it matters It provides the chronological sequence of events, which is essential for calculating all time-based metrics, such as cycle times and durations. Where to get Extracted from various date and time fields depending on the activity, such as creation date and time (VBRK-ERDAT, VBRK-ERZET), change timestamps (CDHDR-UDATE, CDHDR-UTIME), or posting date (BKPF-BUDAT). Examples 2023-04-15T10:30:00Z2023-04-20T14:00:00Z2023-05-10T09:15:00Z | |||
| Customer Name CustomerName | The name of the customer to whom the invoice was issued. | ||
| Description This attribute identifies the legal name of the customer being billed. It is sourced from the central customer master data in SAP. Analyzing the process by customer allows for the identification of patterns specific to certain accounts. For instance, it can reveal which customers consistently pay late, which ones raise the most disputes, or for whom the billing process is most inefficient. This enables targeted customer relationship management and tailored collection strategies. Why it matters It enables customer-centric analysis, helping to identify payment behaviors, dispute frequencies, and process inefficiencies for specific accounts. Where to get Retrieved from customer master data table KNA1 (Field: NAME1), linked via the Payer ID in the invoice header (VBRK-KUNRG). Examples Springfield Power PlantKwik-E-MartCyberdyne Systems | |||
| End Time EndTime | The precise timestamp indicating when an activity or event was completed. | ||
| Description The End Time marks the completion of an activity. In process mining, this is often inferred as the Start Time of the subsequent activity in the case, or it can be sourced directly if the system logs both start and end events. This attribute is essential for calculating the Processing Time of individual activities. By subtracting the Start Time from the End Time, one can measure the duration of each step, which is crucial for bottleneck analysis, such as identifying delays in the invoice approval stage. Why it matters It enables the calculation of the exact duration (processing time) of each activity, which is fundamental for bottleneck analysis. Where to get This is a derived attribute for process mining. It is typically calculated as the StartTime of the next event in the case sequence. In some scenarios, specific tables might log completion times. Examples 2023-04-15T11:00:00Z2023-04-20T14:05:00Z2023-05-10T09:45:00Z | |||
| Invoice Amount InvoiceAmount | The total net value of the invoice. | ||
| Description This attribute represents the total monetary value of the goods or services being billed, excluding taxes. It is a fundamental financial data point for each invoice case. Invoice Amount is used in a wide range of analyses. It allows for the segmentation of the process by value, for example, to see if high-value invoices are processed differently or experience more delays. It is also the basis for financial reporting and for calculating the total value of outstanding receivables. Why it matters It quantifies the financial value of each invoice, enabling value-based analysis, prioritization of collections, and financial impact assessment. Where to get SAP Table: VBRK, Field: NETWR Examples 1500.0025000.50125.75 | |||
| Invoice Date InvoiceDate | The official date on which the invoice was issued to the customer. | ||
| Description The Invoice Date, also known as the billing date in SAP, serves as the starting point for many financial calculations. It is the date from which payment terms, due dates, and the age of the receivable are determined. This date is a critical case-level attribute for financial analysis. It is the baseline for calculating the Days Sales Outstanding (DSO) KPI and for creating outstanding invoice aging reports, which are essential tools for managing cash flow and collections. Why it matters It is the primary date for financial calculations, acting as the starting point for DSO, payment due dates, and invoice aging analysis. Where to get SAP Table: VBRK, Field: FKDAT Examples 2023-03-202023-04-012023-05-18 | |||
| Payment Due Date PaymentDueDate | The date by which the customer is expected to pay the invoice. | ||
| Description The Payment Due Date is calculated based on the invoice date and the agreed-upon payment terms. It represents the deadline for receiving payment without the invoice becoming overdue. This attribute is essential for monitoring collections effectiveness and cash flow forecasting. It is used directly in calculating the On-Time Payment Rate KPI and for segmenting invoices in aging reports. Analyzing deviations between the due date and the actual payment date helps evaluate the effectiveness of different payment terms. Why it matters It sets the deadline for customer payment, making it crucial for calculating on-time payment rates and managing accounts receivable. Where to get This date is not directly stored but is calculated based on the Invoice Date (VBRK-FKDAT) and the Payment Terms key (VBRK-ZTERM) using SAP's standard date determination functions. Examples 2023-04-192023-05-012023-06-17 | |||
| Region Region | The geographical region of the customer. | ||
| Description The Region attribute indicates the geographical area, such as a state or province, associated with the customer's address. This data is typically part of the customer master record. This attribute is key for the Regional Billing Performance dashboard. It allows for benchmarking key metrics like cycle times, error rates, and DSO across different regions. This comparison can highlight regional differences in process execution, compliance, or efficiency, paving the way for targeted improvements and standardization of best practices. Why it matters It enables comparison of billing performance across different geographical areas, helping to identify regional disparities and standardize processes. Where to get Retrieved from customer master data table KNA1 (Field: REGIO), linked via the Payer ID in the invoice header (VBRK-KUNRG). Examples CANYTXBA | |||
| User Name UserName | The user ID of the employee who executed the activity. | ||
| Description This attribute captures the SAP user ID responsible for a particular event, such as creating an invoice, posting a document, or clearing a payment. It provides a link between process steps and the individuals or teams performing them. Analyzing by User Name helps identify high-performing individuals, training needs, or workload distribution imbalances. It is also crucial for compliance analysis, showing who performed critical activities, and for understanding variations in how different users execute the same process. Why it matters It links process activities to specific users, enabling analysis of workload, performance, and compliance at the individual or team level. Where to get For creation events, this is in VBRK-ERNAM. For subsequent changes, it's found in change history tables like CDHDR-USERNAME or in workflow logs. Examples CBURNSHSIMPSONLLEONARD | |||
| Billing Document Type BillingDocumentType | A code that classifies the billing document, such as an invoice, credit memo, or cancellation. | ||
| Description The Billing Document Type is a key field that categorizes transactions within the billing process. It controls how the document is processed, including its number range and accounting posting rules. This attribute allows for filtering the process to analyze specific types of transactions. For example, one could create a separate process view just for credit memos to understand the reasons and process flow for financial corrections, or analyze standard invoices separately from cancellations to get a clearer picture of the primary billing process. Why it matters It classifies transactions, enabling focused analysis on specific document flows like standard invoices, credit memos, or cancellations. Where to get SAP Table: VBRK, Field: FKART Examples F2G2S1L2 | |||
| Company Code CompanyCode | The organizational unit for which the financial transaction is recorded. | ||
| Description The Company Code is a fundamental organizational entity in SAP Financials, representing a legally independent company for which financial statements are created. Each billing document is assigned to a specific company code. Analyzing by Company Code is essential in multi-company organizations to compare process performance, financial metrics like DSO, and compliance across different legal entities. It provides a high-level organizational filter for all process dashboards. Why it matters It allows for process analysis to be segmented by legal entity, enabling performance comparison and financial consolidation across the organization. Where to get SAP Table: VBRK, Field: BUKRS Examples 10002000US01 | |||
| Credit Memo Reason CreditMemoReason | The reason code indicating why a credit memo was issued. | ||
| Description When an invoice is incorrect and needs to be credited, a reason is typically assigned to the credit memo document. This provides a structured way to categorize the sources of billing errors. This attribute directly supports the Billing Error Rate KPI. By aggregating and analyzing the reasons for credit memos, a company can identify the most common types of errors, such as pricing mistakes or product returns. This analysis drives process improvements aimed at reducing the need for financial corrections and rework. Why it matters It categorizes the reasons for issuing credit, which helps pinpoint the most frequent sources of billing errors and drives quality improvements. Where to get SAP Table: VBRK, Field: AUGRU (Order Reason). This field is used on credit/debit memo requests that are then billed. Examples 001 - Price Difference002 - Poor Quality005 - Customer Return | |||
| Currency Currency | The currency code for the invoice amount. | ||
| Description This attribute specifies the currency in which the invoice amounts are denominated, such as USD, EUR, or JPY. It provides the necessary context for all monetary values. In a global organization, currency is essential for correct financial analysis and reporting. It allows for proper aggregation of financial data by converting all amounts to a common reporting currency and enables comparison of billing performance across regions with different local currencies. Why it matters It provides essential context for all monetary values, ensuring accurate financial analysis and reporting, especially in multi-national operations. Where to get SAP Table: VBRK, Field: WAERK Examples USDEURGBP | |||
| Dispute Reason CustomerDisputeReason | The reason provided by a customer for disputing an invoice. | ||
| Description When a customer contests an invoice, the reason for the dispute is often recorded. This could be due to pricing errors, incorrect quantities, or damaged goods. This information may be stored in the SAP Dispute Management module or as text notes. Analyzing dispute reasons is fundamental to the Billing Error Rate KPI and the associated error analysis. It helps identify the root causes of billing inaccuracies, allowing the business to address systemic issues in upstream processes, improve invoice quality, and enhance customer satisfaction. Why it matters It explains why invoices are being disputed, providing direct insight into the root causes of billing errors and customer dissatisfaction. Where to get If SAP Dispute Management is used, this information can be found in tables like UDM_DISPUTE. Otherwise, it may be derived from reason codes on related documents or text fields. Examples Incorrect PriceQuantity MismatchDamaged Goods Received | |||
| Is Paid On Time IsPaidOnTime | A boolean flag indicating whether the invoice was paid on or before its due date. | ||
| Description This is a calculated attribute that compares the actual payment date with the scheduled payment due date. It resolves to 'true' if the payment was on time and 'false' if it was late. This flag simplifies the calculation and visualization of the On-Time Payment Rate KPI. It allows for easy filtering and segmentation to analyze the characteristics of invoices that are paid late versus those paid on time. This can help uncover patterns related to specific customers, regions, or payment terms that lead to late payments. Why it matters It simplifies performance measurement by clearly flagging each invoice as 'on-time' or 'late,' directly supporting the On-Time Payment Rate KPI. Where to get This is a calculated field. The logic compares the timestamp of the 'Customer Payment Received' activity against the value in the 'PaymentDueDate' attribute. Examples truefalse | |||
| Last Data Update LastDataUpdate | The timestamp indicating when the data for this event was last extracted or refreshed. | ||
| Description This attribute records the date and time of the last data pull from the source system. It is a metadata field that is critical for understanding the freshness of the data being analyzed. This information is used to validate the recency of the analysis and to manage data refresh schedules. It ensures that stakeholders are aware of the data's timeliness when making decisions based on the process mining dashboards and insights. Why it matters It indicates the freshness of the data, which is vital for trusting the analysis and understanding its relevance to the current state of operations. Where to get This timestamp is generated and stamped onto each record during the data extraction and loading (ETL) process. Examples 2023-06-01T02:00:00Z2023-06-02T02:00:00Z | |||
| Payment Status PaymentStatus | The current status of the invoice payment, such as Open, Paid, or Overdue. | ||
| Description Payment Status provides a snapshot of where an invoice is in the collections lifecycle. This is not a single field in SAP but is derived by checking the clearing status of the corresponding accounting document. This attribute is essential for the Outstanding Invoice Aging dashboard. It allows for the segmentation of all open invoices by their status and age, helping the collections team prioritize their efforts effectively. Tracking the transitions between statuses is also a way to monitor the collections process itself. Why it matters It provides a clear, at-a-glance view of an invoice's collections status, which is vital for managing receivables and prioritizing collection efforts. Where to get Derived by checking the clearing status of the accounting document (VBRK-BELNR) in financial tables like BSID (open items) and BSAD (cleared items). Examples OpenPaidOverduePartially Paid | |||
| Payment Terms PaymentTerms | The code defining the payment conditions, such as the period allowed for payment. | ||
| Description Payment Terms are predefined conditions agreed upon with a customer that dictate when an invoice payment is due. Examples include 'Net 30' (payment due in 30 days) or '2/10 Net 30' (a 2% discount if paid in 10 days, otherwise due in 30 days). Analyzing by payment terms helps assess their effectiveness. By correlating different payment terms with the actual time taken to receive payment, a business can determine which terms are most successful in encouraging prompt payment and optimize its terms to improve cash flow. Why it matters It defines the agreed payment schedule, allowing for analysis of which terms are most effective at ensuring timely payment from customers. Where to get SAP Table: VBRK, Field: ZTERM Examples Z030Z060ZB60 | |||
| Processing Time ProcessingTime | The duration of an activity, calculated from its start to its end time. | ||
| Description Processing Time measures the time spent actively working on a task, as opposed to waiting time between tasks. It is calculated as the difference between the End Time and Start Time of an activity. This calculated metric is a cornerstone of performance analysis. It is used in dashboards like the Invoice Approval Bottleneck Analysis to quantify how long specific steps take. High processing times for certain activities can indicate inefficiencies, complexity, or a need for automation. Why it matters It measures the active duration of process steps, helping to identify inefficient activities that are prime candidates for optimization or automation. Where to get Calculated metric, derived by subtracting the 'StartTime' from the 'EndTime' during the data transformation process. Examples PT30MPT5MPT1H15M | |||
| Sales Order Number SalesOrderNumber | The identifier of the original sales order that led to the invoice. | ||
| Description The Sales Order Number links the billing document back to the preceding sales activities. A single sales order can result in one or more invoices, and this link provides the complete document flow. This attribute is critical for a true end-to-end Order-to-Cash analysis. It allows the process view to be extended upstream, connecting billing issues with their potential root causes in the sales order creation or fulfillment phases. For instance, it helps calculate the overall Invoice Generation Cycle Time starting from when the order was fulfilled. Why it matters It links the invoice to the original sales order, enabling a broader, end-to-end view of the Order-to-Cash process beyond just billing. Where to get SAP Table: VBRP (Billing Document Item Data), Field: AUBEL Examples 100001231000045610000789 | |||
| Source System SourceSystem | Identifies the specific source system from which the data was extracted. | ||
| Description This attribute specifies the origin of the data, which is particularly useful in environments with multiple SAP instances or other integrated systems. It typically includes the system ID and client number. In analysis, it helps differentiate processes and performance across different systems or organizational entities. It ensures data lineage and provides context, especially when data from multiple sources is combined for a holistic process view. Why it matters It provides crucial context about the data's origin, ensuring clarity in multi-system environments and supporting data governance. Where to get This is typically a static value defined during data extraction, often combining the system ID (SY-SYSID) and client (SY-MANDT). Examples S4H_PROD_100S4H_QAS_200ECC_PROD_300 | |||
Order to Cash - Billing & Invoicing Activities
| Activity | Description | ||
|---|---|---|---|
| Cash Applied/Reconciled | Represents the moment the incoming customer payment is matched and used to clear the open invoice item from the accounts receivable subledger. This activity completes the transaction from a financial perspective. | ||
| Why it matters Measures the efficiency of the cash application process. Delays here can misrepresent the true state of customer accounts and create unnecessary work for collections teams. Where to get This event is captured by the clearing date (BSEG-AUGDT) on the original invoice's accounting document line item. This date is populated when a clearing document clears the item. Capture Captured from the clearing date (AUGDT) field in the BSEG/ACDOCA table for the invoice line item. Event type explicit | |||
| Customer Payment Received | This activity marks the posting of an incoming payment from a customer into the financial system. The payment may not yet be applied to a specific invoice at this stage, but the funds have been recorded. | ||
| Why it matters A crucial milestone for calculating Days Sales Outstanding (DSO). It signifies that cash has been received, even if reconciliation is still pending. Where to get Captured from the posting date (BKPF-BUDAT) of the customer payment document (typically document type 'DZ' in table BKPF). Capture Event is based on the creation of the payment document in BKPF/BSEG. Event type explicit | |||
| Invoice Closed | This activity signifies the final state of a successfully paid invoice. It is functionally the same as 'Cash Applied/Reconciled' and indicates that the process for this invoice is complete. | ||
| Why it matters Serves as the primary 'happy path' end event for the process. Measuring the total cycle time to this point provides a complete view of the end-to-end billing and invoicing lifecycle. Where to get Inferred from the status of the customer line item in the accounting document. An item is closed or 'cleared' when the clearing date (BSEG-AUGDT) and clearing document (BSEG-AUGBL) fields are populated. Capture Inferred from the population of the clearing date (AUGDT) in the BSEG/ACDOCA table for the invoice line item. Event type inferred | |||
| Invoice Generated | This activity marks the creation of the billing document in the system. It is an explicit event captured when a user executes a transaction like VF01 or when a background job creates the invoice, resulting in a new entry in the billing document header table. | ||
| Why it matters This is the primary start event for the billing process. Analyzing the time from order fulfillment to this activity is crucial for measuring Invoice Generation Cycle Time and identifying initial process delays. Where to get Recorded in the SAP S/4HANA VBRK table (Billing Document: Header Data) upon creation. The creation date (VBRK-ERDAT) and time (VBRK-ERZET) serve as the timestamp. Capture Event is captured from the creation timestamp of the billing document record in table VBRK. Event type explicit | |||
| Invoice Posted To Accounting | Represents the successful posting of the billing document to the financial accounting module. This is a critical milestone where the invoice becomes an official accounts receivable item, creating entries in the general ledger. | ||
| Why it matters This activity confirms the invoice is a legal financial document. The time between generation and posting is a key performance indicator, highlighting internal processing efficiency. Where to get This event is captured when the corresponding accounting document is created. The billing document (VBRK-VBELN) is linked to the accounting document (BKPF-BELNR) via VBRK-BELNR, and the posting date is BKPF-BUDAT. Capture Captured from the posting date (BUDAT) of the accounting document in table BKPF linked to the billing document. Event type explicit | |||
| Billing Rework Identified | A calculated event that identifies a rework loop where an invoice was cancelled and then a new one was generated for the same sales order. It is not a single transaction but a pattern of events. | ||
| Why it matters Directly supports the Billing Rework Rate KPI by quantifying instances of correction. This helps pinpoint inefficiencies and measure the cost of poor quality in the billing process. Where to get This pattern is calculated by identifying an 'Invoice Cancelled' event followed by a new 'Invoice Generated' event that both trace back to the same source document, such as a sales order number. Capture Derived by detecting a sequence of 'Invoice Cancelled' and 'Invoice Generated' for the same sales order reference. Event type calculated | |||
| Credit Memo Created | This activity represents the creation of a credit memo, which is issued to a customer to correct an overcharge or provide a credit for returned goods. It is often linked to an original invoice. | ||
| Why it matters Highlights issues that result in financial adjustments after billing. Analyzing credit memos can uncover pricing errors, product issues, or other root causes of revenue leakage. Where to get Explicitly created as a new billing document (in VBRK) with a specific billing type for credit memos (e.g., 'G2'). It often references the original sales order or invoice. Capture Captured from the creation of a billing document in VBRK with a credit memo billing type. Event type explicit | |||
| Customer Dispute Opened | This activity occurs when a customer raises a dispute against an invoice, which is then formally logged in the system. This requires the use of the SAP Dispute Management module. | ||
| Why it matters Highlights issues with billing accuracy, product quality, or service delivery that lead to payment delays. Analyzing dispute reasons can help address root causes and improve customer satisfaction. Where to get Logged upon the creation of a dispute case in the Dispute Management tables (e.g., UDM_CASE), which is linked to the accounting document line item. Capture Captured from the creation timestamp of the dispute case record linked to the invoice. Event type explicit | |||
| Invoice Cancelled | Occurs when a previously created invoice is cancelled, which typically involves creating a corresponding cancellation document. This effectively reverses the original invoice and its accounting impact. | ||
| Why it matters Indicates rework, corrections, or billing errors. A high frequency of cancellations points to significant upstream problems in sales order entry or billing configuration. Where to get Captured when a cancellation billing document is created (e.g., document type 'S1'). This new document in VBRK will reference the original invoice number in the VBRK-SFAKN field. Capture Event is captured from the creation date of the cancellation document in VBRK that references the original invoice. Event type explicit | |||
| Invoice Posting Blocked | This event occurs if an invoice is created but automatically blocked from being posted to financial accounting due to various reasons, such as credit checks or data inconsistencies. This status is inferred from the posting status field on the billing document. | ||
| Why it matters Identifies bottlenecks where invoices are created but not immediately released to finance, delaying the entire cash collection cycle. It is a key indicator of data quality issues or credit management problems. Where to get Inferred from the posting status field in the billing document header table (VBRK-RFBSK). A status like 'A' (Billing document blocked for forwarding to FI) indicates a block. Capture Inferred by checking the value of the posting status field (VBRK-RFBSK) immediately after the invoice is generated. Event type inferred | |||
| Invoice Sent To Customer | This activity marks when the invoice was transmitted to the customer, for example, via print, email, or EDI. The capture mechanism depends on the output management configuration in SAP. | ||
| Why it matters The official start of the payment clock from the customer's perspective. Delays in sending the invoice directly impact Days Sales Outstanding (DSO) and cash flow. Where to get Can be explicitly logged in the output control tables (like NAST for older methods or its S/4HANA equivalent). If not explicitly logged, it is often inferred to occur at the same time as 'Invoice Posted To Accounting'. Capture Check processing logs in output management tables for a timestamp associated with the invoice output type. Event type explicit | |||
| Payment Due Date Reached | A calculated event representing the date on which payment for the invoice is officially due according to the agreed payment terms. It is not a transactional event but is derived from invoice data. | ||
| Why it matters This provides a critical baseline for measuring on-time payment performance and analyzing customer payment behavior. It helps distinguish between timely and overdue payments. Where to get Calculated based on the baseline date for payment (BSEG-ZFBDT) and the payment terms stored in the customer line item of the accounting document. Capture Derived by adding the payment term days to the baseline payment date found in the accounting document line item (BSEG). Event type calculated | |||
| Payment Reminder Issued | Represents the sending of a payment reminder or dunning notice to a customer for an overdue invoice. This is an explicit event generated by the automated dunning procedure. | ||
| Why it matters Allows for the analysis of the dunning process effectiveness. It helps determine if reminders accelerate payments and which dunning levels are most impactful. Where to get Recorded in the dunning history tables (MAHNV, MHND) when the dunning run (Transaction F150) is executed for the invoice's open item. Capture Captured from the run date of the dunning notice recorded in the dunning history tables. Event type explicit | |||
Extraction Guides
Steps
- Prerequisites: Ensure you have a user account in SAP S/4HANA with the necessary authorizations to query Core Data Services (CDS) views. Specifically, you need read access to views like I_BillingDocument, I_JournalEntryItem, I_Customer, I_Outgmgmtdocumentoutputreq, I_DisputeCase, and I_DunningHistory.
- Access Data Extraction Tool: Log in to your SAP S/4HANA system. You can use various tools to execute SQL queries against CDS views, such as the SAP HANA Studio, DBeaver connected via the SAP HANA client, or the SAP Analysis for Microsoft Excel plugin. For this guide, we will assume a standard SQL client.
- Identify System Parameters: Before running the query, identify the specific Company Codes and the relevant date range for your analysis. It is recommended to start with a limited scope, for instance, the last 3 to 6 months of data, to ensure manageable query execution times.
- Prepare the SQL Query: Copy the complete SQL query provided in the 'query' section of this document into your chosen SQL client.
- Customize Placeholders: Modify the placeholder values in the query. Replace
'YYYY-MM-DD'with your desired start and end dates. Replace'XXXX'with your target Company Code(s). You may also need to adjust the placeholder for credit memo document types, for example,'G2', based on your system configuration. - Execute the Query: Run the modified SQL query against the SAP S/4HANA database. The execution time will vary depending on the data volume within your selected date range.
- Review the Results: Once the query finishes, review the output. The result set should be a flat table where each row represents a single activity in the billing process. This is your event log.
- Data Transformation (if needed): The query is designed to produce a clean event log format. However, check the timestamp format to ensure it is compatible with your process mining tool. The query uses
ABAP_SYSTEM_UTCL_TO_TIMESTAMPto convert to a standard UTC timestamp, which should be widely compatible. - Export the Event Log: Export the complete result set from your SQL client into a CSV file. Ensure the file is UTF-8 encoded to prevent character issues.
- Upload to ProcessMind: Upload the generated CSV file to the ProcessMind platform, mapping the columns from the file, like InvoiceNumber, ActivityName, and EventTime, to the corresponding fields in the tool.
Configuration
- Date Range: Set the start and end dates in the
WHEREclause of the initial Common Table Expression (CTE). A range of 3 to 6 months is recommended for an initial analysis to balance data volume and performance. The filter is onBillingDocumentDate. - Company Code: Filter by one or more
CompanyCodevalues to restrict the extraction to relevant legal entities. This is a critical filter to manage data scope. - Document Types: The query includes logic to identify credit memos based on the
BillingDocumentType. You must configure the placeholder, for example,('G2', 'CR'), with the specific document types used for credit memos in your organization. - Prerequisites: Access to the underlying CDS views is mandatory. This requires specific roles and authorizations assigned by your SAP security team. Additionally, for activities like 'Customer Dispute Opened' or 'Payment Reminder Issued', the respective SAP modules, SAP Dispute Management and SAP Financials Dunning, must be actively used in your system.
- Performance: The query uses multiple joins and unions. For very large datasets, for instance, several years of data, consider executing it during off-peak hours or applying more restrictive filters to limit the initial data pull.
a Sample Query sql
WITH BaseInvoices AS (
SELECT
bd.BillingDocument AS InvoiceNumber,
bd.CreationDateTime,
bd.BillingDocumentDate AS InvoiceDate,
bd.NetDueDate AS PaymentDueDate,
bd.TotalNetAmount AS InvoiceAmount,
bd.CreatedByUser AS UserName,
bd.SDDocumentPostingStatus,
bd.AccountingDocument,
bd.IsCancelled,
bd.CancelledBillingDocument,
bd.PrecedingSDDocument,
bd.CompanyCode,
bd.BillingDocumentType,
cust.CustomerName,
reg.RegionName AS Region
FROM I_BillingDocument AS bd
LEFT JOIN I_Customer AS cust ON bd.SoldToParty = cust.Customer
LEFT JOIN I_Region AS reg ON cust.Region = reg.Region
WHERE
bd.BillingDocumentDate BETWEEN '2023-01-01' AND '2023-12-31' -- Placeholder: Set your date range
AND bd.CompanyCode = 'XXXX' -- Placeholder: Set your Company Code
AND bd.BillingCategory IN ('M', 'N', 'O', 'P', 'U', 'V', '5', '6') -- Filters for customer invoices/credit memos
)
-- 1. Invoice Generated
SELECT
bi.InvoiceNumber,
'Invoice Generated' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EventTime,
bi.UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
UNION ALL
-- 2. Invoice Posting Blocked
SELECT
bi.InvoiceNumber,
'Invoice Posting Blocked' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EventTime,
bi.UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
WHERE bi.SDDocumentPostingStatus = 'A' -- A = Billing document blocked for posting
UNION ALL
-- 3. Invoice Posted To Accounting
SELECT DISTINCT
bi.InvoiceNumber,
'Invoice Posted To Accounting' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(je.CreationDateTime) AS EventTime,
je.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(je.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_JournalEntry AS je ON bi.AccountingDocument = je.AccountingDocument
WHERE bi.AccountingDocument IS NOT NULL AND bi.AccountingDocument <> ''
UNION ALL
-- 4. Invoice Sent To Customer
SELECT DISTINCT
bi.InvoiceNumber,
'Invoice Sent To Customer' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(om.OutputRequestLastChgDateTime) AS EventTime,
om.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(om.OutputRequestLastChgDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_Outgmgmtdocumentoutputreq AS om ON bi.InvoiceNumber = om.SenderBusinessObject
WHERE om.OutputRequestStatus = 'S' -- Status 'S' for 'Successfully Processed'
UNION ALL
-- 5. Payment Due Date Reached
SELECT
bi.InvoiceNumber,
'Payment Due Date Reached' AS ActivityName,
CAST(bi.PaymentDueDate AS TIMESTAMP) AS EventTime,
'System' AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
CAST(bi.PaymentDueDate AS TIMESTAMP) AS EndTime
FROM BaseInvoices AS bi
WHERE bi.PaymentDueDate IS NOT NULL AND bi.PaymentDueDate <= CURRENT_DATE
UNION ALL
-- 6. Customer Dispute Opened
SELECT DISTINCT
bi.InvoiceNumber,
'Customer Dispute Opened' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(dc.CreationDateTime) AS EventTime,
dc.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(dc.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_DisputedItem AS di ON bi.InvoiceNumber = di.BillingDocument
JOIN I_DisputeCase AS dc ON di.DisputeCase = dc.DisputeCase
UNION ALL
-- 7. Payment Reminder Issued
SELECT DISTINCT
bi.InvoiceNumber,
'Payment Reminder Issued' AS ActivityName,
CAST(dh.DunningRunDate AS TIMESTAMP) AS EventTime,
dh.DunningRunUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
CAST(dh.DunningRunDate AS TIMESTAMP) AS EndTime
FROM BaseInvoices AS bi
JOIN I_JournalEntryItem AS jei ON bi.AccountingDocument = jei.AccountingDocument AND bi.CompanyCode = jei.CompanyCode
JOIN I_DunningHistory AS dh ON jei.CompanyCode = dh.CompanyCode AND jei.Customer = dh.Customer AND jei.AccountingDocument = dh.AccountingDocument
UNION ALL
-- 8, 9, 10. Payment Received, Cash Applied/Reconciled, Invoice Closed
SELECT
bi.InvoiceNumber,
ActivityName,
EventTime,
clearing_je.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
EventTime AS EndTime
FROM BaseInvoices AS bi
JOIN I_JournalEntryItem AS jei ON bi.AccountingDocument = jei.AccountingDocument AND bi.Customer IS NOT NULL
JOIN I_JournalEntry AS clearing_je ON jei.ClearingJournalEntry = clearing_je.AccountingDocument
CROSS JOIN (
VALUES ('Customer Payment Received'), ('Cash Applied/Reconciled'), ('Invoice Closed')
) AS Activities(ActivityName)
WHERE jei.ClearingDate IS NOT NULL AND jei.ClearingJournalEntry IS NOT NULL AND jei.ClearingJournalEntry <> ''
UNION ALL
-- 11. Invoice Cancelled
SELECT
bi.InvoiceNumber,
'Invoice Cancelled' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(cancellation_doc.CreationDateTime) AS EventTime,
cancellation_doc.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(cancellation_doc.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_BillingDocument AS cancellation_doc ON bi.CancelledBillingDocument = cancellation_doc.BillingDocument
WHERE bi.IsCancelled = 'X'
UNION ALL
-- 12. Credit Memo Created
SELECT
bi.InvoiceNumber,
'Credit Memo Created' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EventTime,
bi.UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
WHERE bi.BillingDocumentType IN ('G2') -- Placeholder: Adjust with your credit memo document types
UNION ALL
-- 13. Billing Rework Identified
WITH CancelledInvoices AS (
SELECT
bi.PrecedingSDDocument,
bi.CompanyCode,
cancellation_doc.CreationDateTime AS CancellationTime
FROM BaseInvoices bi
JOIN I_BillingDocument AS cancellation_doc ON bi.CancelledBillingDocument = cancellation_doc.BillingDocument
WHERE bi.IsCancelled = 'X' AND bi.PrecedingSDDocument IS NOT NULL AND bi.PrecedingSDDocument <> ''
)
SELECT
rework.InvoiceNumber,
'Billing Rework Identified' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(rework.CreationDateTime) AS EventTime,
rework.UserName,
rework.InvoiceDate,
rework.PaymentDueDate,
rework.InvoiceAmount,
rework.CustomerName,
rework.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(rework.CreationDateTime) AS EndTime
FROM BaseInvoices AS rework
JOIN CancelledInvoices AS cancelled ON rework.PrecedingSDDocument = cancelled.PrecedingSDDocument
AND rework.CompanyCode = cancelled.CompanyCode
WHERE rework.CreationDateTime > cancelled.CancellationTime AND rework.IsCancelled = ''
ORDER BY InvoiceNumber, EventTime; Steps
- Prerequisites: Ensure you have a user account in SAP S/4HANA with the necessary authorizations to query Core Data Services (CDS) views. Specifically, you need read access to views like I_BillingDocument, I_JournalEntryItem, I_Customer, I_Outgmgmtdocumentoutputreq, I_DisputeCase, and I_DunningHistory.
- Access Data Extraction Tool: Log in to your SAP S/4HANA system. You can use various tools to execute SQL queries against CDS views, such as the SAP HANA Studio, DBeaver connected via the SAP HANA client, or the SAP Analysis for Microsoft Excel plugin. For this guide, we will assume a standard SQL client.
- Identify System Parameters: Before running the query, identify the specific Company Codes and the relevant date range for your analysis. It is recommended to start with a limited scope, for instance, the last 3 to 6 months of data, to ensure manageable query execution times.
- Prepare the SQL Query: Copy the complete SQL query provided in the 'query' section of this document into your chosen SQL client.
- Customize Placeholders: Modify the placeholder values in the query. Replace
'YYYY-MM-DD'with your desired start and end dates. Replace'XXXX'with your target Company Code(s). You may also need to adjust the placeholder for credit memo document types, for example,'G2', based on your system configuration. - Execute the Query: Run the modified SQL query against the SAP S/4HANA database. The execution time will vary depending on the data volume within your selected date range.
- Review the Results: Once the query finishes, review the output. The result set should be a flat table where each row represents a single activity in the billing process. This is your event log.
- Data Transformation (if needed): The query is designed to produce a clean event log format. However, check the timestamp format to ensure it is compatible with your process mining tool. The query uses
ABAP_SYSTEM_UTCL_TO_TIMESTAMPto convert to a standard UTC timestamp, which should be widely compatible. - Export the Event Log: Export the complete result set from your SQL client into a CSV file. Ensure the file is UTF-8 encoded to prevent character issues.
- Upload to ProcessMind: Upload the generated CSV file to the ProcessMind platform, mapping the columns from the file, like InvoiceNumber, ActivityName, and EventTime, to the corresponding fields in the tool.
Configuration
- Date Range: Set the start and end dates in the
WHEREclause of the initial Common Table Expression (CTE). A range of 3 to 6 months is recommended for an initial analysis to balance data volume and performance. The filter is onBillingDocumentDate. - Company Code: Filter by one or more
CompanyCodevalues to restrict the extraction to relevant legal entities. This is a critical filter to manage data scope. - Document Types: The query includes logic to identify credit memos based on the
BillingDocumentType. You must configure the placeholder, for example,('G2', 'CR'), with the specific document types used for credit memos in your organization. - Prerequisites: Access to the underlying CDS views is mandatory. This requires specific roles and authorizations assigned by your SAP security team. Additionally, for activities like 'Customer Dispute Opened' or 'Payment Reminder Issued', the respective SAP modules, SAP Dispute Management and SAP Financials Dunning, must be actively used in your system.
- Performance: The query uses multiple joins and unions. For very large datasets, for instance, several years of data, consider executing it during off-peak hours or applying more restrictive filters to limit the initial data pull.
a Sample Query sql
WITH BaseInvoices AS (
SELECT
bd.BillingDocument AS InvoiceNumber,
bd.CreationDateTime,
bd.BillingDocumentDate AS InvoiceDate,
bd.NetDueDate AS PaymentDueDate,
bd.TotalNetAmount AS InvoiceAmount,
bd.CreatedByUser AS UserName,
bd.SDDocumentPostingStatus,
bd.AccountingDocument,
bd.IsCancelled,
bd.CancelledBillingDocument,
bd.PrecedingSDDocument,
bd.CompanyCode,
bd.BillingDocumentType,
cust.CustomerName,
reg.RegionName AS Region
FROM I_BillingDocument AS bd
LEFT JOIN I_Customer AS cust ON bd.SoldToParty = cust.Customer
LEFT JOIN I_Region AS reg ON cust.Region = reg.Region
WHERE
bd.BillingDocumentDate BETWEEN '2023-01-01' AND '2023-12-31' -- Placeholder: Set your date range
AND bd.CompanyCode = 'XXXX' -- Placeholder: Set your Company Code
AND bd.BillingCategory IN ('M', 'N', 'O', 'P', 'U', 'V', '5', '6') -- Filters for customer invoices/credit memos
)
-- 1. Invoice Generated
SELECT
bi.InvoiceNumber,
'Invoice Generated' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EventTime,
bi.UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
UNION ALL
-- 2. Invoice Posting Blocked
SELECT
bi.InvoiceNumber,
'Invoice Posting Blocked' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EventTime,
bi.UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
WHERE bi.SDDocumentPostingStatus = 'A' -- A = Billing document blocked for posting
UNION ALL
-- 3. Invoice Posted To Accounting
SELECT DISTINCT
bi.InvoiceNumber,
'Invoice Posted To Accounting' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(je.CreationDateTime) AS EventTime,
je.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(je.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_JournalEntry AS je ON bi.AccountingDocument = je.AccountingDocument
WHERE bi.AccountingDocument IS NOT NULL AND bi.AccountingDocument <> ''
UNION ALL
-- 4. Invoice Sent To Customer
SELECT DISTINCT
bi.InvoiceNumber,
'Invoice Sent To Customer' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(om.OutputRequestLastChgDateTime) AS EventTime,
om.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(om.OutputRequestLastChgDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_Outgmgmtdocumentoutputreq AS om ON bi.InvoiceNumber = om.SenderBusinessObject
WHERE om.OutputRequestStatus = 'S' -- Status 'S' for 'Successfully Processed'
UNION ALL
-- 5. Payment Due Date Reached
SELECT
bi.InvoiceNumber,
'Payment Due Date Reached' AS ActivityName,
CAST(bi.PaymentDueDate AS TIMESTAMP) AS EventTime,
'System' AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
CAST(bi.PaymentDueDate AS TIMESTAMP) AS EndTime
FROM BaseInvoices AS bi
WHERE bi.PaymentDueDate IS NOT NULL AND bi.PaymentDueDate <= CURRENT_DATE
UNION ALL
-- 6. Customer Dispute Opened
SELECT DISTINCT
bi.InvoiceNumber,
'Customer Dispute Opened' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(dc.CreationDateTime) AS EventTime,
dc.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(dc.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_DisputedItem AS di ON bi.InvoiceNumber = di.BillingDocument
JOIN I_DisputeCase AS dc ON di.DisputeCase = dc.DisputeCase
UNION ALL
-- 7. Payment Reminder Issued
SELECT DISTINCT
bi.InvoiceNumber,
'Payment Reminder Issued' AS ActivityName,
CAST(dh.DunningRunDate AS TIMESTAMP) AS EventTime,
dh.DunningRunUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
CAST(dh.DunningRunDate AS TIMESTAMP) AS EndTime
FROM BaseInvoices AS bi
JOIN I_JournalEntryItem AS jei ON bi.AccountingDocument = jei.AccountingDocument AND bi.CompanyCode = jei.CompanyCode
JOIN I_DunningHistory AS dh ON jei.CompanyCode = dh.CompanyCode AND jei.Customer = dh.Customer AND jei.AccountingDocument = dh.AccountingDocument
UNION ALL
-- 8, 9, 10. Payment Received, Cash Applied/Reconciled, Invoice Closed
SELECT
bi.InvoiceNumber,
ActivityName,
EventTime,
clearing_je.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
EventTime AS EndTime
FROM BaseInvoices AS bi
JOIN I_JournalEntryItem AS jei ON bi.AccountingDocument = jei.AccountingDocument AND bi.Customer IS NOT NULL
JOIN I_JournalEntry AS clearing_je ON jei.ClearingJournalEntry = clearing_je.AccountingDocument
CROSS JOIN (
VALUES ('Customer Payment Received'), ('Cash Applied/Reconciled'), ('Invoice Closed')
) AS Activities(ActivityName)
WHERE jei.ClearingDate IS NOT NULL AND jei.ClearingJournalEntry IS NOT NULL AND jei.ClearingJournalEntry <> ''
UNION ALL
-- 11. Invoice Cancelled
SELECT
bi.InvoiceNumber,
'Invoice Cancelled' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(cancellation_doc.CreationDateTime) AS EventTime,
cancellation_doc.CreatedByUser AS UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(cancellation_doc.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
JOIN I_BillingDocument AS cancellation_doc ON bi.CancelledBillingDocument = cancellation_doc.BillingDocument
WHERE bi.IsCancelled = 'X'
UNION ALL
-- 12. Credit Memo Created
SELECT
bi.InvoiceNumber,
'Credit Memo Created' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EventTime,
bi.UserName,
bi.InvoiceDate,
bi.PaymentDueDate,
bi.InvoiceAmount,
bi.CustomerName,
bi.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(bi.CreationDateTime) AS EndTime
FROM BaseInvoices AS bi
WHERE bi.BillingDocumentType IN ('G2') -- Placeholder: Adjust with your credit memo document types
UNION ALL
-- 13. Billing Rework Identified
WITH CancelledInvoices AS (
SELECT
bi.PrecedingSDDocument,
bi.CompanyCode,
cancellation_doc.CreationDateTime AS CancellationTime
FROM BaseInvoices bi
JOIN I_BillingDocument AS cancellation_doc ON bi.CancelledBillingDocument = cancellation_doc.BillingDocument
WHERE bi.IsCancelled = 'X' AND bi.PrecedingSDDocument IS NOT NULL AND bi.PrecedingSDDocument <> ''
)
SELECT
rework.InvoiceNumber,
'Billing Rework Identified' AS ActivityName,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(rework.CreationDateTime) AS EventTime,
rework.UserName,
rework.InvoiceDate,
rework.PaymentDueDate,
rework.InvoiceAmount,
rework.CustomerName,
rework.Region,
ABAP_SYSTEM_UTCL_TO_TIMESTAMP(rework.CreationDateTime) AS EndTime
FROM BaseInvoices AS rework
JOIN CancelledInvoices AS cancelled ON rework.PrecedingSDDocument = cancelled.PrecedingSDDocument
AND rework.CompanyCode = cancelled.CompanyCode
WHERE rework.CreationDateTime > cancelled.CancellationTime AND rework.IsCancelled = ''
ORDER BY InvoiceNumber, EventTime;