IS485ABAPLab1

advertisement
IS 485
ABAP LAB 1
CREATING A FIRST ABAP PROGRAM
ABSTRACT
In this lab, you will log in to the SAP system and create a first ABAP program. You will see both how to create a syntax
error and how to correct one. You will also learn about the following ABAP statements:




REPORT to create an executable program.
WRITE to send output to the output list.
SKIP to write a blank line.
ULINE to write an underline across the width of the page
TASK: LOGGING IN TO SAP
1. Start the SAP GUI by double-clicking the SAP Login icon on the desktop or using the Start menu. You should see
the following login screen:
2. Click the host Verona and then click Log On at the top of the screen to display the following login dialog:
Page 1 of 7
3. Enter the host number 100. Enter the login and password credentials that I gave you. Make sure that you enter
the client number. If you do not, you will not be able to log in.
4. Note that the first time you log in, you will be requested to change your password. Note that if you forget your
password, I can reset it. I will need to know your user number.
5. Once you have logged in successfully, you will see the SAP Easy Access menu as follows. Note that I have
expanded the menu items so that you can see the ABAP editor.
6. Double-click the ABAP editor or enter transaction code SE38. The ABAP Editor: Initial Screen appears as follows:
Page 2 of 7
From this screen, you can create new programs and edit existing ones. Note that user (customer) programs
must begin with the letters “Y” or “Z”. Note also that program names are not case sensitive. Program names
starting with any other letter are considered SAP programs and require an access code. For example, if I were to
try to create a program named SAPTEST, the following dialog will appear requesting that an access code be
entered:
The above access code is provided to users by SAP. It allows SAP to track any modifications to their software. If
you call technical support, and they see modified code, you are on your own! Don’t worry though. You don’t
have one of these codes.
7. Next, you will begin creating your first program. Unlike most development environments that you are used to,
SAP code is stored inside of the SAP database itself. Programs are not stored as separate files. In addition, you
are all creating programs in the same database. So that you do not create conflicts with other users, I suggest
the following naming conventions for programs:



The first character of all programs should be the letter “Z”.
The next two characters should be the last two digits of your user number. Mine is 00.
Finally, use a descriptive name for the program. I’ll use Demo1.
So my first program will be named Z00DEMO1. Note that program names are not case sensitive.
Page 3 of 7
8. In the ABAP Editor: Initial Screen, enter the program name. Make sure that the subobject Source Code is
selected. Finally, click the Create button.
Note that the first time you create a program you will be asked to enter a developer key. This is the developer
key that I gave you on the handout. Make sure that you use the developer key that corresponds to your account.
Note that the developer key is different that the access code requested in the previous figure.
The following screen will appear asking you to enter the program’s attributes:
9. Enter a descriptive title. The Type attribute defines the kind of program you are created. Set the Type to
Executable program. Executable programs can be run directly without a transaction code. You will learn about
other types of programs later in the course. Set the Status to Test Program. Note that programs are roughly
categorized as Customer programs or SAP programs. Set the Application to Basis. This is just another way to
categorize and find applications. We will discuss the other options later in the course. When finished, click the
Save button. When you do, the following dialog box will appear:
10. Enter the Package name $TMP, and click the Local Object button to create the program.
Page 4 of 7
While not obvious from this dialog, setting the package is important in the deployment (transport) phase. At
some point, a system administrator will deploy packages to test and production systems.
11. The ABAP editor appears as shown in the following figure:
TASK: CREATING A FIRST PROGRAM
The ABAP language is very similar to the COBOL language. This is logical as the people that started SAP were
engineers from IBM. Thus, many of the original constructs resemble those from the old IBM mainframe days. Note
the following about ABAP programs:






Any line beginning with the * character is considered a comment. Blank lines are also considered
comments.
All statements must end with a period.
ABAP commands and reserved words appear in blue.
Programs must be activated before they can be run. When activated, a program is copied out of the data
dictionary to the database for execution. To activate a program, click Program, Activate on the menu bar. If
there are multiple objects to activate, they appear in another dialog box listing in inactive programs waiting
to be activated.
You can get help on any command by selecting the command, and then pressing F1.
String literals are enclosed in single quotation marks.
1. First, you will see how to get program help. In the ABAP Editor, click on the REPORT statement to select it,
and then press F1. The Help page appears as shown in the following figure:
Page 5 of 7
2. Next you will create the statement that will write a string to the output list (report). The WRITE statement
sends data to the output list (report). To write a literal string, the string value should be enclosed in single
quotation marks. The statement must end with a period. The following statement writes the string HELLO to
the output list:
WRITE ‘HELLO’.
3. Enter the above statement in the ABAP Editor. However, don’t enter a period at the end of the statement so
that you can see how a syntax error is treated by the ABAP interpreter.
4. On the menu bar, click Program, Check, Syntax. The syntax error is detected as shown in the following
screen. The description indicates that the statement terminator (period) is missing. The syntax indicates that
the error appears on line 9 and is a fatal error. A program with fatal errors cannot be compiled.
5. Correct the syntax error by entering the period at the end of the statement. Compile the program again. You
should see the following message in the status bar at the bottom the screen indicating that the program is
correct:
Page 6 of 7
6. Press F8 to run the program. You can also use the menu path Program, Test, Direct Processing. Note that as
you make changes to the program, you will need to recompile and reactivate it.
7. Click the Back button to return to the ABAP editor.
8. Next, add a second WRITE statement as follows and run the program again. Note that the word Hello
appears twice on the same line.
9. To write output followed by a carriage return, the WRITE / statement is used (introducing the / character.
Modify the program as follows.
10. Run the program again and note that the output appears on different lines.
11. The ULINE statement writes an underline across the report. Enter the ULINE statement as the last statement
and run the program again.
Page 7 of 7
Download