Вы находитесь на странице: 1из 42

Greetings.

The present blog is only the adaptation of another one I wrote before. Unfortunately,
changing consulting jobs gives farewell to a SCN account to welcome a new one at the new
assignment. With that and not having a possibility that SAP consolidates content created by
the same individual, or having access to old SCN accounts, do not allow to easily update
blogs. Hopefully one day … one day.

This is an update of blog: https://blogs.sap.com/2014/01/24/basic-brfplus-example-to-


confirm-if-an-employee-is-a-team-lead-manager-or-not/

Functional and technical SAP users sometimes do not have a SAP Developer Key, which
refrain them from having access to write basic ABAP code to explore particular scenarios,
themselves. BRFPlus is a tool still for which there is no needed a SAP Developer Key. That
fact provides some freedom to us, non-SAP-Developers, who still have basic SQL or SAP
Query experience.

Scenario of this blog.

1. We want to confirm if an Employee (EE), who is also a Business Partner (BP), is a


Manager of an Organizational Unit. Using BRFPlus we will conclude with the use of
DB lookups and a final Boolean variable if the EE entered is Manager (1) or not (0).
2. We will add the BRFPlus call within an ABAP program.

In order to achieve that, we divided the blog in three parts:

Part 1, shows the HR piece of information.

Part 2, how to create the BRF+ Function.

Part 3, how to test out and how to call the function in an ABAP program.

Let’s begin.

1. The HR abouts.

In SAP HR, a relationship A012 defines if an EE is Manager.

In Part 2 of one of our previous blogs we explained in step 5 how the HR data is stored in
Solution Manager: http://scn.sap.com/community/it-management/alm/solution-
manager/blog/2014/01/22/sap-crmsolman-charm-multiple-target-agents-via-sap-workflow–
minimal-abap-development–part-2

In HR in general, data reflected in the Org Structure and displayed via transactions like
PPOMA_CRM, and is stored in tables HRP1000 and HRP1001, respectively. Let’s see with
an example.

1.1 To retrieve the records we start with a BP number (BP 233), which is stored in field
SHORT of table HRP1000. The entry found contains in field OBID the correspondent CP
(Central Person) number associated to that BP.
1.2 With that we can now search in table HRP1001 for a record which Object ID (OBJID)
matches the one we retrieved in the step before. From the records found, we pick up the one
with SCLAS = S (Position). From that record, we retrieve the content of field SOBID. That
is the S (Position) the BP holds.

1.3 Once more we search in table HRP1001, where ObjectID = the SOBID entry found
above. If among the records retrieved, there is an active entry (BEGDA and ENDA), with
SUBTY = A012, we conclude that the S (Position) we have is Manager of the Org Unit,
found in field SOBID.

Note: In other words, we followed the path CP-S-O (Central Person to Position to Org.
Unit), to get to know if a BP is Manager of an Org. Unit.

2. Create the BRFPlus scenario.

The BRFPlus function receives a BP number and provides an output in a Boolean variable
confirming whether the entered BP is a Manager (1) or not (0).

2.1 Launch transaction BRFPLUS.

2.2 Create a container where all your BRFPlus developments will be stored.
Provide some basic information, like package name and save and activate (always).
2.3 Create the Function.

With the cursor in the new folder, right click and create a function.

Note: Core objects in BRFPlus are functions. You can create many additional objects to
support a function like rules, actions, data objects, expressions, etc., but the only elements
that interact with the exterior (ABAP Programs, Services calls, etc.), are Functions.

Select the Tab Signature and add the Import Parameter.


Now add the Export Variable.
Things should look like this, so far: A function with a input and output variables.
2.4 Data retrieval. In the same tab Signatures, Select Mode > Function and Event Mode.
In the new line that appears below, click the little square below and select create [Top
expression]
The top expression that we are about to create is the gate we use to enter the HR tables. It is
the first select statement.
A list of things to keep in mind:

 Making objects Reusable is a very handy and saves a lot of time in the future.
 We are not attaching all the screens, as there are many that question you if you want
to save the parent object. Always answer yes to those questions.
 The key to populate most of the fields below is achieved by clicking the little triangles
on the side of the field to search or pick the possible value that fits your needs.
 Keep in mind also the mapping you should enter almost every time. That is reflected
at the bottom of the picture below. It is quite easy to forget about mapping. You
always need to expand mapping if it is not displayed by default.

Time to create the 1st data retrieval.


Save your changes for now. The 1st type of the retrieval is completed.

Press the back button of the object to continue.

Now we create a Ruleset.


After this, we will add two rules: one to retrieve the S (Position), and the other one to confirm
that the S found is a Manager or Not.

Note: This area is possible one of the trickiest pieces of BRF+. It is not straight forward how
to create the select statements and a lot of test and trial may be required up until you are able
to control the beast and know how to properly insert the correct SQLs statements. Just be
patient when doing the work fo the first time. It will eventually click in.

Click the Insert Rule button > Create.


and so on and so forth ..
Select from the available fields FINALOBJECT.

In Mapping assigned the select to Source Field SOBID, then Check, Save, and Activate.
If you press the Back button you will see that the 1st rule is completed. Let’s finish the same
way by Inserting the second rule.
The screen will look like this for now. Click on LOOK4MGR.
The processing is the same as before, so we only attach the final screen.
Go back the ruleset.

We continue completing the SQL statements to complete the exercise and test the solution.
Same way with the Else

To complete the whole statement like this:

Note: If by any chance a rule is not in the right order as in the case below, pick it up and
move it up or down:
Now that the rules are in the right execution order, check, save, and activate. Remember to
confirm any message to activate any depending or referenced objects.
Your Function is ready for testing. Double-click on it and press the Simulation button.
There are different flavors in the simulation that you may want to explore on your own in the
future. For now, let’s follow the happy path:
We will use the same BP we manually used at the beginning of this blog, so that we can
confirm the intermediate steps all come up to extract the same data. Note that you can also
import data from an external file to test your function.
The result shows that the entered BP is a Manager. The nice thing about the step by step
simulation is that you can see what happened at each step, the intermediate results and
evaluate if you need to fix something if the processing is broken somewhere between the
begin and the end.
As you can confirm also via transaction PPOMA_CRM, the BP 233 is a Manager, so the
function is correct. The little man with the hat represents a manager ob the object
immediately above.
We can also quickly testing the function with BP 663, which is not a manager, so the result
will be False. That BP is not a Manager.

Part 3. How do I use the BRFPlus function externally?

There are various uses, among the three most common: you can Generate a Function Module
(RFC), a Web Service, or simply call the function from an ABAP Program.

For the first two:


In order to use it in a program, by expanding the General section, if not expanded, you need
to grab the ID, which is the piece to be used when called by ABAP.
All the code below is standard, hence you need to define all the variables exactly as
mentioned below. The only elements we provided are the ones in bold characters:

The BRFPlus unique identifier: 3EF6AD60D5021EE7AEE163935BA2C766.

The BRFPlus Input Parameter name: BP_INPUT

The BRFPlus Input Parameter variable: lv_rfcrequester type crmt_partner_no

The BRFPlus Output variable: lv_ismanager type boolean.

You will need to add the code below to your ABAP program.

data: lo_factory type ref to if_fdt_factory,

lo_function type ref to if_fdt_function,

lo_context type ref to if_fdt_context,

lo_result type ref to if_fdt_result,

lv_result_string type string,

lx_fdt type ref to cx_fdt.


* Init BRFPlus

lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance( ).

lo_function = lo_factory->get_function( iv_id =


‘3EF6AD60D5021EE7AEE163935BA2C766‘ ).

try.

lo_context = lo_function->get_process_context( ).

lo_context->set_value( iv_name = ‘BP_INPUT’ ia_value = lv_rfcrequester ).

lo_function->process( exporting io_context = lo_context

importing eo_result = lo_result ).

lo_result->get_value( importing ea_value = lv_ismanager ).

catch cx_fdt into lx_fdt.

loop at lx_fdt->mt_message assigning <ls_message>.

write / <ls_message>–text.

endloop. endtry.

* End of BRFPlus

Finally, time for desert.

Some bibliography for you.

1. BRFPlus – Business Rule management for ABAP Applications.

http://www.sap-press.com/products/BRFplus-%E2%80%94-Business-Rule-Management-for-
ABAP-Applications.html

2. BRFPlus. There is this 1-2 days training in BRFplus you can get for free. Excellent
material, well organized. There are 3 sessions that tell you how that works.

http://scn.sap.com/docs/DOC-8824?rid=/webcontent/uuid/90754865-f283-2b10-6d9f-
b10f3c28c3a0

Enjoy,
Juan-Carlos

Вам также может понравиться