Bpath Lesson 01 What Is Bpath
Bpath Lesson 01 What Is Bpath
To answer the question in the header at the very beginning, here comes a quote, raised some time ago after
the first part of of development was done:
BPath is a new way to access BOL objects, which allows data / object access controlled by a dynamic,
XPATH-like character string.
The initial request is very simple. Dynamic access to SAPs BOL/Genil Layer. Something that evaluates
requests such as
"../AddressRelation[@MAIN="X"]/EmailAddressRelation[@BUSINESS="X"]/@EMAILADR".
Something like XPath for XML data. Some of the concepts were taken over, some didn't fit, and somehow the
topic got its own life.
Well, these statements are still valid, with two remarks: The "own life" expressed in the statement got us
already pretty far away from the origins. And with the latest enhancements it is possible to attach BPath to
other frameworks also, not only to BOL. But since we should begin at the beginning and anyway only one other
"driver" (which allows access to internal tables) is developed as of now, above "definition" remains to be fine for
the moment.
My name is Jürgen Gatter, at the time of development I was part of the CRM UI Framework team (which turned
into a TIP Core UI framwork team nowadays). With this blog here I want to showcase the feasibilities of an
interpreted computer language developed over the past years within our team, which is called BPath and is
available with WEBCUIF 7.0 EhP1. More exactly it is the starting point to a blog series covering the features of
BPath, as for today we only discuss the fundamentals and ideas behind.
The beginning of the development was nearly as simple as expressed in the quote above. BOL should be
enriched with a feature allowing to access the data in an XPath-like manner returning either a Business
Collection or the data itself. So let us first take a look on the question to which extend we can compare XML
data and Business objects:
• XML data is always organized as a hierarchical, finite tree. This is not the case for Business Data.
Even though business data may appear to be hierarchical organized (on storing a Business Object
one typically saves an hierarchically organized sub-tree), in general it is not. Relations can occur
from any node to any other node and infinite pathes can be found without problem. So we have to
conclude that Business data is neither hierarchical nor finite. Consequently it is not possible to apply
some of the features of XPATH (as the searches on all nodes of the subtree).
• The start object for the Bpath has to be provided always (equally the XML document has to be
provided for XPath). Since we always operate from the starting object the differentiation between
relative and absolute pathes makes hardly sense.
• Since hierarchy and finiteness are not guaranteed even for a (business) root object, there is no way
to "scan" the complete tree. As a consequence the "//" operation as known in XPath (I cite from
w3schools: "Selects nodes in the document from the current node that match the selection no matter
where they are") has no counterpart in Bpath.
• The data returned by the XPath is also an XML entity and can be structured very inhomogeneous.
The return of BPATH is either a flat collection or an data structure. In both cases there are limitations
in respect to the inhomogeneity we can handle. For example it is practically not possible to deal with
requests as //book | //cd
• Some concepts as "Parent" and the prefixing of attributes with @ and the notation in respect to
relations are quite similar in both concepts. Note that in XML the names refer to the objects, whereas
the names used in BPATH refer to the relations between the objects.
Even though the comparison with XPath is very good to illustrate the startup, we will leave these grounds
already in lesson 2 or 3. So I will no more point to similarities and differences with XPath from here.
Enuff theory, let us try out some BPath statements, even though you still do not know how to apply them -
that's one of the topics of the next lesson. Just some remarks in advance to sketch the environment:
• BPath is available with WEBCUIF 7.0 EhP1, shipped with CRM 7.0 EhP1 (and to my knowledge with
the SAP Business Suite 7 Innovation 2010)
• Base of a query is either a Business Object or a "Business Collection with Uniform Entity
Type" (CL_CRM_BOL_ENTITY_COL_UT)
• for all examples we use the standard "FLIGHT" model, more exactly we use an UIFSearchResFlight
query result object or collection as base.
• If a query execution runs into a problem, a shortdump will be raised. This might be either the dump
from the underlying layers or a CX_WCF_BPATH_PARSING_ERROR.
*
Code Example 1: *, fetching the attribute structure
The "shortest BPath statement which does something". Well ok, it is not the shortest BPath statement of all,
since the emtpy statement is also a valid statement. But - surprise - the empty statement does nothing.
The '*' is a bit overloaded in BPath, it is used as multiply operator, and as we have it here, as "get it all"-
operator. And 'all' means the complete attribute structure. If your statement was fired from a Business
Object, the query returns the attribute structure from the respective object. If it was executed from a Business
Collection, it returns the attribute structure of the first found object in the collection.
@CITYTO
./@CARRID
We are nearing ourselves to a different topic, the usage of pathes. The first is the path to the object itself, doing
not much, but making the code slightly more readable.
SearchResFlightRel/FlightBookRel/*
../*
SearchResFlightRel/FlightBookRel/*$
Code Example 6, $ (add to table)
The dollar sign makes the difference. Up to now, the evaluation was stopped after the first entry found and the
corresponding attribute or structure was returned. Now a table (of structures or of the attribute) is returned. This
is also the case if only one entry is found.
The return structure is built up during procession, this can not be done if no data is found. In general applies to
all BPath queries: If no data is found, NULL is returned.
The dollar may appear after any relation, but as it is used here we suggest to add it at the end. The differences
between the approaches will be explained later.
Vikas Singh
Jul 13, 2014 2:33 AM
Thanks for the document - very useful indeed !
John Paul
Jul 3, 2013 3:05 PM
A very useful document. It will definetly save a lot of time.Thanks for sharing such a good concept.
Regards JP
Juergen Gatter
Apr 8, 2011 1:50 AM
... I hope the second lesson is ready by mid/end of next week. So stay tuned :-)
[real life examples]. I have to admit they are still rare...so that's your job ;-). The original targeted usage
(tagging feature) was solved in a different way, so it is implemented for one feature only at the moment. I
will speak with the colleagues whether we spend some lines on this integration in one of the coming lessons
(lesson 3 or higher I suppose).
Tobias Trapp
Apr 7, 2011 8:47 AM
Thanks for sharing this! I think it’s really useful and I would like to know whether this framework
is limited to SAPs BOL/Genil Layer or can be used for somehow arbitrary deep ABAP structures?
In my opinion access to tree liked objects is quite a common task in AS ABAP and often an XPath-
like syntax is needed: think of access to parts of WDA contexts and in private communication I
could give you more examples in AS ABAP that can deal with data references. So sometimes I’m
asking whether a general tool would be useful because I can imagine many more use cases.
Best Regards,
Tobias Trapp
Regards,
Luis
Shobhit Srivastava
Apr 7, 2011 8:22 AM
Thanks Juergen for giving insight to this new area. I was really wondering from last few weeks when I first
heard about this term. We are waiting for more and if you can include some real time requirement where we
need to use this BPath then it would be really appreciable.
Thanks again.
Best Regards,
Shobhit