You are on page 1of 45

SAP R/3 Release 4.

7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

The following exercises are designed to help you understand the basics of the ABAP
programming language.

The solutions for the programs can be found in package “YABAP47TRG”. Written
solutions can be found in your ABAP manuals.

Before you begin the Introduction to ABAP exercises, you must create a new Package and
a new Change Request, so your work is stored as it might be on a client project.
To do this, find the sheet used for your first Package and Change Request Exercise and use this
if you need it to help you through the abbreviated instructions below:

Create a new Package, by going to the Repository Browser (transaction SE80), and typing
YAPXXB 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 ‘Intro to ABAP
Package for <your name>’.

NOTE: When you hit the save button, do not use your previous Change Request. Instead,
when the Change Request Query Screen appears, click on the Create Request pushbutton,
enter a short description, such as ‘Intro to ABAP Change Request for <your name>’, and save.

Write down the number of your change request here: ____________________________

Use the green arrow to go back to your new Package, and ensure that all your programs in the
Introduction to ABAP section of the course are stored in this Package.

March 2005
Page 1
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 2, Exercise 1
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 Repository Browser, perform the following steps:

1. Ensure your new package (YAPXXB) is displayed in the Repository Browser


2. Click on the package name.
3. Click on the ‘Create’ pushbutton (or choose menu path “Development object > Create”).
4. Select the “Program objects” option and press the ‘Enter’ key (or click on the ‘Continue’
[green check] pushbutton).
5. In the dialog box that is displayed, enter the program name “YAPxx03_1” (where ‘xx’ is the
last two digits of your logon id) and click on the ‘Create’ pushbutton.
6. In the new dialog box that is displayed, turn off the “With TOP INCL.” option and press the
‘Enter’ key (or click on the ‘Continue’ [green check] pushbutton).

The next screen you come to is the Program Attributes screen. Here you maintain the attributes
of your program. The required attributes are a title, type, and application.

7. Enter a title for your program (e.g. Simple ABAP Report Program)
8. Enter ‘1’ for the program type. Type ‘1’ indicates that this program is a report (executable)
program. We will learn other program types in future sections of the ABAP course.
9. Enter ‘S’ for the program application. This application is a means to classify programs in
different areas. For example, ‘S’ classifies the program as a system (or basis) program and
‘F’ classifies the program as a financial accounting program.
10. Click on the ‘Save’ pushbutton (or choose menu path “Program > Save”).

11. In the dialog box that is displayed, enter your change request and press the ‘Enter’ key (or
click on the ‘Continue’ [green check] pushbutton). Your change request may be defaulted. If
not, you can click on the ‘Own request’ pushbutton to get a display of your change requests.

12. Back in the Program Attributes screen, click on the ‘Source code’ pushbutton to navigate into
your program in the ABAP Editor.

In the ABAP Editor, notice that the “REPORT” statement is defaulted for you. In the next
exercise, you will add code to this program to create a simple ABAP report. Before moving on to
the next exercise, you should become familiar with the menubar and toolbar options in the ABAP
Editor.

March 2005
Page 2
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 3, Exercise 1
Program Name: YAPxx03_1 (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).

Using the program you created in the previous 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: SY-
DATUM, SY-UZEIT, and SY-UNAME. To display all the available system fields, click on the
‘Help’ pushbutton in a program and enter the table structure “SY”.

Use the following icons: ICON_DATE, ICON_TIME, and ICON_ADDRESS. To display all the
available icons, execute the program “SHOWICON” from the initial screen of the ABAP Editor
(transaction code “SE38”).

You should not use any text literals in the program. To display your name and address lines, use
the numbered text elements (text symbols).

Use the “Titles and Headers” section of the text elements to maintain the report’s list header
(“User Address Information”).

March 2005
Page 3
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 4, Exercise 1
Program Name: YAPxx04_1 (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 objects in an ABAP
program.

You 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 have a program in your package, the first six steps in the chapter 2
exercise can be changed to:
1. Go to your Intro to ABAP package in the Repository Browser.
2. Click on the “Programs” branch in the hierarchy list.
3. Click on the ‘Create’ pushbutton (or choose menu path “Development object > Create”).
4. In the dialog box that is displayed, enter the program name “YAPxx04_1” (where ‘xx’ is the
last two digits of your logon id) and turn off the “With TOP INCL.” option.
5. Press the ‘Enter’ key (or click on the ‘Continue’ [green check] pushbutton) to go into the
Program Attributes screen.

When you are defining the program’s variables, use the “LIKE” option wherever 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).

Use the “Titles and Headers” section of the text elements to maintain the report’s list header
(“Adding Machine”).

Use the “Selection texts” section of the text elements to maintain the parameter texts on the
selection screen.

See the sample selection screen and list on the next page.

March 2005
Page 4
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 5
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 4, Exercise 2

Program Name: YAPxx04_2 (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 objects and
performing date calculations.

You are to create a program that calculates how many days old you are and when your 10,000th
day birthday will be (or was). Your birthday should be entered as a parameter (set your birthday
as the default). See the sample output to determine the contents and layout of the report.

The birthday parameter should be created “TYPE SYDATUM”.

Do not maintain any text elements. Instead of using text symbols, you can use constants or text
literals. In practice, you would not use hard-coded text literals. However, 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 every time.

March 2005
Page 6
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 7
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 4, Exercise 3

Program Name: YAPxx04_3 (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 objects and user-
defined data types.

You are to create a program that calculates the temperature in Celsius from a Fahrenheit
temperature entered as a parameter. See the sample output to determine the contents and
layout of the report. Notice that the standard page header with an underline is not on the report
(hint: get help on the REPORT statement).

The equation for this temperature conversion is: Celsius = 5/9 * (Fahrenheit - 32). Use constants
to define the conversion values (i.e. 5/9 and 32).

When declaring the variables for Fahrenheit and Celsius, you should use a user-defined data
type named “DEGREES”. This data type should be a length 7 packed field that will store the
temperature with two decimal places.

Do not maintain any text elements. Instead of text symbols, you can use constants or text
literals.

March 2005
Page 8
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 5, Exercise 1

Program Name: YAPxx05_1 (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 Open SQL “SELECT”
statement to read data from a database table.

You are to create a program that reads the data in the YMOVIE table and generates a report with
this information. The YMOVIE table contains Academy Award information. This table is not a
standard SAP table (notice that its name starts with a “Y”). We created this table for the purpose
of your ABAP exercises. Keep in mind that the concepts you learn using the YMOVIE table can
be applied to any ABAP Dictionary table.

Before coding this program, you should examine the structure of the YMOVIE table. Also, you
should view the table contents. You can display a table’s contents using the Data Browser
(transaction code “SE16”). You can also display a table’s contents from the ABAP Dictionary by
choosing the “Utilities > Table contents” menu path.

Maintain the column headings for the report using the text elements; however, do not maintain
any text symbols.

See the sample output to determine the contents and layout of the report. Make sure that you
can scroll to the right to see the entire Academy Award note (hint: get help on the REPORT
statement).

Be sure to check SY-SUBRC to determine if any records exist in YMOVIE. If not, write an
appropriate message. The SY-SUBRC check should always come immediately after the
“ENDSELECT”. Do you know why it should always occur at this point and not within the
“SELECT… ENDSELECT” loop?

March 2005
Page 9
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Please note that the actual contents of the YMOVIE 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. You can always execute the solution programs to determine
the exact contents that your reports should display.

Chapter 5, Exercise 2
Program Name: YAPxx05_2 (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 retrieved from the
database table.

You are to create a program that reads the data in the YMOVIE table for a specific category
entered as a parameter. See 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.

You can copy your previous program and make the necessary changes. To copy a program,
select it in the Repository Browser and click on the ‘Copy’ pushbutton (or choose the
“Development object > Copy” menu path). You can also copy a program from the initial screen
of the ABAP Editor (transaction code “SE38”).

Maintain the column headings for the report using the text elements; however, do not maintain
any text symbols.

March 2005
Page 10
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Be sure to check SY-SUBRC to determine if any records exist in YMOVIE for the specified
category. If not, write an appropriate message. The SY-SUBRC check should always come
immediately after the “ENDSELECT”.

March 2005
Page 11
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Notice the drop-down arrow on the category parameter. You should not create a search help for
this parameter. The drop-down arrow to get a list of possible values is on this parameter
because it was defined “LIKE YMOVIE-CATEGORY”. The category field in the YMOVIE table
points to a domain that has a set of valid values. Because of the valid values at the domain
level, any parameter defined “LIKE” the category field will have a drop-down arrow to get a list of
possible values.

Chapter 6, Exercise 1

March 2005
Page 12
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Program Name: YAPxx06_1 (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.

You are to create a program that acts as a calculator to perform addition, subtraction,
multiplication, or division. On the selection screen, the user should enter two integers and an
operator (+, -, *, or /).

The report generated should show the two integers, the operator, and the result. See the sample
output to determine the contents and layout of the report. If an invalid operator is entered, an
appropriate message should be displayed on the report. If trying to divide by zero, an
appropriate message should be displayed on the report.

Do not maintain any text elements. Remember to use the “LIKE” addition when defining
variables wherever possible.

March 2005
Page 13
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 14
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 6, Exercise 2
Program Name: YAPxx06_2 (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. You are to
create a program that calculates the total seats occupied for each artist in the YCONCERT table.
The YCONCERT table contains information about music concerts. This table is not a standard
SAP table (notice that its name starts with a “Y”). We created this table for the purpose of your
ABAP exercises. Keep in mind that the concepts you learn using the YCONCERT table can be
applied to any ABAP Dictionary table.

Before coding this program, you should examine the structure of the YCONCERT table. Also,
you should view the table contents. You can display a table’s contents using the Data Browser
(transaction code “SE16”). You can also display a table’s contents from the ABAP Dictionary by
choosing the “Utilities > Table contents” menu path.

See the sample output to determine the contents and layout of the report. The following fields
will be used in the report: YCONCERT-ARTIST, YCONCERT-EVENTDATE, YCONCERT-
SEATSMAX, YCONCERT-SEATSOCC, and YCONCERT-LOCATION.

The total seats occupied should be printed at each artist break. CAUTION: ABAP may not
understand the difference between the first record selected and a normal control break. If this
does not make sense now, it will when you begin testing your program. (hint: the system field
SY-DBCNT indicates the records selected in a SELECT loop and it is incremented with each loop
pass).

Because you are grouping the data in the YCONCERT 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 retrieve records. Code your “SELECT” statement as follows:
SELECT * FROM YCONCERT ORDER BY ARTIST.

We will cover the “ORDER BY” addition (and others) in a later chapter.

Maintain the column headings for the report using the text elements; however, do not maintain
any text symbols.

March 2005
Page 15
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 16
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 7, Exercise 1
Program Name: YAPxx07_1 (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.

You are to create a program that generates a report of the top five concerts with the highest
attendance (seats occupied).

You should create an internal table (with a header line) with fields for the following information:
artist, date, seats occupied, and location.

Read the YCONCERT table entries into the internal table and list the top five concerts on the
report. If no entries exist in the table, an appropriate message should be displayed. See the
sample output to determine the contents and layout of the report.

Do not maintain any text elements.

March 2005
Page 17
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 7, Exercise 2
Program Name: YAPxx07_2 (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.

You are to create a program that generates a report of the concerts with attendance over 18,000
(seats occupied). The report should also display the total combined attendance for these
concerts.

You should create an internal table (with a header line) with fields for the following information:
artist, date, seats occupied, and location.

Read the YCONCERT table entries into the internal table and list the concerts with attendance
over 18,000 (note: the internal table should contain all the concert entries, but the report should
be limited to those concerts with attendance over 18,000). If no concerts meet this criteria, an
appropriate message should be displayed. This list should be sorted by concert attendance in
descending order. See the sample output to determine the contents and layout of the report.

Do not maintain any text elements.

March 2005
Page 18
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 7, Exercise 3

Program Name:YAPxx07_3 (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.

You should copy the previous program (YAPxx07_2) to create this new program (YAPxx07_3).
Change the program to use an internal table without a header line.

The output is identical to the previous exercise.

March 2005
Page 19
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 8, Exercise 1
Program Name: YAPxx08_1 (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.

You are to create a program that generates a report with Academy Award information (from the
YMOVIE 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 value. In this subroutine, all records for the specified year should be selected. If
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. See
the sample output to determine the layout of the report. Do not maintain any text elements.

March 2005
Page 20
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 8, Exercise 2
Program Name: YAPxx08_2 (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.

You are to create a program that generates a report with concert information (from the
YCONCERT table). This report should contain the artist, date, attendance (seats occupied),
price of ticket, and total sales. See the sample output to determine the layout of the report.

Use the “Y_SALES_XX” 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 to/from the function module. Also, you should check out the
exception(s) that could be raised in the function module.

Remember to use the menu path “Edit > Insert statement” (or the ‘Pattern’ pushbutton) to code
the “CALL FUNCTION” statement. You should never manually type in the “CALL FUNCTION”
statement.

You should only write an entry to the report if a total sales amount was calculated (i.e. no
exceptions were raised).

Do not maintain any text elements.

March 2005
Page 21
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 22
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 8, Exercise 3
Program Name: YAPxx08_3 (where ‘xx’ is the last two digits of your logon id)
Function Group: YFxx
Function Module Y_SALES_xx

The purpose of this exercise is for you to become familiar with creating function modules.

You should copy the previous program (YAPxx08_2) to create this new program (YAPxx08_3).
Change the program to use your own function module, “Y_SALES_xx” (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 “YFxx”
(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). If not, an exception should be raised.

The output is identical to the previous exercise.

March 2005
Page 23
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 9, Exercise 1
Program Name: YAPxx09_1 (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.

You are to create a program that generates a report with Academy Award information (from the
YMOVIE table) for a specific year and category. The year and category should be entered as
parameters. Define the year parameter “LIKE YMOVIE-AAYEAR” and the category parameter
“LIKE YMOVIE-CATEGORY”.

The report should display the year, category, winner, and nominees for the specified year and
category. If an entry does not exist, an appropriate message should be displayed. The report
will contain information in the following YMOVIE fields: AAYEAR, CATEGORY, WINNER,
NAME1, NAME2, NAME3, NAME4, NAME5. See the sample output to determine the contents
and layout of the report. Do not maintain any text elements.

March 2005
Page 24
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 10, Exercise 1


Program Name: YAPxx10_1 (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.

You are to create a program that generates a report with concert information (from the
YCONCERT 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 average number of seats occupied. You should
use aggregate functions to calculate these amounts.

See the sample output to determine the contents and layout of the report.

Do not maintain any text elements.

Remember that the actual information you will see on your report depends on the data in the
YCONCERT table at the time you execute your program. If your report looks different than the
above screen print, execute the solution program to verify the actual contents of the table. This
should be done for any report accessing information from a database table.

March 2005
Page 25
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 10, Exercise 2


Program Name: YAPxx10_2 (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.

You are to create a program that generates a report with Academy Award information (from the
YMOVIE table). You should use a cursor to select only the year, category, and winner fields for
all records in the YMOVIE table. The selected records should be in descending order by
category. Within each category, the selected records should be in descending order by year.

See the sample output to determine the contents and layout of the report. Do not maintain any
text elements.

March 2005
Page 26
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Exercise 3
Program Name: YAPxx10_3 (where ‘xx’ is the last two digits of your logon id)

Understanding the concept of inner and outer joins will be an important part of your ABAP
training. Projects will generally discourage the use of nested selects and/or logical databases.
For all the exercises that follow, you should use joins wherever possible.

A) Using an inner join, write a report that gives the following information about sales documents
created by “Thompson":

Sales document #
Date of Creation
Creator
Description
Item Category

B) Comment out your inner join statement. Using an outer join, write a report that returns the
same fields.

Questions:

Which table is the driving table, and why?

Does the OUTER JOIN return a different list? Why or why not?

March 2005
Page 27
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Exercise 4
Program Name:YAPxx10_4 (where ‘xx’ is the last two digits of your logon id)

This program will familiarize you with the HAVING clause.

A sales manager would like a report that returns the names of employees that have created an
excess of a specified amount of sales documents in, a given month, year, or a specific date.

Your selection screen should have the following parameters: YEAR, MONTH, DAY and
AMOUNT. If YEAR, MONTH, or DAY is left blank, your application should return a list of names
based on the remaining “date” parameters. I.e., if the user enters the month “12,” and an
AMOUNT of “20,” your program will return a list of employees that have created 20 or more sales
documents in December of any year.

This program deals with the sales document table VBAK. You must use the HAVING clause in
conjunction with one select statement. Also, your program may only contain one select
statement and no IF statements.

Hint: Use the “COUNT( * )” aggregate function.

Exersise 5
Program Name:YAPxx10_5 (where ‘xx’ is the last two digits of your logon id)

March 2005
Page 28
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

This exercise will familiarize you with the concept of subqueries. This is a very brief exercise,
and should only take you a few minutes.

Using a sub-query, find all the records in the SCARR table, that do not exist in SFLIGHT. Write
out the name of the airline carrier, and their carrier Ids.

You report will return 17 records.

Question:

How is your subquery related to the inner join found in chapter 11?

Chapter 12, Exercise 1


Program Name: YAPxx12_1 (where ‘xx’ is the last two digits of your logon id)

March 2005
Page 29
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

The purpose of this exercise is for you to become familiar with using authority checks.

You are to create a program that checks the activities allowed (e.g. create, change, display, and
delete) on vendor master records for the user executing the program. The activity should be
entered as a parameter. This parameter should be a length 2 numeric character field.

Some of the valid activities on the vendor master records are:


01 - create
02 - change
03 - display
06 - mark for deletion

The appropriate authority object for this authorization check is “F_LFA1_APP”. This authority
object has two fields:
ACTVT (activity)
APPKZ (application)

You should suppress the check for the “APPKZ” field. The check for the “ACTVT” field should be
on the activity parameter.

To code the “AUTHORITY-CHECK OBJECT” statement, use the menu path “Edit > Insert
statement” (or the ‘Pattern’ pushbutton). You need to enter the name of the authority object in
the “Authority-Check” field and the system will automatically code the appropriate “AUTHORITY-
CHECK OBJECT” statement. By using this method, you cannot make a mistake typing in the
proper authority object 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 activity was passed or failed. See 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 vendor master records. Without the authority check, any
user executing the program may be able to change or delete records.

Pass Authority Check:

March 2005
Page 30
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Fail Authority Check:

March 2005
Page 31
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 13, Exercise 1


Program Name: YAPxx13_1 (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 “SELECT”
statements to access information in hierarchically related tables (i.e. key fields are passed down
to lower level tables).

You are to create a program that retrieves vendor information from the LFA1 and LFB1 tables.
These tables contain vendor master records and are hierarchically related. Both of these tables
are client-dependent (i.e. MANDT is one of the key fields). Remember that with Open SQL, you
do not have to specify the client in the WHERE clause. By default, Open SQL statements
operate on data for the current client.

LFA1 contains general vendor data (e.g. vendor name and address). The key field to this table,
besides the client, is the vendor number (LIFNR).

LFB1 contains a vendor’s company code information. One vendor can be assigned to multiple
company codes (i.e. LFB1 can contain multiple records per vendor). The key fields to this table,
besides the client, are the vendor number (LIFNR) and the company code (BUKRS).

Use nested “SELECT” statements to access the data for each vendor and generate a report. To
limit the total number of vendors displayed on the report, the “SELECT” statement for LFA1
should use the condition: WHERE LIFNR BETWEEN ‘VEND012’ AND ‘VEND100’.

See the sample output to determine the contents and layout of the report. Notice that the top of
the report begins with a “VENDOR INFORMATION” line. Also, the total number of vendors
processed is listed at the end of the report (hint: you should not have to define a variable for this
count; the system field SY-DBCNT [database count] indicates the number of records processed
by a “SELECT” statement).

The following fields from LFA1 and LFB1 should appear on the report:
LFA1-LIFNR (vendor number)
LFA1-NAME1 (vendor name 1)
LFB1-BUKRS (company code)

Do not maintain any text elements.

March 2005
Page 32
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Top of Report:

End of Report:

March 2005
Page 33
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 34
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 13, Exercise 2


Program Name: YAPxx13_2 (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 level
tables).

You should copy the previous program (Yxx14_1) to create this new program (Yxx14_2).
Change the program to use the logical database KDF, instead of the nested “SELECT”
statements.

Before coding this program, you should examine the structure of logical database KDF. You can
use the use the Logical Database function (menu path “Development > Programming environ. >
Logical databases” or transaction code “SE36”) to view to components of a logical database.
You can also use the Repository Information System to view the structure of a logical database.

The report generated by this program should be identical to the previous example. Remember
that the top of the report should contain a “VENDOR INFORMATION” line and the end of the
report should contain the number of vendors processed (hint: you cannot use the SY-DBCNT
system field in this case because your program does not contain the “SELECT” statement for the
LFA1 table).

Do not forget to indicate the logical database KDF 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 vendors displayed on the report, specify the
range of vendors from ‘VEND012’ to ‘VEND100’ on the vendor account of the selection screen.

Remember that an event processing block is introduced by an event key word. The event
processing block ends when: (1) the next event key word is encountered, (2) a subroutine begins
(i.e. a “FORM” statement is encountered), or (3) the end of the program is encountered. If your
program includes more than one event processing block, you should always explicitly code the
START-OF-SELECTION event (assuming you want to use this event).

March 2005
Page 35
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 13, Exercise 3


Program Name: YAPxx13_3 (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 level
tables).

You should copy the previous program (Yxx14_2) to create this new program (Yxx14_3).
Change the program to include a total number of company codes processed for each vendor.

See the sample output to determine the contents and layout of the report. Again, the top of the
report should contain a “VENDOR INFORMATION” line and the end of the report should contain
the number of vendors processed.

Remember to limit the total number of vendors displayed on the report by specifying the range of
vendors from ‘VEND012’ to ‘VEND100’ on the vendor account of the selection screen.

March 2005
Page 36
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Top of Report:

End of Report:

March 2005
Page 37
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

March 2005
Page 38
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 13, Exercise 4


Program Name: YAPxx13_4 (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 level
tables). This program is more detailed than the previous ones in this chapter, so read the
exercise carefully.

You are to create a program that uses the logical database KDF to retrieve vendor information
from the LFA1, LFB1, and BSIK tables. These tables contain vendor master records and are
hierarchically related. All three tables are client-dependent (i.e. MANDT is one of the key fields).
Remember that with Open SQL, you do not have to specify the client in the WHERE clause. By
default, Open SQL statements operate on data for the current client.

LFA1 contains general vendor data (e.g. vendor name and address). The key field to this table,
besides the client, is the vendor number (LIFNR).

LFB1 contains a vendor’s company code information. One vendor can be assigned to multiple
company codes (i.e. LFB1 can contain multiple records per vendor). The key fields to this table,
besides the client, are the vendor number (LIFNR) and the company code (BUKRS).

BSIK contains invoices for particular vendor and company code. A vendor in one company code
can have many invoices (i.e. BSIK can contain multiple records per vendor and company code).
Some of the key fields to this table, besides the client, are the vendor number (LIFNR), the
company code (BUKRS), fiscal year (GJAHR), and accounting document number (BELNR).

Along with displaying the vendors and company codes, this report should display the open
invoices for a particular vendor and company code. An invoice is “open” if BSIK-BSCHL is ‘31’.
The report should also contain a total invoice amount per company code. This amount should be
displayed only if it is greater than zero. A total invoice amount per vendor should also be
displayed.

See the sample output to determine the contents and layout of the report. Again, the top of the
report should contain a “VENDOR INFORMATION” line and the end of the report should contain
the number of vendors processed.

March 2005
Page 39
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Limit the total number of vendors displayed on the report by specifying the range of vendors
from ‘VEND040’ to ‘VEND050’ on the vendor account of the selection screen.

The following fields from LFA1, LFB1, and BSIK should appear on the report:
LFA1-LIFNR (vendor number)
LFA1-NAME1 (vendor name 1)
LFB1-BUKRS (company code)
BSIK-GJAHR (fiscal year)
BSIK-BELNR (accounting document number)
BSIK-DMBTR (amount in local currency)

Do not maintain any text elements.

Top of Report:

March 2005
Page 40
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

End of Report:

March 2005
Page 41
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 14, Exercise 1


Program Name: YAPxx14_1 (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. Each program has only one selection screen. Two ABAP statements allow you to add to
the selection screen. The “PARAMETERS” 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
“SELECT-OPTIONS” statement allows you to create a selection table on the selection screen. If
the program uses a logical database, these two statements will add to the bottom of the selection
screen provided by the logical database. If the program does not use a logical database, these
two statements will create the program’s selection screen.

You should copy the previous program (Yxx14_4) to create this new program (Yxx15_1).
Change this program to include two additions to the selection screen provided by the logical
database KDF.

First, a selection table should be created for the invoice amount (BSIK-DMBTR) to allow the user
to specify a range of amounts to display on the report. If the amount retrieved from the BSIK
table does not fall into the selection table values, the record should not be displayed.

Second, a parameter should be created for your name. This field should not automatically be
capitalized by the system. You should set a default value for this parameter in an event-
processing block, not with the “DEFAULT” addition. You must use the only event that occurs
before the selection screen is displayed.

March 2005
Page 42
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 14, Exercise 2


Program Name: YAPxx14_2 (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.

You should copy the program “Yxx10_1” to create this new program (Yxx15_2). Program
“Yxx10_1” used the “SELECT SINGLE” statement to display information for a unique record in
the YMOVIE 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 “ZA”. It’s message number is “030”. This
message’s text is: “No record exists for & &”. The ampersands (&) represent variables in the
message. When the message is issued in the program, these message variables should be sent
the year and category.

March 2005
Page 43
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 15, Exercise 1

Program Name: YAPxx15_1 (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.

You are to create a program that generates a report of the sales document data held in tables
vbak (Sales Document Header table) and vbap (Sales Document Item table). The report should
display the header and line detail information for the fields vbak-vbeln (document number),
vbak-kunnr (customer number), vbak-erdat (creation date) vbap-posnr (item number) and vbap-
matnr for each sales documents with document numbers from 4000 to 5000, sorted by document
number only.

You should create an extract by declaring three field-groups, header, general and detail, and
assigning fields to them with the INSERT statement. Select the data using a nested select
(although if you have time try alternatives to improve performance). Write the document number
on every line.
The list output should be as below:

March 2005
Page 44
SAP R/3 Release 4.7
Exercises: Introduction to
ABAP Programming SAP Development ABAP Training

Chapter 16, Exercise 1


Program Name: YAPxx16_1 (where ‘xx’ is the last two digits of your logon id)

Copy the program YXX16_1 to your own package. Change the XX to your ABAP number.
Correct the code so that it compiles. Then use the Debugger to correct any other errors.

Exercise 2
Program Name: YAPxx16_2 (where ‘xx’ is the last two digits of your logon id)

Copy the program YXX16_2 to your own package. Change the XX to your ABAP number.
Correct the code so that it compiles. Then use the Debugger to correct any other errors.

Exercise 3
Program Name: Yxx16_3 (where ‘xx’ is the last two digits of your logon id)

Copy the function module Y_SALES_DEBUG_XX (can be found at the very bottom of the
objects in package Y170) to your own function group that you created in the exercises for chapter
7. Change the XX to your ABAP number. Copy the program YXX16_3 to your own package.
Change the XX to your ABAP number. In the program, change the function call to the function
module you just copied. Correct the code so that it compiles. Then use the Debugger to correct
any other errors.

March 2005
Page 45

You might also like