Sunteți pe pagina 1din 36

Chapter 02 ABAP/4 Development Workbench

Overview of ABAP/4
ABAP/4 Developm ent W orkbench
Editor
Syntax
SELECT Statem ent
W RITE Statement

SAP AG
Chapter 02 Objectives

How to work with the ABAP/4 Development


W orkbench
W hat to rem em ber when creating a report
How to use the editor in different modes
How to read data from database tables with a
'SELECT' statement
How to output data to a list with a 'WRITE' statem ent

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

host host reporting


1 2

Host com munication Sequential datasets


SAP AG

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

Dev. class object types Program

Dictionary objects Global data

Programs PBO m odules

Function groups PAI modules

Includes Subroutines

Transactions Screens

Logical databases GUI status

Message classes Includes

.
. 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

Program objects Status............. T Test

Application..... S System

Authorization SAB1
group..............
Attributes
Development SAB1
class...............
F4 F4
Authorization group

Typ 1: Report Status T: Test program


M: M odule pool, dialog P: Production program
program K: Customer program
V: Update p rogram S: System program
.
.
.
SAP AG

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

Authorization SAB1 ABAP/4 training...


group.............

Development SAB1
class..............
F4 F4

Class Application Text


Application Development class
G: General Ledger Table TADIR DEBI F Customers
F: Financial Accounting KRED F Vendors
SCHU S Training

SAP AG

You must maintain the attributes Type and Application.


ABAP/4 Development Workbench objects are assigned to a development class. This class determines
the transport attributes of the objects.
Customer-specific development classes begin with Y or Z. If you do not want your objects to be
transported, you can flag them as "local objects" (development class: $TMP).
You can find out the meaning and the possible input values for the individual attributes by pressing
F1 or F4.
The ABAP/4 Editor

The ABAP/4 Editor can run in three different modes:

Comm and m ode

PC m ode with line numbering

PC m ode without line numbering

SAP AG

As of Release 3.0, the ABAP/4 Editor can also run in PC mode.


In this mode, you can execute all functions with the mouse.
You can switch between editor modes by choosing Settings → Editor mode...
ABAP/4 Editor (Command Mode)

ABAP/4 Editor

Editor command line


ABAP/4
Editor Line ABAP/4
commands program lines

SAP AG

You use the ABAP/4 Editor to write and edit programs.


To scroll though the program code, you can use either the standard function keys F23 (forwards) and
F22 (backwards) or the general scrolling keys.
F21 takes you to the beginning of the program, F24 to the end.
To go to a particular program line, you can either double-click in the number area of the relevant line
or enter * and press ENTER. Otherwise, you can use the Position cursor... function.
The set of editor commands is divided into those which you enter in the command line and those you
use in the line numbering area. Nearly all these functions are available in the Program and Edit
menus.
Editor Command Line (Command Mode)
ABAP/4 Editor

Editor command line

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 Editor HELP <statement>


with syntax check

program lines online documentation

ABAP/4
developm ent

ABAP/4 debugging mode SHOW <table>

program lines display ABAP/4


display / change Dictionary tables
field contents

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

Line comm ands have been replaced by pushbuttons/


function keys/menu functions
No input field for header comm ands; these can be entered in
a separate window by choosing Edit->More functions->
Com mand input

Select lines and blocks of lines with pushbuttons/function


keys/m enu functions

Pressing ENTER splits the line at the current cursor position


(Concatenate line joins together split lines)

Pressing ENTER at the beginning of a line inserts a blank line


before the current line

Pressing ENTER at the end of a line inserts a blank line after


the current line

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

IC comm ands can be accessed with the Pattrn pushbutton

You can generate and maintain your own statem ent


structures from the editor by choosing Utilities --> More
Utilities --> Edit pattern

The SHOW and HELP comm ands can be accessed via the
pushbutton 'i'

The Undo function allows you to cancel the last change

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 .

key word parameter, field,


constant
SAP AG

An ABAP/4 program consists of individual statements.


Each statement must end with a period.
The first word of a statement is known as the key word.
Words are separated from each other by at least one blank.
Statements can be indented.
Statements can extend over several lines.
Chain Statements

WRITE 'XYZ'.
WRITE NAME.
WRITE COUNTER.

WRITE: 'XYZ', NAME,


COUNTER.

ADD 1 TO COUNTER1.
ADD 1 TO COUNTER2.
ADD 1 TO COUNTER3.

ADD 1 TO: COUNTER1,


COUNTER2,
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

DATA: SUM TYPE P, " Totals field


COUNTER TYPE P.

* New account
* Initialize totals field

CLEAR SUM.

SAP AG

You can insert comments into a program in two ways:


- An asterisk (*) in column 1 flags the whole line as a comment.
- A quotation mark (") within a line flags the remainder of the line as a comment.
SELECT Statement I
Table description SBOOK
SHOW SBOOK Dict.
SBOOK-CARRID CHAR C 3

Table SBOOK-CONNID NUMC N 4


SBOOK SBOOK-FLDATE DATS D 8
SBOOK-BOOKID NUMC N 8

Table work area SBOOK Name Type Length

CARRID CONNID FLDATE BOOKID

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: 'Date', SY-DATUM.


WRITE: 'Time', SY-UZEIT.
SKIP 2.
WRITE: '******************************'.

ABAP/4 Program m Attribute

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

ABAP/4 Program m Attribute


Title

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.

WRITE: TEXT-001, 10 SY-DATUM,


/ TEXT-002, 10 SY-UZEIT.

Text elements
No Text Language D

001 Date

Text symbols 002 Tim e


Date 01.01.1996

Tim e 13:25:07

SAP AG

To maintain text symbols, choose Text elements -> Text symbols.


You can translate texts into other languages by using the Translate function.
There are two ways you can address text symbols in a program:
- TEXT-xxx (here, xxx is a three-character string)
-'
string'(xxx).
One of the advantages of using text symbols is that the string is no longer hard-coded in the program.
This means that you can maintain the text without having to access the source code.
Such a procedure is particularly significant for software which exists in several languages.
Starting an ABAP/4 Report
1 2
Starting via the m enu Starting from the ABAP/4 Editor

ABAP/4

Development ABAP/4 Program


ABAP/4 m Attribute
Editor RSDEMO00

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.

Include 0D101F01 SELECT * FROM SBOOK... .


Include B170D01 PERFORM UPRO

Markers

Initial marker
Permanent markers
Tem porary markers

SAP AG

The Mark function allows you to mark lines in the editor.


(In command mode, use the Mark pushbutton. In PC mode, use the Mark line pushbutton when
displaying, or the menu path Edit -> Edit line -> Mark line when editing.)
If you choose Markers, you get a list of all the lines you have marked and can then branch directly to
one of these
(In command mode, use the Markers pushbutton. In PC mode, use the Markers pushbutton or the
menu path Goto -> Markers.)
Each object list you pass is automatically logged as a temporary marker. However, you can also
specify that you want an object list to be marked as a permanent marker (Save temp. marker).
When you log off, temporary markers are deleted, but you can keep them by specifying them as
permanent markers.
In the Object Browser, you can define the place where you want to enter the ABAP/4 Development
Workbench as an initial marker. To do this, choose Settings -> Define init.position.
W here-used List

W ithin program System-wide

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

Explanatory notes on step 2:


- You use the line commands XX ... XX to select a block of lines and place them in the X clipboard.
- The editor command FETCH prog2 gets the program prog2 and places it in the editor.
- The program prog1 is then deleted from the editor. If you have made changes to this progam and
have not yet saved them, you must first perform an UPDATE.
- You use the line command X to copy the contents of the X clipboard after the line marked by X.
- In addition to the line commands XX ... XX and X, you can use the line commands YY ... YY and Y
as well as the line commands ZZ ... ZZ and Z. This means that you can copy up to three blocks of
lines in one single process. The line commands WW...WW und W allow you to store lines in the
general clipboard and copy them back to your program later.
- You can delete the contents of the X,Y and Z clipboards with the line command CLEAR.
- The Select and Insert from buffer functions allow you to place blocks of lines in a buffer and to copy
them from the buffer back into the editor.
System Fields
Editor command

SHOW SY

SHOW SY

Name Type Length M eaning

SY-DATUM DATE 8 Date


SY-UZEIT TIME 6 Tim e
SY-UNAME CHAR 12 User name
SY-SUBRC HEX 2 Return code
SY-REPID CHAR 8 Program name
SY-LANGU CHAR 1 Logon language
.
.
.

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

You create ABAP/4 programs in the ABAP/4


Development Workbench using a program editor
which can run in 3 different modes.
For data selection and data output, you use the
SELECT and WRITE statem ents.

SAP AG
Exercises Chapter 2: ABAP/4 Development Workbench

1. Name of your report: ZBCA##B1


##: Group number
Development class: $TMP (local)

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

Bookings of airline carrier LH 1


-----------------------------------------------------------------------------------------
Airline Flight Flight date Booking Weight Weight
carrier conn. number of unit
code luggage
-----------------------------------------------------------------------------------------
LH 0400 08.11.1995 00016445 0 kg

LH 0400 08.11.1995 00016446 50 kg

LH 0400 31.12.1995 00016605 50 kg

.
.

-----------------------------------------------------------------------------------------

This list was created:

on : 29.04.1994

at : 13:40:13

by : LOTZ

-----------------------------------------------------------------------------------------
Solutions Chapter 2: ABAP/4 Development Workbench

1. REPORT RSAAA022.
TABLES: SBOOK.

SELECT * FROM SBOOK

WHERE CARRID = ´LH´

AND CONNID = ´0400´


WRITE: / SBOOK-CARRID

10 SBOOK-CONNID,

20 SBOOK-FLDATE,

35 SBOOK-BOOKID,

50 SBOOK-LUGGWEIGHT,

60 SBOOK-WUNIT.

ENDSELECT.

IF SY-SUBRC NE 0.

WRITE: / TEXT-001.

*D: TEXT-001: ´No entries exist for this selection´

ENDIF.

SKIP 5.

ULINE.

SKIP.

WRITE: / 15 TEXT-002.

SKIP 2.
WRITE: /TEXT-003 UNDER TEXT-002, 23 SY-DATUM,

/TEXT-004 UNDER TEXT-002, SY-UZEIT UNDER SY-


DATUM,

/TEXT-005 UNDER TEXT-002, SY-UNAME UNDER SY-


DATUM.

SKIP.

ULINE.

S-ar putea să vă placă și