Understanding Type casting of classes in SAP Ariba

Objective

After completing this lesson, you will be able to perform typecasting to read field values across dependent classes

Type casting of classes in SAP Ariba

Casting is a method utilized in Java that uses an object of one type in place of another type, among the objects permitted by inheritance and implementations. The class and their respective hierarchy paths are shown in the table below:

ClassHierarchy Path
RequisitionBaseObjectClusterRootApprovableLineItemCollectionPunchOutLineItemCollectionProcureLineItemCollectionReceivableLineItemCollectionRequisitionShoppingCart
ReqLineItemBaseObjectLineItemPunchOutLineItemProcureLineItemReqLineItemShoppingCartLineItemLineItem
PurchaseOrderBaseObjectClusterRootApprovableLineItemCollectionPunchOutLineItemCollectionProcureLineItemCollectionReceivableLineItemCollectionPurchaseOrder

DirectOrder, PCardOrder, ERPOrder, CopyOrder

POLineItemBaseObjectLineItemPunchOutLineItemProcureLineItemPOLineItemCopyPOLineItem
Invoice/InvoiceReconciliationBaseObjectClusterRootApprovableLineItemCollectionPunchOutLineItemCollectionProcureLineItemCollectionStatementCoreApprovableStatement (Invoice, InvoiceReconciliation)
Contract/ContractRequestBaseObjectClusterRootApprovableLineItemCollectionPunchOutLineItemCollectionProcureLineItemCollectionReceivableLineItemCollectionContractCoreApprovable (Contract, ContractRequest)

Certain field paths can be used in customization without the use of casting, such as using the field path LineItemCollection.IsNonPO from a custom field created on the InvoiceLineItem class. There is a direct path for this in the system, so no special method such as casting needs to be used. However, if you wish to navigate between certain classes, casting needs to be used to facilitate the necessary field path. Casting follows the following basic format:

Code Snippet
12
(@(line-level class)field that links the accounting class and line-level class).desired field path on the line-level class

If you need to employ two instances of casting simultaneously, you can use the following format:

Code Snippet
1
(@(header-level class)(@(line-level class)field that links the accounting class and line-level class).field that links the line-level class and header-level class).desired field path on the header-level class

The below examples help explain this:

  1. Casting from the SplitAccounting class to the InvoiceLineItem class:

    Use case: The customer has implemented a custom validity condition on a certain accounting field but does not want to validate this field on tax line items. This can be achieved by adding the following OR statement within the validity statement. The casting allows the system to rule out the validation for tax line items.

    Code Snippet
    12
    thisField != null or ((@(ariba.invoicing.core.InvoiceLineItem)LineItem).LineType.UniqueName.contains('Tax'))
  2. Casting from the Accounting class to the Contract header (ContractCoreApprovable class, which encompasses both Contract and ContractRequest):

    Use case: The customer wants to require a certain accounting field only for non-release contracts. The casting allows the system to rule out the validation for release-order contracts.

    Code Snippet
    12
    (@(ariba.contract.core.ContractCoreApprovable (@(ariba.contract.core.ContractCoreApprovableLineItem)LineItem).LineItemCollection).ReleaseType == 0 ? thisField != null : true

You can apply a similar type of casting to read values across dependent classes based on customer business scenarios to be used on custom conditions as part of the deployment.

Log in to track your progress & complete quizzes