0% found this document useful (0 votes)
307 views

2 - ABAP Program Analysis

Analisis ABAP Program
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
307 views

2 - ABAP Program Analysis

Analisis ABAP Program
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Analyse Problem - SAP Fundamentals

ABAP Program Analysis

Active Global Support


March 2009

2. ABAP Program Analysis

Introduction

Analysing
ABAP Messages

ABAP Program Analysis

Analysing
Authorisation Errors

Screens & Interfaces

Analysing
Database Access

Data Declaration

Analysing
ABAP Program Terminations

Program Modularisation

New ABAP Debugger

SAP 2009 / Page 2

2. ABAP Program Analysis

Contents

Basic ABAP Syntax

Basic Tools for ABAP Program Analysis

Basic Debugging

Objectives
At the end of this unit, you will be able to:

Read and Understand simple programs

Get the missing information

Navigate efficiently in the editor and use standard functionality in your


analysis

Use the ABAP Debugger

SAP 2009 / Page 3

2. ABAP Program Analysis

Basic ABAP Syntax


Tools for Analyzing ABAP Programs
ABAP Debugger

SAP 2009 / Page 4

General ABAP Syntax: Key Words


TABLES
DATA
PARAMETERS

sbc400_carrier .
wa_scarr TYPE scarr .
pa_car TYPE scarr-carrid .

START-OFSTART
OF-SELECTION .
START-OF-SELECTION
SELECT
SELECT SINGLE * FROM scarr
INTO CORRESPONDING FIELDS OF wa_scarr
WHERE carrid = pa_car .
IF sy-subrc = 0 .
IF
MOVE-CORRESPONDING
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier..
MOVE
CALL SCREEN 100 .
MOVE-CORRESPONDING
MOVE-CORRESPONDING sbc400_carrier TO wa_scarr..
MOVE
WRITE :

wa_scarr-carrid ,,
wa_scarr-carrname ,
wa_scarr-currcode .

Chained
statement

ENDIF.
ENDIF
ABAP
key word

Additions (depending on keyword)

Period (ends all


ABAP statements)

SAP 2009 / Page 5

ABAP programs are made up of individual statements.


Each statement ends with a period.
The first word in a statement is called a keyword.
Words must always be separated by at least one space.
Statements can be indented.
Statements can take up more than one line.
You may have multiple statements in a single line.
Consecutive statements with identical initial keywords can be condensed into one
chained statement:
In chained statements, the initial part of the statement containing the keyword must be
followed by a colon.
Individual elements that come after the colon must always be separated by commas.
Blank spaces are allowed before and after all punctuation (colons, commas, periods).
Be aware that the system still considers the individual parts of a chained statement to be
complete statements that are independent of one another.

Comments

START-OF-SELECTION.
* Read data record from database table SCARR

Comment takes up
whole line

SELECT SINGLE * FROM scarr


INTO CORRESPONDING FIELDS OF wa_scarr
WHERE carrid = pa_car.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier.
CALL SCREEN 100. " Process screen 100
MOVE-CORRESPONDING sbc400_carrier TO wa_scarr.
WRITE:

Comment on
rest of line

wa_scarr-carrid,
wa_scarr-carrname,
wa_scarr-currcode.

ENDIF.

SAP 2009 / Page 6

There are two ways to insert comments into a program:


A star (*) in column 1 allows you to designate the whole line as a comment.
Quotation marks (") in the middle of a line designate the remainder of the line as a

comment.

Analyzing the Sample Program Source Code


Definitions:
TABLES
DATA
PARAMETERS

sbc400_carrier.
wa_scarr TYPE scarr.
pa_car TYPE scarr-carrid.

Executable Source Code


START-OF-SELECTION.
SELECT SINGLE * FROM scarr
INTO CORRESPONDING FIELDS OF wa_scarr
WHERE carrid = pa_car.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier.
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier TO wa_scarr.
WRITE:

wa_scarr-carrid,
wa_scarr-carrname,
wa_scarr-currcode.

ENDIF.

SAP 2009 / Page 7

If you need more precise information on parts of the source code, you can analyze it.
The following slides explain the most important statements in the sample program.
The definition of the data objects are being read immediately after the program is
loaded. More precisely this is done when the system triggers an event named
Initialization. You cannot follow the processing of the data declarations in Debugger.
The Executable Source Code is being executed afterwards.

2. ABAP Program Analysis

Basic ABAP Syntax


Tools for Analyzing ABAP Programs
ABAP Debugger

SAP 2009 / Page 8

Basic Techniques for Analysis

Execute transaction or program

check the output

Compare the behavior with a reference system

Ensure reproducibility

On Screens:

Use System Status to find out where you are ...


... and to navigate into the editor

Use F1-help to get information what fields are affected

Use forward navigation to get the definition of an object

Remember:
Different objects may have the same name, e.g. data element and domain

Check relevant DB tables

Use the Data browser (SE16)

SAP 2009 / Page 9

Additional Tools for Analysis

Additional help you can get from:


Editors (SE*) of the ABAP Workbench

Getting static information on

programs, tables, types, and

Their relation: e.g. Where-used-list, Search, Call hierarchy, Versions, Attributes

Debugger

Analyzing program flow step by step

Checking data at runtime

Trace Tools

For analyzing e.g. Program flow, SQL-requests, Authority-checks, ...

SAP 2009 / Page 10

10

F1 Help

Do
ub
lecli

ck

DATA wa_flight_occ TYPE sbc400focc


sbc400focc .

F1
Help
Data element
S_CARR_ID

Technical info
Technical info

SBC400_CARRIER

Field name

CARRID

Data element

S_CARR_ID
S_CARR_ID

Field type
DoFields
ub
lecl i
ck
CARRID S_CARR_ID
CONNID
...

Do
ub

Structure

le
-c
lic

Field Data

Structure type
SBC400FOCC

SAP 2009 / Page 11

You can find more information on elementary ABAP Dictionary types:


For screen fields: Using F1 -> Technical info. or by double-clicking the output field

next to the data element


For local types in programs or data objects: By double-clicking the type

Technical types and technical domains may be directly assigned to data elements. If
you want more information on other data elements found within the same domain, you
can navigate to the domain from the data element by double-clicking and then executing
the function Where-used list.

11

Analyzing Table Contents (SE16)

Using SE16
SAP 2009 / Page 12

12

Data Objects in a Program's Object List and in


the Where-Used List
SAPBC400WBT_GETTING_STARTED
Types
Dictionary structures
SBC400_CARRIER
Fields
PA_CAR
WA_BC400
Change
Events
Display
Screens
Where-used list

TABLES structures
All the data objects
created using DATA

List of all the lines in the ABAP program,


in which the data object occurs

SAP 2009 / Page 13

Elementary data objects appear in the program object list under the Fields node.
From the object list, you can use the right mouse button to navigate to the part of the
source code where the data object is defined.
You can use the Where-used list function to display all lines of source code where the
data object is used.
Structures created using the TABLES statement are a special case. They are stored
under the object type Dictionary structures, for historical reasons.

13

Navigation Features
Help for local
data type declaration

F1

ABAP program

<type>
Types:
TYPES <user_defined_type> TYPE <type>.
Do
u
Help for local
data object declaration

F1
DATA:
<type>.Double-click
DATA <dataobject> TYPE <type>

bl
ec

lic

Navigates to local
data type declaration
or ABAP Dictionary
type declaration

F1
Keyword
documentation
for predefined types

SAP 2009 / Page 14

Generally, data objects are typed using either a complete local program type or a
complete global type. Double-click the name of the type to display its definition. For local
program types this means: Navigate to the line in the source codes where the type has
been defined. For global program types this means: Navigate to the Dictionary and
display the global type.
You can use the complete predefined ABAP types directly, to provide a type for
variables. If you do so, double-clicking on the type after the TYPE statement has no
effect. For more information on pre-defined types, refer to the keyword documentation
on TYPES or DATA.
The following predefined ABAP types are complete:
d
Date: (YYYYMMDD)
t
Time: HHMMSS)
i
Integer
f
Floating Point Number
string character String (string, of variable length)
xstring byte sequence (heXadecimal string, of variable length)
You must define the length for these types.
c
Character
n
Numeric text (Numeric Character)
x
Byte (heXadecimal)
p
Packed number (= Binary Coded Decimals). You must enter the number of
decimal places.
14

Navigation in the Editor: Double-Clicking


Definition of a database table
in the ABAP Dictionary

Definition of a structure
(or of a structured field)

Do
ub
Do
leub
cli
leck
START-OF-SELECTION.
cli
ck
SELECT SINGLE * FROM scarr
scarr
INTO CORRESPONDING FIELDS OF wa_scarr
wa_scarr
WHERE carrid = pa_car.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier.
CALL SCREEN 100
100. Double-click
Definition of a screen
MOVE-CORRESPONDING sbc400_carrier TO(inwa_scarr.
the Screen Painter)

WRITE:

wa_scarr-carrid,
wa_scarr-carrname,
wa_scarr-currcode.

ENDIF.

SAP 2009 / Page 15

You can display detailed information on single objects in the Editor by double-clicking:
Double-clicking the name of a database table displays the database table definition

using the ABAP Dictionary in the object window of the Object Navigator.
Double-clicking a field name displays the part of the program source code where the

data object is defined.


Double-clicking a screen number displays the screen using the Screen Painter in the

object window of the Object Navigator.


If an object specified in the Coding does not exist so far, the system response to

Double-clicking will be a popup asking you weather youd like to create this object.
Use the Back function to get back to the program source code display in the Editor.

15

Keyword Documentation in the Editor

Editor

Help
START-OF-SELECTION.
SELECT SINGLE * FROM scarr
Editor Help
INTO wa_scarr
ABAP Overview
WHERE carrid = pa_car.
WRITE
ABAP Term
IF sy-subrc = 0.
ABAP News
MOVE-CORRESPONDING wa_scarr TO
ABAP Docu and Examples
sbc400_carrier.
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier

WRITE
WRITE:

F1
ENDIF.

TO wa_scarr.
wa_scarr-carrid,
wa_scarr-carrname,
wa_scarr-currcode.

Keyword Documentation

SAP 2009 / Page 16

Even for experienced Supporters it will often be necessary to get documentation about
ABAP statements to understand what is going on.
There are various ways of navigating to keyword documentation for an ABAP
statement:F1 on a keyword displays the documentation for the statement on which the
cursor is positioned.The Information icon displays a dialog box offering you various
views of the keyword documentation.
Apart from a precise description of the keywords the documentation provides a lot of
additional information including various examples.

16

Search for Keywords and Strings

Global search for strings


in ABAP program

SAP 2009 / Page 17

Remember the search function of the Editors (see Exercise 1).


You can use the technical information that you recieve from System Status or from F1
technical info from sceens to search for ABAP field names in the Source Code. You
can also search for keywords or any character string.
The system will display you a list with all the coding lines that match the search criteria.
You can navigate to the lines by double-click.
Note that the result of yur search maybe different, depending on
Wheather you are searching only in the current program (e.g. an include program or

the main program) or in the whole program


Wheather you are searching for a string or a word

By Double Clicking on a field you will navigate to ist definition (this is either in the source
code of the current program or in the ABAP Dictionary.

17

Call Graph

SAP 2009 / Page 18

Via Utilities Call Graph Called by you can display a list containing all the modules
that call a particular module (form or program or screen etc)

18

Version Management

SAP 2009 / Page 19

19

Version Compare

SAP 2009 / Page 20

20

Modifications

Any Change to a Repository Object created by SAP


is considered a Modification.
Any Modification is recorded in a change request.
As of Release 45B the Modification Assistent allows recording of Modifications with
much finer granularity.
Errors that are caused by incorrect Customer Modifications are an issue for Remote
Consulting (XX-RC). SAP Support is not to take responsibility for any required
correction, but SAP Support will help the customer if there is a quick answer / hint for
solving his problem.

SAP 2009 / Page 21

21

Modification Assistent

Modification Overview

SAP 2009 / Page 22

22

2. ABAP Program Analysis

Basic ABAP Syntax


Tools for Analyzing ABAP Programs
ABAP Debugger

SAP 2009 / Page 23

23

Starting a Program in Debugging Mode

STOP

Editor

Navigation area

REPORT sapbc400wbt_getting_started.
Program
TABLES
sbc400_carrier.
DATA
wa_scarr TYPE scarr.
PARAMETERS pa_car TYPE scarr-carrid.
SAPBC400WBT_GETTING START-OF-SELECTION.
2 : Set breakpoint and
start
Execute
Direct processing
SELECT SINGLE
* program
FROM scarr
INTO CORRESPONDING
Debugging
WHERE carrid = pa_car.
Debugging
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc4
1 : Get program name
CALL SCREEN 100.
using context menu
MOVE-CORRESPONDING sbc400_carrier T
SAPBC400WBT_GETTING

WRITE:/

wa_scarr-carrid,
wa_scarr-carrname,

SAP 2009 / Page 24

The ABAP Debugger allows to follow a program step by step.


You can watch the source code that is being executed between two screens. It is also
possible to display the contents of fields and structures and internal tables at runtime.
Usually it is very time consuming to proceed step-by-step, as there maybe thousends of
coding lines before you come to the commands of interest. Breakpoints and watchpoints
allow you to stop at the right line and skip all the lines in between. Details on
breakpoints and watchpoints will be discussed in Chapter 4.
There are several ways to start a program in Debugging mode, without having to change
the program:
Using the context menu for a program name in the program object list, choose Execute

-> Debugging.
Using a breakpoint in the Editor: You can select a statement in the program that the

runtime system in Debugging mode should switch to. To do this, navigate to the line in
the program, select it, and choose the Breakpoint icon (that is, the STOP sign). Then
start the program, either by choosing Execute -> Direct processing or F8.

24

Switch to Debugging Mode at Runtime

System

Help

/h
+ Enter

Utilities

Debugging Screen
Debugging ABAP

1 : By choosing System ->


Utilities from the menu

2 : By entering /h in the
command field

SAP 2009 / Page 25

You can switch to Debugging Mode at runtime:


Choose System -> Utilities -> Debugging Screen to debug the screen.
Choose System -> Utilities -> Debugging ABAP to debug the ABAP code.

You can also switch to Debugging mode by typing /h in the command field in the tool
bar, followed by Enter.

25

Investigating the Behavior of ABAP Programs at


Runtime: Breakpoints in the Debugging Mode
X

SAP

ABAP Debugger

H
chws

Watchpoint
Felder
ZJJ_KURS_000
SingleZJJ_FORMS
step
Quelltext von
Hauptprogramm

Festpunktarithmetik
15 30 5

SELECT SINGLE * FROM scarr


INTO CORRESPONDING FIELDS OF wa_scarr
WHERE carrid = pa_car.
4 IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier.
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier TO wa_scarr.
1 - 4 6
Variante
Variante

SY-SUBRC

SY-TABIX

SY-DBCNT
BIN (1) (000)

ds0025 INS
o

SAP 2009 / Page 26

Starting the program in Debugging mode allows you to execute the program line by line
using the Single Step icon. You can display up to eight variables. To trace the variable
values, enter the field names in the left input field. You can also see this entry by doubleclicking the field name in the code displayed.

26

Tracing Data Flow in the Debugger:


Field View
X

SAP

ABAP Debugger

H
chws

Watchpoint

Felder
Fields
Main program
Source code of

ZJJ_KURS_000
ZJJ_FORMS

Fixed point arithmetic


15 30 5

SELECT SINGLE * FROM scarr


INTO CORRESPONDING FIELDS OF wa_sbc400
WHERE carrid = pa_car.
4 IF sy-subrc = 0.
MOVE-CORRESPONDING wa_sbc400 TO sbc400_carrier.
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier TO wa_sbc400.
1 - 4 6
Variant
Variant

pa_car

LH

SAP 2009 / Page 27

You can trace the field contents of up to eight data objects in debugging mode by
entering the field names on the left side or by creating the entry by double-clicking on a
field name.
You can change field values at runtime by overwriting the current value and pressing the
Change icon.

27

Structures in the Debugger


ABAP Debugger

H
chws

Watchpoint
Fields
Main program
Source code of

ZJJ_KURS_000
ZJJ_FORMS

Fixed point arithmetic


15 30 5

SELECT SINGLE * FROM


scarr field
wa_sbc400
Structured
INTO CORRESPONDING FIELDS OF wa_sbc400
WHERE
= pa_car.
Lengthcarrid
(in bytes)
58
4 IF sy-subrc = 0.
No. Component
name TO Type
Length Contents
MOVE-CORRESPONDING
wa_sbc400
sbc400_carrier.
CALL SCREEN 100.
1 MANDT
100
C TO wa_sbc400.
3
MOVE-CORRESPONDING sbc400_carrier
2 CARRID
AA
C
3
1 - 4 6
Variant
Variant
3 CARRNAME
American
Airlines
C
20
wa_sbc400
4 CURRCODE
USD
C
5
5 MARK
C
1
Double-click
6 UNAME
C
12
7 UTIME
000000
T
6
8 DATE
00000000
D
8

SAP 2009 / Page 28

You can trace the field contents of a structure by entering the name of the structure in the
left column. The field view of the structure is displayed if you double-click on this entry.

28

Breakpoints in the Debugging Mode


X

SAP

ABAP Debugger

H
chws

Watchpoint
Fields
ZJJ_KURS_000

Main program

ZJJ_FORMS
Source codeContinue
of

Fixed point arithmetic


15 30 5

4SELECT SINGLE * FROM scarr


INTO CORRESPONDING FIELDS OF wa_scarr
WHERE carrid = pa_car.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier.
STOP CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier TO wa_scarr.
1 - 46
Variante
Variante

SY-SUBRC

SY-TABIX

SY-DBCNT
BIN (1) (000)

ds0025 INS
o

SAP 2009 / Page 29

You can set a breakpoint by double-clicking in front of a line of source code in the
debugging mode. If you then click on the Continue icon, the program will be executed up
to the point where the next breakpoint is defined (or up to the next screen).
When you have already entered the Debugger you can also create a breakpoint from the
menu by choosing. Breakpoints can be placed at:
ABAP Statement

e.g. if you create a breakpoint on statement select the

program
will stop at any select statement
Function module,

e.g. if you create a breakpoint on function module ABC the


program will stop whenever you enter the specified function
module (that is directly after the call function has been

executed)
Form,

e.g.if you create a breakpoint on a form routine the program

will
stop whenever you enter this form.
System Exception

You can also create a breakpoint before you start debugging. This can be done in the
ABAP Editor.
You can find information on content-related breakpoints in the ABAP Statements and
Data Declarations unit.
29

Navigation Using the Active Call Stack

Double-click this line in


order to navigate to this
function of the call stack .

SAP 2009 / Page 30

The call stack shows the current call hierarchy (which program was called by which
program)
It is always possible to switch to the other levels of the hierarchy. Within this level it is
possible to access all variables and their values but you have to keep in mind that only
the local variables have their current values; global variables might have been changed
in the meantime. The switching itself is triggered by double-clicking on the desired level.
Please always keep in mind ,that you only see the simple call hierarchy. If the program
jumped to another routine and returned you are not able to find a trace in the call stack.
(For this task use ABAP Trace (SE30))
If system debugging mode is off, then you will not see system modules in the stack !
(switch on system debugging: /hs)

30

ABAP Program Analysis:


Summary
Now you are able to:

Read and Understand simple programs

Get the missing information

Navigate efficiently in the editor and use standard functionality


in your analysis

Use the ABAP Debugger

SAP 2009 / Page 31

31

Copyright 2009 SAP AG


All Rights Reserved
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein
may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries,
eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+,
POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex,
MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other
countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos
are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and
services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries.
Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only.
National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only,
without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group
products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed
as constituting an additional warrant.

SAP 2009 / Page 32

32

You might also like