18_Online Programming Exercises
18_Online Programming Exercises
6.0
Online Programming:
Exercises SAP Development ABAP Training
The following exercises are designed to help you understand online programming. Remember that an
online program can also be called a module pool program, a dialog program.
For many of the online programs you create, you will be using the “YMOVIE_OP” database table that
contains Academy Award information. We created this table for the purpose of demonstrating online
programming techniques. Keep in mind that the concepts you learn using the “YMOVIE_OP” table can
be applied to any online program using any ABAP Dictionary table(s).
Each of the exercises contains a testing section. This is not a comprehensive test plan. The questions
asked in this section for each program should be used to make sure the basics in your program are
functioning properly. If you can think of any other important testing conditions, feel free to list them.
The solutions for the programming section can be found in package “YABAP47TRG” . If you are
having trouble figuring out how an online program should work, execute the solution online program.
Written solutions can be found in your ABAP manuals.
Before you begin EACH Online Programming exercises, you must assign your created objects to
a Package and a Change Request provided by the instructor, so your work is stored as it might
be on a client project.
Dec-2008
Page 1
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx1 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx1
Initial screen: 9000
Screen 9000: next screen = 9001
Screen 9001: next screen = 9000
The purpose of this exercise is for you to create a simple online program to become familiar with the
basic components of an online program. As you are creating this online program, try to identify each
component you are creating: screen attributes, screen layout, field attributes, flow logic, PBO modules,
PAI modules, and global data.
This online program will act as an adding machine. On the initial screen (9000), the user will enter two
integers. After pressing the ‘Enter’ key, the user should be taken to the next screen (9001).
On this second screen, the two integers from the first screen will be displayed along with the result of the
addition operation. These three fields should be display fields only (i.e. the user should not be able to
enter values in these three fields). After pressing the ‘Enter’ key, the user should be taken back to the
initial screen. The previous values should be cleared out when the user returns to the initial screen.
Don’t forget you need to create a transaction code to execute this online program. Because you have not
learned how to code an exit in an online program, the easiest way to execute the program is to use a
“/o<tcode>” in the command field of the standard toolbar. By opening up a new session with your
transaction, you can “exit” the transaction by closing the session. If you do not open a new session for
your transaction, you can “exit” the transaction by using a “/n” or “/n<tcode>” in the command field of your
transaction (e.g. a “/nse80” will exit the transaction and take you to the Object Browser).
Tip: Pressing the ‘CTRL’ and ‘TAB’ keys will move the cursor to the command field.
Dec-2008
Page 2
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Screen 9000
Screen 9001
Dec-2008
Page 3
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
(1) Can you enter a number with decimals on the initial screen? (expected = no)
(3) Are all three values displayed on the second screen? (expected = yes)
(4) Can you enter values on the second screen? (expected = no)
(5) Are the values cleared out when you return to the initial screen? (expected = yes)
(6) Does the program loop from screen 9000 to 9001 and back to 9000 as you press ‘Enter’? (expected
= yes)
Dec-2008
Page 4
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx2 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx2
Initial screen: 9000
Screen 9000: next screen = 9001
The purpose of this exercise is for you to learn how to create the various graphical elements on a screen:
radio buttons, check boxes, frames, and pushbuttons. You will not code any logic into this program. You
should not spend more than 45 minutes on this program.
The “Instructor” input/output template should be 30-length character field. The “Evaluation” input/output
template should be a scrollable field with a defined length of 60 characters and a visible length of 30
characters. The ‘Submit Evaluation’ pushbutton should have an icon and be assigned the function code
“EVAL”.
Dec-2008
Page 5
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
Dec-2008
Page 6
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx3 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx3
Initial screen: 9000
Screen 9000: next screen = 9001
Screen 9001: next screen = 9000
The purpose of this exercise is for you to learn how to use ABAP Dictionary fields in an online program.
You will build upon this program in future exercises.
Screen 9000
On this initial screen, the user will enter a year and category. These fields (both the templates and text
labels) should be “painted” from the “YMOVIE_OP” table. The year template should be a required field.
After pressing the ‘Enter’ key, the user should be taken to the next screen (9001).
Screen 9001
On this second screen, the two values from the first screen will be displayed. These two fields should be
display fields only. Also on this screen, the winner, the five nominees, and the notes should be displayed
for the specified year and category. These fields (both the templates and text labels) should be “painted”
from the “YMOVIE_OP” table. These fields should be both input and output fields. After pressing the
‘Enter’ key, the user should be taken back to the initial screen. The previous values should be cleared
out when the user returns to the initial screen.
Dec-2008
Page 7
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Screen 9000
Screen 9001
Dec-2008
Page 8
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
(1) Are “PIC”, “MAL”, and “FEM” the only acceptable entries for the category template on the initial
screen? (expected = yes)
(2) Is the year field required on the initial screen? (expected = yes)
(3) Is the proper record being selected from “YMOVIE_OP”? (expected = yes) [Note: look at the table
contents in the ABAP Dictionary (SE11) or Data Browser (SE16)]
(4) Are the winner, nominees, and notes fields open for input on the second screen? (expected = yes)
(5) Are the year and category fields display only on the second screen? (expected = yes)
(6) If you enter a non-existing record (e.g. 1910, PIC) on the initial screen, are the winner, nominees, and
notes fields blank on the second screen? (expected = yes)
(7) Are the values cleared out when you return to the initial screen? (expected = yes)
(8) Does the program loop from screen 9000 to 9001 and back to 9000 as you press ‘Enter’? (expected
= yes)
Dec-2008
Page 9
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx4 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx4
Initial screen: 9000
Screen 9000: next screen = 9001
Screen 9001: next screen = 9000
The purpose of this exercise is for you to learn how to use messages in an online program, flag fields as
open for input, and set default values and cursor positioning.
You should copy your SAPMYOPxx3 program to create program SAPMYOPxx4. First create the
new Package, then select program SAPMYOPxx3 in the Object Browser and click on the copy
pushbutton (or use the “Development object > Copy” menu path). Make sure you select all the
components to copy (documentation, variants, GUI status, screens, includes). You will be prompted to
create new include programs -- just click on the ‘Copy’ pushbutton or press the ‘Enter’ key. The Package
screen should appear – enter the new Package here, and ensure the new Change Request is used.
The appearance of the screens will not change in this program. Add the following functionality:
Screen 9000
You need to code two checks into this screen. First, if the user enters an invalid year, an appropriate
message (e.g. “Invalid year”) should force the user to make a change before moving on to the next
screen. A year is invalid if it is before 1927 or after the current year. This current year should not be
hard-coded (i.e. this year should be current for the time the transaction is executed). If the message is
issued, the year and category fields should be open for input.
Second, if the user enters a record that does not exist, an appropriate message (e.g. “No record exists”)
should force the user to make a change before moving on to the next screen. If the message is issued,
the year and category fields should be open for input. The invalid year check should occur before this
one -- there is no reason to attempt to select the record if an invalid year was entered.
To issue these messages, you should create your own messages in your own message class (ID).
(Create message class YXX, where your last two digits of your SAP Logon ID should replace XX)
Default values should appear in the year and category fields on the initial screen. Use parameter IDs to
accomplish this task.
Screen 9001
Dec-2008
Page 10
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
(1) If an invalid year is entered, is an appropriate error message is displayed and the year and category
fields left open for input? (expected = yes)
[Don’t forget to test the boundaries here. ‘1927’ should pass the year check, but ‘1926’ should
not. Likewise, ‘1997’ should pass the year check, but ‘1998’ should not.]
(2) If a record does not exist, is an appropriate error message is displayed and the year and category
fields left open for input? (expected = yes)
(3) When either check fails, does the user have to make a change to move on to the next screen?
(expected = yes)
(4) Do default values appear in the year and category fields? (expected = yes)
(5) On the second screen, is the cursor positioned on the notes field? (expected = yes)
Online program name: SAPMYOPxx5 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx5
Initial screen: 9000
Screen 9000: next screen = 9000
Screen 9001: next screen = 9001
Screen 9002 (dialog box): next screen = 9002
The purpose of this exercise is for you to learn how to use a Graphical User Interface (GUI) in an online
program and how to dynamically determine the screen sequence based on the user’s actions.
You should copy your SAPMYOPxx4 program to create program SAPMYOPxx5. First create the
new package, then select program SAPMYOPxx4 in the Object Browser and click on the copy
pushbutton (or use the “Development object -> Copy” menu path). Make sure you select all the
components to copy (documentation, variants, GUI status, screens, includes). You will be prompted to
create new include programs -- just click on the ‘Copy’ pushbutton or press the ‘Enter’ key. The Package
screen should appear - enter the new Package here, and ensure the new Change Request is used.
Dec-2008
Page 11
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
The GUI for this program will include the following function codes:
The screen descriptions and screen prints below will help you determine which of these function codes is
used on what GUI status. Remember the GUI status type depends on the screen type.
Screen 9000
This screen should use the GUI status ‘FIRST’ with the following function codes: EXIT, EDIT, and ADD.
With the ‘Edit Record’ and ‘Add Record’ pushbuttons, the user determines whether to insert a new record
or update an existing record based on the specified year and category. If the user clicks on the ‘Edit
Record’ pushbutton (which invokes the ‘EDIT’ function code), an error message should be issued if the
record does not exist. If the user clicks on the ‘Add Record’ pushbutton (which invokes the ‘ADD’
function code), an error message should be displayed if the record already exists. Once this check is
passed, and the invalid year check from the previous example, the user should be taken to screen 9001.
It is on screen 9001 where the user will add or edit the record.
If the user clicks on the ‘Exit’ pushbutton (which invokes the ‘EXIT’ function code), the transaction should
be terminated.
If the user presses the ‘Enter’ key, the user should not be taken to the next screen.
Dec-2008
Page 12
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Screen 9001
This screen should use the GUI status ‘SECOND’ with the following function codes: EXIT, INIT, and
MODI.
On this screen, the user will ultimately be able to insert or update a record with the ‘Modify Record’
pushbutton. You will not add this functionality to the ‘MODI’ function code until the next example.
If the user clicks on the ‘Exit’ pushbutton (which invokes the ‘EXIT’ function code), the transaction should
be terminated. If the user clicks on the ‘Initial Screen’ pushbutton (which invokes the ‘INIT’ function
code), the user should be taken back to screen 9000. If the user presses the ‘Enter’ key, the user should
not be taken back to screen 9000.
You will need to add two new fields to this screen. First, the critic template should be “painted” from the
“YMOVIE_OP” table (only the template should be “painted”, not the key word). This field should be a
display only field. Second, you should create the ‘Enter Critic’ pushbutton and assign it the function code
‘NAME’. If the user clicks on the ‘Enter Critic’ pushbutton (which invokes the ‘NAME’ function code), the
user should be taken to screen 9002 (a dialog box).
Dec-2008
Page 13
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Dec-2008
Page 14
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Screen 9002
You will have to create this new screen. It is a dialog box that will be “called” from screen 9001. The only
two fields on this screen should be “painted” from the “YMOVIE_OP” table. You want both the critic
template and critic key word.
This screen should use the GUI status ‘THIRD’ with the function code ‘RET’. This function code should
be assigned to the ‘Enter’ key.
If the user presses the ‘Enter’ key (which invokes the ‘RET’ function code), the user should be taken back
to the “calling” screen.
Dec-2008
Page 15
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
(1) If the user clicks on the ‘Exit’ pushbutton on screen 9000 or 9001, is the transaction terminated?
(expected = yes)
(2) If the user clicks on the ‘Initial Screen’ pushbutton on screen 9001, is the user returned to screen
9000? (expected = yes)
(3) If the user clicks on the ‘Edit Record’ pushbutton on screen 9000 and the record does not exist, is an
appropriate error message displayed and the year and category fields left open for input? (expected
= yes)
(4) If the user clicks on the ‘Add Record’ pushbutton on screen 9000 and the record already exists, is an
appropriate error message displayed and the year and category fields left open for input? (expected
= yes)
(5) If the user clicks on the ‘Add Record’ pushbutton on screen 9000 and the record does not exist, is the
user taken to screen 9001 with all the fields (except the year and category) blank? (expected = yes)
[A good way to test this one completely is to try to add an existing record (e.g. 1994, PIC). You
should get an error message. Then, change the year and category to one that does not exist and
click on ‘Add’ again. All the fields (except the year and category) should be blank on screen
9001.]
(5) Is the critic field display only on screen 9001? (expected = yes)
(6) If the user clicks on the ‘Enter Name’ pushbutton on screen 9001, is the user taken to the dialog box
screen 9002? (expected = yes)
(7) If the user hits the ‘Enter’ key on screen 9002, is the user taken back to screen 9001 with the
appropriate critic displayed? (expected = yes)
Dec-2008
Page 16
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Dec-2008
Page 17
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx6 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx6
Initial screen: 9000
Screen 9000: next screen = 9000
Screen 9001: next screen = 9001
Screen 9002 (dialog box): next screen = 9002
The purpose of this exercise is for you to learn how to conditionally execute modules, update or insert a
record in the database, and use the logical locking mechanism.
You should copy your SAPMYOPxx5 program to create program SAPMYOPxx6. First create the
new Package, then select program SAPMYOPxx5 in the Object Browser and click on the copy
pushbutton (or use the “Development object > Copy” menu path). Make sure you select all the
components to copy (documentation, variants, GUI status, screens, includes). You will be prompted to
create new include programs -- just click on the ‘Copy’ pushbutton or press the ‘Enter’ key. The Package
screen should appear – enter the new Package here, and ensure the new Change Request is used.
The appearance of the screens will not change in this program. Make sure that the ‘EXIT’ and ‘INIT’
function codes on your GUI are defined as type ‘E’ function codes.
To use the logical locking mechanism, you can use the existing lock object ‘EZ_MOVIEXX’ or you can
create your own. If you create your own lock object, it should be named ‘EZ_MOVIEXX’ (where ‘XX’ is
the last two digits of your logon id). Remember that a lock object is an ABAP Dictionary object.
Screen 9000
If the user clicks on the ‘Exit’ pushbutton (which invokes the ‘EXIT’ function code of type ‘E’), the
transaction should be terminated even before the automatic screen field checks occur.
If the user clicks on the ‘Edit Record’ or ‘Add Record’ pushbutton and the record is currently locked, an
error message should be issued (e.g. “This record is currently locked”). If this error message is
displayed, the year and category fields should be open for input.
Screen 9001
If the user clicks on the ‘Modify Record’ pushbutton (which invokes the ‘MODI’ function code):
(1) The record will be updated in the database if the user had clicked on the ‘Edit Record’
pushbutton (‘EDIT’ function code) on the initial screen
or
Dec-2008
Page 18
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
(2) The record will be inserted into the database if the user had clicked on the ‘Add Record’
pushbutton (‘ADD’ function code) on the initial screen.
If the update/insert is successful, the changes should be confirmed to the database and the user should
be taken back to screen 9000. If the update/insert is not successful, the changes should be canceled
and the user should be taken back to screen 9000. You can display appropriate messages for each
scenario, but make sure that the user can return to the initial screen (i.e. do not use an error or abend
message).
If the user clicks on the ‘Exit’ pushbutton (which invokes the ‘EXIT’ function code of type ‘E’), the
transaction should be terminated even before the automatic screen field checks occur.
If the user clicks on the ‘Initial Screen’ pushbutton (which invokes the ‘INIT’ function code of type ‘E’), the
user should be taken back to screen 9000 even before the automatic screen field checks occur.
Before the user returns to screen 9000, the record should be unlocked. Remember that you will have
more than one way back to the initial screen.
Dec-2008
Page 19
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
(1) If the user clicks on the ‘Exit’ pushbutton on screen 9000 or 9001, is the transaction terminated
before any automatic screen field checks occur? (expected = yes)
(2) If the user clicks on the ‘Initial Screen’ pushbutton on screen 9001, is the user returned to screen
9000 before any automatic screen field checks occur? (expected = yes)
(3) Are records being locked and unlocked correctly? (expected = yes)
[A good way to test this one is to have multiple sessions running the transaction. With multiple
transactions, you can try to edit/add a record that is currently locked. Once you determine that
the “locking” is working, make sure that the records are being “unlocked”.]
Dec-2008
Page 20
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx7 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx7
Initial screen: 9000
Screen 9000: next screen = 9000
Screen 9001: next screen = 9001
Screen 9002 (dialog box): next screen = 9002
Screen 9003: next screen = 9000
The purpose of this exercise is for you to learn how to create and use a step-loop block. You should
not code this program until you have caught up on your other exercises. However, you should
understand the concept of step-loops before going back to your other exercises.
You should copy your SAPMYOPxx6 program to create program SAPMYOPxx7. First create the
new Package, then select program SAPMYOPxx6 in the Object Browser and click on the copy
pushbutton (or use the “Development object > Copy” menu path). Make sure you select all the
components to copy (documentation, variants, GUI status, screens, includes). You will be prompted to
create new include programs -- just click on the ‘Copy’ pushbutton or press the ‘Enter’ key. The new
Package screen should appear – enter the new Package here, and ensure the new Change Request is
used.
Screen 9000
Add the ‘Winners for Year’ pushbutton to the GUI. This pushbutton should be assigned the ‘LOOP’
function code. If the user clicks on the ‘Winners for Year’ pushbutton, the user should be taken to screen
9003 to display all the winners for the specified year. If no winners exist for the specified year, an
appropriate error message should be issued.
Dec-2008
Page 21
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Screen 9003
You will have to create this new screen. It is a “normal” type screen and its “next screen” attribute should
be 9000.
This screen should use the GUI status ‘FOURTH’ with the function code ‘INIT’.
The text label and template for the year should be “painted” from the “YMOVIE_OP” table. The
category/winner block should be created as a fixed step loop block. The values in the step-loop block are
the winners in each category for the year specified on the initial screen. No processing takes place on
this screen. The appropriate values are just displayed to the user. All fields on this screen are display
only fields.
If the user presses the ‘Enter’ key, the user should be taken back to screen 9000. If the user clicks on
‘Initial Screen’ pushbutton, the user should be taken back to screen 9000.
Dec-2008
Page 22
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Testing Section
(1) If the user clicks on the ‘Winners for Year’ pushbutton on screen 9000 and at least one record exists
for the specified year, is the user taken to screen 9003? (expected = yes)
(2) If the user clicks on the ‘Winners for Year’ pushbutton on screen 9000 and no records exist for the
specified year, is the appropriate error message issued? (expected = yes)
(3) Are the correct values being placed in the step-loop fields? (expected = yes)
(4) If the user presses the ‘Enter’ key on screen 9003, is the user taken back to screen 9000? (expected
= yes)
Online program name: SAPMYOPxx8 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx8
Initial screen: 9000
Screen 9000: next screen = 9001
Screen 9001: next screen = 9001
Screen 9100 (Subscreen): next screen = 9100
In this exercise, you will create and program which uses a tabstrip control that changes with the
application server. Your tabstrip control will return fields from the YMOVIE_OP table based on a year
that the user enters in screen 9000 and which tab is selected in screen 9001. All your tabs will display
the same fields in subscreen 9100.
Dec-2008
Page 23
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Screen 9000
Screen 9001
Dec-2008
Page 24
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Online program name: SAPMYOPxx9 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx9
Initial screen: 9000
Screen 9000: next screen = 9001
Screen 9001: next screen = 9001
Screen 9100 (Subscreen):
Screen 9101 (Subscreen):
In this exercise, you will create and program which uses a tabstrip control that changes without the
application server. Your tabstrip control will return fields from the YMOVIE_OP table based on the year
and category that the user enters in screen 9000. Remember, all field held within the tabstrip must be
populated before the tabstrip screen is displayed. In your tabstrip, you will have two tabs. One will hold
the information of a winner for a specific category, while the other holds nominee information.
Dec-2008
Page 25
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
9000
9001 (Winner)
Dec-2008
Page 26
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
9001 (Nominees)
Dec-2008
Page 27
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
Programming Section
Online program name: SAPMYOPxx10 (where ‘xx’ is the last two digits of your logon id)
Transaction code: YOPxx10
Initial screen: 9000
Screen 9000: next screen = 9001
Screen 9001: next screen = 9001
In this exercise, you will create a program that uses a table control. Your table control will display (in
screen 9001), fields from the YMOVIE_OP table based on a year that the user enters in screen 9000.
The YMOVIE_OP fields to display in screen 9001 are: YEARC, CATEGORY, WINNER, NAME1,
Dec-2008
Page 28
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
NAME2, NAME3, NAME4 and NAME5. The year and category columns are fixed columns, while the
others are scrollable.
9000
For this screen’s PAI, you should select records for the chosen year and put those records in an internal
table.
Dec-2008
Page 29
ECC
6.0
Online Programming:
Exercises SAP Development ABAP Training
9001
Choose the table control size so that it can show two records. In the PBO for this screen, you should loop
through the internal table containing the records and display them in the table control.
Dec-2008
Page 30