Logo

    Home

    Documentation

    Use Cases

    Training

    Applications

    Release Notes

    ProCode backend logic- ABL

    ProCode backend logic- ABL

    1 Context:

    🧠
    In this example, we will implement an ABL Business Task, which will provide information regarding a specific customer. (ex. number of orders, number of shipped orders and the balance)

    2 Step by step guide:

    1. Create a BusinessTask class in src/backend/Training/, with the name CustomerTask.cls
    2. Generate the business task definition using the b1-logicClass snippet:
    3. Create a BusinessTask Method Parameter class src/backend/Training/GetCustomerDataParameter.cls
    4. Generate its definition using the b1-logicParameter snippet
    5. BLOCK-LEVEL ON ERROR UNDO, THROW.
      
      CLASS Training.GetCustomerDataParameter
        INHERITS Consultingwerk.JsonSerializable:
      
        /* Input properties */
        { Akioma/Swat/JsonSerializableProperty.i InputProperty LOGICAL }.
      
        /* Output properties */
        { Akioma/Swat/JsonSerializableProperty.i OutputProperty LOGICAL }.
        { Akioma/Swat/JsonSerializableProperty.i Message CHARACTER }. 
      END CLASS.
    6. Adjust the properties of the class to:
    7. Add references to the parameter in the business task class, by replacing myParameterObject with Training.GetCustomerDataParameter
    8. Change the method name from myMethod to GetCustomerData:
    9. Add the logic to fetch the information and return it:
    10. After trimming the PASOE, the Business Task can be invoked using the following call:
    11. b1.v1.App.invokeServerTask({
      	name: "Training.CustomerTask",
        methodName: "GetCustomerData",
        paramObj: { plcParameter: { CustomerNumber: 82 } }
      })

    Full Code Example:

    3 Explanation:

    ☝
    In contrast to the server event handler, the business task methods act as endpoints which allow custom complex logic to be handled, independent of any data source.
    Logo
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Training.CustomerTask
      IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
    
      METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
        DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
    
        oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
          "myMethod", GET-CLASS(myParameterObject)).
    
        RETURN oCatalog.
      END METHOD.
    
      METHOD PUBLIC VOID myMethod(poParameter AS myParameterObject):
        // enter your code here
        
      END METHOD.
    END CLASS.
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Training.GetCustomerDataParameter
      INHERITS Consultingwerk.JsonSerializable:
    
      /* Input properties */
      { Akioma/Swat/JsonSerializableProperty.i CustomerNumber INTEGER }.
    
      /* Output properties */
      { Akioma/Swat/JsonSerializableProperty.i TotalOrders INTEGER }.
      { Akioma/Swat/JsonSerializableProperty.i ShippedOrders INTEGER }.
      { Akioma/Swat/JsonSerializableProperty.i Balance INTEGER }.
    END CLASS.
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Training.CustomerTask
      IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
    
      METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
        DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
    
        oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
          "myMethod", GET-CLASS(Training.GetCustomerDataParameter)).
    
        RETURN oCatalog.
      END METHOD.
    
      METHOD PUBLIC VOID myMethod(poParameter AS Training.GetCustomerDataParameter):
        // enter your code here
        
      END METHOD.
    END CLASS.
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Training.CustomerTask
      IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
    
      METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
        DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
    
        oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
          "GetCustomerData", GET-CLASS(Training.GetCustomerDataParameter)).
    
        RETURN oCatalog.
      END METHOD.
    
      METHOD PUBLIC VOID GetCustomerData(poParameter AS Training.GetCustomerDataParameter):
        // enter your code here
        
      END METHOD.
    END CLASS.
    METHOD PUBLIC VOID GetCustomerData(poParameter AS Training.GetCustomerDataParameter):
      DEF VAR iCount AS INT NO-UNDO.    
      DEF VAR iNumShipped AS INT NO-UNDO.
    
      DEFINE BUFFER bCustomer FOR sportsdb.customer.
      DEFINE BUFFER bOrder FOR sportsdb.order.
    
      FIND bCustomer WHERE bCustomer.CustNum EQ poParameter:customerNumber.
    
      ASSIGN iCount = 0 iNumShipped = 0.
      // for each fetched Customer, go through all contacts in the DB     
      FOR EACH bOrder WHERE bOrder.custNum = poParameter:CustomerNumber NO-LOCK:
        iCount = iCount + 1.
        IF bOrder.orderStatus = "Shipped" THEN ASSIGN iNumShipped = iNumShipped + 1.
      END.
      poParameter:TotalOrders = iCount.
      poParameter:ShippedOrders = iNumShipped.
      poParameter:Balance = bCustomer.Balance.
    END METHOD.
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Training.CustomerTask
      IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
    
      METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
        DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
    
        oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
          "GetCustomerData", GET-CLASS(Training.GetCustomerDataParameter)).
    
        RETURN oCatalog.
      END METHOD.
    
      METHOD PUBLIC VOID GetCustomerData(poParameter AS Training.GetCustomerDataParameter):
        DEF VAR iCount AS INT NO-UNDO.    
        DEF VAR iNumShipped AS INT NO-UNDO.
    
        DEFINE BUFFER bCustomer FOR sportsdb.customer.
        DEFINE BUFFER bOrder FOR sportsdb.order.
    
        FIND bCustomer WHERE bCustomer.CustNum EQ poParameter:customerNumber.
    
        ASSIGN iCount = 0 iNumShipped = 0.
        // for each fetched Customer, go through all contacts in the DB     
        FOR EACH bOrder WHERE bOrder.custNum = poParameter:CustomerNumber NO-LOCK:
          iCount = iCount + 1.
          IF bOrder.orderStatus = "Shipped" THEN ASSIGN iNumShipped = iNumShipped + 1.
        END.
        poParameter:TotalOrders = iCount.
        poParameter:ShippedOrders = iNumShipped.
        poParameter:Balance = bCustomer.Balance.
      END METHOD.
    END CLASS.