Documente Academic
Documente Profesional
Documente Cultură
Gabor Viragh
1/20/2014
This document is partially based on the development blog ‘How to Develop in ABAP’ by
Thomas Weiss.
Contents
Developing on the server .............................................................................................................................. 2
Navigation in the Application Server ............................................................................................................ 3
A Hello World Program ................................................................................................................................. 4
The Debugger ................................................................................................................................................ 5
The Data Dictionary ...................................................................................................................................... 6
Data Types................................................................................................................................................. 6
Structures and Tables ............................................................................................................................... 7
Program Elements......................................................................................................................................... 8
Data Declarations ...................................................................................................................................... 8
Most common statements........................................................................................................................ 8
IF............................................................................................................................................................ 8
DO ......................................................................................................................................................... 9
WHILE .................................................................................................................................................... 9
Messages............................................................................................................................................... 9
OpenSQL statements ............................................................................................................................ 9
Dealing with internal tables .................................................................................................................... 10
Subroutines ............................................................................................................................................. 11
Function Modules ................................................................................................................................... 12
Parameters and selection screen............................................................................................................ 13
System Fields............................................................................................................................................... 14
Common Transactions ................................................................................................................................ 15
Usefull Links ................................................................................................................................................ 15
Developing on the server
Command field for the 'transaction code'. This is a shortcut to the transaction
(functionality) 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 a their right side provide a ‘search-help’ that display 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).
A Hello World Program
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’.
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.
Data Declarations
Besides simple variables, in ABAP it’s 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.
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
OpenSQL statements
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:
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 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 has 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