Part 3 - Navigating The BOPF - Working With The BOPF API
Part 3 - Navigating The BOPF - Working With The BOPF API
In my previous blog post, we explored the anatomy of business objects within the BOPF. There, we were able to observe the various entities that make up a BO: nodes/attributes, actions, associations, determinations, validations, and queries. Now that you have a feel for what these entities are, we're ready to begin taking a look at the API that is used to manipulate these entities. To guide us through this demonstration, we'll explore the construction of a simple ABAP report program used to perform CRUD operations on a sample BOPF BO shipped by default by SAP:/ B O B F / D E M O _ C U S T O M E R . You can download the complete example program source code here. Note: The code bundle described above has been enhanced as of 9/18/2013. The code was reworked to factor out a BOPF utilities class of sorts and also demonstrate how to traverse over to dependent objects (DOs).
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
1/20
11/2/2014
In the upcoming sections, I'll show you how these various API classes collaborate in typical BOPF use cases. Along the way, we'll encounter other useful classes that can be used to perform specific tasks. You can find a complete class listing within package / B O B F / M A I N . Note: As you'll soon see, the BOPF API is extremely generic in nature. While this provides tremendous flexibility, it also adds a certain amount of tedium to common tasks. Thus, in many applications, you may find that SAP has elected to wrap the API up in another API that is more convenient to work with. For example, in the SAP EHSM solution, SAP defines an "Easy Node Access" API which simplfies the way that developers traverse BO nodes, perform updates, and so on.
Our sample program provides a basic UI as shown below. Here, users have the option of creating, changing, and displaying a particular customer using its ID number. Sort of a simplified Transaction XK01-XK03 if you will.
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
2/20
11/2/2014
Getting Started
To drive the application functionality, we'll create a local test driver class called L C L _ D E M O . As you can see in the code excerpt below, this test driver class loads the core BOPF API objects at setup whenever the C O N S T R U C T O Rmethod is invoked. Here, the factory classes illustrated in the UML class diagram shown in the previous section are used to load the various object references. C L A S Sl c l _ d e m oD E F I N I T I O NC R E A T EP R I V A T E . P R I V A T ES E C T I O N . D A T Am o _ t x n _ m n g rT Y P ER E FT O/ b o b f / i f _ t r a _ t r a n s a c t i o n _ m g r . D A T Am o _ s v c _ m n g rT Y P ER E FT O/ b o b f / i f _ t r a _ s e r v i c e _ m a n a g e r . D A T Am o _ b o _ c o n f T Y P ER E FT O/ b o b f / i f _ f r w _ c o n f i g u r a t i o n . M E T H O D S : c o n s t r u c t o rR A I S I N G/ b o b f / c x _ f r w . E N D C L A S S . C L A S Sl c l _ d e m oI M P L E M E N T A T I O N . M E T H O Dc o n s t r u c t o r . " O b t a i nar e f e r e n c et ot h eB O P Ft r a n s a c t i o nm a n a g e r : m e > m o _ t x n _ m n g r= / b o b f / c l _ t r a _ t r a n s _ m g r _ f a c t o r y = > g e t _ t r a n s a c t i o n _ m a n a g e r () . " O b t a i nar e f e r e n c et ot h eB O P Fs e r v i c em a n a g e r : m e > m o _ s v c _ m n g r= / b o b f / c l _ t r a _ s e r v _ m g r _ f a c t o r y = > g e t _ s e r v i c e _ m a n a g e r ( / b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ b o _ k e y) . " A c c e s st h em e t a d a t af o rt h e/ B O B F / D E M O _ C U S T O M E RB O : m e > m o _ b o _ c o n f= / b o b f / c l _ f r w _ f a c t o r y = > g e t _ c o n f i g u r a t i o n ( / b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ b o _ k e y) . E N D M E T H O D . "M E T H O Dc o n s t r u c t o r E N D C L A S S .
For the most part, this should seem fairly straightforward. However, you might be wondering where I came up with theI V _ B O _ K E Yparameter in the G E T _ S E R V I C E _ M A N A G E R ( )and G E T _ C O N F I G U R A T I O N ( )factory method calls. This value
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 3/20
11/2/2014
is provided to us via the BO's constants interface (/ B O B F / I F _ D E M O _ C U S T O M E R _ Cin this case) which can be found within the BO configuration in Transaction /BOBF/CONF_UI (see below). This auto-generated constants interface provides us with a convenient mechanism for addressing a BO's key, its defined nodes, associations, queries, and so on. We'll end up using this interface quite a bit during the course of our development.
11/2/2014
instance. For the most part, this involves little more than a call to the M O D I F Y ( )method of the/ B O B F / I F _ T R A _ S E R V I C E _ M A N A G E Robject reference. Of course, as you can see in the code excerpt below, there is a fair amount of setup that we must do before we can call this method. C L A S Sl c l _ d e m oD E F I N I T I O NC R E A T EP R I V A T E . P U B L I CS E C T I O N . C L A S S M E T H O D S : c r e a t e _ c u s t o m e rI M P O R T I N Gi v _ c u s t o m e r _ i d T Y P E/ b o b f / d e m o _ c u s t o m e r _ i d . . . . E N D C L A S S . C L A S Sl c l _ d e m oI M P L E M E N T A T I O N . M E T H O Dc r e a t e _ c u s t o m e r . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al o _ d r i v e r D A T Al t _ m o d T Y P ER E FT Ol c l _ d e m o . T Y P E/ b o b f / t _ f r w _ m o d i f i c a t i o n .
D A T Al o _ c h a n g e T Y P ER E FT O/ b o b f / i f _ t r a _ c h a n g e . D A T Al o _ m e s s a g e T Y P ER E FT O/ b o b f / i f _ f r w _ m e s s a g e . D A T Al v _ r e j e c t e dT Y P Eb o o l e _ d . D A T Al x _ b o p f _ e x T Y P ER E FT O/ b o b f / c x _ f r w . D A T Al v _ e r r _ m s g T Y P Es t r i n g . D A T Al r _ s _ r o o t T Y P ER E FT O/ b o b f / s _ d e m o _ c u s t o m e r _ h d r _ k .
D A T Al r _ s _ t x t T Y P ER E FT O/ b o b f / s _ d e m o _ s h o r t _ t e x t _ k . D A T Al r _ s _ t x t _ h d r T Y P ER E FT O/ b o b f / s _ d e m o _ l o n g t e x t _ h d r _ k . D A T Al r _ s _ t x t _ c o n tT Y P ER E FT O/ b o b f / s _ d e m o _ l o n g t e x t _ i t e m _ k . F I E L D S Y M B O L S : < l s _ m o d >L I K EL I N EO Fl t _ m o d . " U s et h eB O P FA P It oc r e a t ean e wc u s t o m e rr e c o r d : T R Y . " I n s t a n t i a t et h ed r i v e rc l a s s : C R E A T EO B J E C Tl o _ d r i v e r . " B u i l dt h eR O O Tn o d e : C R E A T ED A T Al r _ s _ r o o t . l r _ s _ r o o t > k e y=/ b o b f / c l _ f r w _ f a c t o r y = > g e t _ n e w _ k e y () . l r _ s _ r o o t > c u s t o m e r _ i d l r _ s _ r o o t > s a l e s _ o r g l r _ s _ r o o t > c u s t _ c u r r l r _ s _ r o o t > a d d r e s s =i v _ c u s t o m e r _ i d . =' A M E R ' . =' U S D ' . =' 1 2 3 4A n yS t r e e t ' .
A P P E N DI N I T I A LL I N ET Ol t _ m o dA S S I G N I N G< l s _ m o d > . < l s _ m o d > n o d e < l s _ m o d > k e y < l s _ m o d > d a t a =/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t . =l r _ s _ r o o t > k e y . =l r _ s _ r o o t . < l s _ m o d > c h a n g e _ m o d e=/ b o b f / i f _ f r w _ c = > s c _ m o d i f y _ c r e a t e .
11/2/2014
l r _ s _ t x t > t e x t =' S a m p l eC u s t o m e rR e c o r d ' . l r _ s _ t x t > l a n g u a g e=s y l a n g u . A P P E N DI N I T I A LL I N ET Ol t _ m o dA S S I G N I N G< l s _ m o d > . < l s _ m o d > n o d e =/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t _ t e x t . < l s _ m o d > c h a n g e _ m o d e=/ b o b f / i f _ f r w _ c = > s c _ m o d i f y _ c r e a t e . < l s _ m o d > s o u r c e _ n o d e=/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t . < l s _ m o d > a s s o c i a t i o n= / b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ a s s o c i a t i o n r o o t r o o t _ t e x t . < l s _ m o d > s o u r c e _ k e y =l r _ s _ r o o t > k e y . < l s _ m o d > k e y < l s _ m o d > d a t a =l r _ s _ t x t > k e y . =l r _ s _ t x t .
" B u i l dt h eR O O T _ L O N G _ T E X Tn o d e : " I fy o ul o o ka tt h en o d et y p ef o rt h i sn o d e ,y o u ' l ln o t i c et h a t " i t ' sa" D e l e g a t e dN o d e " .I no t h e rw o r d s ,i ti sd e f i n e di nt e r m s " o ft h e/ B O B F / D E M O _ T E X T _ C O L L E C T I O Nb u s i n e s so b j e c t .T h ef o l l o w i n g " c o d ea c c o u n t sf o rt h i si n d i r e c t i o n . C R E A T ED A T Al r _ s _ t x t _ h d r . l r _ s _ t x t _ h d r > k e y=/ b o b f / c l _ f r w _ f a c t o r y = > g e t _ n e w _ k e y () . A P P E N DI N I T I A LL I N ET Ol t _ m o dA S S I G N I N G< l s _ m o d > . < l s _ m o d > n o d e =/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t _ l o n g _ t e x t . < l s _ m o d > c h a n g e _ m o d e =/ b o b f / i f _ f r w _ c = > s c _ m o d i f y _ c r e a t e . < l s _ m o d > s o u r c e _ n o d e < l s _ m o d > a s s o c i a t i o n =/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t . =
" C r e a t et h eC O N T E N Tn o d e : C R E A T ED A T Al r _ s _ t x t _ c o n t . l r _ s _ t x t _ c o n t > k e y =/ b o b f / c l _ f r w _ f a c t o r y = > g e t _ n e w _ k e y () . l r _ s _ t x t _ c o n t > l a n g u a g e =s y l a n g u . l r _ s _ t x t _ c o n t > t e x t _ t y p e =' M E M O ' . l r _ s _ t x t _ c o n t > t e x t _ c o n t e n t=' D e m oc u s t o m e rc r e a t e dv i aB O P FA P I . ' . A P P E N DI N I T I A LL I N ET Ol t _ m o dA S S I G N I N G< l s _ m o d > . < l s _ m o d > n o d e = l o _ d r i v e r > m o _ b o _ c o n f > q u e r y _ n o d e ( i v _ p r o x y _ n o d e _ n a m e=' R O O T _ L O N G _ T X T . C O N T E N T ') . < l s _ m o d > c h a n g e _ m o d e=/ b o b f / i f _ f r w _ c = > s c _ m o d i f y _ c r e a t e . < l s _ m o d > s o u r c e _ n o d e=/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t _ l o n g _ t e x t . < l s _ m o d > s o u r c e _ k e y =l r _ s _ t x t _ h d r > k e y . < l s _ m o d > k e y =l r _ s _ t x t _ c o n t > k e y . < l s _ m o d > d a t a =l r _ s _ t x t _ c o n t . < l s _ m o d > a s s o c i a t i o n= l o _ d r i v e r > m o _ b o _ c o n f > q u e r y _ a s s o c ( i v _ n o d e _ k e y =/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t _ l o n g _ t e x t i v _ a s s o c _ n a m e=' C O N T E N T ') . " C r e a t et h ec u s t o m e rr e c o r d : C A L LM E T H O Dl o _ d r i v e r > m o _ s v c _ m n g r > m o d i f y
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 6/20
11/2/2014
E X P O R T I N G i t _ m o d i f i c a t i o n=l t _ m o d I M P O R T I N G e o _ c h a n g e =l o _ c h a n g e e o _ m e s s a g e =l o _ m e s s a g e .
" C h e c kf o re r r o r s : I Fl o _ m e s s a g eI SB O U N D . I Fl o _ m e s s a g e > c h e c k ()E Qa b a p _ t r u e . l o _ d r i v e r > d i s p l a y _ m e s s a g e s (l o _ m e s s a g e) . R E T U R N . E N D I F . E N D I F . " A p p l yt h et r a n s a c t i o n a lc h a n g e s : C A L LM E T H O Dl o _ d r i v e r > m o _ t x n _ m n g r > s a v e I M P O R T I N G e o _ m e s s a g e =l o _ m e s s a g e e v _ r e j e c t e d=l v _ r e j e c t e d . I Fl v _ r e j e c t e dE Qa b a p _ t r u e . l o _ d r i v e r > d i s p l a y _ m e s s a g e s (l o _ m e s s a g e) . R E T U R N . E N D I F . " I fw eg e tt oh e r e ,t h e nt h eo p e r a t i o nw a ss u c c e s s f u l : W R I T E :/' C u s t o m e r ' ,i v _ c u s t o m e r _ i d ,' c r e a t e ds u c c e s s f u l l y . ' . C A T C H/ b o b f / c x _ f r wI N T Ol x _ b o p f _ e x . l v _ e r r _ m s g=l x _ b o p f _ e x > g e t _ t e x t () . W R I T E :/l v _ e r r _ m s g . E N D T R Y . E N D M E T H O D . E N D C L A S S . "M E T H O Dc r e a t e _ c u s t o m e r
As you can see in the code excerpt above, the majority of the code is devoted to building a table which is passed in theI T _ M O D I F I C A T I O Nparameter of the M O D I F Y ( )method. Here, a separate record is created for each node row that is being modified (or inserted in this case). This record contains information such as the node object key (N O D E ), the edit mode (C H A N G E _ M O D E ), the row key (K E Y ) which is an auto-generated GUID, association/parent key information, and of course, the actual data (D A T A ). If you've ever worked with ALE IDocs, then this will probably feel vaguely familiar. Looking more closely at the population of the node row data, you can see that we're working with data references which are created dynamically using the C R E A T ED A T Astatement. This indirection is necessary since the BOPF API is generic in nature. You can find the structure definitions for each node by double-clicking on the node in Transaction /BOBF/CONF_UI and looking at the Comb ined Structure field (see below).
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
7/20
11/2/2014
Once the modification table is filled out, we can call the M O D I F Y ( )method to insert the record(s). Assuming all is successful, we can then commit the transaction by calling the S A V E ( )method on the/ B O B F / I F _ T R A _ T R A N S A C T I O N _ M A N A G E Rinstance. Should any errors occur, we can display the error messages using methods of the / B O B F / I F _ F R W _ M E S S A G Eobject reference which is returned from both methods. This is evidenced by the simple utility method D I S P L A Y _ M E S S A G E S ( )shown below. That's pretty much all there is to it. C L A S Sl c l _ d e m oD E F I N I T I O NC R E A T EP R I V A T E . P R I V A T ES E C T I O N . M E T H O D S : d i s p l a y _ m e s s a g e sI M P O R T I N Gi o _ m e s s a g e T Y P ER E FT O/ b o b f / i f _ f r w _ m e s s a g e . E N D C L A S S .
C L A S Sl c l _ d e m oI M P L E M E N T A T I O N . M E T H O Dd i s p l a y _ m e s s a g e s . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al t _ m e s s a g e sT Y P E/ b o b f / t _ f r w _ m e s s a g e _ k . D A T Al v _ m s g _ t e x tT Y P Es t r i n g . F I E L D S Y M B O L S< l s _ m e s s a g e >L I K EL I N EO Fl t _ m e s s a g e s . " S a n i t yc h e c k : C H E C Ki o _ m e s s a g eI SB O U N D . " O u t p u te a c ho ft h em e s s a g e si nt h ec o l l e c t i o n : i o _ m e s s a g e > g e t _ m e s s a g e s (I M P O R T I N Ge t _ m e s s a g e=l t _ m e s s a g e s) . L O O PA Tl t _ m e s s a g e sA S S I G N I N G< l s _ m e s s a g e > . l v _ m s g _ t e x t=< l s _ m e s s a g e > m e s s a g e > g e t _ t e x t () . W R I T E :/l v _ m s g _ t e x t . E N D L O O P . E N D M E T H O D . "M E T H O Dd i s p l a y _ m e s s a g e s
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 8/20
11/2/2014
E N D C L A S S .
As we learned in the previous blog post, most BOs come with one or more queries which allow us to search for BOs according to various node criteria. In the case of the / B O B F / D E M O _ C U S T O M E Rbusiness object, we want to use theS E L E C T _ B Y _ A T T R I B U T E Squery attached to the R O O Tnode (see below). This allows us to lookup customers by their ID value.
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
9/20
11/2/2014
The code excerpt below shows how we defined our query in a method called G E T _ C U S T O M E R _ F O R _ I D ( ) . As you can see, the query is executed by calling the aptly named Q U E R Y ( )method of the / B O B F / I F _ T R A _ S E R V I C E _ M A N A G E R instance. The query parameters are provided in the form of an internal table of type/ B O B F / T _ F R W _ Q U E R Y _ S E L P A R A M . This table type has a similar look and feel to a range table or S E L E C T O P T I O N . The results of the query are returned in a table of type / B O B F / T _ F R W _ K E Y . This table contains the keys of the node rows that matched the query parameters. In our sample case, there should be only one match, so we simply return the first key in the list. C L A S Sl c l _ d e m oD E F I N I T I O NC R E A T EP R I V A T E . P R I V A T ES E C T I O N . M E T H O D S : g e t _ c u s t o m e r _ f o r _ i dI M P O R T I N Gi v _ c u s t o m e r _ i d T Y P E/ b o b f / d e m o _ c u s t o m e r _ i d R E T U R N I N GV A L U E ( r v _ c u s t o m e r _ k e y ) T Y P E/ b o b f / c o n f _ k e y R A I S I N G/ b o b f / c x _ f r w . E N D C L A S S .
11/2/2014
" T h o u g hw ec o u l dc o n c e i v a b l yl o o k u pt h ec u s t o m e ru s i n ga nS Q Lq u e r y , " t h ep r e f e r r e dm e t h o do fs e l e c t i o ni saB O P Fq u e r y : A P P E N DI N I T I A LL I N ET Ol t _ p a r a m e t e r sA S S I G N I N G< l s _ p a r a m e t e r > . < l s _ p a r a m e t e r > a t t r i b u t e _ n a m e= / b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ q u e r y _ a t t r i b u t e r o o t s e l e c t _ b y _ a t t r i b u t e s c u s t o m e r _ i d . < l s _ p a r a m e t e r > s i g n < l s _ p a r a m e t e r > o p t i o n < l s _ p a r a m e t e r > l o w =' I ' . =' E Q ' . =i v _ c u s t o m e r _ i d .
C A L LM E T H O Dl o _ d r i v e r > m o _ s v c _ m n g r > q u e r y E X P O R T I N G i v _ q u e r y _ k e y = / b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ q u e r y r o o t s e l e c t _ b y _ a t t r i b u t e s i t _ s e l e c t i o n _ p a r a m e t e r s=l t _ p a r a m e t e r s I M P O R T I N G e t _ k e y =l t _ c u s t o m e r _ k e y s . " R e t u r nt h em a t c h i n gc u s t o m e r ' sK E Yv a l u e : R E A DT A B L El t _ c u s t o m e r _ k e y sI N D E X1A S S I G N I N G< l s _ c u s t o m e r _ k e y > . I Fs y s u b r cE Q0 . r v _ c u s t o m e r _ k e y=< l s _ c u s t o m e r _ k e y > k e y . E N D I F . E N D M E T H O D . E N D C L A S S . "M E T H O Dg e t _ c u s t o m e r _ f o r _ i d
11/2/2014
T Y P E/ b o b f / d e m o _ c u s t o m e r _ i d .
P R I V A T ES E C T I O N . M E T H O D S : g e t _ n o d e _ t a b l eI M P O R T I N Gi v _ k e yT Y P E/ b o b f / c o n f _ k e y i v _ n o d e _ k e yT Y P E/ b o b f / o b m _ n o d e _ k e y i v _ e d i t _ m o d eT Y P E/ b o b f / c o n f _ e d i t _ m o d e D E F A U L T/ b o b f / i f _ c o n f _ c = > s c _ e d i t _ r e a d _ o n l y R E T U R N I N GV A L U E ( r r _ d a t a )T Y P ER E FT Od a t a R A I S I N G/ b o b f / c x _ f r w , g e t _ n o d e _ r o wI M P O R T I N Gi v _ k e yT Y P E/ b o b f / c o n f _ k e y i v _ n o d e _ k e yT Y P E/ b o b f / o b m _ n o d e _ k e y i v _ e d i t _ m o d eT Y P E/ b o b f / c o n f _ e d i t _ m o d e D E F A U L T/ b o b f / i f _ c o n f _ c = > s c _ e d i t _ r e a d _ o n l y i v _ i n d e xT Y P EiD E F A U L T1 R E T U R N I N GV A L U E ( r r _ d a t a )T Y P ER E FT Od a t a R A I S I N G/ b o b f / c x _ f r w , g e t _ n o d e _ t a b l e _ b y _ a s s o cI M P O R T I N Gi v _ k e yT Y P E/ b o b f / c o n f _ k e y i v _ n o d e _ k e yT Y P E/ b o b f / o b m _ n o d e _ k e y i v _ a s s o c _ k e yT Y P E/ b o b f / o b m _ a s s o c _ k e y i v _ e d i t _ m o d eT Y P E/ b o b f / c o n f _ e d i t _ m o d e D E F A U L T/ b o b f / i f _ c o n f _ c = > s c _ e d i t _ r e a d _ o n l y R E T U R N I N GV A L U E ( r r _ d a t a )T Y P ER E FT Od a t a R A I S I N G/ b o b f / c x _ f r w , g e t _ n o d e _ r o w _ b y _ a s s o cI M P O R T I N Gi v _ k e yT Y P E/ b o b f / c o n f _ k e y i v _ n o d e _ k e yT Y P E/ b o b f / o b m _ n o d e _ k e y i v _ a s s o c _ k e yT Y P E/ b o b f / o b m _ a s s o c _ k e y i v _ e d i t _ m o d eT Y P E/ b o b f / c o n f _ e d i t _ m o d e D E F A U L T/ b o b f / i f _ c o n f _ c = > s c _ e d i t _ r e a d _ o n l y i v _ i n d e xT Y P EiD E F A U L T1 R E T U R N I N GV A L U E ( r r _ d a t a )T Y P ER E FT Od a t a R A I S I N G/ b o b f / c x _ f r w . E N D C L A S S . C L A S Sl c l _ d e m oI M P L E M E N T A T I O N . M E T H O Dd i s p l a y _ c u s t o m e r . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al o _ d r i v e r T Y P ER E FT Ol c l _ d e m o . D A T Al v _ c u s t o m e r _ k e yT Y P E/ b o b f / c o n f _ k e y . D A T Al x _ b o p f _ e x T Y P ER E FT O/ b o b f / c x _ f r w . D A T Al v _ e r r _ m s g T Y P Es t r i n g . D A T Al r _ s _ r o o tT Y P ER E FT O/ b o b f / s _ d e m o _ c u s t o m e r _ h d r _ k . D A T Al r _ s _ t e x tT Y P ER E FT O/ b o b f / s _ d e m o _ s h o r t _ t e x t _ k . " T r yt od i s p l a yt h es e l e c t e dc u s t o m e r : T R Y . " I n s t a n t i a t et h et e s td r i v e rc l a s s : C R E A T EO B J E C Tl o _ d r i v e r . " L o o k u pt h ec u s t o m e r ' sk e ya t t r i b u t eu s i n gaq u e r y :
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 12/20
11/2/2014
W R I T E :/' D i s p l a yC u s t o m e r ' ,l r _ s _ r o o t > c u s t o m e r _ i d . U L I N E . W R I T E :/' S a l e sO r g a n i z a t i o n : ' ,l r _ s _ r o o t > s a l e s _ o r g . W R I T E :/' A d d r e s s : ' ,l r _ s _ r o o t > a d d r e s s . S K I P . " T r a v e r s et ot h eR O O T _ T E X Tn o d et od i s p l a yt h ec u s t o m e rs h o r tt e x t : l r _ s _ t e x t? = l o _ d r i v e r > g e t _ n o d e _ r o w _ b y _ a s s o c ( i v _ k e y=l v _ c u s t o m e r _ k e y i v _ n o d e _ k e y=/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t i v _ a s s o c _ k e y=/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ a s s o c i a t i o n r o o t r o o t _ t e x t i v _ i n d e x=1) . W R I T E :/' S h o r tT e x t : ' ,l r _ s _ t e x t > t e x t . C A T C H/ b o b f / c x _ f r wI N T Ol x _ b o p f _ e x . l v _ e r r _ m s g=l x _ b o p f _ e x > g e t _ t e x t () . W R I T E :/l v _ e r r _ m s g . E N D T R Y . E N D M E T H O D . "M E T H O Dd i s p l a y _ c u s t o m e r
M E T H O Dg e t _ n o d e _ t a b l e . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al t _ k e y T Y P E/ b o b f / t _ f r w _ k e y . D A T Al s _ n o d e _ c o n fT Y P E/ b o b f / s _ c o n f r o _ n o d e . D A T Al o _ c h a n g e D A T Al o _ m e s s a g e T Y P ER E FT O/ b o b f / i f _ t r a _ c h a n g e . T Y P ER E FT O/ b o b f / i f _ f r w _ m e s s a g e .
11/2/2014
" C h e c kt h er e s u l t s : I Fl o _ m e s s a g eI SB O U N D . I Fl o _ m e s s a g e > c h e c k ()E Qa b a p _ t r u e . d i s p l a y _ m e s s a g e s (l o _ m e s s a g e) . R A I S EE X C E P T I O NT Y P E/ b o b f / c x _ d a c . E N D I F . E N D I F . E N D M E T H O D . "M E T H O Dg e t _ n o d e _ t a b l e M E T H O Dg e t _ n o d e _ r o w . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al r _ t _ d a t aT Y P ER E FT Od a t a . F I E L D S Y M B O L S< l t _ d a t a >T Y P EI N D E XT A B L E . F I E L D S Y M B O L S< l s _ r o w >T Y P EA N Y . " L o o k u pt h en o d ed a t a : l r _ t _ d a t a= g e t _ n o d e _ t a b l e (i v _ k e y =i v _ k e y i v _ n o d e _ k e y =i v _ n o d e _ k e y i v _ e d i t _ m o d e=i v _ e d i t _ m o d e) . I Fl r _ t _ d a t aI SN O TB O U N D . R A I S EE X C E P T I O NT Y P E/ b o b f / c x _ d a c . E N D I F . " T r yt op u l lt h er e c o r da tt h es p e c i f i e di n d e x : A S S I G Nl r _ t _ d a t a > *T O< l t _ d a t a > . R E A DT A B L E< l t _ d a t a >I N D E Xi v _ i n d e xA S S I G N I N G< l s _ r o w > . I Fs y s u b r cE Q0 . G E TR E F E R E N C EO F< l s _ r o w >I N T Or r _ d a t a . E L S E . R A I S EE X C E P T I O NT Y P E/ b o b f / c x _ d a c . E N D I F . E N D M E T H O D . "M E T H O Dg e t _ n o d e _ r o w M E T H O Dg e t _ n o d e _ t a b l e _ b y _ a s s o c . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al t _ k e y T Y P E/ b o b f / t _ f r w _ k e y . D A T Al s _ n o d e _ c o n f T Y P E/ b o b f / s _ c o n f r o _ n o d e . D A T Al s _ a s s o c i a t i o nT Y P E/ b o b f / s _ c o n f r o _ a s s o c . D A T Al o _ c h a n g e D A T Al o _ m e s s a g e T Y P ER E FT O/ b o b f / i f _ t r a _ c h a n g e . T Y P ER E FT O/ b o b f / i f _ f r w _ m e s s a g e .
14/20
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
11/2/2014
F I E L D S Y M B O L S< l s _ k e y >L I K EL I N EO Fl t _ k e y . F I E L D S Y M B O L S< l t _ d a t a >T Y P EI N D E XT A B L E . " L o o k u pt h ea s s o c i a t i o nm e t a d a t at of i n do u tm o r e " i n f o r m a t i o na b o u tt h et a r g e ts u b n o d e : C A L LM E T H O Dm o _ b o _ c o n f > g e t _ a s s o c E X P O R T I N G i v _ a s s o c _ k e y=i v _ a s s o c _ k e y i v _ n o d e _ k e y =i v _ n o d e _ k e y I M P O R T I N G e s _ a s s o c =l s _ a s s o c i a t i o n . I Fl s _ a s s o c i a t i o n t a r g e t _ n o d eI SN O TB O U N D . R A I S EE X C E P T I O NT Y P E/ b o b f / c x _ d a c . E N D I F . " U s et h en o d ec o n f i g u r a t i o nm e t a d a t at oc r e a t et h er e s u l tt a b l e : l s _ n o d e _ c o n f=l s _ a s s o c i a t i o n t a r g e t _ n o d e > * . C R E A T ED A T Ar r _ d a t aT Y P E( l s _ n o d e _ c o n f d a t a _ t a b l e _ t y p e ) . A S S I G Nr r _ d a t a > *T O< l t _ d a t a > . " R e t r i e v et h et a r g e tn o d e : A P P E N DI N I T I A LL I N ET Ol t _ k e yA S S I G N I N G< l s _ k e y > . < l s _ k e y > k e y=i v _ k e y . C A L LM E T H O Dm o _ s v c _ m n g r > r e t r i e v e _ b y _ a s s o c i a t i o n E X P O R T I N G i v _ n o d e _ k e y =i v _ n o d e _ k e y i t _ k e y =l t _ k e y i v _ a s s o c i a t i o n=i v _ a s s o c _ k e y i v _ f i l l _ d a t a =a b a p _ t r u e I M P O R T I N G e o _ m e s s a g e =l o _ m e s s a g e e o _ c h a n g e e t _ d a t a =l o _ c h a n g e =< l t _ d a t a > .
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
15/20
11/2/2014
" L o o k u pt h en o d ed a t a : l r _ t _ d a t a= g e t _ n o d e _ t a b l e _ b y _ a s s o c (i v _ k e y =i v _ k e y i v _ n o d e _ k e y =i v _ n o d e _ k e y i v _ a s s o c _ k e y=i v _ a s s o c _ k e y i v _ e d i t _ m o d e=i v _ e d i t _ m o d e) . I Fl r _ t _ d a t aI SN O TB O U N D . R A I S EE X C E P T I O NT Y P E/ b o b f / c x _ d a c . E N D I F . " T r yt op u l lt h er e c o r da tt h es p e c i f i e di n d e x : A S S I G Nl r _ t _ d a t a > *T O< l t _ d a t a > . R E A DT A B L E< l t _ d a t a >I N D E Xi v _ i n d e xA S S I G N I N G< l s _ r o w > . I Fs y s u b r cE Q0 . G E TR E F E R E N C EO F< l s _ r o w >I N T Or r _ d a t a . E L S E . R A I S EE X C E P T I O NT Y P E/ b o b f / c x _ d a c . E N D I F . E N D M E T H O D . "M E T H O Dg e t _ n o d e _ r o w _ b y _ a s s o c E N D C L A S S .
Note: In this simple example, we didn't bother to drill down to display the contents of the R O O T _ L O N G _ T E X Tnode. However, if we had wanted to do so, we would have needed to create a separate service manager instance for the/ B O B F / D E M O _ T E X T _ C O L L E C T I O Nbusiness object since the data within that node is defined by that delegated BO as opposed to the / B O B F / D E M O _ C U S T O M E RBO. Otherwise, the process is the same.
C L A S Sl c l _ d e m oI M P L E M E N T A T I O N . M E T H O Dc h a n g e _ c u s t o m e r . " M e t h o d L o c a lD a t aD e c l a r a t i o n s : D A T Al o _ d r i v e r T Y P ER E FT Ol c l _ d e m o . D A T Al v _ c u s t o m e r _ k e yT Y P E/ b o b f / c o n f _ k e y .
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 16/20
11/2/2014
D A T Al t _ m o d D A T Al o _ c h a n g e D A T Al o _ m e s s a g e D A T Al v _ r e j e c t e d D A T Al x _ b o p f _ e x D A T Al v _ e r r _ m s g
T Y P E/ b o b f / t _ f r w _ m o d i f i c a t i o n . T Y P ER E FT O/ b o b f / i f _ t r a _ c h a n g e . T Y P ER E FT O/ b o b f / i f _ f r w _ m e s s a g e . T Y P Eb o o l e _ d . T Y P ER E FT O/ b o b f / c x _ f r w . T Y P Es t r i n g .
F I E L D S Y M B O L S : < l s _ m o d >L I K EL I N EO Fl t _ m o d . D A T Al r _ s _ r o o tT Y P ER E FT O/ b o b f / s _ d e m o _ c u s t o m e r _ h d r _ k . " T r yt oc h a n g et h ea d d r e s so nt h es e l e c t e dc u s t o m e r : T R Y . " I n s t a n t i a t et h et e s td r i v e rc l a s s : C R E A T EO B J E C Tl o _ d r i v e r . " A c c e s st h ec u s t o m e rR O O Tn o d e : l v _ c u s t o m e r _ k e y=l o _ d r i v e r > g e t _ c u s t o m e r _ f o r _ i d (i v _ c u s t o m e r _ i d) . l r _ s _ r o o t? = l o _ d r i v e r > g e t _ n o d e _ r o w (i v _ k e y=l v _ c u s t o m e r _ k e y i v _ n o d e _ k e y=/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t i v _ e d i t _ m o d e=/ b o b f / i f _ c o n f _ c = > s c _ e d i t _ e x c l u s i v e i v _ i n d e x=1) . " C h a n g et h ea d d r e s ss t r i n go nt h ec u s t o m e r : l r _ s _ r o o t > a d d r e s s=' 1 2 3 4B o a r d w a l kA v e . ' . A P P E N DI N I T I A LL I N ET Ol t _ m o dA S S I G N I N G< l s _ m o d > . < l s _ m o d > n o d e =/ b o b f / i f _ d e m o _ c u s t o m e r _ c = > s c _ n o d e r o o t . < l s _ m o d > c h a n g e _ m o d e=/ b o b f / i f _ f r w _ c = > s c _ m o d i f y _ u p d a t e . < l s _ m o d > k e y < l s _ m o d > d a t a =l r _ s _ r o o t > k e y . =l r _ s _ r o o t .
" U p d a t et h ec u s t o m e rr e c o r d : C A L LM E T H O Dl o _ d r i v e r > m o _ s v c _ m n g r > m o d i f y E X P O R T I N G i t _ m o d i f i c a t i o n=l t _ m o d I M P O R T I N G e o _ c h a n g e =l o _ c h a n g e e o _ m e s s a g e =l o _ m e s s a g e . " C h e c kf o re r r o r s : I Fl o _ m e s s a g eI SB O U N D . I Fl o _ m e s s a g e > c h e c k ()E Qa b a p _ t r u e . l o _ d r i v e r > d i s p l a y _ m e s s a g e s (l o _ m e s s a g e) . R E T U R N . E N D I F . E N D I F . " A p p l yt h et r a n s a c t i o n a lc h a n g e s : C A L LM E T H O Dl o _ d r i v e r > m o _ t x n _ m n g r > s a v e I M P O R T I N G
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 17/20
11/2/2014
e o _ m e s s a g e =l o _ m e s s a g e e v _ r e j e c t e d=l v _ r e j e c t e d . I Fl v _ r e j e c t e dE Qa b a p _ t r u e . l o _ d r i v e r > d i s p l a y _ m e s s a g e s (l o _ m e s s a g e) . R E T U R N . E N D I F . " I fw eg e tt oh e r e ,t h e nt h eo p e r a t i o nw a ss u c c e s s f u l : W R I T E :/' C u s t o m e r ' ,i v _ c u s t o m e r _ i d ,' u p d a t e ds u c c e s s f u l l y . ' . C A T C H/ b o b f / c x _ f r wI N T Ol x _ b o p f _ e x . l v _ e r r _ m s g=l x _ b o p f _ e x > g e t _ t e x t () . W R I T E :/l v _ e r r _ m s g . E N D T R Y . E N D M E T H O D . "M E T H O Dc h a n g e _ c u s t o m e r E N D C L A S S .
Next Steps
I often find that the best way to learn a technology framework is to see how it plays out via code. At this level, we can clearly visualize the relationships between the various entities and see how they perform at runtime. Hopefully after reading this post, you should have a better understanding of how all the BOPF pieces fit together. In my next blog post, we'll expand upon what we've learned and consider some more advanced features of the BOPF API.
4824 View s
12 Comments
Thanks.
Like (0) Keerthi Vasan Jul 4, 2013 1:14 PM
Very helpful. Could you please provide me the code to read the long text as well. Thanks
Like (0) James Wood Sep 17, 2013 10:21 PM (in response to S B)
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 18/20
11/2/2014
The complete code bundle can be downloaded from here: http://www.bowdark.com/downloads/BOPFDemoProgram.zip Thanks.
Like (0) S B Sep 18, 2013 5:51 PM (in response to James Wood)
James, I have downloaded the full program. Neither the full program nor the blog post have the logic to read the long text from node ROOT_LONG_TEXT. Could you please share that logic if you have so. Thanks
Like (0) James Wood Sep 18, 2013 10:54 PM (in response to S B)
Ah, I missed the long text part. Please find an updated version of the code at the download link above. I made some wholesale changes to the code so that it's cleaner and more organized. Alas, the original demo was rather primitive. Let me know if you have any further questions. Thanks.
Like (0) S B Sep 20, 2013 6:16 PM (in response to James Wood)
Hi James, This blog seems very helpful, so I'd like to start at the beginning of the series. Unfortunately the link in your first paragraph is broken. Any idea where I can find it? Thanks, Eric
Like (0) Manish Kumar Sep 19, 2013 10:21 AM (in response to Eric Peterson)
It looks like the blogs were originally posted in personal space, and then moved to ABAP Development space. Here are the correct links. Navigating the BOPF: Part 1 - Getting Started Navigating the BOPF: Part 2 - Business Object Overview Navigating the BOPF: Part 3 - Working with the BOPF API Navigating the BOPF: Part 4 - Advanced BOPF API Features Navigating the BOPF: Part 5 - Enhancement Techniques Navigating the BOPF: Part 6 - Testing & UI Integration
Like (1) Andrew Hampton Oct 9, 2013 5:17 PM
Hi James Great blogs, starting to give me some understanding of BOPF. I have a question though. I have a requirement for my client for a monster "super query" against the EHHSS_INCIDENT business object which basically would allow them to query all Incidents by any combination of any selection criteria from any nodes! I have already told them I think this is out of the question. However I want to at least be able to give them something. My main challenge is that it seems that Queries are attached to nodes, but what I really want is a cross-node query. For example there is one node called "Persons involved" (table EHHSSD_INC_PINV) and another node called "Person Role" (table EHHSSD_INC_PROLE). This would allow me to query the persons involved
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api 19/20
11/2/2014
in an Incident (selecting by John Smith for example) or the roles of people involved in an incident (eg Witness). But what it does not allow me to do is to query the Incidents where John Smith is a Witness. To do that I have to use a foreign key relationship in a GUID on EHHSSD_INC_PROLE to point to the DB_KEY on EHHSSD_INC_PINV. So my main question is: Is it possible to do cross-node queries? If so how? I thought about creating a database view as a join of the two tables, but then I don't know how to hook this database view onto the BO processing framework and how to attach queries to it. Or is the way of having a transient structure which is a join of the two tables & somehow hook this into database retrieval & queries. Would really appreciate some guidance on this. Thanks Andy
Like (0) James Wood Oct 10, 2013 5:21 PM (in response to Andrew Hampton)
Hi Andrew, To answer your question: yes. For your specific use case(s), I think the approach would be to create custom queries. So, for example, if you want to create a query in which you pull all incidents where John Smith is a witness, I think you'd simply want to create a custom query against the ROOT node. Here, you'd have a data structure to capture the selection criteria (e.g. person name and role) and a custom class to implement the query logic using a SQL JOIN. A decent example of this would be the SELECT_BY_OSHA_CRIT query defined against the PERSON_INVOLVED node. Hope this helps. Thanks, James
Like (0) Andrew Hampton Oct 11, 2013 3:03 PM (in response to James Wood)
Thanks James, good to know it is possible. I'll be giving it a try over the next few days.
http://scn.sap.com/community/abap/blog/2013/01/16/navigating-the-bopf-part-3--working-with-the-bopf-api
20/20