<< 07. Model Check, exceptions and attribute longtext | Lesson 09. Groupings >> |
Hello everybody,
the last lesson caused some discussions on various difficulties to formulate correct BPath statements as some pieces of information were simply not yet communicated fully in this Blog Series. So before describing new content I want to go back some steps and clarify some topics and provide some tables with information.
Keep in mind that the BPath Parser only deals with operations with 2 operands, so (1+1+1) will result in an error and should be rephrased to ((1+1)+1). This of course also applies to comparisons, so ((x=0)&(y=0)&(z=0)) cannot be parsed. Instead (((x=0)&(y=0))&(z=0)) should be used.
There was a request in respect to raw data types, this is not supported. Raw fields might be read, but the content can not be compared to literals or other values as now corresponding data type exists.
Short | Name | Null | Description |
---|---|---|---|
S | String | "" | Character strings, encapsulated with ". Every "-character in the string has to be escaped with "" (double double quotes). |
N | Numeric | 0 | numeric values without sign, e.g 3.141. Negative literals have to be written as 0-value |
D | Date | #19000101# | Date values in the following format #yyyymmdd#. |
B | Boolean | false | true/false value |
R | Data ref. | reference to data entity, typically returned by a sub function | |
O | Object ref. | reference to object | |
X | invalid | internally used for invalid objects, which are later handled by the GET() function |
The Null value is the only value of the specific type where the function NOT(...) returns true.
Meaning | String | Num | Date | Bool | |
---|---|---|---|---|---|
& | and, concat | S & S -> S (concat) | B & B -> B (and) | ||
| | or | B | B -> B (or) | |||
+ | add, add days, number to string string to number | S + S -> S (concat) S + N -> S *3 | N + N -> N (add) N + S -> N *4 | D + N -> D *1 | B + B -> B (or) |
- | minus, substr replace first, substract days, remove last chars | S - S -> S *6 S - N -> S *7 | N - N -> N (substr.) | D - N -> D *2 | B - B -> B *5 |
* | (string) multiply,if | S * N -> N *8 S * B -> S *9 | N * N -> N (mlt) N * B -> N *9 | D * B -> D *9 | B * B -> S (and / if) |
% | divide, replace all, remove first chars | S % S -> S *10 S % N -> S *11 | N % N -> N (Div) | B % B -> B *12 | |
Comp*13 | comparison | S X S -> B | N X N -> B | D X D -> B | B X B -> B |
NOT | not | NOT(S) -> B | NOT(N) -> B | NOT(D) -> B | NOT(B) -> B |
IFF | ? Operator | IFF(B,X,X)->X |
1. Adds number of days to a date
2. Subtracts number of days from a date
3. Converts number into string (as provided by ABAP) and concatenates it to the given string
4. Converts string into number (as provided by ABAP) and adds it to number.
5. Op1 = True or Op2 = False
6. Replace first occurrence of op2 in Op1 with empty string
7. Removes last n characters from string (if n <= strlen)
8. String multiplication (e.g. "la" * 3 = "lalala" ) [if n >= 0]
9. Logical if. If Boolean value is true original element is returned otherwise NULL element ("" / 0 / #19000101# / FALSE ).
10. Replace all occurrences of op2 in Op1 with empty string
11. Removes first n characters from string (if n <= strlen)
12. Op1 = True and Op2 = False
13. Supported are the standard comparisons =, <, >, <=, >=, <>. The types of the compared elements must be equal.
14. NOT: returns true if element is equal to NULL element
15. IFF: returns Parameter 2 if Parameter 1 is true otherwise Parameter 3. Parameter 1 must be of type Boolean, the other parameters are not checked (theoretically P2 and P3 must not be of the same type, but logically they should)
Additional remark:
As BPath has no concept of returnings errors some of the functions are defined in a way that the error case is caught and a Special value is returned. This is the case for the simple divide operation X % 0, which will always return 0 if the second Operand is 0. Attempts to convert a string, which does not contain a number to a number, will also result in a 0. Example would be the Expression: 1+"test"
With version 2.2 BPath was enhanced to Support full numeric values (instead of integer), internally they base on DECFLOAT34. Some remarks:
~*/SearchResFlightRel/FlightBookRel[@LUGGWEIGHT>23.5]{!A=@LUGGWEIGHT;!B=@LUGGWEIGHT*2}$
Code Example 35, [@LUGGWEIGTH>23.5], numeric calculations
In case you simply want to copy an attribute from the current structure you might use the syntax as specified in the example:
~*/SearchResFlightRel/FlightBookRel{@FORCURAM;@FORCURKEY;@@CUSTTYPE}$
Code Example 36,{@FORCURAM;@FORCURKEY;@@CUSTTYPE}, direct attribute retrieval
This should work for enhanceable structures as well as for non-enhanceable structures. For normal fields a target with the same name is used, for long text fields the suffix '_LONG' will be appended to the target name. The assignment block in the example above is simply a shortcut for the slightly longer syntax: {!FORCURAM:=@FORCURAM;!FORCURKEY:=@FORCURKEY;!CUSTTYPE_LONG:=@@CUSTTYPE}.
Typically any assignment based on expressions or functions has a well defined result. This may be no more true in case the right side of the assignment contains a sub-function, since the sub function returns initial if the BPATH query can not be executed till the end (typically if a relation is used which delivers no elements).
Originally the initial reference was assigned to the target structure, but this leads to problems (means dumps) in case a following entry returns a valid entry which is not of type 'data reference'.
This leads to the following change: Assignments to initial references are not executed. If there is a valid entry following afterwards, the column will be created then including the omitted entries. If there is no valid entry following the column will not be part of the target structure.
Please note that this handling has some side effects:
As with the language definition it was overseen that it is allowed to have relation names, structure names and field names containing a slash. This is very uncommon in development (at least in the areas we developed) but may occur at customer site.
The change, which is available with the mentioned note (or with version 2.4 of course) allows to mask a slash with a preceeding backslash within the following entites:
This means, if your BPATH wants to make use of a relation CRM/CustomerRel with the attribute CRM/CustomerNumer the BPATH fragment in this respect looks like: /CRM\/CustomerRel/@CRM\/CustomerNumber.
All surrounding generic consumers of BPATH should be able to handle this accordingly.
As the following topics are of a bigger size, I will stop the lesson here. Next Topic is Groupings.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
24 | |
11 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 |