You are on page 1of 36

IBM Romania

ABAP for Functional Consultants

Logistic area

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 1


IBM Romania

Table of Contents

Overview

ABAP dictionary

ABAP programming language

Debugger

Enhancements

Examples (Q&A)

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 2


IBM Romania

Client Server Architecture

Central Database
(Storage of all data)

Access to Dataase:
(Read / Write data)

Database

Input / Output
of data to users

Processing of data
Application using application logic

Presentation of the
processed data to
Presentation the user

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 3


IBM Romania

ABAP Workbench ABAP Workbench includes tools that


are required for the creation and
editing of repository objects.
ABAP Editor: It is used for editing the
source code. (SE38)
ABAP Dictionary: It is used for
creation of database table definitions,
data types, data elements and so on.
(SE11)
Screen painter: It is used for
configuring screen along with the
functions for user dialogs. (SE51)
Menu painter: It is used for defining
user interfaces like menu bar, standard
toolbar, application tool bar and
function key settings. (SE41)
Function Builder: It is used for
creation and maintenance of function
modules. (SE37)
Class builder: It is used for
maintaining global classes and
interfaces. (SE24)
Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 4
IBM Romania

Searching the Repository


There is a Search tool you can
use to search the repository
information system. This is
used to make random
searches like search for all
programs by a particular
package
To get to the repository
information system, follow the
menu path from SAP access
Menu. Tools->ABAP
Workbench->Overview-
>Information system or use
transaction SE84 or SE80

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 5


IBM Romania

ABAP Workbench

Each of the repository objects can be edited using a respective tool. For our convenience we can access
all these tools in The Object navigator, Transaction SE80.
Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 6
IBM Romania

Table of Contents

Overview

ABAP dictionary

ABAP programming language

Debugger

Enhancements

Examples (Q&A)

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 7


IBM Romania

Structures Name of the


structure

Type to which
Name of the component is
component assigned

You can define a structure using transaction SE11.


Structure variables are defined in the ABAP program with DATA statements
DATA lw_mara_b TYPE mara_b.
LOCAL Structure variables are defined in the ABAP program with DATA statements
DATA: BEGIN OF lw_mara_b,
matnr TYPE matnr,
maktx TYPE maktx,
lvorm TYPE lvorm,
meins TYPE lvorm,
END OF lw_mara_b.

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 8


IBM Romania

Tables

Tables defined using transaction SE11


Tables defined in the application as a part of the corresponding database table that stores the actual
data.
The fields of the table point to the corresponding columns on the database table.
Key fields are to declared at the beginning of the table. This determines the Primary key of the table
Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 9
IBM Romania

Table of Contents

Overview

ABAP dictionary

ABAP programming language

Debugger

Enhancements

Examples (Q&A)

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 10


IBM Romania

Introduction to ABAP Programming Language


***************************************** ABAP does not differentiate between upper
** Program: BOOKINGS and lowercase for keywords.
** Author: Joe Byte, 07-Jul-2007 Comment lines begin with a *
** ***************************************
REPORT zmat_texts. Double quotes indicate the rest of the
* Read material texts from the database statement is comment
SELECT SINGLE * FROM makt SQL consists of a set of ABAP statements
WHERE matnr = '4792' that perform operations on the central
AND spras = sy-langu. "logon language database in the SAP System.

System field Description


(structure SYST)
sy-subrc After every SQL statement contains the value 0 if the operation was successful
sy-tcode Current Transaction Code
sy-datum Current Date of Application Server
sy-uzeit Current Time of Application Server
sy-repid Name of the current program
sy-langu Language Key of Current Text Environment
sy-uname User Name

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 11


IBM Romania

Internal Tables

Internal table is a data object to keep identically structured data records at runtime.
ABAP internal tables are STORED IN MEMORY not on the DATABASE.
Individual records are known as table rows or table entries.
Used in retaining data from database tables or sequential files for future processing.
DATA gt_makt1 TYPE makt OCCURS 10.
DATA gt_makt2 TYPE TABLE OF makt.
DATA gt_mara_b1 TYPE mara_b OCCURS 10.
DATA gt_mara_b2 TYPE TABLE OF mara_b.

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 12


IBM Romania

Internal tables - operations

You can ADD lines to an Internal Table


using the APPEND or INSERT Commands.

You can READ, CHANGE, or DELETE rows


of an Internal Table.
You also serially read an Internal Table
using the LOOP AT ENDLOOP Construct.

LOOP AT <ITAB> INTO <WA>


WHERE <Condition>.
*Process the Data From <WA>
ENDLOOP.

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 13


IBM Romania

Conditional instructions
IF log_exp1. CASE operand.
[statement_block1] [WHEN operand1 [OR operand2 [...]]].
[ELSEIF log_exp2. [statement_block1]]
[statement_block2]] [WHEN OTHERS.
[ELSE. [statement_blockn]]
[statement_blockn]] ENDCASE.
ENDIF.

DATA lv_time TYPE t.

CASE sy-ucomm.
lv_time = sy-uzeit.
WHEN 'BACK'.
LEAVE TO SCREEN 100.
IF lv_time < '120000'.
WHEN 'CANCEL'.
WRITE: / lv_time, 'AM' .
LEAVE SCREEN.
ELSEIF lv_time > '120000' AND
WHEN 'EXIT'.
lv_time < '240000'.
LEAVE PROGRAM.
lv_time = lv_time - 12 * 3600.
WHEN OTHERS.
WRITE: / lv_time, 'PM' .
MESSAGE '...' TYPE 'E'.
ELSE.
ENDCASE.
WRITE / 'High Noon'.
ENDIF.

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 14


IBM Romania

Loops instructions
DO [n TIMES]. WHILE log_exp
[statement_block] [statement_block]
ENDDO. ENDWHILE.
DATA square TYPE i. DATA text TYPE string
VALUE `One Two Three`.
DO 10 TIMES.
square = sy-index ** 2. WHILE sy-subrc = 0.
WRITE: / sy-index, square. REPLACE ` ` IN text WITH `-`.
ENDDO. ENDWHILE.

LOOP AT SCREEN INTO wa.


...
ENDLOOP.
DATA screen_wa TYPE screen.

LOOP AT screen INTO screen_wa.


IF screen_wa-name = 'VAL'.
screen_wa-required = '1'.
screen_wa-intensified = '1'.
MODIFY screen FROM screen_wa.
ENDIF.
ENDLOOP.
Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 15
IBM Romania

SELECT instruction
SELECT result
FROM source
INTO|APPENDING target
[[FOR ALL ENTRIES IN itab] WHERE sql_cond]
[ORDER BY sort_key].
[ENDSELECT].
SELECT s~carrid s~carrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON s~carrid = p~carrid
AND p~cityfrom = p_cityfr.
SELECT carrid connid fldate
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE result_tab
FOR ALL ENTRIES IN entry_tab
WHERE carrid = entry_tab-carrid
AND connid = entry_tab-connid
ORDER BY carrid DESCENDING.

SY-SUBRC Meaning
0 The SELECT statement sets sy-subrc to 0 for every value passed to an ABAP data object.
The SELECT statement also sets sy-subrc to 0 before it exits a SELECT loop with ENDSELECT if at least one row was passed.
4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 16


IBM Romania

Transaction code ABAPDOCU

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 17


IBM Romania

Forms
Forms are used to group a set of instructions in order to execute it multiple times

FORM subr [TABLES table_parameters]


[USING parameters]
[CHANGING parameters].
...
ENDFORM

* form definition
FORM fill_table USING wa TYPE any
CHANGING ptab TYPE INDEX TABLE.
APPEND wa TO ptab.
ENDFORM. "fill_table

* in main program
PERFORM fill_table USING lw_mseg
CHANGING lt_mseg.

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 18


IBM Romania

Function modules
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.
Examples (use transaction code SE37)
MB_READ_T156
/SPE/GET_T156
RV_LIPS_PSTYV_DETERMINE

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 19


IBM Romania

Questions

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 20


IBM Romania

Coffee break

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 21


IBM Romania

Table of Contents

Overview

ABAP dictionary

ABAP programming language

Debugger

Enhancements

Examples (Q&A)

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 22


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 23


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 24


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 25


IBM Romania

ABAP Debugger set breakpoint

A Session breakpoint
Session External is valid as long the
breakpoint breakpoint user stays connected
An External breakpoint
has time validity (even
if the user reconnects)

Breakpoint can be se
dynamically

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 26


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 27


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 28


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 29


IBM Romania

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 30


IBM Romania

ABAP Debugger - run

Function Description

Single step Use this option to execute the program statement by


statement. This allows you to branch to other program units
Execute Use this option to process a program line by line. All of the
statements of the current line are processed in a single
step.
Return The debugger returns to the point at which control is passed
back to the main program. Use this option to return from
other program units.
Continue Use this option to process the program up to the next
breakpoint. If there are no more breakpoints in the program,
the system exists debugging mode and executes the rest of
the program normally.
Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 31
IBM Romania

Table of Contents

Overview

ABAP dictionary

ABAP programming language

Debugger

Enhancements

Examples (Q&A)

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 32


IBM Romania

Enhancements
The R/3 enhancement concept allows you to add your own functionality to SAPs standard business
applications without having to modify the original applications
Advantages
They do not affect standard SAP source code
They do not affect software updates and upgrades

There are multiple types of enhancements, mainly in logistics are used the following:
User exit (transaction SMOD/CMOD) example MBCF0002
Function module attached can be found in the program as CALL CUSTOMER-FUNCTION

Called in
program
SAPMM07M

Classic BAdI (transaction SE18/SE19) example MB_DOCUMENT_UPDATE


New BAdI - Enhancement (transaction SE18/SE19) can affect standard SAP

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 33


IBM Romania

Table of Contents

Overview

ABAP dictionary

ABAP programming language

Debugger

Enhancements

Examples (Q&A)

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 34


IBM Romania

Real examples for debugging


Free choice

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 35


IBM Romania

Thank you !!!

Roland Obcescu | IBM RO GDC | 04.06.2015 Internal use only Page 36

You might also like