You are on page 1of 45

SAP R/3 Release 4.

7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
The following exercises are designed to help you understand the basics of the ABAP
programming language.
!"e solutions #or t"e rograms can $e #ound in ac%age &'ABAP47!R(). Written
solutions can be found in your ABAP manuals.
Be#ore *ou $egin t"e Introduction to ABAP exercises+ *ou must create a ne, Pac%age and
a ne, -"ange Re.uest+ so *our ,or% is stored as it mig"t $e on a client ro/ect.
To do this, find the sheet used for your first Package and Change e!uest "xercise and use this
if you need it to help you through the abbre#iated instructions below$
Create a new Package, by going to the epository Browser %transaction &"'(), and typing
'APXXB in the package field %where XX is the last two digits of your logon id). Click on the
display pushbutton, and create the new Package, calling it something like *+ntro to ABAP
Package for ,your name-..
01!E: 2"en *ou "it t"e save $utton+ do not use *our revious -"ange Re.uest. +nstead,
when the Change e!uest /uery &creen appears, click on the -reate Re.uest pushbutton,
enter a short description, such as *+ntro to ABAP Change e!uest for ,your name-., and sa#e.
Write down the number of your change re!uest here$ 0000000000000000000000000000
1se the green arrow to go back to your new Package, and ensure that all your programs in the
+ntroduction to ABAP section of the course are stored in this Package.
2arch 3((4
Page 5
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 3+ Exercise 4
The purpose of this exercise is for you to learn how to create an ABAP report program. There
are many ways for you to create a program.
To create a program from within the epository Browser, perform the following steps$
5. "nsure your new package %6APXXB) is displayed in the epository Browser
3. Click on the package name.
7. Click on the *Create. pushbutton %or choose menu path 89e#elopment ob:ect - Create;).
<. &elect the 8Program ob:ects; option and press the *"nter. key %or click on the *Continue.
=green check> pushbutton).
4. +n the dialog box that is displayed, enter the program name 86APxx(705; %where *xx. is the
last two digits of your logon id) and click on the *Create. pushbutton.
?. +n the new dialog box that is displayed, turn off the 8With T@P +ACB.; option and press the
*"nter. key %or click on the *Continue. =green check> pushbutton).
The next screen you come to is the Program Attributes screen. Cere you maintain the attributes
of your program. The re!uired attributes are a title, type, and application.
D. "nter a title for your program %e.g. &imple ABAP eport Program)
'. "nter *5. for the program type. Type *5. indicates that this program is a report %executable)
program. We will learn other program types in future sections of the ABAP course.
E. "nter *&. for the program application. This application is a means to classify programs in
different areas. For example, *&. classifies the program as a system %or basis) program and
*F. classifies the program as a financial accounting program.
5(. Click on the *&a#e. pushbutton %or choose menu path 8Program - &a#e;).
55. +n the dialog box that is displayed, enter your change re!uest and press the *"nter. key %or
click on the *Continue. =green check> pushbutton). 6our change re!uest may be defaulted. +f
not, you can click on the *@wn re!uest. pushbutton to get a display of your change re!uests.
53. Back in the Program Attributes screen, click on the *&ource code. pushbutton to na#igate into
your program in the ABAP "ditor.
+n the ABAP "ditor, notice that the 8"P@T; statement is defaulted for you. +n the next
exercise, you will add code to this program to create a simple ABAP report. Before mo#ing on to
the next exercise, you should become familiar with the menubar and toolbar options in the ABAP
"ditor.
2arch 3((4
Page 3
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 3+ Exercise 4
Program 0ame$ 6APxx(705 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to create a simple ABAP report using system fields, icons,
and numbered text elements %text symbols).
1sing the program you created in the pre#ious example, code the appropriate statements to
generate the report shown in the sample output$
For the current date, time, and user name %logon id), use the following system fields$ &6G
9AT12, &6G1H"+T, and &6G1AA2". To display all the a#ailable system fields, click on the
*Celp. pushbutton in a program and enter the table structure 8&6;.
1se the following icons$ +C@A09AT", +C@A0T+2", and +C@A0A99"&&. To display all the
a#ailable icons, execute the program 8&C@W+C@A; from the initial screen of the ABAP "ditor
%transaction code 8&"7';).
6ou should not use any text literals in the program. To display your name and address lines, use
the numbered text elements %text symbols).
1se the 8Titles and Ceaders; section of the text elements to maintain the report.s list header
%81ser Address +nformation;).
2arch 3((4
Page 7
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 4+ Exercise 4
Program 0ame$ 6APxx(<05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with creating data ob:ects in an ABAP
program.
6ou are to create a program that acts as an adding machine. Two integers should be entered as
parameters. These integers and the result should be used to generate the report %or list).
Because you already ha#e a program in your package, the first six steps in the chapter 3
exercise can be changed to$
5. Io to your +ntro to ABAP package in the epository Browser.
3. Click on the 8Programs; branch in the hierarchy list.
7. Click on the *Create. pushbutton %or choose menu path 89e#elopment ob:ect - Create;).
<. +n the dialog box that is displayed, enter the program name 86APxx(<05; %where *xx. is the
last two digits of your logon id) and turn off the 8With T@P +ACB.; option.
4. Press the *"nter. key %or click on the *Continue. =green check> pushbutton) to go into the
Program Attributes screen.
When you are defining the program.s #ariables, use the 8B+J"; option where#er possible.
Again, you should not use any text literals in the program. To display the text on the list, use the
numbered text elements %text symbols).
1se the 8Titles and Ceaders; section of the text elements to maintain the report.s list header
%8Adding 2achine;).
1se the 8&election texts; section of the text elements to maintain the parameter texts on the
selection screen.
&ee the sample selection screen and list on the next page.
2arch 3((4
Page <
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page 4
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 4+ Exercise 3
Program 0ame$ 6APxx(<03 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with creating data ob:ects and
performing date calculations.
6ou are to create a program that calculates how many days old you are and when your 5(,(((th
day birthday will be %or was). 6our birthday should be entered as a parameter %set your birthday
as the default). &ee the sample output to determine the contents and layout of the report.
The birthday parameter should be created 8T6P" &69AT12;.
9o not maintain any text elements. +nstead of using text symbols, you can use constants or text
literals. +n practice, you would not use hardGcoded text literals. Cowe#er, in your remaining
exercises, these text literals are acceptable because we want you to focus on the new concepts
in each exercise, not creating text elements e#ery time.
2arch 3((4
Page ?
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page D
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 4+ Exercise 3
Program 0ame$ 6APxx(<07 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with creating data ob:ects and userG
defined data types.
6ou are to create a program that calculates the temperature in Celsius from a Fahrenheit
temperature entered as a parameter. &ee the sample output to determine the contents and
layout of the report. Aotice that the standard page header with an underline is not on the report
%hint$ get help on the "P@T statement).
The e!uation for this temperature con#ersion is$ Celsius K 4LE M %Fahrenheit G 73). 1se constants
to define the con#ersion #alues %i.e. 4LE and 73).
When declaring the #ariables for Fahrenheit and Celsius, you should use a userGdefined data
type named 89"I""&;. This data type should be a length D packed field that will store the
temperature with two decimal places.
9o not maintain any text elements. +nstead of text symbols, you can use constants or text
literals.
2arch 3((4
Page '
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 5+ Exercise 4
Program 0ame$ 6APxx(405 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to be able to use the basic @pen &/B 8&"B"CT;
statement to read data from a database table.
6ou are to create a program that reads the data in the 62@N+" table and generates a report with
this information. The 62@N+" table contains Academy Award information. This table is not a
standard &AP table %notice that its name starts with a 86;). We created this table for the purpose
of your ABAP exercises. Jeep in mind that the concepts you learn using the 62@N+" table can
be applied to any ABAP 9ictionary table.
Before coding this program, you should examine the structure of the 62@N+" table. Also, you
should #iew the table contents. 6ou can display a table.s contents using the 9ata Browser
%transaction code 8&"5?;). 6ou can also display a table.s contents from the ABAP 9ictionary by
choosing the 81tilities - Table contents; menu path.
2aintain the column headings for the report using the text elementsO howe#er, do not maintain
any text symbols.
&ee the sample output to determine the contents and layout of the report. 2ake sure that you
can scroll to the right to see the entire Academy Award note %hint$ get help on the "P@T
statement).
Be sure to check &6G&1BC to determine if any records exist in 62@N+". +f not, write an
appropriate message. The &6G&1BC check should always come immediately after the
8"A9&"B"CT;. 9o you know why it should always occur at this point and not within the
8&"B"CTP "A9&"B"CT; loopQ
2arch 3((4
Page E
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Please note that the actual contents of the 62@N+" table may be different when you create this
program from the contents at the time of the following screen print. This is true for all screen
prints displaying database records. 6ou can always execute the solution programs to determine
the exact contents that your reports should display.
-"ater 5+ Exercise 3
Program 0ame$ 6APxx(403 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to be able to restrict the records retrie#ed from the
database table.
6ou are to create a program that reads the data in the 62@N+" table for a specific category
entered as a parameter. &ee the sample output to determine the contents and layout of the
report. Again, make sure that you can scroll to the right to see the entire Academy Award note.
6ou can copy your pre#ious program and make the necessary changes. To copy a program,
select it in the epository Browser and click on the *Copy. pushbutton %or choose the
89e#elopment ob:ect - Copy; menu path). 6ou can also copy a program from the initial screen
of the ABAP "ditor %transaction code 8&"7';).
2aintain the column headings for the report using the text elementsO howe#er, do not maintain
any text symbols.
2arch 3((4
Page 5(
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Be sure to check &6G&1BC to determine if any records exist in 62@N+" for the specified
category. +f not, write an appropriate message. The &6G&1BC check should always come
immediately after the 8"A9&"B"CT;.
2arch 3((4
Page 55
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Aotice the dropGdown arrow on the category parameter. 6ou should not create a search help for
this parameter. The dropGdown arrow to get a list of possible #alues is on this parameter
because it was defined 8B+J" 62@N+"GCAT"I@6;. The category field in the 62@N+" table
points to a domain that has a set of #alid #alues. Because of the #alid #alues at the domain
le#el, any parameter defined 8B+J"; the category field will ha#e a dropGdown arrow to get a list of
possible #alues.
-"ater 6+ Exercise 4
2arch 3((4
Page 53
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Program 0ame$ 6APxx(?05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with control statements in ABAP.
6ou are to create a program that acts as a calculator to perform addition, subtraction,
multiplication, or di#ision. @n the selection screen, the user should enter two integers and an
operator %R, G, M, or L).
The report generated should show the two integers, the operator, and the result. &ee the sample
output to determine the contents and layout of the report. +f an in#alid operator is entered, an
appropriate message should be displayed on the report. +f trying to di#ide by Sero, an
appropriate message should be displayed on the report.
9o not maintain any text elements. emember to use the 8B+J"; addition when defining
#ariables where#er possible.
2arch 3((4
Page 57
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page 5<
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 6+ Exercise 3
Program 0ame$ 6APxx(?03 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with control statements in ABAP.
Control break processing is common to all programming languages, including ABAP. 6ou are to
create a program that calculates the total seats occupied for each artist in the 6C@AC"T table.
The 6C@AC"T table contains information about music concerts. This table is not a standard
&AP table %notice that its name starts with a 86;). We created this table for the purpose of your
ABAP exercises. Jeep in mind that the concepts you learn using the 6C@AC"T table can be
applied to any ABAP 9ictionary table.
Before coding this program, you should examine the structure of the 6C@AC"T table. Also,
you should #iew the table contents. 6ou can display a table.s contents using the 9ata Browser
%transaction code 8&"5?;). 6ou can also display a table.s contents from the ABAP 9ictionary by
choosing the 81tilities - Table contents; menu path.
&ee the sample output to determine the contents and layout of the report. The following fields
will be used in the report$ 6C@AC"TGAT+&T, 6C@AC"TG"N"AT9AT", 6C@AC"TG
&"AT&2AT, 6C@AC"TG&"AT&@CC, and 6C@AC"TGB@CAT+@A.
The total seats occupied should be printed at each artist break. CA1T+@A$ ABAP may not
understand the difference between the first record selected and a normal control break. +f this
does not make sense now, it will when you begin testing your program. %hint$ the system field
&6G9BCAT indicates the records selected in a &"B"CT loop and it is incremented with each loop
pass).
Because you are grouping the data in the 6C@AC"T table by artist, you need to be sure that
the table is sorted on this field. Because you cannot assume that it is sorted in this manner, you
can specify the order in which to retrie#e records. Code your 8&"B"CT; statement as follows$
&"B"CT M F@2 6C@AC"T @9" B6 AT+&T.
We will co#er the 8@9" B6; addition %and others) in a later chapter.
2aintain the column headings for the report using the text elementsO howe#er, do not maintain
any text symbols.
2arch 3((4
Page 54
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page 5?
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 7+ Exercise 4
Program 0ame$ 6APxx(D05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with internal table processing.
6ou are to create a program that generates a report of the top fi#e concerts with the highest
attendance %seats occupied).
6ou should create an internal table %with a header line) with fields for the following information$
artist, date, seats occupied, and location.
ead the 6C@AC"T table entries into the internal table and list the top fi#e concerts on the
report. +f no entries exist in the table, an appropriate message should be displayed. &ee the
sample output to determine the contents and layout of the report.
9o not maintain any text elements.
2arch 3((4
Page 5D
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 7+ Exercise 3
Program 0ame$ 6APxx(D03 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with internal table processing.
6ou are to create a program that generates a report of the concerts with attendance o#er 5',(((
%seats occupied). The report should also display the total combined attendance for these
concerts.
6ou should create an internal table %with a header line) with fields for the following information$
artist, date, seats occupied, and location.
ead the 6C@AC"T table entries into the internal table and list the concerts with attendance
o#er 5',((( %note$ the internal table should contain all the concert entries, but the report should
be limited to those concerts with attendance o#er 5',(((). +f no concerts meet this criteria, an
appropriate message should be displayed. This list should be sorted by concert attendance in
descending order. &ee the sample output to determine the contents and layout of the report.
9o not maintain any text elements.
2arch 3((4
Page 5'
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 7+ Exercise 3
Program Aame$ 6APxx(D07 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with internal table processing.
6ou should copy the pre#ious program %6APxx(D03) to create this new program %6APxx(D07).
Change the program to use an internal table without a header line.
The output is identical to the pre#ious exercise.
2arch 3((4
Page 5E
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 7+ Exercise 4
Program 0ame$ 6APxx('05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with passing parameters to
subroutines.
6ou are to create a program that generates a report with Academy Award information %from the
62@N+" table) for a particular year entered as a parameter. The main processing of this
program should be in two subroutines.
The first subroutine should be passed the year entered as a parameter. This parameter should
be passed by #alue. +n this subroutine, all records for the specified year should be selected. +f
no records exist for the year, an appropriate message should be displayed. For each record
selected, a second subroutine should write out the record.s information.
The second subroutine should be passed the field string %structure) that contains the record
selected. The year, category, and winner should be written to the report in this subroutine. &ee
the sample output to determine the layout of the report. 9o not maintain any text elements.
2arch 3((4
Page 3(
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 7+ Exercise 3
Program 0ame$ 6APxx('03 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using function modules.
6ou are to create a program that generates a report with concert information %from the
6C@AC"T table). This report should contain the artist, date, attendance %seats occupied),
price of ticket, and total sales. &ee the sample output to determine the layout of the report.
1se the 860&AB"&0TT; function module to calculate each concert.s total sales. Before coding
this program, you should examine the interface of this function module to determine the
parameters being passed toLfrom the function module. Also, you should check out the
exception%s) that could be raised in the function module.
emember to use the menu path 8"dit - +nsert statement; %or the *Pattern. pushbutton) to code
the 8CABB F1ACT+@A; statement. 6ou should never manually type in the 8CABB F1ACT+@A;
statement.
6ou should only write an entry to the report if a total sales amount was calculated %i.e. no
exceptions were raised).
9o not maintain any text elements.
2arch 3((4
Page 35
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page 33
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 7+ Exercise 3
Program 0ame$ 6APxx('07 %where *xx. is the last two digits of your logon id)
8unction (rou$ 6Fxx
8unction 9odule 60&AB"&0xx
The purpose of this exercise is for you to become familiar with creating function modules.
6ou should copy the pre#ious program %6APxx('03) to create this new program %6APxx('07).
Change the program to use your own function module, 860&AB"&0xx; %where *xx. is the last two
digits of your logon id).
Before creating the new function module, you must create your own function group called 86Fxx;
%where *xx. is the last two digits of your logon id).
The function module you create should calculate the total sales for a concert. This total sales is
based on an attendance number %seats occupied) and a ticket price. Before calculating the total
sales, this function module should check to see that the concert has already taken place %i.e. the
concert date is before the current date). +f not, an exception should be raised.
The output is identical to the pre#ious exercise.
2arch 3((4
Page 37
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater :+ Exercise 4
Program 0ame$ 6APxx(E05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with selecting a single record.
6ou are to create a program that generates a report with Academy Award information %from the
62@N+" table) for a specific year and category. The year and category should be entered as
parameters. 9efine the year parameter 8B+J" 62@N+"GAA6"A; and the category parameter
8B+J" 62@N+"GCAT"I@6;.
The report should display the year, category, winner, and nominees for the specified year and
category. +f an entry does not exist, an appropriate message should be displayed. The report
will contain information in the following 62@N+" fields$ AA6"A, CAT"I@6, W+AA",
AA2"5, AA2"3, AA2"7, AA2"<, AA2"4. &ee the sample output to determine the contents
and layout of the report. 9o not maintain any text elements.
2arch 3((4
Page 3<
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 4;+ Exercise 4
Program 0ame$ 6APxx5(05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using aggregate functions.
6ou are to create a program that generates a report with concert information %from the
6C@AC"T table).
This report should include the number of entries in the table, the sum of the seats occupied, the
maximum number of seats occupied, and the a#erage number of seats occupied. 6ou should
use aggregate functions to calculate these amounts.
&ee the sample output to determine the contents and layout of the report.
9o not maintain any text elements.
emember that the actual information you will see on your report depends on the data in the
6C@AC"T table at the time you execute your program. +f your report looks different than the
abo#e screen print, execute the solution program to #erify the actual contents of the table. This
should be done for any report accessing information from a database table.
2arch 3((4
Page 34
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 4;+ Exercise 3
Program 0ame$ 6APxx5(03 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using cursor processing.
6ou are to create a program that generates a report with Academy Award information %from the
62@N+" table). 6ou should use a cursor to select only the year, category, and winner fields for
all records in the 62@N+" table. The selected records should be in descending order by
category. Within each category, the selected records should be in descending order by year.
&ee the sample output to determine the contents and layout of the report. 9o not maintain any
text elements.
2arch 3((4
Page 3?
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Exercise 3
Program 0ame$ 6APxx5(07 %where *xx. is the last two digits of your logon id)
1nderstanding the concept of inner and outer :oins will be an important part of your ABAP
training. Pro:ects will generally discourage the use of nested selects andLor logical databases.
For all the exercises that follow, you should use :oins where#er possible.
A< 1sing an inner :oin, write a report that gi#es the following information about sales documents
created by 8ThompsonU$
&ales document V
9ate of Creation
Creator
9escription
+tem Category
B< Comment out your inner :oin statement. 1sing an outer :oin, write a report that returns the
same fields.
=uestions:
Which table is the dri#ing table, and whyQ
9oes the @1T" W@+A return a different listQ Why or why notQ
2arch 3((4
Page 3D
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Exercise 4
Program Aame$ 6APxx5(0< %where *xx. is the last two digits of your logon id)
This program will familiariSe you with the CAN+AI clause.
A sales manager would like a report that returns the names of employees that ha#e created an
excess of a specified amount of sales documents in, a gi#en month, year, or a specific date.
6our selection screen should ha#e the following parameters$ 6"A, 2@ATC, 9A6 and
A2@1AT. +f 6"A, 2@ATC, or 9A6 is left blank, your application should return a list of names
based on the remaining 8date; parameters. +.e., if the user enters the month 853,; and an
A2@1AT of 83(,; your program will return a list of employees that ha#e created 3( or more sales
documents in 9ecember of any year.
This program deals with the sales document table NBAJ. 6ou must use the CAN+AI clause in
con:unction with one select statement. Also, *our rogram ma* onl* contain one select
statement and no I8 statements.
Cint$ 1se the 8C@1AT% M ); aggregate function.
Exersise 5
Program Aame$ 6APxx5(04 %where *xx. is the last two digits of your logon id)
2arch 3((4
Page 3'
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
This exercise will familiariSe you with the concept of sub!ueries. This is a #ery brief exercise,
and should only take you a few minutes.
1sing a subG!uery, find all the records in the &CA table, that do not exist in &FB+ICT. Write
out the name of the airline carrier, and their carrier +ds.
6ou report will return 5D records.
=uestion:
Cow is your sub!uery related to the inner :oin found in chapter 55Q
-"ater 43+ Exercise 4
Program 0ame$ 6APxx5305 %where *xx. is the last two digits of your logon id)
2arch 3((4
Page 3E
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
The purpose of this exercise is for you to become familiar with using authority checks.
6ou are to create a program that checks the acti#ities allowed %e.g. create, change, display, and
delete) on #endor master records for the user executing the program. The acti#ity should be
entered as a parameter. This parameter should be a length 3 numeric character field.
&ome of the #alid acti#ities on the #endor master records are$
(5 G create
(3 G change
(7 G display
(? G mark for deletion
The appropriate authority ob:ect for this authoriSation check is 8F0BFA50APP;. This authority
ob:ect has two fields$
ACTNT %acti#ity)
APPJH %application)
6ou should suppress the check for the 8APPJH; field. The check for the 8ACTNT; field should be
on the acti#ity parameter.
To code the 8A1TC@+T6GCC"CJ @BW"CT; statement, use the menu path 8"dit - +nsert
statement; %or the *Pattern. pushbutton). 6ou need to enter the name of the authority ob:ect in
the 8AuthorityGCheck; field and the system will automatically code the appropriate 8A1TC@+T6G
CC"CJ @BW"CT; statement. By using this method, you cannot make a mistake typing in the
proper authority ob:ect name and field names.
The report generated by this program is simple. The line written to the report will indicate
whether the authority for the selected acti#ity was passed or failed. &ee the sample output for
the content and layout of the report in both scenarios.
Although the processing logic of this program is not complex, imagine this authority check being
used in a program that is maintaining #endor master records. Without the authority check, any
user executing the program may be able to change or delete records.
Pass Authority Check$
2arch 3((4
Page 7(
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Fail Authority Check$
2arch 3((4
Page 75
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 43+ Exercise 4
Program 0ame$ 6APxx5705 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using nested 8&"B"CT;
statements to access information in hierarchically related tables %i.e. key fields are passed down
to lower le#el tables).
6ou are to create a program that retrie#es #endor information from the BFA5 and BFB5 tables.
These tables contain #endor master records and are hierarchically related. Both of these tables
are clientGdependent %i.e. 2AA9T is one of the key fields). emember that with @pen &/B, you
do not ha#e to specify the client in the WC"" clause. By default, @pen &/B statements
operate on data for the current client.
BFA5 contains general #endor data %e.g. #endor name and address). The key field to this table,
besides the client, is the #endor number %B+FA).
BFB5 contains a #endor.s company code information. @ne #endor can be assigned to multiple
company codes %i.e. BFB5 can contain multiple records per #endor). The key fields to this table,
besides the client, are the #endor number %B+FA) and the company code %B1J&).
1se nested 8&"B"CT; statements to access the data for each #endor and generate a report. To
limit the total number of #endors displayed on the report, the 8&"B"CT; statement for BFA5
should use the condition$ WC"" B+FA B"TW""A *N"A9(53. AA9 *N"A95((..
&ee the sample output to determine the contents and layout of the report. Aotice that the top of
the report begins with a 8N"A9@ +AF@2AT+@A; line. Also, the total number of #endors
processed is listed at the end of the report %hint$ you should not ha#e to define a #ariable for this
countO the system field &6G9BCAT =database count> indicates the number of records processed
by a 8&"B"CT; statement).
The following fields from BFA5 and BFB5 should appear on the report$
BFA5GB+FA %#endor number)
BFA5GAA2"5 %#endor name 5)
BFB5GB1J& %company code)
9o not maintain any text elements.
2arch 3((4
Page 73
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Top of eport$
"nd of eport$
2arch 3((4
Page 77
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page 7<
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 43+ Exercise 3
Program 0ame$ 6APxx5703 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using a logical database to
access information in hierarchicallyGrelated tables %i.e. key fields are passed down to lower le#el
tables).
6ou should copy the pre#ious program %6xx5<05) to create this new program %6xx5<03).
Change the program to use the logical database J9F, instead of the nested 8&"B"CT;
statements.
Before coding this program, you should examine the structure of logical database J9F. 6ou can
use the use the Bogical 9atabase function %menu path 89e#elopment - Programming en#iron. -
Bogical databases; or transaction code 8&"7?;) to #iew to components of a logical database.
6ou can also use the epository +nformation &ystem to #iew the structure of a logical database.
The report generated by this program should be identical to the pre#ious example. emember
that the top of the report should contain a 8N"A9@ +AF@2AT+@A; line and the end of the
report should contain the number of #endors processed %hint$ you cannot use the &6G9BCAT
system field in this case because your program does not contain the 8&"B"CT; statement for the
BFA5 table).
9o not forget to indicate the logical database J9F on the program attributes screen. Because
this program uses a logical database, you will be presented with a selection screen when
executing the program. To limit the total number of #endors displayed on the report, specify the
range of #endors from *N"A9(53. to *N"A95((. on the #endor account of the selection screen.
emember that an e#ent processing block is introduced by an e#ent key word. The e#ent
processing block ends when$ %5) the next e#ent key word is encountered, %3) a subroutine begins
%i.e. a 8F@2; statement is encountered), or %7) the end of the program is encountered. +f your
program includes more than one e#ent processing block, you should always explicitly code the
&TATG@FG&"B"CT+@A e#ent %assuming you want to use this e#ent).
2arch 3((4
Page 74
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 43+ Exercise 3
Program 0ame$ 6APxx5707 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using a logical database to
access information in hierarchicallyGrelated tables %i.e. key fields are passed down to lower le#el
tables).
6ou should copy the pre#ious program %6xx5<03) to create this new program %6xx5<07).
Change the program to include a total number of company codes processed for each #endor.
&ee the sample output to determine the contents and layout of the report. Again, the top of the
report should contain a 8N"A9@ +AF@2AT+@A; line and the end of the report should contain
the number of #endors processed.
emember to limit the total number of #endors displayed on the report by specifying the range of
#endors from *N"A9(53. to *N"A95((. on the #endor account of the selection screen.
2arch 3((4
Page 7?
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Top of eport$
"nd of eport$
2arch 3((4
Page 7D
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
2arch 3((4
Page 7'
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 43+ Exercise 4
Program 0ame$ 6APxx570< %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using a logical database to
access information in hierarchically related tables %i.e. key fields are passed down to lower le#el
tables). This program is more detailed than the pre#ious ones in this chapter, so read the
exercise carefully.
6ou are to create a program that uses the logical database J9F to retrie#e #endor information
from the BFA5, BFB5, and B&+J tables. These tables contain #endor master records and are
hierarchically related. All three tables are clientGdependent %i.e. 2AA9T is one of the key fields).
emember that with @pen &/B, you do not ha#e to specify the client in the WC"" clause. By
default, @pen &/B statements operate on data for the current client.
BFA5 contains general #endor data %e.g. #endor name and address). The key field to this table,
besides the client, is the #endor number %B+FA).
BFB5 contains a #endor.s company code information. @ne #endor can be assigned to multiple
company codes %i.e. BFB5 can contain multiple records per #endor). The key fields to this table,
besides the client, are the #endor number %B+FA) and the company code %B1J&).
B&+J contains in#oices for particular #endor and company code. A #endor in one company code
can ha#e many in#oices %i.e. B&+J can contain multiple records per #endor and company code).
&ome of the key fields to this table, besides the client, are the #endor number %B+FA), the
company code %B1J&), fiscal year %IWAC), and accounting document number %B"BA).
Along with displaying the #endors and company codes, this report should display the open
in#oices for a particular #endor and company code. An in#oice is 8open; if B&+JGB&CCB is *75..
The report should also contain a total in#oice amount per company code. This amount should be
displayed only if it is greater than Sero. A total in#oice amount per #endor should also be
displayed.
&ee the sample output to determine the contents and layout of the report. Again, the top of the
report should contain a 8N"A9@ +AF@2AT+@A; line and the end of the report should contain
the number of #endors processed.
2arch 3((4
Page 7E
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
Bimit the total number of #endors displayed on the report by specifying the range of #endors
from *N"A9(<(. to *N"A9(4(. on the #endor account of the selection screen.
The following fields from BFA5, BFB5, and B&+J should appear on the report$
BFA5GB+FA %#endor number)
BFA5GAA2"5 %#endor name 5)
BFB5GB1J& %company code)
B&+JGIWAC %fiscal year)
B&+JGB"BA %accounting document number)
B&+JG92BT %amount in local currency)
9o not maintain any text elements.
Top of eport$
2arch 3((4
Page <(
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
"nd of eport$
2arch 3((4
Page <5
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 44+ Exercise 4
Program 0ame$ 6APxx5<05 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with maintaining a program.s selection
screen. "ach program has only one selection screen. Two ABAP statements allow you to add to
the selection screen. The 8PAA2"T"&; statement allows you to create a single field on the
selection screen %remember$ this field can be created as a check box or radio button). The
8&"B"CTG@PT+@A&; statement allows you to create a selection table on the selection screen. +f
the program uses a logical database, these two statements will add to the bottom of the selection
screen pro#ided by the logical database. +f the program does not use a logical database, these
two statements will create the program.s selection screen.
6ou should copy the pre#ious program %6xx5<0<) to create this new program %6xx5405).
Change this program to include two additions to the selection screen pro#ided by the logical
database J9F.
First, a selection table should be created for the in#oice amount %B&+JG92BT) to allow the user
to specify a range of amounts to display on the report. +f the amount retrie#ed from the B&+J
table does not fall into the selection table #alues, the record should not be displayed.
&econd, a parameter should be created for your name. This field should not automatically be
capitaliSed by the system. 6ou should set a default #alue for this parameter in an e#entG
processing block, not with the 89"FA1BT; addition. 6ou must use the only e#ent that occurs
before the selection screen is displayed.
2arch 3((4
Page <3
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 44+ Exercise 3
Program 0ame$ 6APxx5<03 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with using messages.
6ou should copy the program 86xx5(05; to create this new program %6xx5403). Program
86xx5(05; used the 8&"B"CT &+AIB"; statement to display information for a uni!ue record in
the 62@N+" table. Change this program to issue an information message if no record exists,
instead of writing this message to the report.
The predefined message is in the message class 8HA;. +t.s message number is 8(7(;. This
message.s text is$ 8Ao record exists for X X;. The ampersands %X) represent #ariables in the
message. When the message is issued in the program, these message #ariables should be sent
the year and category.
2arch 3((4
Page <7
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 45+ Exercise 4
Program 0ame$ 6APxx5405 %where *xx. is the last two digits of your logon id)
The purpose of this exercise is for you to become familiar with processing using extracts.
6ou are to create a program that generates a report of the sales document data held in tables
#bak %&ales 9ocument Ceader table) and #bap %&ales 9ocument +tem table). The report should
display the header and line detail information for the fields #bakG#beln %document number),
#bakGkunnr %customer number), #bakGerdat %creation date) #bapGposnr %item number) and #bapG
matnr for each sales documents with document numbers from <((( to 4(((, sorted by document
number only.
6ou should create an extract by declaring three fieldGgroups, header, general and detail, and
assigning fields to them with the +A&"T statement. &elect the data using a nested select
%although if you ha#e time try alternati#es to impro#e performance). Write the document number
on e#ery line.
The list output should be as below$
2arch 3((4
Page <<
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Develoment ABAP !raining
-"ater 46+ Exercise 4
Program 0ame$ 6APxx5?05 %where *xx. is the last two digits of your logon id)
Copy the program 6TT5?05 to your own package. Change the TT to your ABAP number.
Correct the code so that it compiles. Then use the 9ebugger to correct any other errors.
Exercise 3
Program 0ame$ 6APxx5?03 %where *xx. is the last two digits of your logon id)
Copy the program 6TT5?03 to your own package. Change the TT to your ABAP number.
Correct the code so that it compiles. Then use the 9ebugger to correct any other errors.
Exercise 3
Program 0ame$ 6xx5?07 %where *xx. is the last two digits of your logon id)
Copy the function module 60&AB"&09"B1I0TT %can be found at the #ery bottom of the
ob:ects in package 65D() to your own function group that you created in the exercises for chapter
D. Change the TT to your ABAP number. Copy the program 6TT5?07 to your own package.
Change the TT to your ABAP number. +n the program, change the function call to the function
module you :ust copied. Correct the code so that it compiles. Then use the 9ebugger to correct
any other errors.
2arch 3((4
Page <4

You might also like