Documente Academic
Documente Profesional
Documente Cultură
Overview of ABAP/4
ABAP/4 Developm ent W orkbench
Editor
Syntax
SELECT Statem ent
W RITE Statement
SAP AG
Chapter 02 Objectives
SAP AG
The ABAP/4 Programming Language
A dvanced
B usiness
A pplication
P rogram ming
/
4
SAP AG
ABAP/4 is a programming language developed by SAP for the interactive development of application
programs.
ABAP/4 is a fourth-generation programming language.
ABAP/4 Development Workbench Architecture
Development
Runtime
SAP AG
The ABAP/4 Development Workbench provides access to SAP’s development tools which cover the
entire software development cycle.
These tools can be used both for customer-specific developments and enhancements to R/3
applications supplied by SAP.
All applications created with the ABAP/4 Development Workbench can run without further
modifications on any platforms, database systems and graphical user interfaces supported by SAP.
ABAP/4: General Programming
Dialog programm ing Batch input
layout
SCREEN
m odule external
checks system SAP
pool
flow logic
ABAP/4
In dialog programming, you use ABAP/4 to create a module pool. Each module is called by the screen
processor in the course of processing a screen.
Batch input is a process allowing for automatic, secure transfer of data to the R/3 System.
ABAP/4 contains statements for writing communication programs according to CPI-C standards.
ABAP/4 contains statements for reading/writing to non-SAP file structures.
Object Browser Initial Screen
Object list
Development class Display
Program
Function group
Local priv. objects
Single object
Program objects Edit
Function group objects
Dictionary objects
Modeling objects
Other objects
SAP AG
To create a program, you first specify a development class (e.g. SAB1 or $TMP for objects which are
not meant to be transported). Customer-specific development classes begin with Y or Z).
You then specify the name of the new program. To proceed, click the radio button Program and
choose Display.
Later, you reach a dialog box where you are asked whether you want the program to be created with a
TOP include. If so, the system creates an include program which can contain all declarations (this
assumes observation of naming conventions such as the program name beginning with SAPM....).
ABAP/4 Program Objects
Development class
Includes Subroutines
Transactions Screens
.
. Transactions
.
SAP AG
You can use the ABAP/4 Development Workbench to create ABAP/4 programs.
You can call objects from the object list generated from the Object Browser initial screen.
The object view is a hierarchical structure in which the development class is the root node.
Once you have generated an object list, it is maintained automatically and dynamically by the system.
You can create, change or display the objects of an ABAP/4 program from the object list.
Attributes I
ABAP/4
Object Browser
ABAP/4 Program Attributes
Type................ 1 Reporting
Application..... S System
Authorization SAB1
group..............
Attributes
Development SAB1
class...............
F4 F4
Authorization group
When creating an ABAP/4 program, you must first maintain the attributes.
The transport system requires you to assign the program to a development class, or flag it as a local,
private object.
The attributes Type, Application and Development class are used to manage ABAP/4 programs.
Whether you are in Reporting or ABAP/4 development, you can generate a directory of ABAP/4
programs stored in the system. In the case of Reporting, the system lists only type ‘1’ programs
(online reports). You can also select the part of the directory you want to display:
For an overview of existing programs, proceed as follows :
In ABAP/4 development: (i.e. on the ABAP/4 Development Workbench screen):
Choose ABAP/4 Editor --> Utilities --> Find program
In Reporting:
Choose System --> Services --> Reporting --> Utilities --> Find program
Attributes II
ABAP/4 Program Attributes
Type................ 1 Reporting
Status............. T Test
Application.... S System
Development SAB1
class..............
F4 F4
SAP AG
SAP AG
ABAP/4 Editor
SAP AG
F1
I(nsert) Insert new lines at end of text
FIND string Multiple string search
N(ext) string Once-only string search
R(eplace) string1 string2 Replace string1 by string2
IC abc Insert a structure
PP Call Pretty Printer
SAP AG
By pressing F1 on one of the command lines, you can display a list of editor commands which can be
specified on that line. By placing the cursor on the editor command line and pressing F1, you get a list
of all editor functions.
The FIND, NEXT and REPLACE commands do not differentiate between lower and upper case. If
string contains blanks, you must enclose the character strings in delimiters, e.g. R /ab cd/x yz/.
IC (Insert Command): IC abc inserts the structure of the statement abc or the comment block abc (can
also be implemented with the appropriate function key).
Pretty Printer: Indents program lines in accordance with the control statements (IF, CASE,
WHILE,...).
If you choose an ABAP/4 key word with the cursor and press F1, the documentation for that key word
is displayed.
ABAP/4 Editor (Command Mode)
ABAP/4
developm ent
SAP AG
The functions listed are those which are most essential to get started. The Utilities menu contains
more functions.
For further information about the command mode, see the Appendix.
ABAP/4 Editor (PC Mode) 1
SAP AG
To check the program code for syntax errors, choose Program --> Check --> Current program or the
click on the Check button.
With many syntax errors, you can apply the automatic corrections proposed by the system.
If you want to perform an even more detailed check, you can call the extended syntax check (choose
Programs --> Check --> Extended prog. check). This check is divided into 14 different sub-tests. The
F1 online help gives you an overview of what these sub-tests check.
ABAP/4 Editor (PC Mode) 2
The SHOW and HELP comm ands can be accessed via the
pushbutton 'i'
SAP AG
To check the program code for syntax errors, choose Program --> Check --> Current program or the
click on the Check button.
With many syntax errors, you can apply the automatic corrections proposed by the system.
If you want to perform an even more detailed check, you can call the extended syntax check (choose
Programs --> Check --> Extended prog. check). This check is divided into 14 different sub-tests. The
F1 online help gives you an overview of what these sub-tests check.
Editor in PC Mode
Program Edit Goto Utilities Block/clipboard Settings ...
Help
Find Pattern
Undo Concatenate
Select Duplicate
Insert from buffer Move
Copy to buffer
Cut
Insert line
Stack
W here-used list
Check
Display <-> Change
SAP AG
In PC mode (with or without line numbering), the program editor is similar to other PC editors.
Here, you use pushbuttons, function keys and menu functions rather than line or header commands.
If you press the right mouse button, the system displays a pop-up window with a list of all available
editor commands.
ABAP/4 Syntax
DATA COUNTER TYPE I.
DATA NAME(20).
MOVE 1 TO COUNTER.
MOVE 'ABC' TO NAME.
. ABAP/4 program
.
. statement
WRITE NAME.
WRITE COUNTER.
word 1 word 2 word 3
word 4 .
WRITE 'XYZ'.
WRITE NAME.
WRITE COUNTER.
ADD 1 TO COUNTER1.
ADD 1 TO COUNTER2.
ADD 1 TO COUNTER3.
SAP AG
You can concatenate several consecutive statements with an identical first part into a chain statement.
When doing this, conclude the identical first part with a colon.
After the colon, separate each concatenated part from the next with a comma.
Blanks can appear before and after the separators (colon, comma or period).
Comments
* New account
* Initialize totals field
CLEAR SUM.
SAP AG
REPORT RSAAA02A.
TABLES SBOOK.
SELECT * FROM SBOOK.
WRITE: / SBOOK-CARRID,SBOOK-CONNID,
SBOOK-FLDATE, ... .
ENDSELECT.
SAP AG
You use the SELECT statement to read the table entries (records) of a (database) table.
The editor command SHOW <table> or the pushbutton ' i'allow you to display the structure (field
names, field attributes) of a table.
The TABLES statement makes the structure of a table known to the ABAP/4 program.
You address the fields of a table with the table name followed by the field name.
Note:
This chapter covers only basic forms of the SELECT statement. Chapter 8 on ABAP/4 Open SQL
discusses the SELECT statement in more detail.
SELECT Statement II
REPORT RSAAA02B.
TABLES: SBOOK.
SELECT * FROM SBOOK
WHERE CARRID = 'LH '.
statements
statem ents
ENDSELECT.
IF SY-SUBRC NE 0.
statements
statements
ENDIF.
SAP AG
You can use the WHERE parameter to restrict the number of table entries to be read. The above
example reads only those table entries where the table field SBOOK-CARRID has the value LH.
The field specified in the WHERE clause to the left of the comparison operator must be a field of the
table to be read. In this context, it must be addressed without the table name.
If no table entry is found to satisfy the WHERE condition, the return code of the system field SY-
SUBRC is set to a value other than zero.
W RITE Statement
REPORT RSAAA02C.
WRITE: '******************************'.
SKIP 2.
WRITE: Introduction 1
**********************************************
Date 01.01.1996 Time 14:46:10
**********************************************
SAP AG
WRITE outputs the contents of a field or constant in the format appropriate for the type.
Consecutive WRITE statements output data on the same line. If there is no more space on one line,
the output continues on the next line.
SKIP generates blank lines.
By default, ABAP/4 generates two header lines for each page. The first of these contains the date and
the page number. It also displays the list title (if there is one).
Format Specifications
REPORT RSAAA02D.
WRITE: 5'******************************'.
SKIP.
WRITE: 5 'Date', 20 SY-DATUM,
/5 'Time', 20 SY-UZEIT.
ULINE /5(30).
SKIP2.
ULINE.
ABAP/4 Programm Attribute
W RITE: Format specifications
********************************************
Date 01.01.1996
Time 16:18:38
----------------------------------------------------
---------------------------------------------------------------------
column 5 column 20
SAP AG
You can assign a format to an output value. This allows you to specify a new line, the start column
and the output length.
ULINE generates an underline.
Page Header
Text elements
Save
Title and headers
List header
Column header
SAP AG
For the report list, you can maintain a list header and up to four column headers. To do this, choose
Text elements followed by Title and headers.
Another way of maintaining headers for the generated list is to choose System -> List -> List header.
The advantage of this method is that the list is displayed on the screen and positioning, particularly of
column headers, is thus much easier to determine.
The header lines are displayed in the list automatically the next time you start the report.
If you do not maintain a list header, the report title is displayed instead.
You can translate the texts into other languages. To do this, choose Goto -> Translation.
Text Symbols
REPORT RSAAA02G.
Text elements
No Text Language D
001 Date
Tim e 13:25:07
SAP AG
ABAP/4
Reporting
Execute
Report RSDEMO00.
.
RSDEMO00 Execute .
.
WRITE
Execution
SAP AG
By using the Execute function, you can start an ABAP/4 report directly from the ABAP/4 Editor.
In the context of dialog programming, an ABAP/4 program (module pool) is activated by the assigned
transaction. You maintain the link between a transaction code and an ABAP/4 module pool in the
table TSTC.
Marking Lines and Setting Markers
.
.
.
PERFORM UPRO Note
.
.
.
.
.
.
SELECT * FROM Note
SBOOK ... .
.
.
.
Notep.
Markers
Initial marker
Permanent markers
Tem porary markers
SAP AG
ABAP/4
ABAP/4
SELECT * FROM SBOOK
Workbench
W orkbench
WHERE ... . Dict. objects
Tables
Tab les
SBOOK
W here-used list
W here-used list
RSAAA022
SELECT * FROM SBOOK ...
RSAAA022
TABLES: SBOOK . RSAAA02A
SAP AG
You can request a where-used list for any object where navigation is supported. This can apply just to
your current program or may be system-wide.
To obtain a where-used list for one program from the ABAP/4 Editor, choose Utilities -> Where-used
list.
You can get a system-wide list from the Object Browser by choosing the Single objects radio button
and then Edit, followed by Where-used list on the next screen.
The hit list is integrated into the navigation process.
A where-used list is always up-to-date because the program index is updated when you save the
source code.
Copying ABAP/4 Programs
1 Com plete program including environment
2 Program components
ABAP/4 Step 1: ABAP/4 Editor with source program
Developm ent ABAP/4 Editor with source program
000010 aaaaa
XX 0020 bbbbb Select block of
Copy 000030 ccccc lines and copy
XX 0040 ddddd to clipboard
000050 eeeee
Step 2: Editor comm and line
FETCH target program
Step 3: ABAP/4 Editor with target program
ABAP/4 Editor with target program
000010 mmmmm
X 00020 nnnnn Copy from clipboard
000030 ppppp
SAP AG
SHOW SY
SHOW SY
SAP AG
ABAP/4 provides several system fields. To get a list of these and their definitions, enter the header
command SHOW SY if you are in command mode, or press the pushbutton “i”and select Table
structure if you are in PC mode.
In programs, you address system fields by specifying SY-<field name>.
Chapter 02 Summary
SAP AG
Exercises Chapter 2: ABAP/4 Development Workbench
Task:
Create a copy of the report RSAAA027 and save it under the
above report name.
Copy the blocks of code marked by ==> and <== from the
report RSAAA028 into your report.
Start your report.
2. Name of your report: ZBCA##B2
##: Group number
Development class : $TMP (local)
Task:
Create a program which generates the example list below.
To do this, read the table SBOOK and determine all bookings
of the airline carrier (SBOOK-CARRID) LH with a flight
connection code (SBOOK-CONNID) 0400.
Output the found data records using the following fields:
SBOOK-CARRID, SBOOK-CONNID, SBOOK-FLDATE,
SBOOK-BOOKID, SBOOK-LUGGWEIGHT, SBOOK-WUNIT
At the end of the list, output when the list was created and by
whom. To do this, use the system fields
SY-DATUM, SY-UZEIT and SY-UNAME
Maintain the list and column headers.
a) Example list
.
.
-----------------------------------------------------------------------------------------
on : 29.04.1994
at : 13:40:13
by : LOTZ
-----------------------------------------------------------------------------------------
Solutions Chapter 2: ABAP/4 Development Workbench
1. REPORT RSAAA022.
TABLES: SBOOK.
10 SBOOK-CONNID,
20 SBOOK-FLDATE,
35 SBOOK-BOOKID,
50 SBOOK-LUGGWEIGHT,
60 SBOOK-WUNIT.
ENDSELECT.
IF SY-SUBRC NE 0.
WRITE: / TEXT-001.
ENDIF.
SKIP 5.
ULINE.
SKIP.
WRITE: / 15 TEXT-002.
SKIP 2.
WRITE: /TEXT-003 UNDER TEXT-002, 23 SY-DATUM,
SKIP.
ULINE.