Académique Documents
Professionnel Documents
Culture Documents
This document is partially based on the development blog How to Develop in ABAP by
Thomas Weiss.
Contents
SAP as ERP System ........................................................................................................................................ 3
About SAP ..................................................................................................................................................... 3
Developing on the server .............................................................................................................................. 4
Navigation on the Application Server ........................................................................................................... 6
ABAP Workbench Basics ............................................................................................................................... 8
The Debugger .............................................................................................................................................. 10
The Data Dictionary .................................................................................................................................... 11
Data Types............................................................................................................................................... 11
Structures and Tables ............................................................................................................................. 12
DDIC Overview ........................................................................................................................................ 13
How to create a DB table or structure in SE11 ....................................................................................... 13
Where-Used-List ......................................................................................................................................... 14
Program Elements....................................................................................................................................... 17
Data Declarations .................................................................................................................................... 17
Most common ABAP statements ............................................................................................................ 19
IF.......................................................................................................................................................... 19
DO ....................................................................................................................................................... 19
WHILE .................................................................................................................................................. 19
Messages............................................................................................................................................. 19
OpenSQL statements .......................................................................................................................... 20
Dealing with internal tables .................................................................................................................... 20
Subroutines ............................................................................................................................................. 21
Function Modules ................................................................................................................................... 23
Parameters and Select-Options on a Selection Screen .......................................................................... 24
System Fields............................................................................................................................................... 25
Common Transactions ................................................................................................................................ 26
Usefull Links ................................................................................................................................................ 26
SAP as ERP System
http://en.wikipedia.org/wiki/Enterprise_resource_planning
About SAP
http://en.wikipedia.org/wiki/SAP_SE
o
You write your programs using the ABAP Editor of the ABAP Workbench and the
tools integrated there, which are all part of the server.
Creating or modifying of an object will only create an inactive version of the
object. The inactive object is not visible to other objects or programs. By
activating it, an active version will be generated that is visible to programs,
classes, etc.
Basically every object is visible to any other object in the system, regardless of
package assignment. Development objects are assigned to packages for
administration purposes.
Navigation on the Application Server
Command field for the 'transaction code'. This is a shortcut to the transaction
(program) you want to execute.
The prefix /n ends the current transaction and starts the new one, /o starts the
transaction in a new session.
The SAP Easy Access screen has a folder for your favorite transactions, and
shows the SAP Menu.
Input fields of a transaction marked with a checkbox are mandatory to fill:
. You will not be able to process to the next step
without filling these fields.
Input fields having a button on their right side provide a search-help that
displays a list of possible values:
Navigation buttons:
o The green button is the 'Back' button, which goes back to the previous
screen.
o The yellow button is the 'Exit' button that interrupts the transaction and
takes you straight back to the entry screen.
o The red button is the 'Cancel' button that stops the transaction, but will not
always return you to the entry screen (e.g. it can interrupt an input
validation).
Transactions:
o Programs can be started with transaction codes. A transaction in SAP is
basically an ABAP program.
o Many transactions start with a so-called selection screen. This allows
entering filter criteria for the data that is going to be selected. On a
selection screen there can be parameters or select options. A parameter
means a single value. A select option can define complex criteria for the
filter.
o
o Above you see a simple selection screen. Country key is a parameter. The
selection will read only those lines, that have TR as country key.
Connection number is a select option. The selection will consider all lines
that have this number between 100 and 900. The conditions of the
selection screen will be joined with an AND (that is, the selected lines
have to fulfill all criteria, both country key TR and con. nr. between 100
and 900).
o A select option can define not only intervals, but also more complex
criteria. Click the button with the right arrow to have access to further
options:
o
o In the above example there are three intervals defined (joined with an
OR). But its also possible to define a list of single values, or to exclude
values from the selection.
Double-click navigation:
o Several screen fields respond to double-click. It usually takes you to the
definition of the object, like a table definition in the dictionary.
o Also use double-click in the ABAP code to navigate to the objects
definition (e.g. declaration of a variable or method, dictionary objects, etc.)
ABAP Workbench Basics
REPORT zvg_test.
WRITE: lv_string.
Start a line with * to make it a comment line. Add in-line comments with .
You can place break-points at the most program statements. Use the button
to set break-points. Execute the program and it will stop at the first break-point.
Use the button to create further break-points, like bp. on a command, form,
method, etc.
The Data Dictionary
Data definitions (metadata) are created and managed in the ABAP Dictionary. The
ABAP Dictionary permits a central description of all the data used in the system without
redundancies.
You can create the corresponding objects (tables or views) in the underlying relational
database using these data definitions. The ABAP Dictionary therefore describes the
logical structure of the objects used in application development and shows how they are
mapped to the underlying relational database in tables or views.
Data Types
On the lowest level there are the basic types, like CHAR, DEC, INT4, RAW, etc.
They can not be used directly in programs or structure definitions. They can only
be used to define higher level data types (domains or data elements).
A domain defines the technical properties of the data, the basic type, length,
number of decimal places, value range and some others. For instance
Z_DEC_100 could be of type DEC, length 3, no decimal places, with possible
values between 0 and 100.
A data element defines the semantics of the data. For instance you can define
Z_EFFICIENCY to represent some percentual values, referring to the domain
Z_DEC_100, as the values are decimal and allways between 0 and 100. Data
element definitions also contain texts of different lengths called Field Labels
describing the data type. The field labels will be shown on screens, table
headers, tooltips and so on, like the Program text on the following image:
The multi-level structure of data types allows the re-use of the data definitions and
assures that each data element has a fixed semantics. A new data element,
Z_WATER_TEMP, could use the same Z_DEC_100 domain, providing a new
semantics for values between 0 and 100.
Data elements can refer directly to low level basic data types, skipping the domain, if no
value restriction applies.
Structures and Tables
By defining a table in the Data Dictionary a corresponding table will be created in the
database itself. The definitions of sructures and tables are similar, but structures have
no content, nor a corresponding database object.
Table names can also be used for the above purposes, just like structure names. In all
these cases the table name will mean the structure of the table, and will not define a
internal table or anything similar.
In SE11 enter a table name into the field Database table to edit a table.
Structures and Data Elements are edited by entering their names into the field Data
type.
Note that table types can also be defined in the dictionary. A program variable or
method parameter can be multi-dimensional; you can use a table type to define these
tables.
DDIC Overview
To create a table, enter a name that does not exist yet (and starts with Z ), and click
Create. Add a short text and set the Delivery Class. Navigate to the Field tab and
define the fields of the table: each field has a name and a data type, besides that they
can be marked as key fields.
Most tables will have the MANDT field as the first field, with data type MANDT, making
the table client dependent. That means that each client of the SAP system will access
only those records of the table that belong to it. E.g. programs in client 100 will only
read and write records having 100 as MANDT value. Programs implicitely deal with the
MANDT field. That means that in most cases the developer does not have to deal with
the MANDT field, not even in DB statements like SELECT or UPDATE.
Currency and quantity fields always need a reference field, this can be set on the
Currency/quantity fields tab.
Click the Technical Settings button to maintain mandatory technical properties of the
table.
Where-Used-List
Example:
Click the where-used-list to see where this table is referred. Mark only those object
types that you are interested in:
When you get the result list, you can navigate to the listed objects by double click.
Program Elements
Data Declarations
Besides simple variables, in ABAP its possible to use structures and internal tables as
variables. Structures simply have multiple fields. Tables are called internal tables as
they are available only internally for the running program, just like any other variable.
Tables have a structure and can store multiple lines.
There are no pre-defined arrays in ABAP, in most cases internal tables are used
instead! Although an OO implementation of such data types (array, stack, tree, etc.) is
possible.
DATA:
* simple variable referring to the data element S_CONN_ID:
lv_connid TYPE s_conn_id,
* simple variable that has the same type as the field CARRID of
* the DB table SPFLI
lv_carrid TYPE spfli-carrid,
* structure referring to DB table SPFLI:
ls_flight TYPE spfli,
* internal table referring to DB table SPFLI:
lt_flights TYPE STANDARD TABLE OF spfli,
* internal table defined by a table type defined in the dictionary:
lt_flights_2 TYPE spfli_tab.
Simple variable
Value of lv_connid:
106
Declare it using:
A data element: s_conn_id
A reference to a structure/table field: spfli-connid
Structure
Declare it using:
A table name: spfli
A structure name:
Internal table
Declare it using:
A table type (no table!) defined in the DDIC
A structure/table and TYPE TABLE OF construct, see examples above.
Most common ABAP statements
IF
IF sy-subrc = 0.
lv_carrid = ls_spfli-carrid.
ELSEIF sy-subrc = 1.
CLEAR lv_carrid.
ELSE.
RETURN.
ENDIF.
DO
IF lv_counter = 10.
EXIT.
ENDIF.
ENDDO.
WHILE
Messages
ABAP programs can directly access the database tables. The syntax is ABAP-specific
and independent from the physical database management system (Oracle, DB2, etc.).
Read DB table SPFLI, filter by CARRID, and put the records into the internal table
LT_SPFLI:
If the field list does not fully match the target structure, use the addition INTO
CORRESPONDING FIELDS OF
SELECT carrid connid fltime
FROM spfli
INNER JOIN scarr
ON scarr~carrid = spfli~carrid
INTO CORRESPONDING FIELDS OF TABLE lt_spfli
WHERE carrid = p_carrid
ORDER BY connid.
Modify DB table SPFLI, overwriting the record having the same keys as LS_SPFLI with
the values contained in LS_SPFLI:
CLEAR lt_spfli.
Read a single record of the internal table LT_SPFLI by row number and store it in the
structure LS_SPFLI:
READ TABLE lt_spfli INDEX 2 INTO ls_spfli.
Read the records of the internal table LT_SPFLI one by one and put them into the
structure LS_SPFLI:
LOOP AT lt_spfli INTO ls_spfli.
WRITE: sy-tabix,
ls_spfli-carrid,
/ls_spfli-connid, / means new line
/ls_spfli-fltime.
ENDLOOP.
Note that sy-tabix stores the index (row nubmer) of the current line!
Delete current line within a loop (processing will continue with the next line):
Subroutines
Subroutines in ABAP are called forms. They are only used in the procedural ABAP
programming. In ABAP OO the modularization is accomplished by methods.
Form declaration:
* signature:
FORM read_db_spfli
* parameter table that can be modified, having the sructure SPFLI
TABLES pt_spfli STRUCTURE spfli
* input parameters that can not be modified
USING p_carrid TYPE s_carr_id
p_connid TYPE s_conn_id
* parameter that can be modified
CHANGING p_spfli TYPE spfli.
* coding:
SELECT * FROM spfli
INTO TABLE pt_spfli
WHERE carrid = p_carrid AND
connid = p_connid.
ENDFORM. "read_db_spfli
Calling a form:
PERFORM read_db_spfli
TABLES lt_spfli
USING p_carrid
p_connid
CHANGING ls_spfli.
Function Modules
Function modules allow you to encapsulate and reuse global functions in the SAP
System. They are managed in a central function library.
Function modules are procedures that are defined in special ABAP programs only,
so-called function groups, but can be called from all ABAP programs. Function
groups act as containers for function modules that logically belong together.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Parameters and select-options are variables just like any other variable declared
with DATA. But a so called selection screen will be generated that displays the
corresponding fields, accepting input. Select-options are value ranges (internal
tables) that can be used in the WHERE clauses of SELECT statements ( WHERE
fltime IN so_ftime )
TABLES: spfli.
SELECT-OPTIONS: so_ftime FOR spfli-fltime.
Result:
System Fields
System variables can be accessed during runtime using the sy structure. For a full
list of fields display the structure SYST in SE11.
Usefull Links
Data Dictionary
http://help.sap.com/erp2005_ehp_06/helpdata/en/cf/21ea0b446011d189700000e8322d00/content.ht
m?frameset=/en/cf/21eac5446011d189700000e8322d00/frameset.htm
Flight Model
http://help.sap.com/erp2005_ehp_06/helpdata/en/cf/21f304446011d189700000e8322d00/content.ht
m?frameset=/en/cf/21eac5446011d189700000e8322d00/frameset.htm
Interne Tabelle
http://help.sap.com/saphelp_erp2004/helpdata/de/fc/eb35de358411d1829f0000e829fbfe/frameset.ht
m
Modularisierungstechniken
http://help.sap.com/saphelp_nw2004s/helpdata/de/9f/db970e35c111d1829f0000e829fbfe/content.ht
m
Bildschirme
http://help.sap.com/saphelp_47x200/helpdata/de/d3/2e974d35c511d1829f0000e829fbfe/frameset.ht
m
Funktionsbausteine http://help.sap.com/saphelp_nw70/helpdata/de/9f/db988735c111d1829f0000e82
9fbfe/content.htm