Reading
Reading
Thomas Schneider
Bonn Boston
367.book Seite 5 Montag, 3. Oktober 2011 6:08 18
Contents at a Glance
Contents
Foreword ......................................................................................... 15
About This Book ............................................................................... 17
Introduction ..................................................................................... 21
7
367.book Seite 8 Montag, 3. Oktober 2011 6:08 18
Contents
8
367.book Seite 9 Montag, 3. Oktober 2011 6:08 18
Contents
9
367.book Seite 10 Montag, 3. Oktober 2011 6:08 18
Contents
10
367.book Seite 11 Montag, 3. Oktober 2011 6:08 18
Contents
11
367.book Seite 12 Montag, 3. Oktober 2011 6:08 18
Contents
12
367.book Seite 13 Montag, 3. Oktober 2011 6:08 18
Contents
13
367.book Seite 234 Montag, 3. Oktober 2011 6:08 18
왘 Context
Provides context information, such as the current time in the time
zone of the user, the language, or the Identity UUID of the user that is
currently logged on.
왘 Date, GlobalDateTime, LocalDateTime, Duration
Contain functions for comparing and for simple calculations and
some other useful functionality for dates, global and local time points,
and durations.
왘 CurrencyConversion, QuantityConversion
Contain functions for simple calculations, for comparing and for con-
verting currency-based amounts and quantities.
왘 Numeric, Boolean, ID, Code, UUID, Binary
Provide functions such as a check if a value is initial and a conversion
to/from string.
5.2.1 Transaction
A transaction consists of two phases: During the interaction phase, data
is retrieved and entered, and actions are executed on the business
object. In the save phase, the system performs last determinations and
checks and writes the changed data to the database.
Interaction phase Figure 5.1 shows the process flow of user activities that are triggered in
the interaction phase. If the UI triggers a query, the data is read directly
from the database and search engine. For a retrieve operation, the busi-
ness object buffer is checked first, before data is retrieved from the data-
base and search engine.
234
367.book Seite 235 Montag, 3. Oktober 2011 6:08 18
If data is changed via an action triggered by the UI, the business object
framework acquires a lock for the business object instance, and the
AfterModify and/or the action coding is processed. The AfterModify
event is processed after an action if the coding of the action changed
data of the business object. If data is changed on the UI and an action is
triggered, the AfterModify event is called before and after the action
coding.
Retrieve
or Query
Check Buffer
(Retrieve)
Retrieve
or Query
Change Buffer
(Retrieve)
Display Data
Change Data,
or Action
Acquire Lock
Change Buffer
After Modify,
or Action
Change Buffer
Display Data
Figure 5.2 shows the save phase of a transaction’s lifecycle. In the Before- Save phase
Save event, business objects can still call other services that may change
the state.
235
367.book Seite 236 Montag, 3. Oktober 2011 6:08 18
We recommend using the option to stop the save sequence with care
and only in cases of a severe inconsistency. Instead, a business object
should be saved even in an inconsistent, draft, or “prima nota” status.
Save
Loop at Objects
BeforeSave
Loop at Objects
CheckBeforeSave
Save Not
Possible Loop at Objects
Outbound Processing:
Display Error Loop at Objects
Message
Condition Evaluation
Outbound Processing:
Compile XML Messages
Trigger Database Save
Save and
Commit
Release Locks
Data Saved
Events The business object framework provides the following events that can
be implemented with script coding:
236
367.book Seite 237 Montag, 3. Oktober 2011 6:08 18
5.2.2 Locks
Locks are required to ensure that only one user at a time can change a
particular objects’ content consistently.
To book a vacation, you must check that all necessary components are Example
available: flights, hotels, bus or boat transfers, and so on. The “all or
nothing” principle applies: If no flights are available, you will not need
a hotel room and so on. Since you usually check the availability of the
various components one after the other, you want to be certain that
237
367.book Seite 238 Montag, 3. Oktober 2011 6:08 18
another user doesn’t change any of the items in the sequence before the
entire booking is completed.
Database locks When we are talking about transactions and locks in this section, we
refer to transactions and locks that are managed by the business object
engine of SAP Business ByDesign. The database system also manages
transactions and locks, but these are only used during a very short time
frame when the business object engine saves the business object
changes on the database in the save phase. Database locks are never used
to lock objects through several user interaction steps.
Application locks To lock business object instances through several user transaction steps,
the business object engine of SAP Business ByDesign manages locks
using a central lock server (also called enqueue server) that serves lock
requests for all application servers.
Rules for The following rules apply for transaction and lock handling:
transaction and
lock handling 왘 Queries are always directly served by the database and search engine.
Changes that are made on the business object buffer are not reflected
in the result of a query. This rule applies not only for different trans-
actions, but also within a transaction.
왘 Object-based navigation opens a new transaction. Data that has not
been saved on the database is not visible in the new transaction. In
the site reservation example, a sales order is created when the site res-
ervation is released. If you open the sales order link without saving
the site reservation first, the newly created sales order is not found;
the sales order UI will not terminate but will be empty. You can avoid
this behavior, which users might recognize as an error: Using fron-
tend scripting in the UI allows you to dynamically deactivate the link
if the site reservation is not saved.
왘 The lock behavior is determined by the UI:
왘 The default lock behavior for UIs is the optimistic locking. Objects
are locked as soon as the first round-trip with changed data is pro-
cessed. Opening an object in edit mode does not lock an object. If
you open a site reservation by clicking Edit on the object work
list, it is not yet locked. If you or a second user opens the same
reservation and changes data, the lock will be granted to the sec-
ond transaction. If you as the first user, having opened the site
238
367.book Seite 239 Montag, 3. Oktober 2011 6:08 18
reservation without changing it, try to change the object now, the
lock handler raises an error.
왘 You can also set the lock behavior in the UI (property LockBehav-
ior of a data list) to “exclusive.” In this case, the lock will be set as
soon as the object is read the first time.
왘 If the lock behavior in the UI is set to “read-only,” no change locks
are set and therefore no change operations can be performed.
왘 Locks are set on the object level. If a site reservation is locked, you
cannot add a new instance of the subnode Additional Services from
another transaction. There are some exceptions to this rule for SAP-
delivered business objects.
import ABSL;
// initialization sequence
if ( this.ReleaseStatusCode.IsInitial()) {
this.ReleaseStatusCode = "1";
this.SalesProcessingStatusCode = "1";
if ( this.OriginSiteReservationID.IsInitial() ) {
// (1) normal creation (no copy)
this.ArrivalDate = Context.GetCurrentUserDate();
this.DepartureDate = this.ArrivalDate.
AddDuration(Duration.ParseFromString("P1D"));
}
else {
// (2) Copy
this.Copy();
}
}
239
367.book Seite 240 Montag, 3. Oktober 2011 6:08 18
The coding starts with the import of the namespaces of the SAP Business
ByDesign Scripting Language tools library (import ABSL).
The next coding part is the initialization sequence. It starts with the
statement if (this.ReleaseStatusCode.IsInitial()) and continues
with statements for setting the default values for the status variables.
240
367.book Seite 241 Montag, 3. Oktober 2011 6:08 18
After the initialization sequence, the coding calls the Check action 3. It Checks
is assumed that every business object has a basic set of checks. During
modify, all “local” checks are performed on the nodes that are changed
or change as a side effect. However, checks that are performance critical
are usually not performed in this event. These checks are usually per-
formed in a separate Check action, for example, before an object is
released. In our example, we do not distinguish between performance-
critical and non-critical checks. The Check action is executed in every
AfterModify event.
The next coding block 5 sets the name of the site reservation. The last
part of the coding 6 determines the SiteReservationStatus (also intro-
duced as UI status in Section 3.5.2; see also Table 3.1).
Before Image
The implementation of the AfterModify event as presented in Listing 5.8 has
two disadvantages:
왘 “Expensive” activities, such as the Check action and the update of the sales
order (MaintainSalesOrder action) are executed even if the relevant
input data did not change. This may lead to a performance impact.
왘 The business object itself cannot reject input data, such as a change of the
arrival and departure date after the confirmation of the reservation.
241
367.book Seite 242 Montag, 3. Oktober 2011 6:08 18
1. Define business elements for all input fields that are relevant for the before
image (in our example, for arrival and departure data, site ID, and account
ID).
2. In the AfterModify event, compare the “current” elements with the before
image elements (if (this.ArrivalDate != this.ArrivalDateBe-
fore)). If the current image and the before image are equal, no action has
to be taken. If they differ, the implementation must:
import ABSL;
import AP.FO.BusinessPartner.Global;
var qySiteRes = SiteReservation.QueryByElements;
var selParSiteRes = qySiteRes.CreateSelectionParams();
var found;
var customer;
// (1) set default: consistency status = Consistent (3)
this.ConsistencyStatusCode = "3";
// (2) check date
if ( this.ArrivalDate.IsInitial() ||
this.DepartureDate.IsInitial() ||
this.ArrivalDate.GreaterEquals(this.DepartureDate)) {
this.ConsistencyStatusCode = "2";
raise NoValidPeriod.Create("E");
}
// (3) check site
if ( !this.ToSite.IsSet() ) {
this.ToSite.Reset();
this.ConsistencyStatusCode = "2";
raise NoValidSite.Create("E");
}
// (4) map & check account
if ( !this.MaintenanceIndicator ) {
242
367.book Seite 243 Montag, 3. Oktober 2011 6:08 18
found = false;
if (this.AccountID != "") {
customer = Customer.Retrieve(this.AccountID);
if (customer.IsSet()) {
this.ToAccount = customer; found = true;
}
else {
this.ToAccount.Reset(); found = false;
}
}
else {
this.ToAccount.Reset();
}
}
if ( this.AccountID == "" || !found ) {
this.ConsistencyStatusCode = "2";
raise NoValidAccount.Create("E");
this.AccountID = "";
}
// (5) check site availability
if ( this.ConsistencyStatusCode == "3" ) {
selParSiteRes.Add(qySiteRes.ToSite, this.ToSite);
selParSiteRes.Add(qySiteRes.ReleaseStatusCode, "I", "EQ",
"3");
selParSiteRes.Add(qySiteRes.ArrivalDate, "E", "GE",
this.DepartureDate);
selParSiteRes.Add(qySiteRes.DepartureDate, "E", "LE",
this.ArrivalDate);
selParSiteRes.Add(qySiteRes.ID, "E", "EQ", this.ID);
if (qySiteRes.Execute(selParSiteRes).Count() > 0){
this.ConsistencyStatusCode = "2";
raise SiteAlreadyReserved.Create("E");
}
}
The coding starts with imports of the namespaces of the SAP Business
ByDesign Scripting Language tools library (import ABSL) and of the SAP
business partner and identity management. The next lines are defini-
tions of the required variables.
243
367.book Seite 244 Montag, 3. Oktober 2011 6:08 18
Check of arrival The next part of the coding 2 checks if arrival and departure data are
and departure data entered correctly.
Site ID check The following coding block 3 is the ID check for the site. The business
object Site exposes a human-readable ID as an alternative key. This
means the association to the site can be set directly by the consumer, by
exposing the element SAP_ToSite as an input field on the UI. The valida-
tion of the input is done by the statement if (this.ToSite.IsSet()).
This statement checks if a site with the ID that has been specified in the
input field really exists. If not, the association ToSite is cleared and a
message is raised.
Account ID check The next coding block 4 is the ID mapping and check for the account.
Please look at the differences between this coding block and the previ-
ous check for the site: The human-readable ID of the Customer business
object (InternalID) is not exposed as a stable alternative key, so it can-
not be used to define the association directly. Instead, a separate ele-
ment (AccountID) is used as an input field on the UI that contains the
human-readable ID of the account. In the coding the input needs to be
verified. For this purpose, a Retrieve is performed. If a result is found,
the association to the respective instance of the customer business
object is set. If no matching customer is found, the element AccountID is
cleared and a message is raised.
Site Availability The last coding block 5 checks if a selected site is actually free. The cod-
Check ing is very similar to the coding used in the action GetAvailableSites.
We will explain this coding in the section on this action below (see Sec-
tion 5.3.5, “Status Action: Start Sales Processing“).
var originSiteRes =
SiteReservation.Retrieve(this.OriginSiteReservationID);
244
367.book Seite 245 Montag, 3. Oktober 2011 6:08 18
if (originSiteRes.IsSet()) {
this.AccountID = originSiteRes.AccountID;
this.ArrivalDate = originSiteRes.ArrivalDate;
this.DepartureDate = originSiteRes.DepartureDate;
}
else {
// code block: error handling
<...>
}
The implementation of the Release action of the Site Reservation busi- Release action
ness object is very simple. It looks like:
245
367.book Seite 246 Montag, 3. Oktober 2011 6:08 18
The precondition check 1 evaluates the values of the consistency and the
release status as defined in the status and action model (Chapter 3, Figure
3.5). In the second (execution) part 2, the release status is set to
“Released (3).” If the precondition is not fulfilled, appropriate error mes-
sages have to be raised. If the site reservation is not consistent, the easiest
solution is to execute the Check action, which will raise the appropriate
error message. If the release status is not “Released,” an appropriate mes-
sage has to be defined.
246
367.book Seite 247 Montag, 3. Oktober 2011 6:08 18
this.SalesProcessingStatusCode = "2";
// In process
}
}
}
}
else {
// (3) raise messages
< ...>
}
247
367.book Seite 248 Montag, 3. Oktober 2011 6:08 18
else {
this.MaintainSalesOrder();
this.ToSalesOrder.
FinishFulfilmentProcessingOfAllItems();
if ( this.ToSalesOrder.Status.ConsistencyStatusCode !=
"3" || this.ToSalesOrder.Status.
ItemListFulfilmentProcessingStatusCode != "3" ) {
this.SalesProcessingStatusCode = "5";
// Interrupted
}
else {
this.SalesProcessingStatusCode = "3"; // Finished
}
}
if ( this.SalesProcessingStatusCode == "5" ) {
raise SalesOrderCreationError.Create("E");
}
}
else {
// (3) raise messages
< ...>
}
The action implementation updates the sales order by calling the action
MaintainSalesOrder and calls the action FinishFulfilmentProcessing-
OfAllItems on the Sales Order. This action sets the fulfillment process-
ing status of all items in the sales order to “Finished.” If the processing
was successful, the sales processing status of the site reservation is set to
“Finished,” too. If an error occurs, the status is set to “Interrupted.”
248
367.book Seite 249 Montag, 3. Oktober 2011 6:08 18
The action GetAvailableSites fills the node Available Site based on the
arrival and departure date specified in the site reservation:
import ABSL;
var allSites;
var reservations;
var newSite;
var qySiteRes = SiteReservation.QueryByElements;
var selParSiteRes = qySiteRes.CreateSelectionParams();
var found;
// (1) check date
if ( this.ArrivalDate.IsInitial() ||
this.DepartureDate.IsInitial() ||
this.ArrivalDate.GreaterEquals(this.DepartureDate)) {
raise NoValidPeriod.Create("E"); }
else {
// (2) delete AvailableSites nodes
foreach ( site in this.AvailableSites ) {
site.Delete();
}
// (3) get all sites
allSites = Site.QueryByElements.Execute();
// (4) get all reservations in booking period
selParSiteRes.Add(qySiteRes.ReleaseStatusCode, "I", "EQ",
"3");
249
367.book Seite 250 Montag, 3. Oktober 2011 6:08 18
After checking the validity of the date period 1, the next coding block
2 deletes the instances of the Available Site node.
The availability check follows. The first step of the availability check
(coding block 3) reads all sites into the variable allSites. The next step
4 checks for released site reservations in the time period between the
arrival and the departure date. If no reservation is found, the site is free
and is added to the node Available Site.
this.ToParent.ToSite = this.ToAvailableSite;
250
367.book Seite 251 Montag, 3. Oktober 2011 6:08 18
import ABSL;
import AP.CRM.Global;
var elSO : elementsof SalesOrder;
var newSO;
var newSOItem;
var elSOItem : elementsof SalesOrder.Item;
var quantity;
// (1) check if consistent
if ( this.ConsistencyStatusCode == "3" &&
( this.SalesProcessingStatusCode == "1" ||
this.SalesProcessingStatusCode == "2" ||
this.SalesProcessingStatusCode == "5" ) &&
!this.MaintenanceIndicator ) {
// (2) check service product
if ( this.ToSite.ToSiteCategory.IsSet() ) {
if ( this.ToSite.ToSiteCategory.
ToDefaultServiceProduct.IsSet()) ){
// (3) check if SO is already created
if ( !this.ToSalesOrder.IsSet() ) {
// (4) create sales order
elSO.Name.content = this.Name;
newSO = SalesOrder.Create(elSO);
if ( newSO.IsSet() ) {
this.ToSalesOrder = newSO;
raise SalesOrderCreated.Create("S",
this.ToSalesOrder.ID);
// (5) party node is created automatically
// – maintain buyer party (account)
251
367.book Seite 252 Montag, 3. Oktober 2011 6:08 18
newSO.BuyerParty.PartyKey.PartyID.content =
this.AccountID;
// (6) create item node, enter item product
elSOItem.Description.content = "MAIN";
newSOItem=this.ToSalesOrder.Item.Create(elSOItem);
newSOItem.ItemProduct.ProductKey.ProductID.content
= this.ToSite.ToSiteCategory.
ToDefaultServiceProduct.InternalID.content;
// (7) enter quantity
if ( newSOItem.
FirstRequestedItemScheduleLine.IsSet()) {
quantity = Date.Delta(this.DepartureDate,
this.ArrivalDate).ConvertToDays();
newSOItem.FirstRequestedItemScheduleLine.
Quantity.content = quantity;
}
// (8) enter service duration
if (newSOItem.ItemServiceTerms.IsSet()){
newSOItem.ItemServiceTerms.
ServicePlannedDuration = Duration.
ParseFromString( (quantity * 24).ToString());
}
}
}
else {
// (9) update existing sales order
<...>
}
// (10) check the sales order´s consistency
if ( this.ToSalesOrder.Status.ConsistencyStatusCode
!= "3") {
raise SalesOrderCreationError.Create("E");
}
}
}
else {
// (11) raise error msg: no service product / resource
}
}
else {
// (12) raise error msg: site reservation not consistent
}
252
367.book Seite 253 Montag, 3. Oktober 2011 6:08 18
The initial if clause 1 checks the consistency and the sales processing Initial checks
status of the site reservation. If the object is not consistent or the sales
processing is already completed, the remaining coding is not processed.
It also checks 2 that the category of the selected site is set and has a ser-
vice product and a resource assigned, which is required to fill the sales
order, and that the site reservation is not created for maintenance pur-
poses.
Note
Please note that for a statement with chained associations
(<...>.ToSite.ToSiteCategory.ToDefaultServiceProduct.<...>) you
have to check the existence of the association at runtime on each level. If one
of the associations is not set, the program will terminate. The IsSet method
checks the existence of only the last association in the chain.
The statement if ( newSalesOrder.IsSet() ) 3 opens the two branches Five steps of Sales
(code blocks 4 and 9) for creation and update of the sales order. The Order creation
253
367.book Seite 254 Montag, 3. Oktober 2011 6:08 18
Note
You can see from this example that the business object service provider auto-
matically creates subnode instances on creation of a super-ordinate node
instance, in our example, the Party, the Item Product and the Item Schedule
Line node. In this case you must not create these node instances with a Cre-
ate operation—this would lead to a corrupt object. On the other hand, you
need to check if the expected instance is really created using the IsSet oper-
ation on the association. In case of an error, the service provider may not cre-
ate the subnode instance automatically. Accessing a nonexistent node
instance from your coding will lead to a program termination.
Sales Order update The update branch 9, which is not shown in the listing, consists of three
steps:
Finally the action checks the consistency of the sales order j. If the sales
order is not consistent, the sales processing status is set to error status 5
(Interrupted) and messages are raised k, l.
254
367.book Seite 255 Montag, 3. Oktober 2011 6:08 18
The booking period must be open (see work center General Ledger, function
Open and Close Booking Periods).
import ABSL;
import AP.PC.IdentityManagement.Global;
var identity;
var datetime;
// (1) delete AvailableSites nodes
foreach ( site in this.AvailableSites ) {
site.Delete();
}
identity =
Identity.Retrieve(Context.GetCurrentIdentityUUID());
datetime = Context.GetCurrentSystemDateTime()
.ConvertToGlobalDateTime();
255
367.book Seite 256 Montag, 3. Oktober 2011 6:08 18
if ( this.CreationDateTime.IsInitial() ) {
// (2) Creation date/time, user
this.CreationDateTime = datetime;
if ( identity.IsSet() ) {
this.CreationIdentity = identity; }
}
else {
// (3) Last changed date, time, user
this.LastChangedDateTime = datetime;
if ( identity.IsSet() ) {
this.ToLastChangedIdentity = identity; }
}
if ( !identity.IsSet() ) {
// error handling
}
The first code block 1 deletes the instances of the transient Available
Site node.
The second and third coding blocks set the information about the
creation date/time and user 2 or about the last changed date/time and
user 3.
256
367.book Seite 257 Montag, 3. Oktober 2011 6:08 18
the add-on developer, who can analyze the trace file in SAP Business
ByDesign studio.
The trace will help you to answer the following questions: Trace features
왘 Has a particular script been executed at all, and have the scripts
been executed in the expected order?
The trace automatically logs the execution of each script. This may be
helpful, especially in case of nested action calls and when scripts on
different nodes are involved in a round-trip.
왘 What was the instance a script was executed on?
The trace logs the identifier (UUID) or—if available—the alternative
key of the node that is represented by the this pointer in a script.
왘 Which messages have been raised during execution?
Every message that is raised by a business object operation that is
called during processing is logged. This is especially important when
working with SAP business objects.
왘 What was the result of a retrieve operation?
The trace logs the UUID or—if available—the alternative key of the
result of a retrieve operation.
왘 Which associations has the script accessed?
For every association that is accessed, the trace logs the identifier
(UUID) or—if available—the alternative key of the accessed node.
왘 What was the result of a query?
The number of records that were returned by a query execution is
logged in the trace. This information gives you a hint that something
might have gone wrong if you expect a result from the query and
nothing was returned or if you expected exactly one result record, but
many have been delivered.
import ABSL;
Trace.Error(“Creation failed”);
257
367.book Seite 258 Montag, 3. Oktober 2011 6:08 18
The Trace class has two methods: the Error method reports an error to
the trace; the Info method indicates information. In brackets, you can
provide one or two arguments of type String.
Tutorial: Creating To create a trace for your development user and to analyze the trace,
and analyzing a proceed as follows:
trace
1. Enable the Trace Explorer.
In the SAP Business ByDesign studio menu, select View Toolbars
Trace Explorer. The Trace Explorer toolbar appears.
2. Activate the trace.
In the Trace Explorer toolbar, click Activate Trace. Execute the UI
that you want to test.
3. Deactivate the trace.
In the Trace Explorer toolbar, click Deactivate Trace.
4. Open the Trace Explorer window.
In the Trace Explorer toolbar, click Show Trace Explorer. The Trace
Explorer appears in the side window (see Figure 5.3).
5. Open a trace.
In the Trace Explorer window, navigate to the Local Traces tab, and
click Refresh Traces. The list of traces that are available in the tenant
is displayed, identified by the time the trace was started and the ID of
the user executing the UI (see Figure 5.3). Select a trace and click Get
Trace Details.
6. Analyze the sequence of events.
In the lower window of the Trace Explorer, labeled as Sequence
Explorer in Figure 5.3, the sequence of the traversed events is dis-
played in a hierarchical tree. Figure 5.3 shows the sequence of the
258
367.book Seite 259 Montag, 3. Oktober 2011 6:08 18
259
367.book Seite 260 Montag, 3. Oktober 2011 6:08 18
Enable tracing for a Tracing can be enabled for another business user. This can be necessary
business user when a sequence should be traced for a user who has no access to SAP
Business ByDesign studio but is used for testing the SAP Business ByDe-
sign UI in the final work center. To enable the trace for another user, in
the SAP Business ByDesign studio menu select Tools Options SAP
General. Navigate to the Tracing tab. Enable the tracing for a business
user by entering the business user’s name.
Number range Number ranges assign a serial number that forms a unique human-read-
able key, either alone or with supplementary information (such as an
organization or a fiscal year). A number range assures that previously
assigned numbers are not reissued. A number range contains a number
range interval with a set of permitted characters. The number range
interval is made up of numerical or alphanumeric characters and is lim-
ited by the From-Number and To-Number fields.
260
367.book Seite 261 Montag, 3. Oktober 2011 6:08 18
A reuse service for number ranges is not supported in version FP3.0 of Implementation of
SAP Business ByDesign studio. The following workaround may be used. a Number Range
object
The implementation of a number range service consists of the following
steps:
For the definition of the Number business object, you may use the fol-
lowing coding:
261
367.book Seite 262 Montag, 3. Oktober 2011 6:08 18
왘 NextID element
This element represents the next free number in the interval con-
verted to an element of type ID.
왘 Changed element
This is the indicator for internal processing (see explanation below).
왘 GetNext action
This action increases the number range counter.
You can extend the Number business object, for example, by elements
that define the first value in a number range, that define a prefix, and so
on.
GetNext action The following listing shows the implementation of the GetNext action of
the Number business object:
// Action: GetNext
import ABSL;
this.NextNumberValue = this.NextNumberValue + 1;
this.NextID = this.NextNumberValue.ToString();
Listing 5.19 Implementation of the GetNext Action of the Number Business Object
BeforeSave event The following listing shows the implementation of the BeforeSave event
of the Number business object:
// Event: BeforeSave
this.Changed = false;
Listing 5.20 Implementation of the BeforeSave Event of the Number Business Object
Coding in the The following listings show the implementation of the BeforeSave event
consumer of the consumer business object, in our example the Site Reservation:
business object
// get number
var qyNumber = Number.QueryByElements;
var selParNumber = qyNumber.CreateSelectionParams();
var number;
var found = false;
// (1) check is ID is initial
if (this.ID.IsInitial()) {
selParNumber.Add(qyNumber.RangeIntervalName, "I", "EQ",
"SITERESERVATION");
number = qyNumber.Execute(selParNumber).GetFirst();
262
367.book Seite 263 Montag, 3. Oktober 2011 6:08 18
if ( !number.IsSet() ) {
// (2) number range interval does not exist -> create
number = Number.Create();
number.RangeIntervalName = "SITERESERVATION";
}
if ( number.IsSet() ) {
// (3) number range interval exists -> check if locked
number.Changed = true;
this.Flush();
if ( number.Changed ) {
// (4) successful -> get new number
number.GetNext();
this.ID = number.NextID;
}
else {
// (5) not successful -> raise message
raise NumberRangeLocked.Create("E");
}
}
else {
// (6) error message: No number range interval found
}
}
Listing 5.21 Implementation of the BeforeSave Event of the Consumer Business Object
(Site Reservation)
If the ID of the site reservation is initial (code block 1), a query is exe-
cuted to retrieve the instance of the Number business object that repre-
sents the number range interval that belongs to the Site Reservation busi-
ness object. If no interval is found 2, it is assumed that the number range
interval is not yet created, and the program tries to create a new one.
263
367.book Seite 264 Montag, 3. Oktober 2011 6:08 18
Late versus early If you implement the get number sequence at the end of the BeforeSave
locking of the event, it is very unlikely that a locking conflict occurs, because the time
number range
period between the lock acquisition in the BeforeSave event and the
release of the lock after the physical save on the database is very short.
We call this late locking. If you implement the get number sequence in
the AfterModify event, the number range interval will be locked for
other user sessions until the document is saved.
5.6 Summary
With SAP Business ByDesign Scripting Language, you can implement
business logic in business objects. It therefore refers to the global data
type system and to the business object model of SAP Business ByDesign.
The “atoms” of the language are literals, local variables, and static or
instance references to business objects. Path expressions explore the
hierarchy of a business object model (including associations between
business objects) or a structured data type. Based on these “atoms,”
assignment operations, arithmetic, logical, and conditional operations
can be defined. Control and loop statements are supported as well.
왘 AfterModify event
왘 BeforeSave event
왘 Application-specific actions
264
367.book Seite 265 Montag, 3. Oktober 2011 6:08 18
Summary 5.6
265
367.book Seite 475 Montag, 3. Oktober 2011 6:08 18
Index
500 Internal Server Error 408 Application and User Management work
center 360
A Application error 408
Application-specific query 75, 115, 129
Access rules 414 Approval scenario implementation 373
Account ID check 244 Approval task 372
ACID principle 234, 469 Approval Task Wizard 373
Action 101, 129 Arithmetic operations 338
Check 110 Assigned object, maintaining 190
Confirm Sales Processing 107 Assignment 213
Copy 110 Association 77, 85, 469
GetAvailableSites 110 Composition 77
Instance-based 221 Features 231
MaintainSalesOrder 106, 110 ToParent 251
Mass-enabled 221 ToSite 251
Nested 222 Asynchronous message-based communi-
Parameter 222 cation 69, 378, 379, 394
Pick in the Available Site 110 ATP check 70
Start Sales Processing 106 Attachment management 430
Submit for Approval (Cancel) 107 Authorization
Action evaluation 393 Read and write access 187
Activity diagram 105 Role-based 185
Activity list 267 Authorization check 188, 393, 400
Ad hoc output 358 Instance 188, 190, 191
Adaptation content 269 Instance implementation 191
Add-on solution 48, 66, 274, 283, 288, Start 188
327, 331, 352, 368, 431, 438, 458, 469 Authorization concept 208
Adaptation mode 290 Authorization policy 186, 188
Address data 426 Authorization profile 324
Address Snapshot business object 426 Avoiding a division by zero error 339
Administrator toolbar 466
Administrator user 442 B
Adobe LiveCycle Designer 48, 360, 465
Integrated version 367, 368 B2B (business to business) 54
Adobe Reader 50 B2B service 355
Adopting existing form templates 366 Background process 78
Analytical application 327 Background Processing 52, 53
Analytical data model 327 Basic find 113
Analytics 22 BC option 360
Analytics enabling node 346 BC set 270, 278, 283, 360
Analytics enabling object 346 Block 65
Analytics engine 51 Boolean and conditional operations 339
475
367.book Seite 476 Montag, 3. Oktober 2011 6:08 18
Index
476
367.book Seite 477 Montag, 3. Oktober 2011 6:08 18
Index
477
367.book Seite 478 Montag, 3. Oktober 2011 6:08 18
Index
478
367.book Seite 479 Montag, 3. Oktober 2011 6:08 18
Index
479
367.book Seite 480 Montag, 3. Oktober 2011 6:08 18
Index
K M
Key figure 328, 334 Main memory buffer 58
Basic 329 Main node semantic 124
Calculated 329, 337, 338 Mashup 50, 310, 325, 471
Calculation editor 338 Architecture 310
Counter 337 Category 311
Restricted 329, 337, 343 Configuration and integration 315
Selecting 329 Development 315
Key Figure Wizard 337, 343 Integrated authoring tool 314
Type 310
L Write-back 311
Mashups 31, 464
Lambda expression 217 Mass data run object (MDRO) 53, 78
LAN 471 Master data address 425
Leading business object 140 Master data object (MDO) 78
Learning Center 461 Master data, maintenance 254
Lifecycle management 34, 56, 435, 438, Mathematical operator 213
467 Message 75
Continuous improvement phase 435, Message-based communication 68, 378,
456 382, 414
Deployment phase 435, 447 Method tool tip 222
480
367.book Seite 481 Montag, 3. Oktober 2011 6:08 18
Index
481
367.book Seite 482 Montag, 3. Oktober 2011 6:08 18
Index
Platform tutorial R
Including the Address Snapshot 427
Including the Attachment Folder 430 Real-time analytics 327
Including the text collection 428 Relationship 39, 128
Port type package 133, 177, 312 Release action 245
Position business object 422 Relevance condition 357, 389
Precondition 101 Report Wizard 336, 346
Enabling 103, 248 Repository 48, 54, 74
Inhibiting 103, 248 View 42, 43
Required 104 Request business object 381
Requiring 248 Request/confirmation pattern 70, 393
Primary service provider 49 Reserved word 210
Primitive data type 89 Reset method 232
Process (or document) flow 38 Responsible manager 423
Process automation 27 REST (Representational State Transfer)
Process Communication Error 397 315
Process integration 53, 382, 388, 465 Result list 111
Definition 392 Retrieve method 226
Persistence 379 Retrieve operation 244
Process scenario, extensible 465 Reuse service 425, 433
Process variant 271 Rich Internet application (RIA) 50
Process-integrated output 358 RootQuantity 342
Programming language 209 RSS (Really Simple Syndication) 315
Properties window 43 Rules for transaction and lock handling
Prototype 40 238
Advanced prototype 41 Runtime tool 47
UI prototype 40
Public model 56, 71, 413, 466 S
Q Sales order 80, 383
Creation 253
Qualifier 124 Item 118
Quality review 450 Party 120
Request 451 Party role 120
Quality Review Questionnaire 450 Schedule line 119, 120
Query 111, 227, 238 UI 305
Default set 159 Update 254
Extension 296 Sandbox solution 439
Query operation 59, 405 SAP BI OnDemand 24
Query/response pattern 70 SAP Business ByDesign 23, 42, 53, 79,
Quick Activity Floorplan (QAF) 45, 63, 99, 107, 131, 165, 185, 207, 327, 413,
132 425, 436, 472
Architecture 286
Environment 437
Platform 433
Studio frontend 47, 54, 55
482
367.book Seite 483 Montag, 3. Oktober 2011 6:08 18
Index
483
367.book Seite 484 Montag, 3. Oktober 2011 6:08 18
Index
484
367.book Seite 485 Montag, 3. Oktober 2011 6:08 18
Index
485
367.book Seite 486 Montag, 3. Oktober 2011 6:08 18
Index
Web service definition language 403 Work center view 132, 183, 444
Web service endpoint 403, 408 Adding or removing 321
Web service engine 51 Authorization 401
Web service interface operation 409 Extension 322, 323
Web Service Provisioning Wizard 399 World Wide Web (WWW) 473
Web Service Reliable Messaging 404
While loop 215 X
Whitespace character 210
Wide area network (WAN) 473 Xcelsius 48
Wireframe 40 XML 473
Wiring 382 XML-based message 357
Work center 53, 131, 183, 208, 444
486