You are on page 1of 5

SAP CRM: Webclient UI - Framework: BPath.

Lesson 03: Functions and Assignments

Posted by Juergen Gatter Apr 26, 2011


<< 02: Interpreter, integration, structures and filtering 04: Enhanceable structures, aggregations,
derefencation and transposition. And object
retrieval.>>

This lesson got somehow syntactically corrupted. I tried to fix all issues, but in case you identified any
remaining misleading character do not hesitate to give a small comment below. Thanks, Juergen

Hello everybody,

I hope everybody had a fabolous Easter time and we can concentrate with fresh energy on our path to BPath
wisdom.

Within the second lesson we introduced filters and structures, now we put the spotlight to two different topics:

BPath also includes the concept of functions. Functions are provided by the system (they are hardcoded
and it's not possible to dynamically add functions). A function can have 0 to n parameters. The concept
supports optional parameters also. Some functions (e.g. concatenate which will be explained later) can have
an arbritrary number of parameters. The types of the parameters are checked during execution.

Let us begin with some function examples:

The parameterless function Index() returns the index of the most inner object in the surrounding collection.
Size() returns the size of the surrounding collection.

SearchResFlightRel/FlightBookRel[INDEX()<=(SIZE()%2)]/*$

Code Example 12, INDEX() & SIZE()

Apparently the code examples returns the first half (rounded up) of the bookings of every flight. Note that % is
used for division, as I did not want to overload the / symbol.

Today() is also a function without parameters, returning the actual date. The first function with parameters is
NOT(x). The usage with a boolean parameter should be straight forward. NOT is also defined for parameters of
different type, the function returns true, exactly if the parameter is the NULL value of the respective type ( false,
"", 0, #19000101# ). Note that date literals are encapsulated by #-symbols.

Generated by Jive on 2016-07-14Z


1
SAP CRM: Webclient UI - Framework: BPath. Lesson 03: Functions and Assignments

SearchResFlightRel/FlightBookRel[Not(@ORDER_DATE>(Today()-400))]/*$
Code Example 13, Today() & Not()

The example returns all Bookings which are not done less then 400 days ago.

You like the questionmark operator within C+ ? Well, I do :-). So the next function to be discussed is iff(bool,
var1, var2). var1 and var2 can be of any type, they even do not have to have the same type.

SearchResFlightRel/FlightBookRel[@LUGGWEIGHT<IFF(UPPER(@INVOICE)="X",22,20)]/*$
Code Example 14, IFF(), & UPPER()

The filtering is done against the weight of the luggage which has to be below 20 (kgs, in case nobody changed
the base) for non-invoicers, and 22 for flyers marked as "x" for INVOICE. To be on the save side, a upper case
transformation is done on the invoice field.

So, now we enter the world of assignments. Assignments are maybe the most important enhancement to the
XPath-like access as they allow iterative thinking in an otherwise recursive environment. And they are the base
of many of the features explained in the next lessons.

After any relation a "filter block" may appear, that was part of lesson 2. Now we introduce an assignment block
which may appear at the same place, before or after a filter block. An assignment block is encapsulated with {}
and it contains (an) assignment(s).

But maybe we begin with an example:

~CRMT_NAME_VALUE_PAIR/SearchResFlightRel{!NAME=@CITYFROM}/FlightBookRel{!
VALUE=@PASSNAME}/*$
Code Example 15,{!F=@V}, basic assignments

Well, the concept of assignments allows to calculate the content of fields on every level. The target has to be
prefixed with a "!" and corresponds to a field of the target structure (which has to be explicitely defined).
Note that the move-corresponding initiated by the * at the end of the source code is in fact useless, since no
fields are transported.
The right side of the assignment works with the same evaluation evaluation engine as used with filter, so it is
possible to state more complex assignments as the following:

~CRMT_NAME_VALUE_PAIR/SearchResFlightRel{!NAME=(@CITYFROM&"/")&@CITYTO;!
VALUE=TODAY()-@FLDATE}
Code Example 16,{!F1=(@C&"/")&@D; !F2=@E}, complex assignments separated by semicolon

Generated by Jive on 2016-07-14Z


2
SAP CRM: Webclient UI - Framework: BPath. Lesson 03: Functions and Assignments

As seen, two (or more) assginments are separatable using a semi colon. It is also possible to refer to the target
itself in the assignment:

~CRMT_NAME_VALUE_PAIR/SearchResFlightRel{!NAME="NO Boardings"; !VALUE:=""&((0+!VALUE)+1))}


Code Example 17,{!F:=!F+1}, expressions on targets; automatic conversions

The second assignment shows how an assignment can refer to its own target (or other fields of the target
structure). How this can be used intelligently we show later.
You might have noticed that this example uses a ':=' instead of '=' as in the examples before. Unfortunately
there are two types of assignments in BPath. Within one of the next lessons I will explain the rationale behind
together with some more possibilies. As for now just use ':=' (global assignment), in case you want to refer to
the result later. And '=' otherwise (local assignment).

Here it just does some kind of counting, !VALUE is increased by 1 with every entry. The statement here is a bit
more complex then required since !VALUE is declared as string, where an operation as +1 obviously makes no
sense. Typically all operations contain some automatic conversions, where possible. So if you add a string to a
number "(@N+@S)", the result will be a number where the string is interpreted as number. If you do it the other
way round "(@S+@N)", the number is converted to a string and concatenated to the string. This means that
"0+@S" and ""+@N are nothing else but simple conversions. Hmmm, well. I have to admit ((0+!VALUE)+1) can
be shortened to "(1+!VALUE)".

This example is a good entry point to the operation table, which was promised in our last lesson. Here it comes
- click to enlarge:

Generated by Jive on 2016-07-14Z


3
SAP CRM: Webclient UI - Framework: BPath. Lesson 03: Functions and Assignments

The meaning of the various colors, symbols and identifiers is as follows:

Generated by Jive on 2016-07-14Z


4
SAP CRM: Webclient UI - Framework: BPath. Lesson 03: Functions and Assignments

2288 Views

There are no comments on this post

Generated by Jive on 2016-07-14Z


5

You might also like