0% found this document useful (0 votes)
783 views36 pages

Sappress Abap An Introduction

This document discusses how to handle business data representing dates, times, quantities, and currencies in ABAP applications. It explains that as ABAP programs for large corporations need to work across time zones and currencies, the chapter covers calculating and converting dates and times, handling quantities with different units of measurement, and converting between currencies. It provides examples of using the date data type, adding and subtracting days from dates, and converting between date formats and units.

Uploaded by

fluture
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
783 views36 pages

Sappress Abap An Introduction

This document discusses how to handle business data representing dates, times, quantities, and currencies in ABAP applications. It explains that as ABAP programs for large corporations need to work across time zones and currencies, the chapter covers calculating and converting dates and times, handling quantities with different units of measurement, and converting between currencies. It provides examples of using the date data type, adding and subtracting days from dates, and converting between date formats and units.

Uploaded by

fluture
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

First-hand knowledge.

Browse the Book


Typical consumers of ABAP applications are large corporations with
operations spanning the globe. As a result, ABAP programs need to be
written with the expectation that they can handle working across time
zones and with different
different currencies. This sample chapter explains how
how to
handle business data representing dates, times, units of measureme
measurement, nt,
and currencies in ABAP applications.

“Working with Dates, Times, Quantities,


and Currencies
Contents

Index

The Authors

Brian O’Neill, Jelena Perfiljeva


ABAP: An Introduction
684 pages, 2nd, edition 2020, $69.95
ISBN 978-1-4932-1880-6

www.sap-press.com/4955
Chapter 12
Working with Dates, Times,
Quantities, and Currencies
This chapter explains how to handle business data that represents date
and time, quantities in different units of measure, and amounts in differ-
ent currencies.

Typical consumers of ABAP applications are large corporations with opera-


tions spanning the globe. As a result, ABAP programs need to be written 12
with the expectation that they can handle working across time zones and

with different currencies.


In addition, when working with any large company, the topics of inventory
and quantity can be quite important. An ABAP program may need to work
with converting measurements of products or keep track of how many
items can fit in a given storage location for that item.
In this chapter, we’ll cover various key items to take into account when cal-
culating and converting dates and times in ABAP programs. We’ll also cover
how quantities are handled in ABAP transparent tables and how to convert
quantities between different units of measurement. Then we’ll cover how
currencies are stored in ABAP transparent tables and how to convert

amounts between different currencies. Finally, we’ll update the shopping


cart example program to use quantity and currency fields.

12.1 Dates

In this section, we’ll cover the details on how the date type ( d) works and
some different ways to use dates in ABAP programs. Chapter 3 introduced
the date data type (d), showing how to define a date and that it is stored in a
YYYYMMDD format where the first four digits represent the year, the sec-
ond two represent the month, and last two represent the day.

465
12 Working
Working with Dat
Dates,
es, Times
Times,, Quantit
Quantities,
ies, and Currencie
Currenciess 12
2..1 Da te
te s

12.1.1 Date Type Basics DATA: start_date TYPE d,


my_d
my_dat
atee TY
TYPE
PE d.
Using substring A date is a character string of eight characters, meaning that you can apply
some of the string concepts from the previous chapter, such as using sub-
start_date = '20190101'.
string,, to get specific year, month, and day values, as shown in Listing 12.1.
string
my_date = start_date + 70.
DATA:
DATA: my_
my_date
date TYPE d VALU
VALUEE ‘201
‘2019010
90102’,
2’, WRITE: 'Date in a regular year:', 25 my_date.

year
year TYPE
TYPE i,
month TYPE i, start_date = '20200101'.
day
day TYTYPE
PE i. my_date = start_date + 70.
year = substring( val = my_date off = 0 len = 4 ). WRITE: / 'Date in a leap year:', 25 my_date.
my_month = substring( val = my_date off = 4 len = 2 ).
Listing 12.4 Date Calculation Comparing Regular and Leap Years
my_day = substring( val = my_date off = 6 len = 2 ).

Listing 12.1 Using SUBSTRING to Get Year, Month, and Day Because 2020 is a leap year, the same operation results in a different date
(March 11 instead of March 12), as shown in Figure 12.1.
The code in Listing 12.1 can be used regardless of the user’s date format pref-
12
erences; the value when working with the date data type will always be the
same.
Adding/subtracting Adding days to a date data type can be done by adding an integer to the
days date; the date data type will handle updating the day, month, and year val- Figure 12.1 Result of Date Calculation in Regular versus Leap Year
ues, as shown in Listing 12.2, in which the new date is February 6, 2019.

DATA: my_date TYPE d VALUE ‘20190102’.


Adding a month to a date is not as easy. If you want to add a month to your Adding months to
date, you can call the RP_CALC_DATE_IN_INTERNAL function module shown in a date
my_date = my_date + 35.
Listing 12.5, which will change the date from January 1, 2019, to February 1,
Listing 12.2 Adding 35 Days to January 2, 2019 2019.

You can also subtract days from a date variable in a similar fashion. In the DATA: my_date TYPE d VALUE ‘20190101’.
example shown in Listing 12.3, the result will be January 2, 2019.

DATA: my_date TYPE d VALUE ‘20190206’. CALL FUNCTION ‘RP_CAL


‘RP_CALC_DATE_IN
C_DATE_IN_INTERNAL
_INTERNAL’’
my_date = my_date - 35. EXPORTING
da
date
te = my_dat
my_datee
Listing 12.3 Subtracting 35 days from February 6, 2019
days = 0
months = 1
Leap year ABAP systems can easily handle leap years when calculating dates. The
ye
year
arss = 0
example in Listing 12.4 shows the result of adding 70 days to January 1 in the
IMPORTING
years 2019 and 2020.
calc_date = my_date.

Listing 12.5 Adding Month to Date Using Function Module

466 467
12 Workin
Working
g with Dates,
Dates, Times, Quantiti
Quantities,
es, and Currencies
Currencies 12 ..11 Dat e
ess

Other date Dates also can be compared using the regular comparison operators, such days cannot be calculated. The example in Listing 12.7 demonstrates this
operations as < or >=. The example in Listing 12.6 will always return “True” because effect.
you’re adding 1 to the date and then comparing the result. If you change the
DATA: my_integer TYPE i,
sign from + to - in this example, it will always return “False”.
my_date TYPE d.
DATA: one_date TYPE d VALUE '20190801',
'20190801', my_date = ‘20190230’.
another_date
another_date TYPE d. my_integer = my_date.
IF my_integer = 0.
another_date = one_date + 1.
another_date WRITE: / 'Date is invalid'.
IF another_date > one_date.
one_date. ENDIF.
WRITE: 'True'.
Listing 12.7 Assigning Invalid Date to Integer Variable
ELSE.
WRITE: 'False'.
ENDIF. 12.1.2 Factory Calendars
Listing 12.6 Comparing Dates There may be a situation in which you need to write a program that will act
differently based on which days are working days for a given company. Fac- 12

Date variables are quite amazing in ABAP: you can use string functions with tory calendar days will take into account any public holidays and any rele-
them just like with any character type variables, yet you can perform calcu- vant working days, allowing you to complete date ca lculations based on the
lations with them, just like with the numeric fields. number of actual working days.
But this versatility can sometimes tempt ABAP developers to cut corners Factory calendars are client-independent and typically are created for each Viewing factory
and underestimate the complexity of the task. For example, one might relevant country or region in which a company operates. This allows for a calendars
think: Instead of using a bulky function to add a month to a date, couldn’t factory calendar to incorporate the local public holiday schedule. To view
we just derive the month value (just like we did in Listing 12.1), add 1 to it, all of the calendars in an ABAP system, enter Transaction SCAL, select the
and be done? Factory Calendar radio button, and click the Display button , as pic-
The developers who attempt this quickly realize that when dealing with a tured in Figure 12.2.
date in December they also need to consider the year change. After adding
an IF… condition to increase the year as well, a developer could be very
pleased with the result. It might take several months before worried users
start asking why they’re seeing the date February 30 on their screens.
This brings us to the next point: it’s feasible to assign an incorrect date to
such a variable, and this will not cause a runtime error. There are various
ways to test date validity; using the DATE_CHECK_PLAUSIBILITY function
module is one of them. But there is also an interesting approach that
exploits the fact that when a variable of type d contains an invalid date and
is assigned to a variable of type i (integer), the value of the integer variable
becomes 0. This is because integer presentation of a date is the number of
days since the beginning of SAP time, and for an invalid date the number of Figure 12.2 Initial Screen for Transaction SCAL

468 469
12 Workin
Working
g with Dates,
Dates, Times, Quantiti
Quantities,
es, and Currencies
Currencies 1 22.. 1 D at
at es
es

In the next screen, you’ll see a list of the factory calendars defined in the
system. These are usually based on country or region and will have Valid
From and Valid To dates. Select the calendar you’re interested in viewing
(USA in this example) and click the Calendar button, as shown in Figure 12.3.

Figure 12.3 Selecting Factory Calendar


12

Next, select a relevant year for the calendar that you want to view and click
the Year button, as shown in Figure 12.4.

Figure 12.5 Viewing Working/Nonworking


Working/Nonworking Days and Public Holidays for Factory
Calendar

Now that you understand what a factory calendar is and how to set one up, Converting
you can use factory dates in your ABAP code with the help of some standard factory dates

function modules.
Figure 12.4 Selecting Calendar Year in Transactio
Transaction
n SCAL
Use function module DATE_CONVERT_TO_FACTORYDATE to convert a regular
date into a factory date. The factory date will be a number representing the
Now you’ll see a calendar display for the selected year, showing which days
number of working days since the factory calendar began. If you convert a
are considered working days and which days are nonworking days, includ-
date that isn’t a working day, the next working day will be used.
ing a list of public holidays for the year (Figure 12.5).
You can then perform some calculations using the factory date and convert
it back to a calendar date using the FACTORYDATE_CONVERT_TO_DATE function
module. An example of this is shown in Listing 12.8, which calculates a date
10 working days in the future.

470 471
12 Working
Working with Dates,
Dates, Times, Quantiti
Quantities,
es, and Currencies
Currencies 12
2.. 1 Da te
te s

PARAMETERS: p_date TYPE d OBLIGATORY. factory_calendar_


factory_calendar_id_missi
id_missing
ng = 5
DATA: simple_date TYPE d, factory_calendar_not_foun
factory_calendar_not_foundd = 6
factory_date
factory_date TYPE scal-facdate.
scal-facdate. others = 7
.
simple_date = p_date.
simple_date IF sy-subrc <> 0.
WRITE: / 'Date entered:', p_date. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

CALL FUNCTION 'DATE_CONVERT_TO


EXPORTING 'DATE_CONVERT_TO_FACTORYD
_FACTORYDATE'
ATE' ENDIF. WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
date = simple_date WRITE: / 'Result:', simple_date.
factory_calendar
factory_ calendar_id
_id = 'US'
Listing 12.8 Using Factory Date Conversions to Complete Date Calculation
IMPORTING
fa
fact
ctor
oryd
ydat
atee = fact
factor
ory_
y_da
date
te
When executing this example with August 3, 2019, given as a parameter, the
EXCEPTIONS
result is not August 13 but August 19, 2019, as shown in Figure 12.6.
calendar_buffer_
calendar _buffer_not_load
not_loadable
able = 1
cor
corre
rect_
ct_opt
option
ion_i
_inva
nvalid
lid = 2
date_after_range = 3 12
date_before_range = 4
date_invalid = 5
factory_calendar
factory_ calendar_not_fou
_not_found
nd = 6
Figure 12.6 Factory Date Calculation Example Result
others = 7
.
IF sy-subrc <> 0.
Fiscal Year Calendar
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. Another type of calendar in SAP ERP systems is the fiscal year calendar ,
ENDIF. which is relevant to financial transactions and reports. The fiscal calendar
configuration determines when each fiscal period begins and ends and
ADD 10 TO factory_date. how many periods are in a fiscal year for a specific company. Some compa-
nies may choose to use a fiscal calendar that differs from the physical cal-
CALL FUNCTION 'FACTORYDATE_CON
'FACTORYDATE_CONVERT_TO_D VERT_TO_DATE'
ATE' endar and has less or more than 12 periods. There are special function
EXPORTING modules that help to work with the fiscal calendar dates. An important
fa
fact ctor oryd ydat atee = fact
factor
ory_
y_da
date
te thing to remember here is that the postings in fiscal period 1 do not neces-
factory_calendar_id = 'US' sarily mean the dates from January 1 through January 31 in SAP ERP.
IMPORTING
date = simple_date
EXCEPTIONS 12.1.3 Datum Date Type
calendar_buffer_
calendar _buffer_not_load not_loadable able = 1
The d date type will output the day and month in the order matching the
fac
facto torydrydate ate_af _afte ter_rr_rang angee = 2
user’s preferences when using WRITE or an ALV grid, but it won’t include
factoryd
factorydate_ ate_befo before_r re_rangeange = 3
slashes or dots to separate the day, month, and year.
f aacc ttoo rryy ddaa ttee __ii nnvv aall iidd = 4

472 473
12 Worki
Working
ng with Dates
Dates,, Times, Quan
Quantities
tities,, and Currenc
Currencies
ies 12 ..11 D at
at e
ess

Datum formatting Instead of using the d date type, you can use the datum date type, which will 12.1.4 System Date Fields
be displayed per the style of the user’s date preference any time it’s dis-
There are three system date fields: sy-datum , sy-datlo , and sy-fdayw . All
played to the user (see Listing 12.9 and the resulting output shown in Figure
these system dates return values related to the current date. sy-datum
12.7).
returns the current system date. The system date is dependent on the sys-
DATA: my_datum TYPE datum VALUE '20190801'
'20190801'.. tem’s current time zone. If you’re concerned about the date for the logged
WRITE: 'Type DATUM:', my_datum. in user’s time zone, you can use sy-datlo . Finally, sy-fdayw will return the
factory day of week as an integer, meaning 0 for Sunday and 6 for Saturday.
DATA: my_date TYPE d VALUE '20190801'
'20190801'..
These system date fields can all be directly assigned to valid variables and
WRIT
WRITE:
E: /'Type D:',
D:', my_date.
my_date.
can also be used in the variable declaration, as shown in Listing 12.10.
Listing 12.9 Demonstrating Date Type Differences
DATA
DATA:
: toda
today
y type sy-datum,
sy-datum,
today_local
today_local type sy-datlo,
sy-datlo,
factory_day
factory_day TYPE sy-fdayw.
sy-fdayw.

today = sy-datum.
12
today_local
today_local = sy-datlo.
sy-datlo.
Figure 12.7 Output ofListing 12.9 factory_day
factory_day = sy-fdayw.
sy-fdayw.

Listing 12.10 System Date Fields


User preferences for the date and time f ormat can be maintained in Trans-
action SU3, on the Defaults tab. Figure 12.8 shows an example of the date
and time settings typical for a user located in the United States. 12.1.5 Date-Limited Records
A date-limited record is a record in a database with valid_from and/or valid_ Dates in the

to date fields indicating the dates between which the record is considered database

valid. There are many reasons that a table may contain date-limited
records; for example, a table may contain promotional discounts that are
only valid between two dates, or a table containing an employee’s position
in the company may be date-limited so that it can contain all current and
past positions.
Often, you don’t know when a record will no longer be valid, in which case
the valid_to date will be set to the latest date possible, which is December
Figure 12.8 User’s Date and Time Preferences 31, 9999. An HR record displaying an employee’s current position would
have a valid_to date like that; if the employee’s position changes, the
It’s better to use the datum data type in your program instead of the d data valid_to date is updated to show the last day at that position.
type whenever you’ll be displaying a date to the user. The datum and d date Selecting a date-limited record valid today is easy. First, determine if you
types can be used interchangeably in your code; the underlying data will be will be using the system date (sy-datum ) or the local date ( sy-datlo ).
exactly the same.

474 475
12 Working
Working with Dat
Dates,
es, Times
Times,, Quantit
Quantities,
ies, and Currencie
Currenciess 12 ..2
2 T iim
meess

In the following example, we’ll select a record from user table USR02
USR02,, which 12.2 Times
has optional Valid From and Valid To fields, as shown in Figure 12.9.
In this section, we’ll cover how the time data type ( t) works and some addi-
tional functions for calculating time, as well as other time data types. Chap-
ter 3 introduced the time data type (t), and that time is stored with two
characters for hours, two characters for minutes, and two characters for sec-

onds, in the format HHMMSS.


If you need time that is more exact than seconds, you can also use a time-
stamp, which will be covered in this section. A timestamp will calculate
time to the precision of 100 nanoseconds (ns), which is seven decimal
places, and will also include the date. The timestamp format is YYYYMMD-
Figure 12.9 Table USR02 with Valid from and Valid to Fields DHHMMSS.SSSSSSS.

Using dates To select only the records that have a limited validity and are valid for
in SELECT today, you need to select records with a valid from date less than or equal to
12.2.1 Calculating Time
12
today and a valid to date greater than or equal to today. For this example, Just as with dates, you can compare time using the regular comparison
the valid from field is GLTGV and the valid to field is GLTGB
GLTGB,, as shown in Lis- operators and calculate time using regular math expressions. The example
ting 12.11, which will only return the record for user BGRFC_SUPER
BGRFC_SUPER.. in Listing 12.12 creates two variables of type t and fills in one of them with
the current system time using the sy-uzeit system field. Then the number
“New Open SQL
5 is added to that variable and placed in the another_time variable. At the
SELECT *
end, the variable values are compared for equality.
FROM USR02
INTO TABLE @DATA(results) DA
DATA
TA:: one_
one_ti
time
me TYPE
TYPE t,
WHERE GLTGV <= @sy-datum another_time TYPE t.
AND GLTGB >= @sy-datum.
one_time = sy-uzei
one_time sy-uzeit.
t.
“old Open SQL WRITE: / 'Current time:', one_time.
DATA: results TYPE STANDARD TABLE OF USR02.

SELECT * another_time = one_time + 5.


FROM UR02 WRITE: / 'Current time + 5:', another_time.
INTO TABLE results
WHERE GLTGV <= sy-datum IF one_time = another_time.
AND GLTGB >= sy-datum. WRITE: / 'Time is the same'.
ELSE.
Listing 12.11 Selecting Record Valid for Today
WRITE: / 'Time is different'.
ENDIF.

Listing 12.12 Calculating and Comparing Time Variables

476 477
12 Working
Working with Dat
Dates,
es, Time
Times,
s, Quantities,
Quantities, and Cur
Currenci
rencies
es 12
2.. 2 Ti me
me s

Figure 12.10 shows an example of executing this program. Note that calcu- GET TIME STAMP FIELD my_timestampl.
lations with time occur in seconds; therefore, adding the number 5 to a GET TIME STAMP FIELD data(my_inline_timestamp).
time variable adds five seconds as a result.
Listing 12.13 GET TIME STAMP FIELD

The regular comparison operators can only be used between two time- Comparing
stamps, not between a timestamp and a date or time. The comparisons will timestamps

work between timestamp and timestampl type variables, as shown in Listing


12.14. In this example, the my_timestampl variable will be found to be bigger
Figure 12.10 Time Calculation Result Example and “True” will be displayed.

DATA: my_t
my_timestamp
imestamp TYPE times
timestamp,
tamp,
12.2.2 Timestamps my_timestampl TYPE timestampl.
my_timestamp
my_timest amp = '2019010
'20190101000000'.
1000000'.
A timestamp is a combination of date and time for the Coordinated Univer-
my_timestampl
my_timest ampl = '2019010
'20190101000000.
1000000.0000001'.
0000001'.
sal Time (UTC) time zone. This can be used to record the exact date and time
IF my_times
my_timestampl
tampl > my_timest
my_timestamp.
amp.
when an action was completed by a user without having to rely on the local 12
WRITE: 'True'.
time zone for the user or the server. ENDIF.

Creating
timestamps There are two types of timestamp data types: timestamp and timestampl. Listing 12.14 Comparing TIMESTAMP and TIMESTAMPL Data Types
timestamp is a short-form timestamp, which represents only the date and
time combined with a format of YYYYMMDDHHMMSS. timestampl is a
You can also convert a timestamp to a local date and time variable using the Converting
long-form timestamp and will include up to seven decimal places to cap- timestamps
CONVERT TIME STAMP function. When using this function, you must specify a
ture the time with the precision of up to 100 ns using a format of YYMM-
time zone that exists in table TTZZ. The result can be stored in explicitly
DDHHMMSS.SSSSSSS.
defined date and time variables or using inline declarations, which will be
created as date and time variables. You also can store a Boolean value for
Actual Time Precision whether or not daylight saving time is in ef fect. The example in Listing 12.15
The maximum time precision depends on the operating system of the gets the current UTC timestamp, converts it to a Pacific Standard Time (PST)
application server and can be less precise than allowed by the long-form time zone date and time, and captures the daylight savings indicator. The
timestamp format. DATE, TIME, and DAYLIGH
DAYLIGHTT SAVING TIME additions are all optional, so you can
use only the ones that you need.
You can get the current timestamp using the GET TIME STAMP FIELD func- GET TIME STAMP FIELD DATA(my_utc).
tion, as shown in Listing 12.13. This function will work with both timestamp CONVERT TIME STAMP my_UTC TIME ZONE 'PST'
and timestampl data types. If an inline data declaration is used, timestamp , INTO DATE DATA(my_pst_date)
not timestampl, will be used. TIME DATA(my_
DATA(my_pst_time)
pst_time)
DAYLIGHT SAVING TIME DATA(my_dst).
DATA: my_
my_timestamp
timestamp TYPE timestamp,
timestamp,
my_timestampl
my_timestampl TYPE timestampl.
timestampl. Listing 12.15 Converting Timestamp from UTC to PST Date and Time
GET TIME STAMP FIELD my_timestamp.
my_timestamp.

478 479
12 Working
Working with Dates
Dates,, Times, Quantitie
Quantities,
s, and Currencies
Currencies 12
2.. 2 T im
ime s

The examples in this section use inline declarations. If inline declaration


T iim
meess tta
ammp
p F or
or ma
ma t O ut
ut p
pu
ut
syntax isn’t yet available in your system, use the explicit declaration with
the DATA command, as shown in Listing 12.16. Other examples can be SPACE Based on ISO 8601. Format:
YYYY-MM-DD HH:MM:SS.ZZZZZZZ.
adjusted similarly.
For example, 2019-01-01 12:00:00.0000000.
DATA: my_utc type timestam
timestamp,
p,
my_pst_date
my_pst_date type d, ISO Also based on ISO 8601, but uses a “T” to separate the

my_pst_time type t,
my_pst_time date and time and always uses a comma as the seconds
decimal. Format: YYYY-MM-DDTHH:MM:SS,ZZZZZZZ.
my_dst type abap_boo
abap_bool.
l.
For example, 2019-01-01T12:00:00.0000000.
GET TIME STAMP FIELD my_utc.
CONVERT TIME STAMP my_UTC TIME ZONE 'PST' USER Based on the user’s preferences, which can be changed
INTO DATE my_pst_da
my_pst_date
te by going to System • User Profile • Own Data under the
TIME my_pst_ti
my_pst_time
me Defaults tab. For example: 01/01/2019 12:00:00 PM
DAYLIGHT SAVING TIME my_dst.
ENVIRONMENT Based on the user’s currently selected language envi-
Listing 12.16 Converting Timestamp from UTC to PST Date and Time without ronment. Will display the default for that country,
Inline Declarations regardless of the user defaults. For example: 01/01/ 12
2019 12:00:00 PM.

You Table 12.1 Timestamp Formats for String Templates


into can also perform
a timestamp a reverse
using operation
the CONVERT INTOand convert a local date
MP function.
TIMESTAMP
TIMESTA A and
DATEtime
and
TIME ZONE are both required when using this function, but the TIME and
The syntax to use these different timestamp formats is simple. Within the
DAYLIGHT SAVING TIME variables are optional. An example converting the
string template, between the curly braces you put the timestamp variable
results from Listing 12.15 back into a timestamp is shown in Listing 12.17.
name followed by TIMESTAMP = and then any of the formats listed in Table
Remember that the time zone passed is used to convert the local date and
12.1. The example shown in Listing 12.18 will return 2019-01-01T12:00:
time from that time zone into a UTC time zone.
00.0000000 .
CONVERT DATE my_pst_date
my_pst_date
DATA: unformatt
unformatted
ed TYPE tim
timestampl
estampl
TIME my_pst_t
my_pst_time
ime
VALUE '2019010
'20190101120000.0
1120000.0000000'.
000000'.
DAYLIGHT SAVING TIME my_dst
DATA(my_string)
DATA(my_string) = |{ unformat
unformatted
ted TIMESTAMP = ISO }|.
INTO TIME STAMP my_u
my_utc
tc TIME ZONE ‘PST’.
Listing 12.18 Setting Timestamp Format from within String Template
Listing 12.17 Converting PST Date and Time to UTC Timestamp

You also can convert the time used in the string template to reflect a given
Timestamp When outputting timestamps to a string template, there are special format-
time zone by adding TIMEZON
TIMEZONEE = followed by the desired time zone, as
formatting ting options that can be applied to display the timestamp in a more user-
shown in Listing 12.19, which will return 2019-01-01T04:00:00.0000000 .
friendly format. Table 12.1 provides a list of all the possible formatting
options. my_string = |{ unformatted TIMESTAMP = ISO
TIMEZONE
TIMEZONE = 'PST
'PST'' }|.

Listing 12.19 Setting Timestamp Output and Time Zone for Output in String
Template

480 481
12 Workin
Working
g with Dates,
Dates, Times, Quantiti
Quantities,
es, and Curr
Currencies
encies 12
12.3
.3 Qu
Quan
anti
titi
ties
es

There are some additional timestamp-related functions that use the CL_ You can see the different possible units of measure that are set up in your Display units of
ABAP_TSTMP system class. This class should be used if you want to add or sub- ABAP environment by entering Transaction CUNI, shown in Figure 12.11. measure

tract seconds from a timestamp, calculate the difference between two time- From there, select a dimension such as Length from the dropdown, and
stamps, or convert a long timestamp to a short timestamp or vice versa. click Units of Measurement .

12.2.3 SY-UZEIT (System Time versus Local Time)


System time fields There are a few system fields related to time. Just as with system dates,
there are times based on the system time zone and times based on the
user’s time zone. The system time can be found with the sy-uzeit system
variable, whereas the user’s local time can be found with sy-timlo; both will
return the result in a variable of type t. You can also get the system time
zone using sy-tzone or the user’s local time zone using sy-zonlo, both of
which will return a char variable with a length of 6.
Just as with system dates, you can declare system variables as data types, as 12
shown in Listing 12.20.

DATA: sys_time TYPE sy-uzeit,


sy-uzeit, Figure 12.11 Initial Screen of Transaction CUNI
sys_timezone
sys_timezone TYPE sy-tzone,
sy-tzone,
loc_time TYPE sy-timlo,
sy-timlo,
Next, you’ll see a list of possible measurements for that dimension, as
loc_timezone
loc_timezone TYPE sy-zonlo.
sy-zonlo.
shown in Figure 12.12.
sys_time = sy-uzeit
sy-uzeit.
.
sys_timezone
sys_timezone = sy-tzone
sy-tzone.
.
loc_time = sy-timlo
sy-timlo.
.
loc_timezone
loc_timezone = sy-zonlo
sy-zonlo.
.

Listing 12.20 Declaring and Getting System Time and Local Time Data

12.3 Quantities
Quantitative fields are used in SAP ERP systems to track and convert the
results of different types of measurements, ranging from lengths (e.g.,
meters and inches) to masses (e.g., grams and pounds) and units of packag-
ing (e.g., box and pallet). These fields are always associated with a unit of
Figure 12.12 List of Length Units of Measurement from Transaction CUNI
measure (UOM), which allows for converting the quantitative values from
one unit to another.

482 483

12 Working
Working with Dat
Dates,
es, Times
Times,, Quanti
Quantities,
ties, and Cur
Currenci
rencies
es 12
12.3
.3 Quant
Quantit
itie
iess
12.3.1 Quantity Fields in Data Dictionary
When storing quantities in transparent tables, you need to store the quan-
tity as a QUAN data type and the unit of measure as a UNIT data type. Then,
when creating the table using Transaction SE11, you need to relate the two
fields in the Currency/Quantity Fields tab.
Transparent table To demonstrate this, create table ZQUANTITY , shown in Figure 12.13, using
ZQUANTITY Transaction SE11. The table should contain field MANDT with data element
MANDT, field ID with data element INTEGER, field QUANTITY with data element
BASMN (type QUAN), and field UNIT_OF_MEASURE with data element CGSUNIT (type
UNIT). If some of the data elements don’t look familiar, don’t worry: they’re
SAP-standard data types that should exist in any ABAP system. Figure 12.14 Currency/Quantity Fields Data for Assigning Units to Quantities

12.3.2 Converting Quantities


Within an ABAP program, you can read data stored in a certain unit of mea- 12

sure and then convert the value into a different unit of measure so long as
both are part of the same dimension. For example, you can convert one
length unit, such as centimeters (cm), into another length unit, such as
meters (m).
You can complete the conversion using the UNIT_CONVERSION_SIMPLE func- ABAP unit

tion module, which allows you to pass in a quantity with a unit to convert conversion

from and a unit to convert to. This function module will also round results
Figure 12.13 Table Containing Quantity and Unit of Measure if necessary, and you can optionally pass in a + or – to force it to round up or
down. Listing 12.21 demonstrates converting a quantity of 5 from meters (M)
Next, click the Currency/Quantity Fields tab, and you’ll see that only the to centimeters (CM). The unit of measure used can also be seen in the length
QUANTITY field has an editable row. From here, you can add a reference to units of measure list in Figure 12.12.
the table and field that will describe the quantity’s unit. For this example,
enter the current table, “ZQUANTITY”, and the field, “UNIT_OF_MEAS
“UNIT_OF_MEASURE”,URE”, DATA: my_quantity
my_quantity TYPE i VALUE 5.
CALL FUNCTION 'UNIT_CONVERSION
'UNIT_CONVERSION_SIMPLE'
_SIMPLE'
as pictured in Figure 12.14. Assigning a corresponding unit of measure field EXPORTING
for any quantity data type is required to activate the table. input = my_quantity
Because you store the quantity and unit in the same table, different records unit_in = 'M'
can have data stored in different quantities. unit_out = 'CM'
IMPORTING
It’s possible to store the unit of measure in one table and ref erence it within output = my_quantity
a quantity in another table, if this is required by your business rules. In this EXCEPTIONS
case, you would enter a different table name in the Reference Table field in conversion_not_fo
conversion_not_found
und = 1
Transaction SE11. div
divisi
ision_
on_by
by_ze
_zero
ro = 2

484 485

12 Working
Working with Dat
Dates,
es, Time
Times,
s, Quantities,
Quantities, and Cur
Currenci
rencies
es 12
12.4
.4 Cu
Curr
rren
enci
cies
es
inp uut
t_ i
innva l
li
id = 3 The SAP ERP currency codes are listed in the Currency column and corre-
o ut
ut pu
pu t_
t_ in
in va
va li
li d = 4 sponding ISO currency codes in the ISO column. Note that even though
overflow = 5 most SAP currency codes match the ISO standard, there could be some-
type_invalid = 6 times multiple internal SAP codes for one ISO currency code.
uni tts
s_ m
miiss i
in
ng = 7
When converting amounts across different currencies, the current
un
unit_
it_in_
in_not
not_fo
_founund
d = 8
unit
unit_out
_out_not
_not_fou
_found
nd = 9
exchange rate can be found in Transaction OB08. Because exchange rates
others = 10 regularly change, it’s possible to have the exchange rates in your system
. automatically updated on a daily or weekly basis, which is a topic outside
IF sy-subrc
sy-subrc <> 0. the scope of this book. Figure 12.16 shows that the currency exchange rate
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno between the US dollar and the euro is 0.94 euros to 1 US dollar.
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
WRITE: my_quant
my_quantity.
ity.

Listing 12.21 ABAP Code for Converting Data between Measurements


12

Figure 12.16 Currency Exchange Rates from Transaction OB08

12.4 Currencies
Currencies work a lot like quantities; they’re used to capture both a value 12.4.1 Currency Fields in Data Dictionary
(amount) and a type (currency code). In today’s world of global business, Just as quantities use a QUAN data type to keep track of the quantity and a
transactions can be captured in one currency and then transferred to UNIT data type to keep track of the unit of measure, a currency value
another. This makes it very important to keep track of the currency being requires that the amount of currency be stored in a field with a CURR data
referenced in any financial transaction, which is easy with an ABAP system. type, and the currency key needs to be stored with a CUKY data type. You can
Display currencies You can see a list of currencies defined in your system by entering Transac- then relate the fields in the Currency/Quantity Fields tab in the Change
Table screen from Transaction SE11.
tion OY03. The results will be displayed as shown in Figure 12.15.
To demonstrate this, let’s create table ZCURRENCY , shown in Figure 12.17, Currency in a trans-
using Transaction SE11. The table should contain field MANDT with data ele- parent table

ment MANDT , field ID with data element INTEGER , field PRICE with data ele-
ment PREIS (type CURR), and field CURRENCY with data element USRCUKY (type
CUKY). If some of the data elements don’t look familiar, don’t worry: they’re
standard SAP data types that should exist in any ABAP system.

Figure 12.15 List of Currencies from Transaction OY03

486 487

12 Working
Working with Date
Dates,
s, Times, Q
Quantit
uantities,
ies, and Currencies
Currencies 12
12.4
.4 Curr
Curren
encie
ciess
OB08. You can do so using the CONVERT_TO_LOCAL_CURRENCY function mod-
ule.
When using CONVERT_TO_LOCAL_CURRENCY , you’re required to pass a date that Currency conver-
will be used to determine the exchange rate for converting foreign_amount sion in ABAP

from foreign_currency to local_currency . The result will be returned as


local_amount , as shown in Listing 12.22, and you can also gather additional

information from the function module, such as the exchange rate used, or
you can specify an exchange rate to be used in the conversion.

Figure 12.17 Table ZCURRENCY Using Currency Data Types DATA: local_amount
local_amount TYPE P DECIMALS 2.

CALL FUNCTION 'CONVERT_TO_LOCA


'CONVERT_TO_LOCAL_CURRENC
L_CURRENCY'
Y'
Currency/Quantity You won’t be able to activate table ZCURRENCY until you add a reference for
Fields settings EXPORTING
the currency field. This works just as you saw with the quantity field; select
date = sy-datlo
the Currency/Quantity Fields tab and enter “ZCURRENCY” as the reference
fo
forei
reign_
gn_am
amoun
ount
t = 100
table and “CURRENCY” as the reference field, so that the currency and cur- 12
foreign_currency
foreign_ currency = 'EUR'
'EUR'
rency key fields are linked as shown in Figure 12.18.
loca
local_cu
l_curren
rrency
cy = 'USD
'USD''
IMPORTING
lo
local
cal_am
_amoun
ount
t = lo
local
cal_am
_amoun
ount
t
EXCEPTIONS
no
no_r
_rat
ate_
e_fo
foun
und
d = 1
overflow = 2
no_f
no_facto
actors_f
rs_found
ound = 3
no_s
no_sprea
pread_fo
d_found
und = 4
deri
derived_
ved_2_ti
2_times
mes = 5
others = 6.

IF sy-subrc
sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
Figure 12.18 Currency/Quantity Fields Tab for Table ZCURRENCY WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Because you have a field for currency in the table, each record in the table
can have any currency denomination. And just like with quantity fields, Listing 12.22 Currency Conversion
you also can reference the currency key in another table.

Currency Conversion Factor and Decimal Places


12.4.2 Converting Currencies Due to historic inflation, some currencies, such as Japanese yen (JPY), oper-
Within an ABAP program, you may need to convert an amount from one ate in much larger amounts than other currencies. Such special currencies
currency to another using the current exchange rates shown in Transaction can be configured with a conversion factor (stored in table TCURF) and the

488 489

12 Worki
Working
ng with Date
Dates,
s, Times, Qua
Quantiti
ntities,
es, and Currencies
Currencies 12.5 Updating
Updating th
the
e Shopp
Shopping
ing Ca
Cart
rt Exa
Example
mple
12.5.1 Updating the Database
factor would be applied to the amounts when stored in the database. This
means that the amount of 100 JPY, for example, would be stored as 0.01 in You’re now ready to update the transparent tables to match the updated
the database. ERD diagram. This section will walk through the steps to accomplish that.
Some currencies may also use a different number of decimals than two, or Let’s start by creating data elements for the new fields and then add those
no decimals at all. The information about decimal places in currencies is data elements to the transparent tables.
stored in table TCURX. First, create the data element for the product price field. To begin, enter Price data element
The good news is that the standard SAP functionality incorporates this Transaction SE11, select the Data Type radio button, enter “ZPRODUCT_
configuration into currency field display and conversion. That’s why it’s PRICE” in the corresponding
corresponding textbox, and click the Create button. Select the
important to always reference the currency code when dealing with cur- Data Element radio button in the Data Type popup and click the Continue
rency-specific amounts in ABAP code. button.
In the Change Data Element screen, enter “Product Price for Shopping Cart
You should now be familiar with currencies and the aspects required for Example” in the Short Description textbox. Then, with the Data Type tab
storing and converting them. In the next section, we’ll update the shopping selected, choose the Elementary Type radio button and the Built-in Type
cart example with currencies and quantities. radio button. Enter the Data Type “CURR”, Length “11”, and Decimal Places
12
“2”. We’re using the built-in type option instead of a domain in the new data
elements because we don’t need any of the additional settings available

12.5 Updating the Shop


Shopping
ping Cart Example within a domain. Your data element should look like the one pictured in
Figure 12.20.
Now that you know how to use dates, times, quantities, and currencies, let’s
revisit the shopping cart example to take advantage of the currency and
quantity features.
Shopping cart ERD First, we need to update the ERD to include currency and quantity values. In
Figure 12.19, note the addition of PRICE and CURRENCY in table ZPRODUCT, allow-
ing you to set a price per item for a specified currency. Also, a unit of mea-
surement (UOM) is added to table ZPRODUCT, allowing you to determine the
quantity unit that the price is set for. This quantity unit also is referenced
by the quantity of the material in a cart (the QUANTITY field in table ZCART).

SCUSTOM ZCART ZPRODUCT ZPRODUCT_TEXT


Figure 12.20 Data Type Settings for Data Element ZPRODUCT_PRI
ZPRODUCT_PRICE
CE
PK ID PK, FK3 CUSTOMER PK PROD UCT PK, FK1 PRODUCT
PK, FK1 PRODUCT PK LANGUAGE

NAME QUANTITY PRICE DESCRIPTION


Next, select the Field Label tab and enter “Price” for all Field Label textboxes.
CURRENCY
UOM
Then press (Enter) and the Length textboxes will be automatically popu-
lated, as shown in Figure 12.21. Click the Activate button to activate the data
Figure 12.19 Updated ERD with Currency and Quantity Fields element and save it as a local object in the $TMP package.

490 491

12 Working
Working with Dates,
Dates, Times, Quantiti
Quantities,
es, and Currencies
Currencies 12.5 Updating
Updating th
the
e Shopping
Shopping Cart
Cart E
Example
xample
populated, as shown in Figure 12.23. Click the Activate button to activate the
data element.

Figure 12.21 ZPRODUCT_PRICE Field Label Settings

Currency data Next, return to Transaction SE11, select the Data Type radio button, enter
element “ZPRODUCT_CURRENCY”
“ZPRODUCT_CU RRENCY” in the correspon
corresponding
ding textbox, and click the Cre- Figure 12.23 ZPRODUCT_CURR
ZPRODUCT_CURRENCY
ENCY Field Label Settings
ate button. Select the Data Element radio button in the Data Type popup
12
and click the continue button. Next, return to Transaction SE11, select the Data Type radio button, enter UOM data element
In the Change Data Element screen, enter “Product Currency for Shopping “ZPRODUCT_UOM” in the corresponding textbox, and click the Create but-

Cart Example” in the Short Description textbox. Then, with the Data Type ton. Select the Data Element radio button in the Data Type popup and click
tab selected, choose the Elementary Type radio button and the Built-in Type the Continue button.
radio button. In the Data Type field, use the input help dropdown and select In the Change Data Element screen, enter “Product UOM for the Shopping
the CUKY type. The Length field will be automatically set to 5. Your data ele- Cart Example” in the Short Description textbox. Then, with the Data Type
ment should look like the one pictured in Figure 12.22. tab selected, choose the Elementary Type radio button and the Built-in Type
radio button. Enter the Data Type “UNIT” and Length “3”. Your data element
should look like the one pictured in Figure 12.24.

Figure 12.22 ZPRODUCT_CURR


ZPRODUCT_CURRENCY
ENCY Data Type Settings

Next, select the Field Label tab and enter “Currency” for all Field Label text- Figure 12.24 ZPRODUCT_UOM Data Type Settings
boxes. Then press (Enter) and the Length textboxes will be automatically

492 493

12 Working
Working with Dates, Times,
Times, Quantities
Quantities,, and Currencies
Currencies 12.5 Updating
Updating the Shopping
Shopping Cart Example
Example
Next, select the Field Label tab and enter “Unit” for the Short Field Label text
box and “Unit of Measure” for all other Field Label textboxes. Then press
(Enter) and the Length textboxes will be automatically populated, as
shown in Figure 12.25. Click the Activate button to activate the data ele-
ment.

Figure 12.26 ZCART_QUANTIT


ZCART_QUANTITY
Y Data Type Settings

12

Figure 12.25 ZPRODUCT_UOM Field Label Settings

Quantity data Next, return to Transaction SE11, select the Data Type radio button, enter
element “ZCART_QUANTITY” in the corresponding textbox, and click the Create
button. Select the Data Element radio button in the Data Type popup and
click the Continue button.
In the Change Data Element screen, enter “Cart Quantity for the Shopping Figure 12.27 ZCART_QUANT
ZCART_QUANTITY
ITY Field Label Options
Cart Example” in the Short Description textbox. Then, with the Data Type
tab selected, choose the Elementary Type radio button and the Built-in Type Now that you’ve created the new data elements, let’s update the transpar- Updating table
radio button. Enter the Data Type “QUAN”, Length “13”, and Decimal Places ent tables that use those data elements. First, update transparent table ZPRODUCT
“3”. Your data element should look like the one pictured in Figure 12.26. ZPRODUCT . To do this, go back to Transaction SE11, select the radio button for

Next, select the Field Label tab and enter “Quantity” for all the Field Label Database Table, and enter “ZPRODUCT” in the corresponding textbox.
textboxes. Then press (Enter) and the Length textboxes will be automati- Then press the Change button.
cally populated, as shown in Figure 12.27. Click the Activate button to acti- With the Fields tab selected, add Field “PRICE” with Data element “ZPRO-
vate the data element. DUCT_PRICE”, Field “CURRENCY” with Data element “ZPRODUCT_CUR-
RENCY”, and Field “UOM” with Data element “ZPRODUCT_UOM”, as shown
in Figure 12.28.

494 495

12 Workin
Working
g with Dates
Dates,, Times, Q
Quantit
uantities,
ies, and Currenci
Currencies
es 12.5 Updating
Updating the Shoppin
Shopping
g Cart Example
Figure 12.30 Table ZCART Fields Tab Settings
Figure 12.28 ZPRODUCT Fields Tab Settings

Now, select the Currency/Quantity Fields tab and enter Reference Table
Next, select the Currency/Quantity Fields tab and enter Reference Table
“ZPRODUCT” and Reference Field “UOM” for Field “Quantity”. This will set
“ZPRODUCT” and Reference Field “CURRENCY” for the Field “PRICE”, as
the UOM field in table ZPRODUCT as the unit for the QUANTITY field in this table,
shown in Figure 12.29. This will set the CURRENCY field as the currency key for 12
as shown in Figure 12.31.
the PRICE field.

Figure 12.31 ZCART Currency/Quantity Fields Tab Settings


Figure 12.29 ZPRODUCT Currency/Quantity Fields Tab Settings
Table ZCART is now complete! Click the Activate button to save and activate
Table ZPRODUCT table is now done! Click the Activate button to save and acti- the table.
vate the table. In the next section, we’ll update the global class to use the new currencies
Updating table Now, go back to Transaction SE11, select the radio button for Database and quantities.
ZCART Table,, and enter “ZCART” in the corresponding textbox. Then press the
Table
Change button.
12.5.2 Updating the Global Class
With the Fields tab selected add Field “Quantity” with Data Element
Now that the tables have been updated, you need to update the ZCL_SHOP-
“ZCART_QUANTITY”, as shown in Figure 12.30.
PING_CART global class to use the new information. You’ll need to update the

496 497

12 Working
Working with Date
Dates,
s, Times
Times,, Quantit
Quantities,
ies, and Currencies
Currencies 12.5 Updating
Updating the S
Shoppin
hopping
g Cart Ex
Exampl
ample
e
ADD_PRODUCT method to take an additional parameter for quantity and will Next, update the GET_CART method to return the quantity and unit of mea- Updating GET_CART
need to update the GET_CART method to return the quantity and unit of sure. To do this, first update the t_cart definition to include the quantity
measure for all the items in the cart. and unit of measure variables, as shown in bold in Listing 12.25.

Updating First, let’s update the ADD_PRODUCT method. To do this, update the method …
add_product definition to include the IMPORTING parameter ip_quantity as shown in Lis- PUBLIC SECTION.
method
ting 12.23. Add the new parameter as an optional parameter so that other TYPES: BEGIN OF t_cart,
prod
product
uct TYPE zpro
zproduct
duct-pro
-product
duct,
,
programs aren’t impacted by the change. description
descript ion TYPE zproduct_text-de
zproduct_text-descriptio
scription,
n,

quantity
quantity TYPE zcart-qu
zcart-quantiantity,
ty,
add_product
add_product IMPORTING ip_product
ip_product TYPE zproduct-product
zproduct-product
u om
om T YP
YP E z pr
pr od
od uc
uc t-
t- uo
uo m,
m,
ip_quantity
ip_quant zcart-quantity OPTIONAL,
ity TYPE zcart-quantity
END OF t_cart,


Listing 12.23 Updated Definition for ADD_PRODUCT Method
Listing 12.25 Updates to T_CART Definition in ZCL_SHOPPING_CART

Now you can update the ADD_PRODUCT method implementation. The change 12
Now in the GET_CART method, add the new fields to the SELECT statement, as
will be to check if ip_quantity has a value and, if it does, to use that value in
shown in Listing 12.26.
the local structure; otherwise, set the local structure quantity to 1. You can

also now change the INSERT statement to a MODIFY statement. This will allow METHOD
“using get_cart.
get_cart
new Open.SQL
the ADD_PRODUCT method to be called to change the quantity and to add new
products. This is accomplished using the code in Listing 12.24, which has the SELECT zcart~product,
zcart~product, description , quantity, uom
description,
specific changes in bold. FROM zcart
INNER JOIN zproduct
METHOD add_prod
add_product.
uct. ON zcart~product
zcart~product = zproduct~product
zproduct~product
DATA
DATA:
: cart
cart TYPE zcart.
zcart. INNER JOIN zproduct_text
zproduct_text
cart-customer
cart-customer = customer. ON zcart~product
zcart~product = zproduct_text~pro
zproduct_text~product
duct
cart-product
cart-product = ip_product.
ip_product. WHERE zproduct_text~la
zproduct_text~language
nguage = @sy-langu
@sy-langu
IF ip_quantity IS NOT INITIAL
INITIAL.
. AND zcart~customer = @customer
@customer
cart-quantitity
cart-quantitity = ip_quan
ip_quantity.
tity. INTO TABLE @rt_cart.
@rt_cart.
ELSE.
cart-quantity
cart-quantity = 1. “using old Open SQL
ENDIF. SELECT zcart~product description quantity uom
zcart~product description
INTO TABLE rt_cart.
MODIFY zcart FROM ls_cart. FROM zcart
ENDMETHOD. INNER JOIN zproduct
ON zcart~product
zcart~product = zproduct~product
zproduct~product
Listing 12.24 Updated ADD_PRODUCT Method Implementation
INNER JOIN zproduct_text
zproduct_text
ON zcart~product
zcart~product = zproduct_text~pro
zproduct_text~product
duct

498 499

12 Workin
Working
g with Dates,
Dates, Times, Quantiti
Quantities,
es, and Currencies
Currencies 12.5 Updating
Updating the Shoppi
Shopping
ng Cart
Cart Exam
Example
ple
WHERE zproduct_text~language
zproduct_text~language = sy-langu
AND zcart~customer
zcart~customer = customer.
customer.

ENDMETHOD.

Listing 12.26 Updated GET_CART Method in ZCL_SHOPPING_CART

Now, press the Activate button to activate ZCL_SHOPPING_CART . The ZCL_SHOP-


PING_CART class is now ready to use quantities. In the next section, we’ll
update the ABAP programs to use the new price and quantity fields.

12.5.3 Updating the ABAP Programs Figure 12.32 Updated Selection Texts in ZPRODUCT_MAIN
ZPRODUCT_MAINT
T

ZPRODUCT_MAINT You’re now ready to update the maintenance ABAP programs. First, let’s
parameters update the ZPRODUCT_MAINT program. In Listing 12.27, we add the additional
parameters needed for price, currency, and unit of measurement, all shown 12
in bold.


SELECTION-SCREEN
SELECTION-SCREEN BEGIN OF BLOCK product WITH FRAME TITLE text-001
text-001.
.
PARAMETERS:
PARAMETERS: p_prod TYPE zproduc
zproduct-product
t-product,
,
p_desc TYPE zproduct_text-d
zproduct_text-descripti
escription
on
LOWER CASE,
p_price TYPE zproduct-price,
zproduct-price,
p_curr TYPE zproduct-curr
zproduct-currency,
ency,
p_uo
p_uom
m TYPE zproduc
zproduct-uo
t-uom.
m.
SELECTION-SCREEN
SELECTION-SCREEN END OF BLOCK product. Figure 12.33 Updated ZPRODUCT_MAINT Selection Screen

Listing 12.27 Adding New Parameters to Selection Screen


You can now update the logic in ZPRODUCT_MAINT to save the new parameters ZPRODUCT_MAINT
to the database. To do this, add the bold code in Listing 12.28. logic

Press the Activate button to activate the program so that you can add the
selection texts for the new parameters. …
product-product
product-product = p_prod.
ZPRODUCT_MAINT Next, navigate to the text elements using Goto • Text Elements • Selection
selection text product-price
product-price = p_price.
Texts in SAP GUI or right-click and choose Open Others • Text Elements in
product-currency
product-currency = p_curr.
Eclipse. In the Selection Texts tab, select the checkbox for DDIC Reference
product-uom
product-uom = p_uom.
for all of the new parameters listed, as shown in Figure 12.32. Then click the
product_text-pro
product_text-product
duct = p_prod.
Activate button to activate the new texts.
product_text-des
product_text-description
cription = p_desc.
You can now test the updated selection screen by running the program. It …
should look like Figure 12.33.
Listing 12.28 Updated Code to Save New Parameters in ZPRODUCT_MAINT

500 501

12 Workin
Working
g with Dates, Times,
Times, Quantitie
Quantities,
s, and Currencies
Currencies 12.5 Updating
Updating th
the
e Shopp
Shopping
ing Ca
Cart
rt Exa
Example
mple
When using inline data declarations, the SELECT statement can be quickly Next, let’s update the ZCART_MAINT program to utilize the new currency and ZCART_MAINT
updated to display the new fields, as shown in Listing 12.29. quantity options. In Listing 12.31, you can see that we added a new parame- changes

ter for the quantity and added it as a parameter when calling the ADD_PROD-

UCT method. Notice that we now have to indicate which parameters we’re
SELECT zproduct~
zproduct~product,
product, descripti
description,
on, price, currency, uom
passing when calling the ADD_PRODUCT method.
FROM zproduct
INNER JOIN zproduct_text …
ON zproduct~product
zproduct~product = zproduct
zproduct_text~pr
_text~product
oduct PARAMETERS:
PARAMETERS: p_cust TYPE zcart-customer
zcart-customer OBLIGATORY,
WHERE language = @sy-lang
@sy-languu zcart-product,
p_prod TYPE zcart-product
INTO TABLE @DATA(products). p_qty TYPE zca
zcart-quant
rt-quantity.
ity.
… …
ELSEIF p_add = abap_true.
abap_true.
Listing 12.29 Updating SELECT Statement with Inline Data Declarations
o_cart->add_product( ip_product = p_prod ip_quantity = p_qty ).

When not using inline data declarations, you need to update the type defi-
nition before you can update the SELECT statement, as shown in Listing Listing 12.31 Updates for Program ZCART_MAINT
12.30. 12

Now, press the Activate button to activate these changes and make the new
ELSEIF p_dis = abap_true.
parameter available in the selection texts screen.
TYPES: BEGIN OF t_produc
t_products,
ts,
pro
product
duct TYPE zpr
zproduc
oduct-pr
t-produc
oduct,
t, Navigate to the selection screen texts, as described earlier for the ZPRODUCT_ ZCART_MAINT
description
descript ion TYPE zproduct_
zproduct_text-des
text-description
cription,, MAINT program, and check the DDIC Reference checkbox for the new param- selection texts

pri
price
ce TYP
TYPEE zpr
zprod
oduct
uct-pr
-pric
ice,
e, eter. After activating the changes, the selection screen should look as
currency
currency TYPE zproduct
zproduct-cur-currenc
rency,
y, shown in Figure 12.34.
u om
om T YP
YP E z pr
pr od
od uc
uc t
t-
-uuo
omm,
,
END OF t_products.

DATA: products TYPE STANDARD TABLE OF t_products,


alv_table TYPE REF TO cl_salv_table.

SELECT zproduct~
zproduct~product
product description
description price currency uom
INTO
INTO TABLE prod
products
ucts
FROM zproduct
INNER JOIN zproduct_text
ON zproduct~
zproduct~product
product = zproduct
zproduct_text~pr
_text~product
oduct
WHERE language = sy-langu.

Listing 12.30 Updating SELECT Statement without Inline Data Declarations


Figure 12.34 Updated ZCART_MAINT Selection Screen

You can now press the Activate button to activate the program. The ZPRO-
DUCT_MAINT ABAP program is now ready to handle currencies and quantities.

502 503

12 Workin
Working
g with Dates,
Dates, Times, Quantiti
Quantities,
es, and Currencies
Currencies
The ZCART_MAINT program is now ready to handle quantities. Add data using
both programs to test the new functionality.

12.6 Summary
This chapter covered some important steps and tools for working with

dates, times, and timestamps. With the information covered here, you can
now create ABAP applications that can accurately calculate dates and times
across various time zones and consider working days to calculate import-
ant dates.
We also covered how to work with quantities and currencies in both the
ABAP Dictionary and in ABAP programs and how to read and convert quan-
tities and currencies.
Finally, we updated the shopping cart program from Chapter 10 and Chap-
ter 11 to use quantities and currencies.
In the next chapter, you’ll learn to work with classic dynpro screens.

504
Contents

Preface .....................................................................................................
...............................................................................
.......................... 17

1 Intr
Introd
oduc
ucti
tion
on to SA
SAP’
P’ss ERP
ERP Syst
System
emss 23

1.1
1.1 What
What Are SA
SAP
P and
and AB
ABAP
AP?? ...........................................................................
........................... 23
1.2 Curren
Currentt State
State of SAP’
SAP’ss ERP
ERP System
Systemss ........
...........
...........
...........
..........
...........
...........
...........
............
.......... 24
1.3
1.3 “Old
“Old”” vers
versus
us “Ne
“New”
w” ABA
ABAP
P .........................................................................
......................... 26
1.4 Navig
Navigati
ating
ng SAP ERP Sys
System
temss ....................................................................
................. 28
1.4.1 Overview of SAP GUI ..........
Overview ...........
...........
...........
............
...........
...........
...........
..........
...........
...........
..........
..... 29
1.4.2 Overview
Overview of SAP Fiori .........
...........
...........
..........
...........
...........
...........
...........
..........
...........
...........
..........
..... 33
1.5 Summary ...................................................................................................
.............................................................
........ 34

2 Crea
Creati
ting
ng Yo
Your
ur Fi
Firs
rstt Pr
Prog
ogra
ram
m 35

2.1
2.1 “Hel
“Hello
lo,, W orl
orld!
d!”” ...............................................................................................
........................................... 35
2.1.1 Creating a New Program with Eclipse ...........
Creating ...........
..........
...........
...........
..........
..... 35
2.1.2 Creating
Creating a New Program in Transac
Transaction
tion SE80 ........... ..........
...........
...... 40
2.1.3 Writing a “Hello
“Hello,, World!” Program ...........
...........
...........
..........
..........
...........
...........
...... 45
2.1.4 Adding Featu
Features
res to Your First Program ...........
............
...........
..........
...........
.......... 46
2.2 Summary ...................................................................................................
.............................................................
........ 49

3 ABAP 101 51

3.1 Variab
Variables
les and Con
Consta
stants
nts in ABAP
ABAP .........
...........
...........
..........
...........
...........
..........
...........
...........
...........
....... 51
3.1.1 The DATA Keywor
Keywordd ...........
............
...........
...........
...........
..........
...........
...........
...........
............
...........
...........
...... 51
3.1.2 Numericc Data Types ..........
Numeri ...........
...........
...........
............
...........
...........
...........
..........
...........
...........
..........
..... 53
3.1.3 Character-like
Character-like Data Types ...........
............
............
...........
...........
...........
..........
...........
...........
..........
..... 55

Contents Contents
3.1.4 Boole
Boolean
an ..........
..........
...........
...........
..........
............
...........
...........
...........
..........
...........
...........
...........
.............
..........
...........
.......... 57 3.9
3.9 Tyin
Tying
g IItt All
All Toge
Togeth
ther
er .....................................................................................
................................... 117
3.1.5 Struc
Structure
turess and Internal
Internal Tables Tables .......... ..........
............
..........
...........
...........
..........
............
........
... 58 3.9.1 The Problem .....................................................................................
................................... 118
3.1.6 Inli
Inline
ne Data Declarat
Declarations ions ......... ...........
..........
...........
...........
...........
............
...........
............
...........
.........
... 61 3.9.2 The Solution .....................................................................................
.................................. 119
3.1.7 Const
Constants
ants ...........
...........
..........
............
..........
..........
...........
............
..........
............
...........
...........
...........
..........
...........
.........
... 62
3.
3.10
10 Sum
Sum m
mar
ary
y ..................................................................................................
..............................................................
........ 120
3.1.8 System
System Fields
Fields and Pred Predefine efined d Const
Constants ants .......................
...........
..........
.........
... 63
3.2 Arithmet
Arithmetic
ic an
and
d Ba
Basic
sic Math Functio
Functions ns ................
...........
..........
............
..........
...........
...........
..........
...... 65
3.2.1 Arith
Arithmeti
meticc Oper
Operation
ationss ...... ..........
...........
..........
...........
...........
...........
............
...........
............
..........
..........
..... 65
3.2.2 Math Functions
Functions .......
...........
.........
...........
............
..........
...........
..........
...........
...........
...........
............
...........
............
...... 68 4 Da
Data
ta Dict
Dictio
iona
nary
ry Ob
Obje
ject
ctss 121
3.2.3 CLEAR Command
Command .......
............
..........
...........
..........
...........
..........
...........
...........
...........
...........
..........
...........
..........
.... 70
4.1
4.1 Wh
What
at Is a Dat
Datab
abas
ase?
e? .....................................................................................
................................... 121
3 .3
.3 F lo
lo w C on
on ttrr ol
ol .....................................................................................................
...................................................... 72
3.3.1 IF Statements
Statements ........................
.........
...........
...........
...........
............
...........
...........
...........
..........
...........
............
..........
...... 72 4.2 Wha
Whatt Is
Is a Dat
Data
aDDict
iction
ionary
ary?? ........................................................................
.......................... 122
3.3.2 CASE State
Statement
mentss ......... ..........
..........
...........
...........
...........
..........
...........
............
..........
............
...........
...........
.......... 76 4.
4.3
3 Da
Data
taba
base
se D
Des
esii g
gn
n ............................................................................................
........................................... 123
3.3.3 DO Loops .........
...........
............
...........
.........
...........
...........
...........
.............
..........
...........
...........
..........
............
..........
...........
...... 79 4.3.1 Entity Relationship Diagrams ..................................................... ........ 123
3.3.4 WHIL
WHILE E Loops
Loops ............
...........
............
..........
..........
...........
...........
...........
............
...........
...........
............
............
..........
....... 79 4.3.2 Database Normalization ................................................................................ 124
3.4
3.4 Selec
Selectio
tion
n Scre
Screen
en Progra
Programmi
mming
ng ................................................................
.......... 80 4.3.3 Relationships in ERDs ....................................................................
................. 126
3.4.1 PARAM
PARAMETER
ETER ............ ...........
............
...........
...........
...........
...........
..........
...........
...........
...........
............
............
..........
.......... 81 4.4 Naviga
Navigatio
tion
n to ABAP
ABAP Dict
Diction
ionary
ary Objec
Objects
ts .............................................. 127
3.4.2 SELE
SELECT-OP
CT-OPTIONS
TIONS ............ .........
...........
...........
...........
............
...........
...........
...........
..........
...........
...........
............
..... 85
3.4.3 Sele
Selection
ction Texts ........ ..........
...........
...........
...........
...........
...........
..........
...........
...........
...........
............
...........
............
...... 87 4.5 Table,
Table, Dat
Dataa Eleme
Element,
nt, and Dom ain .........................................................
Domain .......... 129
3.4.4 SELE
SELECTION-
CTION-SCREE
SCREEN N .....................
...........
...........
...........
..........
...........
...........
...........
...........
..........
...........
.......... 88 4.6 Train
Training
ing Data Model and Examp
Example le D
Defini
efinition tion .....................
...........
...........
............
........... 132
3.4.5 BLOCK .......
...........
...........
............
...........
...........
..........
..........
...........
...........
...........
............
...........
............
..........
..........
...........
.......... 88 4.6.1 SAP Flight
Flight an
and
d Booking
Booking Data Model
Model .......... ...........
...........
.........
............
...........
..........
.... 133
3.4.6 Other Sele
Selection
ction Screen Screen Elem Elements ents ............
..........
..........
...........
...........
...........
............
.......... 91 4.6.2 Train
Training
ing Example:
Example: Enhancin
Enhancing g the SAP Model Model .......... ..........
...........
........
... 134

3 .5
.5 Ev
ve
e nt
nt Bl
Bl oc
oc k
kss .....................................................................................................
...................................................... 92 4.7
4.7 Cr
Crea
eati
ting
ng a Ne
New
w Doma
Domain
in .............................................................................
.......................... 135
3.5.1 INITI
INITIALIZA
ALIZATION TION .......................
.........
...........
............
...........
...........
............
...........
...........
...........
..........
............
........
... 93 4.8 Creati
Creating
ng a N
New
ew Dat
Data
a Elem
Element
ent ..................................................................
.................. 139
3.5.2 AT SELE
SELECTION-
CTION-SCREE SCREEN N ...........
...........
...........
...........
..........
...........
...........
...........
............
...........
...........
...... 93
4.9 Creati
Creating
ng and Edi
Editin
tingg Tabl
Tables
es ......................................................................
.................. 144
3.5.3 START
START-OF-S
-OF-SELEC ELECTION TION ........... ..........
...........
............
..........
............
...........
...........
...........
..........
...........
.......... 95
4.9.1 Viewing
Viewing th
the
e Flight
Flight Table Configurat
Configuration ion ......................
..........
............
...........
...... 144
3 ..6
6 Form
Format
atti
ting
ng Co
Code
de ............................................................................................
............................................ 95 4.9.2 Creating an Append Structure ................................................... ........ 151
4.9.3 Creating
Creating a Custom
Custom Transpar
Transparent ent Table .......... ..........
..........
...........
...........
...........
..... 154
3.7 ommen ttss .........................................................................................................
C om ...................................................... 97
3.7.1 Comm
Common on CommCommentin enting g Mist
Mistakes akes .......... ............
..........
...........
............
...........
...........
.......... 98 4.1
4.10
0 Docum
Document
entati
ation
on ...............................................................................................
........................................... 161
3.7.2 Using Comments while Programming Programming .................................... 100
4.11 Viewi
Viewing
ng Data
Data in the
the Database
Database Tables
Tables .................................................. 162
3 ..8
8 D ebu
ebugg
ggin
ing
gBBas
asic
icss ...........................................................................................
............................................ 100 4.11.1 Data Preview in Eclipse .................................................................
.................. 162
3.8.1 Program to Debug ...........................................................................
......................... 101 4.11.2 Data Browser in SAP GUI ..............................................................
................... 164
3.8.2 Breakpoints in Eclipse ....................................................................
................. 103 4.11.3 Setting Up the Flights Example Data ....................................... 169
3.8.3 Breakpoints in the SAP GUI .......................................................... ....... 108
4.12 Table Maint
Maintenanc
enance
eDDialo
ialogs
gs .......................................................................
.................. 170
3.8.4 Watchpoints in Eclipse ..................................................................
................ 113
4.12.1 Generating Maintenance Dialog for a Table ......................... 170
3.8.5 Watchpoints in SAP GUI ................................................................
.................. 116
4.12.2 Table Maintenance Transaction SM30 ................................... 172

8 9

Contents Contents
4.13 Struct
Structures
ures and Table Types .......................................................................
....................... 174 6 St
Stor
orin
ing
gDDat
ata
a in
in W
Wor
orki
king
ng Me
Memo
mory
ry 229
4.13.1 Creating Structures ........................................................................
....................... 174
4.13.2 Creating Table Types .....................................................................
........................ 176
6.1 Using
Using ABAP
ABAP D
Dict
iction
ionary
ary Data
Data T
Type
ypess ........................................................
......... 229
4.14
4.14 Sear
Search
ch Hel
Help
p .......................................................................................................
.................................................. 177
6.2 Creati
Creating
ng Data
Data Typ
Types
es wi
with
th the T
TYPE
YPE Ke
Keywo
yword
rd ..........
...........
...........
...........
............
........... 231
4 .1
.1 5 V iie
e ws
ws ....................................................................................................
...................................................................
............... 181
6.3
6.3 Fi
Fiel
eld
d Sym
Sym b
bol
olss ...................................................................................................
.................................................... 233
4.16
4.16 Su
Sum
m mar
mary
y ...................................................................................................
..........................................................
........ 184
6.4 Def
Defini
ining
ng Intern
Internal
al Tables .............................................................................
Tables .......................... 234
6.4.1 Defining Standard Tables ............................................................. ....... 234
6.4.2 Keys in Internal Tables ..................................................................
................ 236
5 Acce
Access
ssin
ing
g the
the Da
Data
taba
base
se 185 6.4.3 Defining Sorted Tables .................................................................
................. 238
6.4.4 Defining Hashed Tables ...............................................................
................. 240

5.1
5.1 SQ
SQLL Con
Conso
sole
le iin
n Ec
Ecli
lips
pse
e .................................................................................
.................................. 186 6.5 Rea
Readin
ding
g Da
Data
ta fr
from
om IInte
nterna rnall Table
Tabless ........................................................
......... 241
6.5.1 READ TABLE .......................................................................................
................................... 241
5 .2
.2 Re a
ad
d in
in g Da a ...................................................................................................
Da tta ................................................... 187
6.5.2 LOOP AT .............................................................................................
............................................ 247
5.2.1 SELECT Statements ........................................................................
....................... 188
5.2.2 INNER JOIN ........................................................................................
......................................... 192 6.6 Modify
Modifying
ing Intern
Internal
al Tables
Tables .........................................................................
.......................... 250
5.2.3 LEFT OUTER JOIN .............................................................................
................................ 197 6.6.1 Inserting/Appendi
Inserting/Appending ng Rows ......................................................... .......... 250
5.2.4 FOR ALL ENTRIES IN ........................................................................
...................... 199 6.6.2 Changing Rows ................................................................................
.................................... 253
5.2.5 With SELECT-OPTIONS ..................................................................
...................... 201 6.6.3 Deleting Rows ..................................................................................
................................... 255
5.2.6 Aggre
Aggregate
gate Expression
Expressionss iin n SSELECT
ELECT State Statement mentss ............... ............
...... 203 6.7 Other
Other Inte
Interna
rnall Table
Table Ope Operat rationionss .............................................................
......... 257
5.2.7 New Open SQL .................................................................................
................................ 205 6.7.1 Copying Table Data ........................................................................
......................... 257
5.2.8 ABAP CDS Views ..............................................................................
............................... 207 6.7.2 SORT ....................................................................................................
.................................................... 258
5.3
5.3 Chhan
angg iing
ng Da
Data
ta ................................................................................................
.................................................. 210 6.7.3 DELET
DELETEE AADJACE
DJACENT NT DUPL
DUPLICATE ICATESS FROM ............ ............
...........
..........
.............
......... 260
5.3.1 INSERT ................................................................................................
.................................................. 210 6.8 Which
Which Tab
Table
le Should
Should Be U
Used
sed?? ..................................................................
.................. 261
5.3.2 MODIFY/UPDATE ............................................................................
.................................. 211
6.9 Upd
Updati
ating
ng ABAP
ABAP Di
Dicti
ctiona
onary
ry Table
Table Type
Type ................................................. 263
5.3.3 DELETE ................................................................................................
.................................................. 213
6.10 Obsol
Obsolete
ete Wor
Working
king Memory Syntax
Syntax ................................................................ 265
5 .4
.4 Ta
abb le
le L o
occ k
kss .........................................................................................................
................................................. 214
6.10.1 WITH HEADER LINE ........................................................................
......................... 266
5.4.1 Viewing Table Locks .......................................................................
....................... 216
5.4.2 Creating Table Lock Objects ........................................................ ............... 218 6.10.2 OCCURS ..............................................................................................
........................................... 266
6.10.3 Square Brackets ...............................................................................
.................................. 267
5.4.3 Setting Table Locks ........................................................................ ............... 220
6.10.4 Short Form Table Access ..............................................................
.................. 267
5.5
5.5 Pe
Perfo
rform
rman
ance
ce Topi
Topics
cs ......................................................................................
................................. 224 6.10.5 BINARY SEARCH ...............................................................................
................................. 267
5.6 Obs
Obsole
olete
te Da
Datab
tabase
ase Acces
Accesss Key
Keywor
words ds ...................................................
........ 226 6.11
6.11 Sum
Sum m
mar
ary
y ..................................................................................................
.............................................................
......... 268
5.6.1 SELECT…ENDSELECT .......................................................................
........................ 226
5.6.2 Short Form Open SQL ....................................................................
............... 227
5.7 Summary ...................................................................................................
..........................................................
........ 227

10 11

Contents Contents

8.2.2 Creating a Message Class ............................................................


................. 333
7 Ma
Maki
king
ng Pr
Prog
ogra
rams
ms Mo
Modu
dula
larr 269
8.2.3 Using the MESSAGE Keyword .....................................................
........ 336

7.1
7.1 Sepa
Separa
rati
tion
on of
of Conc
Concern
ernss ................................................................................
............................ 269 8 .3
.3 Exce
Except
ptio
ion
n Cla
Class
sses
es ...........................................................................................
........................................... 341
8.3.1 Unhandled Exceptions ..................................................................
................. 342
7. 2 S ub
ub ro
ro u
utt in
ine s ..................................................................................................
.......................................................
.... 272
8.3.2 TRY/CATCH Statements ................................................................................ 348
7.3 Introd
Introductio
uction
n to Object-
Object-Orient
Oriented ed Progra
Programmin mming g ........
...........
..........
...........
............
..... 274 8.3.3 Custom Exception Classes ........................................................... ................ 350
7.3.1 What Is an Object? ..........................................................................
........................... 274
8.4
8.4 No
Non-C
n-Clas
lass-
s-Bas
Based
ed Ex
Excep
cepti
tions
ons .....................................................................
................. 355
7.3.2 Modul
Modulariz
arizing
ing with Obje
Object-Or
ct-Oriente
iented
d Prog
Programm
ramming
ing .......
..........
..... 276
8.5 Summary ...................................................................................................
..............................................................
....... 358
7.4
7.4 St
Stru
ruct
ctur
urin
ing
g Cla
Class
sses
es .........................................................................................
..................................... 277
7.4.1 Implementati
Implementation on versus Definition ........................................... 278
7.4.2 Creating Objects ..............................................................................
.......................... 278
7.4.3 Public and Private Sections .......................................................... ......... 280 9 Pres
Presen
enti
ting
ng Data
Data Usin
Using
g tthe
he
7.4.4 Class Methods ..................................................................................
..................................... 282
ABAP List Viewer 361
7.4.5 Impor
Importing,
ting, Returnin
Returning, g, Export
Exporting, ing, and Chan Changing ging ...........
............
....... 286
7.4.6 Constructors ......................................................................................
................................... 293
9 .1
.1 W ha
ha t I s A LLV
V ? ....................................................................................................
................................................... 361
7.4.7 Recursion ...........................................................................................
............................................ 295
7.4.8 Inheritance ........................................................................................
............................................ 297 9.2 Rep
Report
ort Exa
Example
mple Usi
Using
ng a
an
n SA
SALV
LV T
Table
able ................................................... 366

7.4.9 Composition ......................................................................................


................................... 302 9.3 Rep
Report
ort Exa
Example
mple Usi
Using
ng SALV Tree ............................................................
SALV ....... 371
7.5
7.5 Gl
Glob
obalal C las
lasse
sess ..................................................................................................
............................................... 308 9.4 ALV wit
with
h IInteg
ntegrate
rated
d Data
Data Access ............................................................
Access ....... 380
7.5.1 How to Create Global Classes in Eclipse ................................. 309
9.5
9.5 Out
Outda
dated
ted AL
ALV
V Fr
Frame
amewo
works
rks .......................................................................
......................... 383
7.5.2 How to Creat
Create e GlGlobal
obal ClasClasses ses in Transacti
Transaction on SE80SE80 .................. 310
9.5.1 REUSE_AL
REUSE_ALV_GRI
V_GRID_DI
D_DISPLA
SPLAY Y Funct
Function ion Module
Module ............ ..........
..........
...... 383
7.5.3 Using
Using ththe e Form-
Form-Based Based View in T Trans
ransactioaction n SE80
SE80 .....................
..... 312
9.5.2 CL_GUI_ALV_GRID Class ..............................................................
.................. 385
7.6
7.6 De
Desi
sig
g n Pa
Patt
tter
erns
ns ..............................................................................................
.............................................. 317
9.6 Summary ...................................................................................................
..............................................................
....... 386
7.7
7.7 Fu
Func
ncti
tion
on Mo
Modu
dull es
es ...........................................................................................
..................................... 317
7.7.1 Crea
Creating
ting Function
Function Group Groupss a and
nd Modules
Modules in Eclipse Eclipse ......... .........
.... 318
7.7.2 Crea
Creating
ting Function
Function Group Groupss in in T Trans
ransactio
action n SE80
SE80 ......................
........
... 322
7.7.3 Calling Function Modules ............................................................. .......... 326 10 Crea
Creatin
ting
g a Sho
Shoppin
pping
g Car
Cartt Exa
Exampl
mple
e 387

7.8 Summary .......................................................................................................


.......................................................
.... 327
10.1
10.1 Th
The
e Desi
Design
gn ........................................................................................................
.................................................... 388
10.1.1 The Database ...................................................................................
.................................. 389
10.1.2 The Global Class ..............................................................................
.................................. 390
8 Error H
Ha
andling 329 10.1.3 The Access Programs .....................................................................
........................ 390
10.2
10.2 Databas
Database
e Solution .........................................................................................
Solution ........................................... 392
8. 1 SY- SU
SUBRC .......................................................................................................
.......................................................
.... 329 10.2.1 Data Elements .................................................................................
.................................. 392
8.2
8.2 Mess
Messagage
e C llas
asse
sess .............................................................................................
............................................. 331 10.2.2 Transparent Tables ........................................................................
........................ 397
8.2.1 Displaying a Message Class ......................................................... .......... 331

12 13

Contents Contents

10.3 Accessi
Accessing
ng th
the
e Data
Database
base S
Soluti
olution
on ...........................................................
.............. 405 12.1.3 Datum Date Type .............................................................................
.......................... 473
12.1.4 System Date Fields ..........................................................................
.......................... 475
10.4 Creati
Creating
ng a Mess
Message
age Class
Class for the So
Solutio
lution
n ......................................... 415
12.1.5 Date-Limited Records .....................................................................
.................. 475
10.5 Creati
Creating
ng Cla
Classic
ssic Screens
Screens for the
the Solut
Solution
ion ........................................... 416
1 2. ime s .........................................................................................................
2. 2 T im ................................................................
......... 477
10.5.1 Product Maintenance Program .................................................
..... 417
12.2.1 Calculating Time ..............................................................................
.......................... 477
10.5.2 Shopping Cart Maintenance Program ..................................... 423
12.2.2 Timestamps .......................................................................................
................................... 478
10
10.6
.6 Su
Sum
m mar
mary
y ......................................................................................................
........................................................
...... 429 12.2.3 SY-UZEIT (System Time versus Local Time) ............................ 482
12.3
12.3 Quan
Quantitities .........................................................................................................
ties ...................................................... 482
12.3.1 Quantity Fields in Data Dictionary ........................................... 484
11 Wor
Workin
king
g wit
with
h Str
String
ingss and T
Text
extss 431 12.3.2 Converting Quantities ................................................................... .................. 485
12.4
12.4 Curre
Currenc iess .........................................................................................................
ncie ...................................................... 486
11.1
11.1 Str
String
ing Man
Manipu
ipulat
lation
ion ......................................................................................
...................................... 431 12.4.1 Currency Fields in Data Dictionary ........................................... 487
11.1.1 String Templates ............................................................................
................................ 432 12.4.2 Converting Currencies ................................................................... .................. 488
11.1.2 String Functions ..............................................................................
.............................. 435
12.5 Upda
Updating
ting the
the Shopping
Shopping C
Cart
art Example ..................................................
Example 490
11
11.2
.2 Text
Text Symb
Symbol
olss ....................................................................................................
................................................ 437 12.5.1 Updating the Database .................................................................
................. 491
11.2.1 Creating Text Symbols ...................................................................
...................... 437 12.5.2 Updating the Global Class ............................................................
........ 497
11.2.2 Translatin
Translating g Text Symbols ............................................................. ............. 442 12.5.3 Updating the ABAP Programs .....................................................
........ 500
11.3 Trans
Translatin
lating
gDData
ata in Tables ..........................................................................
.................... 445 12.6
12.6 Sum
Sum m
mary ...........................................................................................................
ary ..................................................... 504
11.4
11.4 Transl
Translati
ating
ng Messa
Messages
ges ..................................................................................
............................... 451
11.5 Obsole
Obsolete
te Stri
String
ng an
and
d Text Comma
Commands
nds ...................................................
...... 453
11.6 Updat
Updating
ing the
the Shop
Shopping
ping C
Cart
art Example
Example ................................................. 454 13 Use
Userr Interf
Interface
ace Tech
Technol
nologi
ogies
es 505
11.6.1 Updating the Database .................................................................
............. 454
11.6.2 Using the Text Table .......................................................................
..................... 460 13.1 Worki
Working
ng wi
with
th Classic
Classic Dynpro Screens ..................................................
Dynpro 505
11
11.7
.7 Su
Sum
m mar
mary
y ......................................................................................................
........................................................
...... 463 13.1.1 Dynpro Screen Events ....................................................................
.................. 506
13.1.2 Creating a Dynpro Screen .............................................................
......... 508
13.2
13.2 Modern
Modern UI Tec
Techno
hnolog ies ..............................................................................
logies ........................... 528
13.2.1 Web Dynpro .......................................................................................
................................... 529
12 Workin
Workinggwwith
ith Dates
Dates,, Tim
Times,
es, Quanti
Quantities,
ties, 13.2.2 SAP Screen Personas .......................................................................
.......................... 531
and Currencies 465 13.2.3 SAP Gateway, SAPUI5, and SAP Fiori .........................................
.............................. 532
13.3
13.3 Sum
Sum m
mary ...........................................................................................................
ary ..................................................... 534
12
2.. 1 D at
at es
es ......................................................................................................
................................................................
.............. 465
12.1.1 Date Type Basics ..............................................................................
............................. 466
12.1.2 Factory Calendars ...........................................................................
.............................. 469

14 15

Contents

14 Wor
Working
king with
with ABAP
ABAP Profes
Professio
sionall
nally
y 535
14.1 ABAP System
System Archi
Architecture
tecture Basics ...........................................................
............ 535
14.2
14.2 Tra
Transp
nsport
ort Managem
Management
ent ..............................................................................
............................. 539
14.3 Authorizat
Authorization
ion Conce
Concept
pt ................................................................................
............................. 550
14.3.1 Authorization Object .....................................................................
................... 550

14.3.2 Performing an Authorization


Authorization Check Check in an
ABAP Program ..................................................................................
..................................... 560
14.4
14.4 Workin
Workingg with
with Files
Files ........................................................................................
...................................... 566
14.4.1 Files on the Presentation Server .................................................. 567
14.4.2 Files on the Application Server ..................................................... 577
14.5 ABAP Devel
Developmen
opmentt Guideli
Guidelines
nes ...............................................................
............. 582
14.6 Maint
Maintaini
aining
ng Docum
Documentati
entation
on ...................................................................
................... 586
14.7
14.7 ABA
ABAP
P Unit
Unit Tes
Tests
ts ..............................................................................................
.............................................. 593
14.8
14.8 Bac
Backgr
kgroun
ound
d Jobs
Jobs ............................................................................................
............................................. 602

14.9
14.9 Too
Tools
ls of
of the Trade ..........................................................................................
the Trade ...................................... 611
14.10 Backward Compatibility and
and Dealing with Legacy Code ..........
........
... 621
14.11 Summ
Summary
ary .......................................................................................................
.......................................................
.... 623

Appendices 525

A Prepa
Prepari
ring
ng Your
Your Deve
Develo
lopm
pmen
entt Envir
Environ
onme
ment
nt ...................................... 627
B Inter
Interfa
face
ces,
s, Fo
Form
rms,
s, En
Enha
hanc
ncem
emen
ents
ts ..........................................................
............. 645
C Diff
Differ
eren
ences
ces Be
Betw
tween
een AB
ABAP
AP Ve
Vers
rsio
ions
ns ....................................................
.... 661
D Other Re
Resources .............................................................................................
............................................. 667
E The Authors ..................................................................................................
.......................................................
.... 671

Index ....................................................................................................
...................................................................................
.............................. 673

16

Index
A ABAP Unit ..................................................... 593
wizard ........................................................ 598
ABAP ABAP versions ................................................ 28
backward compatibility .................... 621 ABAP Workbench, Transaction
code updates .......................................... 621 SE80 ............................................................ 639
modern syntax ...................................... 622 abap_bool ........................................................ ... 57
obsolete code support ........................ 622 abap_false ........................................................
........... 57
system implementation ..................... 622 abap_true .........................................................
........... 57
versions ....................................................
....... 661 ABAP-based IDEs IDEs ........................................ 639
ABAP CDS ............................................ 207, 663 abapGit .............................................................
............ 99
ABAP clients ............................................ 28, 29 abs .......................................................................
.............................. 69
SAP Fiori ......................................................
.......... 28 Activation log
SAP GUI .......................................................
......... 28 warnings .................................................. 154
SAP NetWeaver Business Client ......... 28 ADD ....................................................................
..................... 68
ABAP daemons
daemons ........................................... 665 Adobe LiveCycle
LiveCycle Designer Designer ..................... 654
ABAP Debugger
Debugger .......................................... 108 Aggregatee expressions ............................ 203
Aggregat
ABAP Development Tools in Aliases ............................................................
........... 194
Eclipse ....................................................... 128 ALV .........................................................
...... 361, 602

getting started ....................................... 633 CL_GUI_ALV ........................................... 363 363


ABAP Dictionary ............................... 121, 229 CL_GUI_ALV_GRID .............................. 385
data element .......................................... 230 classic ........................................................
............ 362
fields ..........................................................
............ 129 grid .............................................................
.................... 363
table field ................................................. 230 grid vs. table ............................................ 364
ABAP Dynpro
Dynpro .............................................. 516 outdated ................................................... 383
ABAP Editor
Editor ................................................. 517 REUSE_ALV ............................................. 363
ABAP environments
environments ................................ 536 SALV ........................................................... 364
ABAP guidelines
guidelines ........................................ 583 table ...........................................................
............ 571
ABAP landscape
landscape ......................................... 536 with IDA ........................................... 365, 380
ABAP List Viewer
Viewer (ALV) ........................... 361 Any DB ..............................................................
............. 25
ABAP Managed Database Append structure,
structure, create ........................ 151
Procedures (AMDP) ...................... 28, 663 Application server
server ..................................... 566

ABAP
ABAP on SAPeCloud
packag
package Platform ............... 665
............................................. 540 Application etable
txpressions
able .......................................
Arithmetic expressions .............................146
68
ABAP perspective
perspective ......................................... 36 Arithmetic operations
operations ................................ 65
select ............................................................. 36 AS ............................................................
.................... 194, 206
ABAP report .................................................... 81 AT SELECTION-SCREEN
SELECTION-SCREEN .............................. 93
ABAP statement
statement ............................................ 45 event .............................................................
........... 93
ABAP syntax ................................................... 45 AUTHORITY-CHECK
AUTHORITY-CHE CK ................................. 560
ABAP Test Cockpit
Cockpit ............................ 611, 615 Authorization
ABAP trial
trial .....................................................
........ 628 group .........................................................
............ 170
trace ...........................................................
............ 563
Authorization check check ................................. 550

673

Index Index

Authorizations camelCase ........................................................


......... 52 Currencies .................................................... 486 Database (Cont.)
check ..........................................................
........... 560 Cardinalities ....................................... 127, 157 CONVERT_TO_LOCAL_ normalization ............................... 124, 125
class ..................................................
.......... 552, 554 CASE statements
statements .......................................... 76 CURRENCY .......................................... 489 Date
object .........................................................
........... 550 OR .................................................................. 77 CUKY .......................................................... 487 CL_ABAP_TSTMP .................................. 482
permitted ac tivity ................................. 553 WHEN ........................................................... 76 CURR .......................................................... 487 CONVERT TIME STAMP ...................... 479
role definition ......................................... 554 WHEN OTHERS ......................................... 77 exchange rates ...................................... 487 DATE_CONVE RT_TO_
ceil ...................................................................... 69 Currency/quantity .................................... 149 FACTORYDATE .................................. 471
B Chained statements
statements .................................... 46 Custom exception classes date-limited record .............................. 475
Change document
document ..................................... 142 CX_DYNAMIC_CHECK ....................... 352 datum type .............................................. 473
Background job .......................................... 602 Change Release Management
Management ............... 549 CX_NO_CHECK ..................................... 352 factory calen dars .................................. 469
create .........................................................
........... 603 Character-based data types ...................... 55 CX_STATIC_CHECK .................... 351, 352 FACTORYDA TE_CONVERT_TO_
events ......................................................... 609 ChaRM .............................................................
............... 549 CX_SY_ILLEGAL_HANDLER ............. 352 DATE ......................................................
........ 471
status .........................................................
........... 609 Check table ................................................... 1 148
48 CX_SY_NO_HANDLER ........................ 351 GET TIME STAMP FIELD ..................... 478
step .............................................................
................... 603 CL_GUI_ALV_GRID
CL_GUI_ALV_GRI D ................................... 383 Customizing table ..................................... 146 public holiday ........................................ 469
BAdI CL_GUI_CUSTOM_CONTAIN
CL_GUI_CUST OM_CONTAINER ER ........... 385 RP_CALC_D ATE_IN_INTER NAL ...... 467
new .............................................................
................... 657 Class D sy-datum ...................................................
..... 475
Balsamiq Wireframes
Wireframes ............................... 391 definition .................................................. 408 sy-fdayw ....................................................
....... 475
BEGIN OF .........................................................
........ 58 for testing ................................................. 594 DATA ................................................ 51, 74, 233 sy-timlo ..................................................... 482
BEGIN OF SCREEN ........................................ 88 implementation ..................................... 412 Data class
class ........................................................ 160 sy-tzone .....................................................
....... 482
Best Practice Guidelines for Classic debugger ......................................... 109 types ...........................................................
............... 150 sy-uzeit ...................................................... 482
ABAP Developers
Developers .................................. 584 Classic dynpro ............................................. 505 Data dictionary
dictionary .......................................... 122 sy-zonlo .....................................................
....... 482
BETWEEN...AND ............................................ 72 Classic selection screen activation log ......................................... 154 timestamp ............................................... 477
Binary floating
floating point .................................. 54 programming
programmin g ........................................... 80 documentation ..................................... 161 timestampl .............................................. 478
Binary format .............................................. 567 Clean ABAP ................................................... 5 584
84 transparent table ................................. 230 valid_from/valid_to ............................ 475
Binary logic .................................................... 72 CLEAR ................................................................ 70 Data element .................. 121, 129, 130, 139, Date type ..........................................................
....... 56
BINARY SEARCH
SEARCH ......................................... 267 Client ................................................................
................. 134 148, 392 Deadlock ........................................................
..... 214
Binary search ............................................... 239 Client/serverr architecture ............... 24, 535
Client/serve predefined t ype ..................................... 140 Debug perspective
perspective ....................................... 36
BLOCK .......................................................
............ 80, 88 Clustered tables tables .......................................... 144 redundant ................................................ 125 Debugging .................................................... 100
NO INTERVALS ......................................... 89 Code Inspector ............................................ 611 search help .............................................. 141 execution stack ...................................... 285
WITH FRAME ............................................ 89 Comments ...................................................... 97 Data type ...................................................... ... 148 toolbar .......................................................
....... 104
WITH FRAME TITLE ....................... 89, 417 * .......................................................................
............................ 98 b ...................................................................... 53 decfloat16 .........................................................
...... 53
Boolean ............................................................ 57 \\ .....................................................................
.................... 98 c (character) ........................................ 55, 56 decfloat34 .........................................................
...... 53
yes/no user respo nse ............................. 84 ABAP Doc .................................................. 592 d (date) .................................................. 55, 56 Decimal floating
floating point numbe numbers rs ........... 54
Breakpoint .................................................... 101 mistakes ...................................................... 98 decfloat16 .................................................... ...... 54 Decimal places ............................................... 54
create .........................................................
............ 110 use in programming ............................ 100 decfloat34 .................................................... ...... 54 Default component
component nam namee ..................... 141

Buffering .......................................................
............ 224 CONCATENATE ........................................... 453 f (floating p oint) ....................................... 54 DELETE ........................................ 213, 413, 420
options ......................................................
....... 151 Constants ..................................................
... 52, 62 i .................................................................
.................. 53, 74 FROM...WHERE ....................................... 414
Business Add-Ins
Add-Ins (BAdIs) ........................ 657 abap_false .................................................. 57 n (numeric) ................................... 53, 55, 5 56
6 DELETE ADJACENT DUPLICATES
abap_true ................................................... 57 p (packed) .................................................... ..... 54 FROM ......................................................... 260
C naming ........................................................ 62 s .......................................................................
........................ 53 COMPARING ........................................... 260
Constructor ........................................ 409, 412 string ...................................................... ..... 55, 56 COMPARING ALL FIELDS ................... 260
Calendar Control flow
flow ..................................................... 72 SYST ............................................................... 63 DELETE TABLE
TABLE .................................... 255, 263
factory .......................................................
............ 469 Core data services
services (CDS) ................... 28, 207 t (time) .................................................. 55, 55, 56 hashed table ........................................... 257
fiscal year ................................................. 473 CREATE OBJECT ........................................... 303 Database sorted table ............................................. 257
CALL SELECTION-SCREEN
SELECTION-SCREEN ......................... 88 Crow’s foot notation ................................. 126 definition .................................................... 121 WHERE .......................................................
....... 257
WITH TABLE KEY ................................... 256

674 675

Index Index

Deletion anomaly
anomaly ...................................... 124 Enhancement category ................. 153, 160 File IF ...........................................................................
............................. 72
Delivery and
and maintenance
maintenance .................... 146 Enhancement framework ............ 659, 662 interfaces ................................................. 645 AND ................................................................
.......... 73
DEQUEUE ................................... 216, 220, 223 Enhancements ............................................ 654
Enhancements logical name ........................................... 582 ELSE ................................................................
.......... 73
Design patterns
patterns .......................................... 317 ENQUEUE ....................................................... ..... 220 on application server .......................... 577 ELSEIF ............................................................
.......... 75
DEV environment
environment ..................................... 536 Enterprise resource plan planningning ................. 23 on presentation server ....................... 567 OR ....................................................................
..................... 73
Developmentt guidelines ........................ 582
Developmen Entity ...............................................................
............. 123 transfer protocol ................................... 645 IF statement operators
operators ............................... 76
Developmentt standards
Developmen standards ........................... 42 Entity relationship diagrams Flight model INCLUDE ........................................................ 517
DevOps ........................................................... 535 (ERDs) .........................................................
...... 123 load data .................................................. 169 Initial value .................................... 51, 71, 147
DIV ..................................................................... 66 Entry help/check
help/check ........................................ 159 Floor ...................................................................
................. 69 INITIALIZATION
INITIALIZAT ION ............................................ 92
DIVIDE .............................................................. 68 ERD ..................................... 123, 389, 455, 490
490 Flow control
control ...................................................... 72 Inline data declaration ... 61, 189, 420, 427
DO ...................................................................... 79 crow’s foot notation, relationship Flow logic ...................................................... 516 INNER JOIN .......................................... 192, 414
Documentation
Documentat ion ................................ 161, 586 indication ............................................ 126 FLUSH_ENQUEUE
FLUSH_ENQ UEUE ..................................... 222 Input help ..................................................... 178
Domain .................... 121, 130, 135, 394, 400 normalized ............................................... 125 FOR ALL ENTRIES IIN N ................................. 199 INSERT ......................................... 210, 250, 263
range .......................................................... 137 Event ..................................................................
............... 92 Foreign key key ............................... 126, 148, 399 hashed table ........................................... 252
DSAG guidelines
guidelines ........................................ 584 AT SELECTION SCREEN .......................... 93 cardinality ............................................... 157 INDEX .........................................................
........... 250
Dynamic breakpoints
breakpoints .............................. 106 INITIALIZATION ....................................... 93 create ......................................................... 157 LINES FROM ............................................ 251
Dynamic programprogram ..................................... 505 START-OF-SELECTION ........................... 95 set ................................................................
.................... 156 sorted table ............................................. 252
Dynpro ........................................................... 505 Exception ............................................................ 341 Form ................................................................
.................. 649 Insert anomaly
anomaly ........................................... 125
create screen ........................................... 508 500 SAP interna l server error ........... 343 FORM CHANGING
CHANGING ..................................... 274 Integrateddevelopment
Screen events .......................................... 506 CATCH BEFORE UNWIND ................... 350 FORM...ENDFORM ..................................... 272 environments
environme nts (IDEs) ........................... 627
screen flow diagram ............................ 507 CATCH...INTO .......................................... 349 Format your code ......................................... 96 Internal tables ............................. 59, 229, 261
categories ................................................. 350 frac ......................................................................
................... 69 hashed key ............................................... 237

E custom exception classes ................... 350


function modu les .................................. 356
Fully buffered
buffered ............................................. 225
Function group ....................... 170, 318, 322
hashed table .................................. 240, 261
key ............................................................... 236
Eclipse non-class based exceptions ............... 355 Function modules
modules ............................ 318, 324 secondary keys ....................................... 237
ABAP perspec tive .................................... 36 RAISE EXCEPTIO N TYPE ...................... 349 CALL FUNCTION .................................... 326 SORT ........................................................... 258
ABAP projects ......................................... 636 resumable exceptions ......................... 349 parameters .............................................. 321 sorted key ................................................. 237
create program ........................................ 35 RESUME ..................................................... 350 sorted table .................................... 239, 261
create project ............................................ 39 short dump .............................................. 342 G standard key ........................................... 237
dynpro ....................................................... 509 ST22 ..............................................................
................ 344 standard table ............................... 234, 261
format code ............................................... 96 TRY…CATCH ............................................. 348 Generic area
area buffered
buffered .............................. 225 INTO ................................................................ 206
open project .............................................. 38 unhandled ................................................ 342 GETWA_NOT_ASSIGNED ....................... 233 INTO TABLE
TABLE .................................................... 206
outline ......................................................... 38 Exclusive lock .............................................. 215 Global class .................................................. 389 ipow ..........................................................
........... 69, 102
perspectives ............................................. 634 Execute program ........................................ 610 Global variables
variables ......................................... 272 ITAB_ILLEGAL_SORT_ORD
ITAB_ILLE GAL_SORT_ORDER ER .............. 240
problems ..................................................... 38 Execution stack ........................................... 105

project explorer ....................................... 38


SQL Console ................................... 186, 188 EXIT ....................................................................
Extended Program Check ............. 611, 612
Program 79 H J
versus Transaction SE80 ...................... 38 Hash board .......................................... 240, 263 JavaScript ..........................................................
.......... 34
views ............................................................
.............. 36 F High-level documentation
documentation .................... 586
workspaces .............................................. 633 HTML5 ...............................................................
................ 34 K
Electronic Data Interchange
Interchange (EDI) (EDI) ....... 647 f ............................................................................
................................ 53
ELSE ...................................................................
....................... 73 Field I Key ................................................................... 147
END OF ............................................................. 58 catalog ....................................................... 384 Key fields/candidate
fields/candidate ................................ 157
ENDDO ............................................................. 79 label .............................................................
................ 141 Identifying relationship ......................... 126 Keyword
ENDIF ................................................................ 72 Field symbols ............................................... 233 IDES solution .............................................. 627 APPEND ..................................................... ... 251
ASSIGN ....................................................... 233 IDocs ............................................................... 647 AS .................................................................
.................. 194

676 677

Index Index

Keyword (Cont.) L N Open SQL


SQL ............................................... 28, 185
BEGIN OF .................................................... 58 aggregate expressions ........................ 203
BINARY SEARCH .................................... 267 Learning path ................................................ 18 New ABAP .........................................................
........ 26 DELETE .......................................................
.......... 213
BLOCK .......................................................... 88 LEFT OUTER
OUTER JOIN ....................................... 197 New Open SQL ............................................ 205 DELETE FROM ........................................ 214
CLEAR ................................................... 59, 70 Legacy ABAP ................................................... 26 No input history ........................................ 142 FOR ALL ENTRIES IN ............................ 199
comments .................................................. 97 LENGTH ............................................................ 55 Nonidentifying
Nonidentifyin g rerelationship
lationship ................ 126 INNER JOIN .............................................. 192
DATA ................................................ 51, 57, 71 Local variables ............................................. 272 NULL ............................................................... 147 INSERT ....................................................... 210
................................................................. 233 Lock objects .................................................. 218 Numeric datadata types ..................................... 53 INTO ............................................................
................... 206
DELETE ......................................................
..... 256 Log data options ......................................... 151 INTO TABLE ............................................. 206
DELETE ADJACENT DUPLICA TES
FROM ....................................................
Logical storage parameters
parameters .................... 150 O LEFT OUTER JOIN .................................. 197
...... 260 Loop ................................................................... 79 MODIFY .............................................. 211, 230
END OF ........................................................ 58 infinite ..........................................................
........ 79 Object-oriented
Object-orie nted programming
programming ..... 27, 274 SELECT ....................................................... 187
ENDFORM ................................................ 272 LOOP AT ..........................................................
....... 247 attributes ................................................. 281 SELECT * .....................................................
.......... 188
ENDLOOP ................................................. 247 hashed table ............................................ 249 CHANGING ..................................... 286, 292 SELECT OPTIONS ................................... 201
EXIT ..............................................................
................ 79 WHERE ........................................................
......... 248 class ........................................ 275, 277, 278 SELECT SINGLE ....................................... 189
FIELD-SYMBOLS class definition ...................................... 2 278
78 SELECT SINGLE * .................................... 191
................................................................. 233 M class implementation ......................... 278 SELECT...ENDSELECT ............................ 226
FORM .........................................................
........... 272 composition ............................................ 302 short form ................................................ 227
INSERT ....................................................... 251 Maintenance dialog .................................. 170 CONSTRUCTOR ...................................... 294 SUM ............................................................ 204
INSERT LINES OF ................................... 251 MANDT .................... 134, 156, 157, 210 210,, 536 CREATE OBJECT ..................................... 278 UP TO 1 ROWS ........................................ 226
IS INITIAL ................................................. 199 Math functions
functions ............................................. 68 CREATE PUBLIC ..................................... 309 UP TO n ROWS ....................................... 191
IS NULL ...................................................... 199 syntax ...........................................................
....... 69 EXPORTING .................................... 286, 291 UPDATE .....................................................
.......... 212

LENGTH ............................................................. 55 Message class ..................................... 331, 359 FINAL ......................................................... 309 WHERE .......................................................
.......... 191
LOOP AT .................................................... 247 create ..........................................................
......... 333 global classes ...................... 308, 309 309,, 390 WHERE IS NULL ..................................... 198
MODIFY TABLE ...................................... 253 long text .................................................... 337 IMPORTING ................................... 286, 289 WHERE..IN ............................................... 201
MOVE ........................................................... 65 MESSAGE .................................................. 336 INHERITING FROM .............................. 298 Operand .............................................................
.......... 76
OCCURS ..................................................... 266 WITH ...........................................................
......... 339 INTERFACES ............................................ 305 Operator
ON ...............................................................
.................. 193 Method ............................................................
............... 432 method .................................. 275, 282, 283 ADD ................................................................
................. 68
OPEN DATASET… FOR OUTPUT ....... 579 Middleware ....................................................
...... 645 object ......................................................... 274 DIVIDE ...........................................................
......... 68
PARAMETER .............................................. 81 MOD .................................................................. 66 OPTIONAL ............................................... 290 MULTIPLY ..................................................... 68
PERFORM ................................................. 272 Modalities ......................................................
........ 127 private section ....................................... 280 SUBTRACT ................................................... 68
READ TABLE ............................................ 241 MODIFY ............................. 211, 263, 413, 420 protected sec tion ......................... 280, 301 Optimistic lock ........................................... 216
REPORT ................................................ 39, 81 sorted table .............................................. 254 public section ......................................... 280 OR ........................................................................
............................ 73
SELECT-OPTIONS ..................................... 86 MODIFY TABLE ............................................ 253 READ-ONLY attributes ....................... 281 Order of operations
operations ..................................... 66
SORT ........................................................... 258 INDEX ......................................................... 254 REDEFINITION ....................................... 300 Origin of the the input help .......................... 148

TRANSFER ................................................
TYPE ............................................. 51, 97, 579
51, 231 WHERE ........................................................
......... 253 RETURNING ................................... 286, 287 Output
Output implementation
implementation
program ......................... 649
......................................... 649
Modularization ........................................... 269 returning parameters ......................... 293
USING ........................................................
............ 273 Module pool ................................................. 506 506 subclass .....................................................
..... 298
VALUE ................................................... 51, 71 MOVE ................................................................ 65 superclass ................................................ 298 P
WITH HEADER LINE ............................. 266 MOVE-CORRESPONDING
MOVE-CORRESPO NDING ....................... 258 TYPE REF TO ............................................ 278
WITH KEY ................................................. 245 Multi-paradigm programming .............. 27 One-to-many relation
One-to-many relationship ship .................... 127 Package ................................................. 145,
145, 540
WITH TABLE KEY ................................... 245 MULTIPLY ........................................................ 68 One-to-one relationship ......................... 127 $TMP ........................................................ 39, 43
WRITE ..........................................................
........ 45 Online analytical processing
processing (OLAP) .... 25 Packed numbers
numbers ........................................... 54
Online transactional processing Parameter ..................................................
... 80, 81
(OLTP) ........................................................... 25 _COLLECT ................................................. 222
OPEN DATASET…
DATASET… FOR OUTPU OUTPUT T ........... 579 _WAIT ........................................................ 222

678 679

Index Index

Parameter (Cont.) R SAP Gateway ............................................... 532 SELECT (Cont.)


AS CHECKBOX .......................................... 82 SAP GUI ............................................................ 29 UP TO 1 ROWS ........................................ 226
AS LISTBOX VISIBLE LENGTH ............ ........ 82 Radio buttons ................................................ 83 application toolbar ................................. 31 UP TO n ROWS ....................................... 191
boolean parameters .............................. 84 RAISE ................................................................
........................ 357 breakpoints ............................................. 108 SELECT * INTOINTO CORRESPONDING
CORRESPONDING ....... 374
ID .................................................................
.......................................... 141 RAISING ............................................... 351, 352 developer user menu .............................. 32 SELECT SINGLE ............................................ 189
LOWER CASE .................................... 82, 417 Ranges .............................................................
........................ 202 favorites menu ......................................... 31 * .............................................................
.......................................................
....... 191
MATCHCODE OBJECT ............................ 82 RDBMS .............................................................
.......................... 122 system information ................................ 32 SELECT...UP TO n ROWS .......................... 191
MEMORY ID .............................................. 82 READ TABLE ....................................... 241, 263 toolbar ..........................................................
.................................................. 30 SELECT…ENDSELECT
SELECT…EN DSELECT ................................. .......... 226
OBLIGATORY ................................... 81, 424 ASSIGNING ................................................
......................... 241 SAP GUI
GUI de
debugger
bugger ..................................... 109 Selection screen ................................201, 423
RADIOBUTTON GROUP ..... 82, 418, 424 INDEX ..........................................................
........................... 242 SAP GUI
GUI ttheme
heme ........................................... 510 keywords ......................................................
......................... 80
PERFORM ......................................................
......................................... 272 INTO ............................................................
........................... 241 SAP GUI versions .......................................... 31 Selection text ....................................... 87, 418
Polymorphism ............................................ 301 REFERENCE INTO ....................................
........................... 244 SAP HANA ................................................25, 33 SELECTION-SCREEN
SELECTION -SCREEN ..................................... 80
Pooled tables ............................................... 144 WITH KEY ..................................................
........................ 244 SAP Interactive
Interactive Forms by Adobe ........ 649 BLOCK…WITH FRA ME TITLE ............. ... 423
Pragmas .........................................................
.......................................... 662 Recursion .......................................................
........................ 295 SAP LList
ist Viewer
Viewer (ALV) .............................. 361 SELECT-OPTIONS
SELECT-OPT IONS ........ 80, 85, 86, 149, 201
PRD environmen
environmentt ..................................... 536 Relational database management
management SAP List Viewer with Integrated high ...................................................
.........................................................
......... 203
Pretty print ..................................................... 96 system (RDBMS) .................................... 123 Data Access
Access (ALV with IDA) IDA) .............. 365 low .......................................................
.........................................................
....... 203
Primary key ..................... 123, 147, 265, 410 Relational operators ................................... 76 SAP NetWeaver ............................................. 25 option .........................................................
........ 202
Procedural programming ........................ 26 Remote breakpoint ................................... 110 SAP R/1 ............................................................. 24 Separation of concerns ........................... 269
Process After Input (PAI) (PAI) ........................ 506 Remote function call (RFC) .................... 646 SAP Report Sessions .............................................................
....................... 30
Process Before Output (PBO) ................ 506 REPORT ..................................................... 39, 45 DEMO_CALL_SELECTION_SC REEN ...88 SFLIGHT .........................................................
...... 145
Process on
on Help Request
Request (POH) (POH) ........... 507 REUSE_ALV_GRID_DISPLAY
REUSE_ALV_GRI D_DISPLAY ................. 383 SAP S/4 HANA append structure .................................. 152
Process on Value Request (POV) .......... 507 RFC connection
connection ........................................... 646 extensibility ............................................ 659 primary key ............................................. 147

Program attributes
authorization group .............................. 42 RICEF ......................................
..........................
........................ 611
645 SAP S/4HANA
forms ................................................
........................................ .................. 26
................ 649 Shared
Short lock ................................................... 215
form
Runtime Analysis .......................................
editor lock .................................................. 42 tables ..........................................................
................ 144 \[\] .........................................................
.........................................................
...... 267
fixed point arit hmetic ........................... 43 S SAP Screen
Screen Personas ................................ 531 LOOP AT .................................................... ........ 267
language version .................................... 43 SAP Solution
Solution Manag Manager er ................... 549, 586 OCCURS ..................................................... ........ 266
logical database ...................................... 42 SAIRPORT .......................................................
........................ 134 SAP Transport Management Management READ TABLE ............................................ 267
selection screen ........................................ 42 SALV .................................................................
........................ 364 System (SAP TMS) ................................ 538 WITH HEADER LINE ............................. 266
start using variant .................................. 43 demo programs ......................................
.......................... 371 SAPBC_DATA_GENERATOR
SAPBC_DATA_GEN ERATOR .................. 169 Short form
form Open SQL ............................... 227
status ............................................................
....... 42 table .............................................................
........................... 366 SAPBC_DATAMODEL
SAPBC_DATAMOD EL ................................
......................... 133 Sign ...........................................................
......... 69, 202
Unicode checks active ........................... 43 tree ...............................................................
........................... 371 SAPscript .............................................. 649, 652 Signature ........................................................ ..... 314
Program lifecycle events .......................... 92 SAP Basis .......................................................... 25 SAPTEXTEDIT
SAPTEXTEDI T ...............................................
.............................. 523 Simple Object Access Protocol
Promote optimistic lock ......................... 216 SAP Build ........................................................
........ 391 SAPUI5 .................................................... 33, 532 (SOAP) ........................................................ ..... 648
Pseudocode ..................................................
.......................................... 412 SAP Business Suite powered by Scope ...............................................................
.............. 216 Single quotes .................................................. 45
Screen Painter ............................................. 509 numeric variables .....................................
............................ 57
SAP HANA .................................................. 26 Screen stack ................................................. 111 Single records buffered ........................... 224
Q SAP Cloud Appliance Library ................ 627
Amazon Web Services ......................... 630 Search help ......................................... 149, 178 Size category ................................................ 160
QA eenvironment
nvironment ........................................ 536 Microsoft Azure ......................................
............................ 630 SELECT ........................................ 187, 224, 414 Smart Forms ................................................ 649
Quantities .....................................................
......................................... 482 trial system ...............................................
.......................... 627 * .....................................................................
...................... 188 SORTED TABLE ............................................ 238
QUAN .........................................................
......................................... 484 SAP ERP COUNT ....................................................... ........ 203 Space category ............................................ 151
UNIT ...........................................................
.......................................... 484 output implementation ...................... 649 INTO CORRESPONDING ........... ...........
..........
..... 374 Spool requests ............................................ 609
UNIT_CONVERSION_SIMPLE .............. 485 SAP ERP ECC ..................................................... 24 INTO TABLE ............................................. 188 SQL ............................................................
.........................................................
....... 185
SAP ERP systems .......................................... 23 MAX ............................................................
............. 204 START-OF-SELECTION
START-OF- SELECTION ................................. 93
SAP FFiori
iori ................................................. 33, 532 MIN .............................................................
................ 204 event ..............................................................
........................ 95
SAP FFiori
iori launchpad
launchpad .................................... 33 SUM .............................................................
................ 204

680 681

Index Index

String .................................................. 45, 56, 61 T Transaction SE80 (Cont.) SUIM (User Information System) ... 564
ALIGN ........................................................
............ 433 create screen ........................................... 509 VOFM ......................................................... 657
chaining strings ..................................... 433 Table edit program ............................................. 44 Translate ........................................................
........ 454
concat_lines_of ..................................... 435 custom transparent ............................. 154 format code ............................................... 96 Transparent table ........ 121, 123, 144, 154,
CONDENSE ............................................... 435 normalized ............................................... 134 form-based v iew ................................... 312 210, 235, 236, 388, 389
DECIMALS ................................................ 435 SBOOK .......................................................
.......... 134 IDE settings ................................................ 44 currency/quantity
PAD ............................................................. 433 SCARR ........................................................
.......... 134 pretty print ................................................. 96 fields ................................... 484, 487, 488
SIGN ............................................................ 434 SCUSTOM ................................................. 134 program attribute s ................................. 41 Transport .......................................................
........ 538
string functions ..................................... 435 SFLIGHT ....................................................
....... 134 source code view ................................... 312 view .............................................................
.................... 548

string literals ................................. 432, 438 SPFLI ...........................................................


................... 134 Transactions ................................................... 29 Transport management
management .......................... 539
string template ...................................... 432 technical settings .................................. 149 ABAPDOCU ...................................... 55, 583 Transport organizer ................................. 546
strlen ..........................................................
.................. 435 text table .................................................. 445 AL11 ............................................................. 577 Transport request
request ...................................... 542
substring ......................................... 436, 466 view single row ....................................... 189 CMOD ........................................................ 655 Transport route .......................................... 539
substring_before ................................... 436 Table configuration .................................. 1 144
44 CUNI ........................................................... 483 trunc ...................................................................
.................... 69
substring_from ...................................... 436 Table locks ....................................................
........ 214 FILE ............................................................. 582 TYPE .................................... 51, 57, 74, 97, 231
substring_to ............................................ 436 create .........................................................
........... 218 OB08 .......................................................... 487
timestamp formatting ........................ 480 deadlock ........................................................... 214 OY03 ...........................................................
.......... 486 U
WIDTH ....................................................... 433 mode ..........................................................
........... 217 SAT ..............................................................
.................. 617
Structure .................................... 174, 210, 235 parameter ................................................ 217 SCC4 ............................................................
.................. 538 UBTRACT ...........................................................
.......... 68
Subpackages ................................................ 540 set ................................................................
.................. 220 SE10 ............................................................ 546 UML ................................................................. 408
Subroutines ................................................. ... 272 view .............................................................
................... 216 SE11 ... 122, 128, 129, 135, 139, 142, 144, Units of measurement
measurement ............................ 483
PERFORM ................................................. 272 Table type ......................... 174, 189, 232, 263 154, 170, 174, 176, 216, 218, 264, 393, UPDATE ..........................................................
....... 212

Switch Framework .....................................


......662 Tables ..............................................................
................. 537
227 395, .........................................................
397, 400, 401, 455, 484, 487, 491 Update anomaly
sy-batch ........................................................... 64 client-dependent .................................... SE16N 167 face (UI)........................................
User interface
inter .............................. 80, 505124
sy-datlo ............................................................
............... 64 client-independent ................................ 537 SE38 ............................................................ 169 USING ............................................................. 273
sy-datum ......................................................... 64 Technical settings ......... 150, 160, 400, 404 SE63 ......................................... 446, 459, 589
sy-index ........................................................... 64 Template SE71 ............................................................. 652 V
SYST ................................................................... 63 ABAP Editor ............................................. 596 SE80 .....................................................
...... 40, 408
System fields .......................................... 47, 63 Text editor ....................................................
........ 523 SE91 ....................................................
.......... 331, 333 VALUE .........................................................
.............. 51, 71
editing .........................................................
....... 64 Text formats ................................................ 567 SEGW ......................................................... 649 Value range .................................................. 137
sy-batch ............................................................. 64 Text symbols ............................ 419, 424, 437 SM30 ................................................... 170, 172 Variable
sy-datlo .......................................................
....... 64 comparison .............................................. 439 SM36 .......................................................... 603 assign value to .......................................... 65
sy-datum ............................................. .... 63, 64 translation ............................................... 442 SM37 ........................................................... 606 chain together ........................................... 52
sy-index ....................................................... 64 Third normal form .................................... 125 SM59 .......................................................... 647 Variable naming
naming ........................................... 52
sy-subrc ....................................................... 64 table ............................................................
.................... 125 SM62 .......................................................... 609 Variables ...........................................................
......... 51
sy-tabix .......................................................
....... 64 Transaction SE11 SMDAEMON ........................................... 665
sy-timlo ....................................................... 64 ABAP Dictionary .................................... 123 SMOD .........................................................
.......... 655 W
sy-uzeit ........................................................ 64 Transaction SE63 SOAMANAGER ....................................... 648
sy-subrc ............................... 64, 246, 329, 357 translation editor .................................. 448 SP01 ............................................................ 609 Watchpoints ....................................... 101,101, 113
sy-tabix ......................................... 64, 246, 249 Transaction SE80 ST01 ............................................................ 563 Web Dynpro
Dynpro ABAP .................................... 529
sy-timlo ...........................................................
...... 64 ABAP Workbench .................................... 40 ST22 ....................................................
.......... 344, 350 Web Services
Services ................................................ 648
sy-uzeit ............................................................
............... 64 create new program ............................... 40 STMS .......................................................... 539 WHERE ........................................ 191, 198, 199
create program ........................................ 40 SU01 ........................................................... 551 WHERE IS NULL .......................................... 198
SU21 ............................................................ 551 WHERE..IN .....................................................
....... 201
SU3 .............................................................. 474 WHILE loops ..................................................... 79

682 683

Index

Whitespace ..................................................... 66 Z
Wireframe .................................. 391, 417, 423
WRITE ...............................................................
.................. 45 Zero-to-many relationship .................... 127
127
WRITE Hello, World! program ................ 45 Zero-to-one relationship ......................... 127

xUnit ...............................................................
..................... 593

684

First-hand knowledge.
Brian O’Neill is an ABAP developer with more than 10 ye-
ars of experience working across different SAP ERP modules
and custom applications. His experience includes working
in various IT positions, from SAP support to ABAP develop-

ment, while working in the IT department of SAP customer


IGT (International Game Technology). Brian has also worked
as an SAP Mobility consultant with IBM and most recently
has been working as an independent consultant focusing on SAP mobility
projects. Brian has a bachelor‘s degree in computer information systems from
California State University, Chico, and a master‘s degree in information systems
from the University of Nevada, Reno.

Jelena Perfiljeva is a senior ABAP developer at IBM Global


Finances. She started her SAP career in 2005 and has been
involved in SAP rollouts, upgrades, and support for several
US-based companies. Jelena is an SAP Mentor alumna
and was chosen SAP Community (formerly known as SCN)
Member of the Month in April 2013. She was the recipient
of both the SAP Community Citizenship and Appreciation
awards in 2017. In 2018, she received the SAP Community Hero award. In
2016, Jelena published the book What on Earth is an SAP IDoc? which explains
the nature of IDoc interfaces in SAP ERP. Jelena is a speaker at SAP conferences,
including SAP TechEd in Las Vegas in 2018 and Mastering SAP Technologies in
Melbourne in 2014. She is originally from Riga, Latvia and received a master’s
degree in Computer Science and Economics from the Latvian University.

Brian O’Neill, Jelena Perfiljeva


ABAP: An Introduction
684 pages, 2nd, edition 2020, $69.95 We hope you have enjoyed this reading sample. You may recommend
ISBN 978-1-4932-1880-6 or pass it on to others, but only in its entirety, including all pages. This

reading sample and all its parts are protected by copyright law. All usa-
www.sap-press.com/4955 ge and exploitation rights are reserved by the author and the publisher.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy