Production Quality ABAP Workshop: IBM Global Business Services IBM Global Business Services
Production Quality ABAP Workshop: IBM Global Business Services IBM Global Business Services
Copyright
IBM Corporation 2007
2013
Copyright
IBM Corporation 2007
2013
OVERVIEW
Delivery Class
Data Browser /Table view Maintenance
Technical Settings
Table Maintenance Generator
Data
Dictionary
DELIVERY CLASS
The delivery class controls the transport of table data when installing or upgrading, in a
client copy and when transporting between customer systems.
CLASS A: Application Table (Master and Transaction Data).
Master data is data which is frequently read, but rarely updated. E.g. customer
master, material master.
Transaction data is data which is frequently updated. E.g. sales order, purchase order.
Logically tables of delivery class A are not transported hence no CTS is assigned.
CLASS C: Customizing table.
Customizing data is data which is defined when the system is initialized and then
rarely changed .e.g. company codes, document types.
Logically tables of delivery class C are transported hence CTS is assigned.
DATA CLASS
DATA CLASS: The data class defines the physical area of the database (for ORACLE
the TABLESPACE) in which your table is logically stored. If you choose a data class
correctly, your table will automatically be assigned to the correct area when it is created
on the database.
For custom tables we use the data class USER. The other classes are used by SAP
standard tables.
BUFFERING
Buffering Database Tables:
Buffering a table improves the performance when accessing the data records contained
in the table. The table buffers reside locally on each application server in the system.
10
BUFFERING (Contd.)
You must define whether and how a table is buffered in the technical settings for the table.
There are three possibilities here:
Buffering not permitted: We must not buffer a table if the table data is frequently
modified.
Buffering permitted but not activated:
Buffering activated: Generally custom data are buffered with full buffering or generic
buffering.
11
BUFFERING (Contd.)
The buffering type defines which table records are loaded into the buffer of the application
server when a table record is accessed. There are the following buffering types:
Full buffering: All the records of the table are loaded into the buffer when one record of
the table is accessed.
Generic buffering : When a record of the table is accessed, all the records having this
record in the generic key fields (part of the table key that is left-justified, identified by
specifying a number of key fields) are loaded into the buffer.
Single-record buffering: Only the records of a table that are really accessed are loaded
into the buffer.
12
BUFFERING (Contd.)
Which Tables should be buffered?
Only transparent tables and pooled tables can be buffered. Cluster tables cannot be
buffered.
Character data types must be assigned to all key fields of buffered tables.
13
BUFFERING (Contd.)
14
15
16
17
18
19
20
21
Changes are
recorded by individual
event routines, if
defined, or not at all.
22
Go to transaction se93 to
attach a T code to TMG
23
To create a
parameter T code we
have to choose the
Parameter
transaction
24
25
Database Index
An index helps to speed up selection from the database. An index is a sorted copy of selected
database table fields.
The primary index is always automatically created in an ABAP based SAP system. It consists of the
primary key fields of the database table. This means, for each combination of the index fields exists a
maximum of one record in the table. This kind of index is called a UNIQUE index.
Creating a secondary index
You can use the transaction ABAP Dictionary Change Indexes... Create to create an index. To
make the index unique, select UNIQUE. To specify the fields that will comprise the index, choose
"Choose fields". Then save and activate the index.
Using an index consisting of several fields
Even if an index consists of several fields, you can still use it when only a few of the fields actually
appear in the WHERE clause. The sequence in which the fields are specified in the index is important.
You can only use a field in the index if all of the preceding fields in the index definition are included in
the WHERE condition.
An index can only support search criteria which describe the search value positively, such as EQ or
LIKE. The response time of conditions including NEQ is not improved by an index.
26
You want to select table entries based on fields that are not contained in an index, and the response
times are very slow. The EXPLAIN function in the SQL trace shows which index the system is using. You
can generate a list of the database queries involved in an action by entering Transaction ST05 and
choosing Trace on Execute action Trace off List trace. If you execute the EXPLAIN SQL function
on a EXEC, REEXEC, OPEN, REOPEN or PREPARE statement, the system returns a list containing the
index used in the database query.
The field or fields of the new secondary index are so selective that each index entry corresponds to at
most 5% of the total number of table entries. Otherwise, it is not worth creating the index.
The database table is accessed mainly for reading entries.
Include fields that are often selected and have a high selectivity. In other words, you need to check the
proportion of the table entries that can be selected with this field. The smaller the proportion, the more
selective the field. You should place the most selective fields at the beginning of the index.
27
Note:
Whenever you change table fields that occur in the index, the index itself is also updated.
The amount of data increases.
The optimizer has too many chances to make mistakes by using the 'wrong' index.
If you are using more than one index for a database table, ensure that they do not overlap.
The value NULL is not stored in the index structure of some database systems. The consequence
of this is that the index is not used for that field.
Since indexes are derived entirely from data already in the database, you can delete them
without data being lost.
Note that, in certain circumstances, the database system may have to update the index
corresponding to any data changes, which takes time. Index. Analysis of tables with respect to
index can be done from transaction DB05.
28
Design the selection screen for taking the inputs and do the validations of the entered
inputs. Also do the necessary data filtrations.
Read the data from database table or file in the presentation/application server into
internal tables.
Do the necessary data manipulations, calculations and collate the data into a final
internal table.
29
Events
INITIALIZATION.
30
Value Area
Initial Value
0 to 255
-2.147.483.648 to +2.147.483.647
31
0
IBM Corporation 2013
Value Area
Any alphanumeric characters, however, valid values are only the
digits 0 to 9
The valid length for packed numbers is between 1 and 16 bytes;
two decimal places are packed into one byte, whereby the last
byte only contains one place and the plus/minus sign; after the
decimal separator, up to 14 decimal places are permitted.
Depending on the field length len and the number of decimal
places dec, the following applies for the value area: (-10^(2len
-1) +1) / (10^(+dec)) to (+10^(2len -1) -1) /(10^(+dec)) in steps of
10^(-dec). Values in between this range are rounded off.
Initial Value
"0" for every
position.
string
as for type c
empty string of
length 0
-32.768 to +32.767
32
Value Area
Initial Value
"000000"
hexadecimal 0
xstring
as for type x
empty string of
length 0.
33
Hence in this case we can solve our problem in the following way:
parameters: p_date type sy-datum.
initialization.
p_date = sy-datum + 30.
34
1.Type Declaration.
First Method
types: begin of ty_cepc,
35
Second Method
types: begin of ty_cepc,
end of ty_cepc.
end of ty_cepc.
36
Selection-screen manipulation
37
38
39
1) sign
2) option
3) low
4) high
Sign
40
Meaning
Option
41
Meaning
EQ
Equal to
LT
Less than
GT
Greater than
LE
GE
BT
Between
NE
Not equal to
42
43
If a field has a check table, its contents are automatically offered as possible
values in the input help. The key fields of the check table are displayed.
If you are not satisfied with the described standard display of the data of the check
table, you can attach a search help to the check table. This search help is used for
all the fields that have this table as check table.
Attaching a search help to a check table (or a data element) can result in a high
degree of reusability.
44
START OF SELECTION
This is the event where we retrieve the data from the database table . There are
different ways by which we can fetch the data .
INNER JOIN.
FOR ALL ENTRIES.
In case of inner join it is recommended that we should use not more than 3 tables for
performance issue.
We generally use FOR ALL ENTRIES clause but before that we should ensure that the
table is not initial (empty). Otherwise if the internal table is empty then it will scan all
the data in the dbtable from which we are retrieving the data so performance is again
degraded here.
45
SELECT ENDSELECT
versus
SELECTINTO TABLE
Whenever we select data from database table using select endselect the data selection
flow consists of the following path which is recursive loop:
Presentation server-->application server--->database server.
Hence when we use the select endselect the performance is degraded.
But in the case of select into table the flow is only once (back and forth) so the
performance is better in this case as compared select endselect.
46
Case 1.
Consider a simple example that we have two internal tables say t_makt and t_mara with fields
and data as shown below.
47
48
49
Case 2.
Now in this case instead of combining the two individual internal tables (t_mara and t_makt)
into a final internal table (t_final) we want to add the fields of internal table t_makt into another
already existing table t_mara.
50
Case 2 (Contd.)
In this Case the logic should be as follows:
Declare the internal table t_makt with the fields to be selected from database table
MAKT whereas declare the internal table t_mara with the fields to be selected from
database table MARA plus the fields from t_makt.( the internal table t_mara should
contain the fields of final internal table (t_final) of the previous case).
Initially for t_makt select the data from database table MAKT. For t_mara select the
data from MARA table (the other fields remain blank).
Now populate the blank fields of t_mara by reading from the internal table t_makt.
51
52
wa_mara-maktx = wa_makt-maktx.
ENDLOOP.
* ENDLOOP.
*Note:
*This method(loop under loop) is highly not recommended
Due to performance issues hence we use the method 1 ,described in the next slide.
54
55
Note 1:
In this case instead of modify if we use append then t_mara will look like
below since an append adds a line to the internal table.
56
Note 2:
In the above modify statement if we omit the addition TRANSPORTING
maktx then all the corresponding fields are modified which is not required in
our case since the fields' matnr and mtart remains the same and need not be
modified. Hence only the third field maktx is modified using the addition
TRANSPORTING maktx.
57
Note 3:
In the READ TABLE statement above it's a good practice that we use the
BINARY SEARCH addition for the sake of improving performance but before
this it is mandatory that we SORT (ascending or descending depending on
the requirement) the internal table that we are reading.
In case we are reading an internal table using multiple key fields then the
order in which we must SORT the table should match with the sequence
specified in the READ TABLE statement.
58
In this case before the READ TABLE statement, t_vbpa should be first
sorted by vbeln and then by posnr as shown below.
59
60
61
6) The first field(s) of the DB index should refer to the fields of the FAE driver table in the SQL
WHERE clause.
7) FAE works best when retrieving a small percentage of data from a Database table. When a large
percentage of data is needed, consider getting data out of the DB table without FAE implementation,
and then do additional filtration in your application.
62
MESSAGES
The following are the message available in ABAP .
Message type
Short description
Displaying position
Colors
Success
Green
Information
Abbend
Error
Red
Warning
Yellow
63
MESSAGES (Contd.)
S--- Success --- A success message does not necessarily mean that an action was
successful; It just determines the placement of the message and does not restrict the
user from going on to the next screen.
I ----- Information ---- This message is displayed on the current screen in a dialog box .
The user cannot make any changes to the values in the current screen , After pressing
the Enter key on the dialog box the user will be taken to the next screen (further
processing is allowed) .
A-------- Abend ---- The Abend message is displayed on the current screen in a dialog
box , the user cannot make any changes to the values on the current screen , after
pressing the Enter key on the dialog box the transaction will be terminated .
64
MESSAGES (Contd.)
W------- Warning--- The warning message is displayed at the bottom of the current
screen , the user can make changes to the values of the current screen , but does not
have to make any changes .
E---- Error --- The error message is displayed at the bottom of the screen . The user
must make changes to the values on the current screen. After pressing the Enter key
on the current screen , the user will be taken to the next screen only if the appropriate
correction is made on the current screen .
65
MESSAGES (Contd.)
It is recommended that we should use an ERROR message in SELECTION-SCREEN
(for SELECTION-SCREEN validation) to ensure that we provide valid inputs before
proceeding further.
In START-OF-SELECTION we should use INFORMATION message and not ERROR
message because using the ERROR message will not allow the user to navigate to the
previous screen (selection screen) to make necessary input changes.
After the information message we must also use the 'LEAVE LIST-PROCESSING'
command in order to stop further execution so that before processing further we make
the necessary changes.
66
67
While writing our codes we must use text elements instead of hard coded text.
This becomes mandatory when an entire code is to be translated to some other
language.
For example consider that a code is written in English and now we want to translate it
into Spanish.
We go to GOTO-->TRANSLATION and enter the original language and target
language.
Doing this will translate the code to the target language if the language is available on
the server but the hard coded text will remain as it is.
Hence for the hard coded texts:
First we must create text element (GOTO-->TEXT ELEMENTS or double click on the
hard coded text) and assign the hard coded texts to different text numbers.
After that on the ABAP Text Elements screen GOTO-->TRANSLATION select the
target language after which we get a screen where we can enter the equivalents of the
original texts in the target language so that it is reflected when we open our code in
the target language.
68
69
Debugging :
On entering the debugging mode we see the following screen.
70
DEBUGGING : (CONTD)
F5: Single Step: Executes the report line by line. This is useful if the user wants to see
the program execute one line at a time.
F6: Execute: Processes all of the steps associated with one line of code. For example,
one line of code may be a call to a subroutine. Execute will process that line without
showing all of the activities inside the subroutine
71
DEBUGGING : (CONTD)
72
DEBUGGING : (CONTD)
For e.g. initially the cursor was in line no. 29 and on pressing f6 the cursor moves
directly to line 32 i.e., it executes the entire block of codes inside the subroutine validate
plant at one go.
F7: Return: Returns the user to where the calling program resumes control after a
called routine/function call etc.
F8: Continue: Processes all statements until a breakpoint or the end of the program is
reached. If no breakpoints exist, the system will execute the report in its entirety without
stopping.
73
DEBUGGING : (CONTD)
Importance of WATCHPOINT :
Suppose that while troubleshooting a particular code, instead of analyzing and executing
step by step or manually setting a breakpoint we want the program to stop execution or
a breakpoint to be set when a certain condition is fulfilled for example when a variable
achieves a particular value or loses a particular value.
Eg. In the debugging mode of our code the current value of SY-SUBRC is 0.
Case1: Now we want the program flow to stop when SY-SUBRC changes to any other
value so we set a watch point as follows:
Go to debugging mode---->break/watch points ----> watch points--->create.
After that we get a popup where we can enter the variable name (in this eg. it is SYSUBRC).
74
DEBUGGING : (CONTD)
TO SET WATCHPOINT
75
DEBUGGING : (CONTD)
Case2: If we want we want the program flow to stop when SY-SUBRC changes to a
particular value say 4 then we must click on the No Additional Condition button and enter
the additional condition (SY-SUBRC = 4) on the Free Condition Entry as shown below:
76
DEBUGGING : (CONTD)
77
DEBUGGING : (CONTD)
BREAKPOINT :
It is also possible to set breakpoints at certain ABAP Commands.
For instance we enter an invalid input at any of the selection screen inputs and on doing
so an error message is thrown. Now we wish to go to that part of the code which is
responsible for throwing this message. This can be made possible by using Breakpoints
at ABAP Commands.
78
DEBUGGING : (CONTD)
79
DEBUGGING : (CONTD)
SAVING & LOADING DEBUGGER :
Whenever we keep our code in the debugging mode without using it then after sometime
(timeout) the debugging session expires and consequently all the breakpoints/watch
points that we have saved also expires. Hence in order to avoid this we can save the
debugger before leaving the debugging session.
PATH:
Debugger------->debugger session------->save.
80
DEBUGGING : (CONTD)
81
DEBUGGING:(CONTD)
82
DEBUGGING: (CONTD)
Similarly we can load the debugger session that we have saved when we want.
PATH:
Debugger------->debugger session------->load PATH:
83
DEBUGGING: (CONTD)
84
SYSTEM LANDSCAPE:
Landscape is like a layout of the servers or some may even call it the architecture of the
servers.
A typical system landscape looks like the following:
85
Development
Server
Testing/QA server
Production server
Preproduction
server
86
87
88
PACKAGE
A package is a logical folder kind of thing that contains a group of logically related
development objects.
When entering a configuration/creating a development object, the SAP will prompt the
user for a Change Request.
If the user already has an outstanding Change Request that he/she would like to place
the customizing/development change in, the Own Requests button can be selected.
This will provide the user with a tree structure view of all requests with which that user is
associated. From there, the user may select the appropriate request in which to include
the customizing/development change.
By selecting the Create Request button, a new Change Request will be generated, and
a Task within the new request will be generated.
89
TESTING:
A) Unit testing: ABAP Unit is a test tool integrated in the ABAP runtime environment that you
can use for executing module tests - that is, for checking the functions of code sections in a
program .
Unit testing is done in bit and pieces. Like e.g. in SD standard order cycle; we do have 1Create Order, 2-Delivery, 3-Transfer Order, 4-PGI and 5-Invoice. So we will be testing 1,2,3,4
and 5 separately one by one using test cases and test data. We will not be checking and
testing any integration between order and delivery; delivery and Transfer Order; Transfer
Order and PGI and then invoice.
B) Integration testing : A software system is composed of one or more subsystems, which
are composed of one or more units (which are composed of one or more modules).
Integration is the process of building a software system by combining subsystems into a
working entity. Integration of subsystems should proceed in an orderly sequence. This allows
the operational capabilities of the software to be demonstrated early and thus gives visible
evidence that the project is progressing
Integration testing focuses on testing multiple modules working together. It tests the reliability
and functionality of groups of units (modules) that have been combined together into larger
segments. The most efficient method of integration is to slowly and progressively combine the
separate modules into small segments rather than merging all of the units into one large
component
Integration testing will be cross the modules. MM-SD-FICO for example.
90
TESING :(CONTD)
Objectives:
1>To check that all data exchanged across an interface agree with the data structure
specifications
2>To confirm all the control flows
3>To check the data reliability
4>To check all the communication delays
5>To check the Operating system features like memory consumption
91
TESTING: (contd.)
C) SPT (STRESS PERFORMANCE TESTING) : Performance Test and Load / Stress
Test determine the ability of the application to perform while under load. During
Stress/Load testing the tester attempts to stress or load an aspect of the system to the
point of failure - the goal being to determine weak points in the system architecture. The
tester identifies peak load conditions at which the program will fail to handle required
processing loads within required time spans. During Performance testing the tester
designs test case scenarios to determine if the system meets the stated performance
criteria (i.e. A Login request shall be responded to in 1 second or less under a typical
daily load of 1000 requests per minute.). In both cases the tester is trying to determine
the capacity of the system under a known set of conditions. The same set of tools and
testing techniques can be applied for both types of capacity testing - only the goal of the
test changes.
D) Regression testing : Regression testing is referred to a test which verifies that
some new configuration doesn't adversely impact existing functionality. This will be
done on each phase of testing.
92
Testing Strategies :
Unit Testing Plan (UTP) :
In the technical specification we have Unit Testing Plan section which looks like shown
below.
Normal Functionality - test cases that ensure the workflow functions as it should. (e.g.
updates fields correctly, processes all records).
93
Step
Step
Description
1.Test
normal
execution
of the
report
using valid
selection
conditions
Enter valid
selection
conditions
on the
selection
screen and
execute
94
Test
Data
Expected
Result
Actual
Result
Executed
By/Date
Remarks
An ALV
grid report
of
material
master
details
95
Step
Description
Test
Data
Expected
Result
Actual
Result
Executed
By/Date
Remar
ks
Step
Step
Test
Description Data
Expected
Result
Invalid
Plant
at the
selection
screen
input
Enter
invalid
Plant
In selection
condition
and execute
An error
message
"The plant
entered is
invalid" is
thrown
96
Actual
Result
Executed
By/Date
Remarks
97
98
First we check the validations. For this we go to the event at selection-screen and test
the validations of each field individually. We test whether proper error messages are
thrown on entering wrong inputs etc.
After that we check whether the internal tables are populated or not and depending on
that proper message should be thrown. For this we go to the debugging mode and
inspect the internal tables.
99
100
TRANSPORT REQUEST :
Transports of changes by the CTS allow you to develop in one environment, test your
development work in a test environment, and then, if the tests are successful, use it
productively. This makes sure that productive operations are not placed at risk by faulty
settings or program errors.
The CTS records all changes in change requests. The changes in change requests can
be linked together logically, or can be completely independent of each other. Developers
in a team can use a common request. You can create documentation for a change
request, where you can describe your changes in more detail. This makes it easier to
see which data was changed by which user, and to what purpose.
101
102
Transaction Codes
Transaction Code
Transaction Text
SE80
Object Navigator
SE38
ABAP Editor
SE11
SE16
Data Browser
SM30
SE93
SE37
SE10
Transport Organizer
AL11
103
Transaction Text
SE91
Message Maintenance
SM35
SM37
SM12
SE18
SE19
SE24
Class Builder
SHDB
SQ01
104