SAP ByD- Business Logic

SAP Business ByDesign

Business logic is the part of the program that encodes the real-world business rules that determine how data can be created, displayed, stored, and changed. It is contrasted with the remainder of the software that might be concerned with lower-level details of managing a database or displaying the user interface, system infrastructure, or generally connecting various parts of the program. -Encyclopedia.

184-business logic

The Methods and keywords listed below enable you to implement the business logic for your solution in script files, such as actions, validations and events.

List of Methods and Keywords

The methods and keywords are divided into the following sections.

[pullquote] The Code Completion of path elements, Use CTRL + J to display all options for the current context.[/pullquote]

  1. Contexts
    Contains information about the this keyword.

    • This
  2. Simple Statements
    Contains information about simple statements.

    • Import
    • Declarations
    • Assignment
  3. Complex Statements
    Contains information about control and loop statements.
    [pullquote] The method tooltip displays the documentation of a method and its parameter definitions. To display the method tooltip, Use CTRL + SHIFT + SPACEBAR [/pullquote]

    • If Control Statement
    • Switch Control Statement
    • Foreach Loop Statement
    • While Loop Statement
    • Continue Statement and Break Statement
  4. Expressions
    Contains information about all types of expressions.

    • Literals
    • Function Literals
    • Logical Expressions
    • Conditional Expressions
    • Arithmetic Expressions
    • Path Expressions
    • Name Qualification
    • Action Execution

    Single-line comment://
    Multi-line comment: /* */

  5. Association Handling
    Contains information about accessing, setting, and checking associations.

    • Association Access
    • Set Associations
    • Check Associations (IsSet)
    • Reset Associations
  6. Business Object Lifecyle
    Describes how the lifecycle of a business object instance can be controlled.

    • Lifecycle
    • Create Instance
    • Create with Reference Action
    • Query Execution
    • Retrieve Instance
    • Delete Instance
    • Check Node Existence(IsSet)
  7. Collection Handling
    Contains information about how to define and modify collections.
    [pullquote] The code formatter helps to maintain a clean and readable source code in script files. Use CTRL + K or CTRL + D for code formatter.[/pullquote]

    • Collection Definition
    • Add to Collection
    • Clear Collection
    • Sort Collection (OrderBy)
    • Filter Collection (Where)
    • Remove from Collection
    • Remove Duplicate Rows from Collection (DistinctBy)
    • Get First or Get Last Row of Collection
    • Count Rows of Collection
  8. Message Handling
    Contains information about how to create and raise messages in the implementation phase.

    • Raise Message
  9. Service Integration Methods
    Contains information about indicators and return values used for condition evaluation in service integrations scenarios.
    [pullquote] Complex statements usually contain a code body which is opened and closed by braces { }[/pullquote]

    • Script File Parameter
    • Return Values
    • Process Context

Here we are going to see about some keywords description. In future article, we will see the remaining keywords.

THIS keyword points to the current instance of a business object node.

Syntax:   this.<Expression>;
Example: var name = this.ID;

The import keyword imports business objects or reuse libraries from namespaces that are available in the
studio in the Repository View. Imports have to be defined at the very top of a script file.

Syntax:  import <namespace component>[.<namespace component>]*;
Example: import ABSL;

If Control Statement
The if….else statement executes some code, if a condition is true and another code, if that condition is false.

if (<logical expression>) {<statement list>}
[ else if (<logical expression >) {<statement list>} ]*
[ else {<statement list>} ]?

if (a >= 0 && b < 1) 
   test = this.Actual.content * 0.2; 
else if (a >= 1) 
   test = this.Actual.content * 0.55;
      test = 0; 

An Assignment assigns the value of the expression on the right to the expression on the left.

Syntax:  <a> = <b>;
Example: ID = this.Name;

Foreach Loop Statement
The foreach loop statement allows you to iterate over collections of any type. Variables that are used in a foreach statement are called loop variables.

foreach (var? <identifier> in <path expression>) { <statement list> }

foreach (node in queryVal) {
 count = count + 1;

Arithmetic Expressions
The Arithmetic expressions support the common mathematical operators for addition, subtraction, multiplication, division, and modulo calculations.

literal | <varName> | <path expression>
[ + | — | * | / | % ] <arithmetic expression>;

var val = 10 + 20;
Result val = 30;

Logical Expressions
The logical operators AND (&&) and OR (||) always evaluate the overall expression to a Boolean value.

[!]? <conditional expression> [ && | || [!]? <conditional expression> ]*
if(test > 0 && test2 <10) {....}

Raise Message
You can use the raise keyword to raise messages that have been declared in the business object.

The Create method has one mandatory parameter: The Severity.

You have to supply the severity as a string:

  1. E” for errors
  2. W” for warnings
  3. S” for success messages
raise <message name>.Create(<severity> [, <message text variable>]*);

raise GenInfo.Create("E", "Enter the ID");

In this article, we saw about business logic and few of the keyword description. If you like to add some points with this article, kindly leave your points in comment box. Don’t forget to subscribe it.