Professional Documents
Culture Documents
Version: 3
TABLE OF CONTENTS
1. DOCUMENT REVISION HISTORY..............................................................1
2. INTRODUCTION................................................................................................2
3. GENERAL PROGRAMMING STANDARDS...............................................3
3.1 NAMING CONVENTIONS OF ABAP DEVELOPMENTS....................................3
3.1.1 Internal data declaration:-........................................................................4
3.1.2 Development Classes.................................................................................4
3.1.3 Function Groups........................................................................................5
3.1.4 Functions Modules.....................................................................................5
3.1.5 Functions Modules Tables Declaration.....................................................6
3.1.6 Layout Sets..............................................................................................6
3.1.7 Standard Text.............................................................................................6
3.1.8 Messages....................................................................................................6
3.1.10 Lock Object.............................................................................................7
3.1.11 Transaction Codes..................................................................................7
3.1.12 Using Logical File Names......................................................................7
3.2 PROGRAM ATTRIBUTES..............................................................................11
3.2.1 Title...........................................................................................................11
3.2.2 Type..........................................................................................................11
3.2.3 Status........................................................................................................12
3.2.4 Application...............................................................................................12
3.2.5 Authorization Group................................................................................12
3.2.6 Logical Database.....................................................................................12
3.2.7 From Application.....................................................................................12
3.2.8 Screen.......................................................................................................13
3.2.9 Editor Lock...............................................................................................13
3.2.10 Fixed Point Arithmetic..........................................................................13
3.2.11 Start via Variant....................................................................................13
3.3 UPDATE PROGRAMS, COMMENTS, FORMATTING,......................................13
STRUCTURE........................................................................................................ 13
3.3.1 Update programs.....................................................................................13
3.3.2 Comments.................................................................................................13
3.3.3 Formatting...............................................................................................15
3.3.3.1 Forms..................................................................................................15
3.3.3.2 Text Elements.....................................................................................16
3.3.4 ABAP Coding Structure............................................................................17
3.3.5 Module Program Structure......................................................................18
261454112.doc
Page
Version: 3
04 March 2003
i
DATA TYPES.............................................................................................. 33
DATA FIELDS............................................................................................. 33
ABBREVIATIONS......................................................................................... 34
STANDARD HEADER AND FOOTER.............................................................34
5. ABAP DICTIONARY......................................................................................36
5.1 TABLES..................................................................................................... 36
5.1.1 Transparent Tables...................................................................................36
5.1.2 Views........................................................................................................36
5.1.3 Index.........................................................................................................36
5.2 STRUCTURES............................................................................................. 37
5.3 DATA ELEMENTS....................................................................................... 38
5.4 DOMAINS................................................................................................... 38
5.5 SEARCH HELPS SAP RELEASE 4.X (REPLACES MATCHCODES)................38
5.6 TABLE BUFFERING.................................................................................... 39
5.7 DATA TYPE CONVERSION..........................................................................39
6. ABAP CODING TECHNIQUES....................................................................42
6.1 INTERNAL TABLES................................................................................42
6.1.1 Filling an Internal Table..........................................................................42
6.1.1.1 Select Into...........................................................................................42
6.1.1.2 Append...............................................................................................43
261454112.doc
Page
Version: 3
04 March 2003
ii
6.1.1.3 Insert...................................................................................................44
6.1.2 Retrieving from an Internal Table............................................................44
6.1.2.1 Read Table..........................................................................................44
6.1.2.2 LOOP.................................................................................................44
6.1.2.3 Nested Loops......................................................................................45
6.1.2.4 Events inside the LOOP.....................................................................46
6.1.3 Modifying an Internal Table.....................................................................46
6.1.3.1 Collect................................................................................................46
6.1.3.2 Modify................................................................................................47
6.1.3.3 Delete.................................................................................................47
6.1.4 Sorting Internal Tables.............................................................................48
6.1.5 General Internal Table Techniques..........................................................49
6.1.5.1 DESCRIBE........................................................................................49
6.1.5.2 RANGES............................................................................................49
6.1.5.3 Miscellaneous.....................................................................................50
6.1.6 FIELD GROUPS.....................................................................................51
6.1.7 Generation of Error Log from a Dialog Program...................................51
6.1.8 Display of Traffic Lights..........................................................................52
6.1.9 Generation of Sequence Numbers............................................................53
6.1.10 Use of Packed Numbers........................................................................54
6.1.11 Adding Leading Zeros...........................................................................54
6.1.12 Handling Dates in BDC Session...........................................................55
6.1.13 IF Comparison......................................................................................55
6.2 INTERNAL TABLES - SAP RELEASE 4.X.....................................................55
6.2.1 Memory Allocation for Internal Tables in SAP 4.x.................................56
6.3 CODE TO ADD FUNCTION KEY TO REPORTS...............................................57
6.4 LOGICAL DATABASE.................................................................................. 57
6.4 SUBROUTINES........................................................................................... 59
6.4.1 Forms.......................................................................................................59
6.4.2 Includes....................................................................................................60
6.4.3 Function Modules....................................................................................60
6.4.4 Submit, Call, Leave To.............................................................................61
6.5 SQL.......................................................................................................... 62
6.5.1 ABAP Open SQL......................................................................................62
6.5.1.1 Data Selection from Transparent and Pool Tables..............................63
6.5.1.2 Data Selection from Cluster Tables....................................................63
6.5.1.3 SELECT Aggregates...........................................................................64
6.5.1.4 SELECT with BUFFER support.........................................................65
6.5.1.5 Group Level Data Access..................................................................65
6.5.1.6 Column Update..................................................................................66
6.5.1.7 Filling Internal Tables.........................................................................66
261454112.doc
Page
Version: 3
04 March 2003
iii
6.5.1.8 UP TO nn ROWS...............................................................................67
6.5.1.9 ABAP Open SQL Enhancements SAP Release 4.x.........................67
6.5.1.9.1...........................................................................................Inner Join
67
6.5.1.9.2...................................................................................Left Outer Join
68
6.5.1.10 Catch / Endcatch.............................................................................68
6.5.2 Native SQL...............................................................................................69
6.6 STRING MANIPULATION.............................................................................69
6.6.1 CONCATENATE......................................................................................69
6.6.2 Removing Leading Spaces.......................................................................70
6.6.3 SPLIT.......................................................................................................71
6.6.4 STRLEN....................................................................................................71
6.7 FIELD-SYMBOLS................................................................................... 72
6.8 GENERAL STATEMENTS............................................................................73
6.9 SAP RELEASE 4.0X OBJECT ORIENTED PROGRAMMING...........................74
7. HINTS AND TIPS............................................................................................76
APPENDIX...............................................................................................................I
1/ CONVERSION PROCESS.................................................................................I
1.
1.1
1.2
1.3
2.
3.
4.
2/ EDI MODIFICATIONS...................................................................................IV
3/ CORRECTION AND TRANSPORT SYSTEM (CTS) NAMING
STANDARDS...........................................................................................................V
1. INTRODUCTION............................................................................................... V
2. STANDARD OUTLINE..................................................................................... V
4/ SAP STANDARD CONVERSION PROGRAMS..........................................VI
261454112.doc
Page
Version: 3
04 March 2003
iv
1.
Versio
Requester
n#
1
Vineet Bhatia
29 January
2003
05 February
2
2003
04 March 2003 3
Vineet Bhatia
Vineet Bhatia
Change Description
Initial Version
Change to CTS Naming
Standards Prefix
Addition of Standards for
Report Header and Footer
2. Introduction
This document is a compilation of possible ABAP programming
and efficiency standards and will provide guidance in creating
readable, maintainable code. It is intended for all developers in
the SAP R/3 Implementation Project Diamond at Novartis, USA.
The ABAP language is an event driven, top-down
programming language. The ABAP processor controls the
execution of an event. For example, the event AT SELECTIONSCREEN is executed when the user presses enter on the
selection screen and the event START-OF-SELECTION is
executed when the user executes the program. As the ABAP
language incorporates many event keywords, it is necessary to
implement in-house ABAP coding standards to create consistent
and efficient maintainable code.
As a standard, The Object Browser should be used for all
development in the SAP system.
A Source Code Change Process should be in place and adhered
to prior to making changes to production ABAP programs and
SAP source code.
The reader is also referred to the section dealing with the
Naming standards required by this project when dealing with the
261454112.doc
Page
Version: 3
04 March 2003
1
261454112.doc
Page
Version: 3
04 March 2003
2
3.
3.1
261454112.doc
Page
Version: 3
04 March 2003
3
Z (1) Type
(1)
Underscore
(1)
Brief Desc
(23)
261454112.doc
Page
Version: 3
04 March 2003
4
3.1.2
Development Classes
261454112.doc
Page
Version: 3
04 March 2003
5
Description
Extension of Authorization Fields
Novartis Consumer Health - AM - Assets
Accounting
Novartis Consumer Health - PPC - Production
Planning & Contr
Novartis Consumer Health - DASS
Novartis Consumer Health - RIVA
Novartis Consumer Health - FI - Financial
Accounting
Novartis Consumer Health - Cost Accounting
Novartis Consumer Health - Inventory
Management
Novartis Consumer Health - MM - Materials
Management
Novartis Consumer Health - Workflow
Novartis Consumer Health - Human Resources
Novartis Consumer Health - QSS - Quality
Assurance
Novartis Consumer Health - Basis
Novartis Consumer Health - Temp. Dev.
(Conversion programs)
Novartis Consumer Health - Sales &
Distribution
Novartis Consumer Health - Material Master
Data Management
Novartis Consumer Health - Cross application
261454112.doc
Page
Version: 3
04 March 2003
6
3.1.3
Function Groups
Function groups allow for grouping related function modules and their
components into a common area. Also, common variables may be
shared by all function modules within a function group.
Function groups should adhere to the following naming convention:
Z_CCaxxxxxxxxxxxxxxxxxxxxx
CC Country Code
a - Application ID
x - Open
3.1.4
Functions Modules
The SAP function modules are programs written in ABAP that form
logical units in function groups. They can be shared by multiple ABAP
programs and by other function modules. They are managed centrally
in the function library.
Function modules are grouped together using the function groups.
Function modules may be defined to one and only one function group.
SAP-supplied function groups should never be used to define new
function modules.
Function modules are similar to programs, the primary difference is
they can be called using remote function calls from the operating
system, can be called variably within and across programs, and are not
typically built for reporting using selection criteria.
Function module names can be a maximum of 30 characters. The
following naming convention should be used:
Z_CCa_xxxxxxxxxxxxxxxxxxxxxxxx
CC Country Code
a - Application ID
x - Open (separate words with underscores)
Remarks: All function modules should follow programming standards
outlined in this document. There is no difference between programs
261454112.doc
Page
Version: 3
04 March 2003
7
3.1.6
Layout Sets
SAP script is a tool in R/3 for formatting text documents. The
formatting rules are stored in R/3 objects called a Layout set. Layout
sets can be used to format R/3 standards text or to format the output of
ABAP reports. In particular, SAP script can be used to format R/3
forms (Purchase Order/ GRN / Invoice / etc) when they are displayed
on the screen or printed on a printer.
A maximum of 16 characters can be used to name Layout Sets. The
following naming convention should be used:
ZCCaxxxxxxxxxxxx
CC Country Code
a - Application ID
x - Open (use underscores to separate words and make as meaningful
as possible).
3.1.7
Standard Text
These are standard pieces of text that can be slotted into a layout set
and can contain pieces of standard text that can be called by any layout
set. An example where standard text would be used would be to hold
an address for an invoice approval slip. The address is contained
within the standard text and can be called in the layout set to display
the address when required. If the address changes, only the standard
text needs to be modified for the changes to be effective immediately
where it is called. The menu path for standard text is Tools/Word
Processing/Standard Text or transaction SO10. The transport
procedure is slightly different again in that you have to create a blank
261454112.doc
Page
Version: 3
04 March 2003
8
Messages
The ability to display messages should also follow the principles of
maintainability and be stored as individual messages. Message classes
exist with messages already in them. There are already an extensive
number of messages in each of the classes therefore, more than likely,
you will find the message you require. You can also create a new
message and store it in an appropriate class.
Message Classes:
Message Classes should adhere to the following naming convention:
ZCCaxxxxxxxxxxxxxxxx
CC Country Code
a - Application ID
x - Open
INDIVIDUAL MESSAGES:
Each message is given a sequential number and called by that number
from the program, with the severity of the warning being decided each
time the message is called.
3.1.10Lock Object
When creating a Lock Object, the file name must begin with EZ and
can be a maximum of 16 characters long.
EZCCa_tttttttttttt
CC Country Code
A Application ID
t - primary table name (where multiple Lock Objects are required
for the same primary table, assign a unique digit to the final
position).
261454112.doc
Page
Version: 3
04 March 2003
9
3.1.11
Transaction Codes
Each SAP transaction is identified by a unique transaction code which
is listed in two SAP tables. Table TSTC contains the attributes of the
transaction, while table TSTCT contains the short text associated with
the transaction. Transaction codes should adhere to the following
naming convention:
ZCCaxx
CC Country Code
a Application ID
x Open
All reports should be executed from an area menu or from the reporting
tree.
3.1.12
261454112.doc
Page
Version: 3
04 March 2003
10
261454112.doc
Page
Version: 3
04 March 2003
11
261454112.doc
Page
Version: 3
04 March 2003
12
261454112.doc
Page
Version: 3
04 March 2003
13
4. Use the following Func.Module in your program to get the physical file
name.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
*
CLIENT
= SY-MANDT
LOGICAL_FILENAME
= <program_name>_FILE1
*
OPERATING_SYSTEM
= SY-OPSYS
*
PARAMETER_1
=''
*
PARAMETER_2
=''
*
PARAMETER_3
=''
*
USE_PRESENTATION_SERVER = ' '
*
WITH_FILE_EXTENSION = ' '
*
USE_BUFFER
=''
IMPORTING
*
EMERGENCY_FLAG
=
*
FILE_FORMAT
=
FILE_NAME
= loadfile
EXCEPTIONS
FILE_NOT_FOUND
=1
OTHERS
= 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
:
:
:
:
:
START-OF-SELECTION.
open dataset loadfile for output in text mode message ws_message.
3.2
Program Attributes
3.2.1
Title
261454112.doc
Page
Version: 3
04 March 2003
14
Program attributes are set from the Attributes option on the initial
ABAP editor screen. All program attributes for an ABAP are to be set
as follows: Title
The title should be a short concise description. This is the title which
appears in the header section of a report when it is executed.
Example:
Create BDC Session for Transaction MM01 - Create Material
Master
3.2.2
Type
The following types are available:
Executable program for reports/interfaces
Include programs. These are not directly executable and are
included in other executable or non-executable programs.
Module pool processing the flow logic of a dynpro.
Function group.
Subroutine Pools.
Interface pools
Class pools
Blank
3.2.3
Status
SAP standard production program.
Customer production program.
System Program.
Test Program.
261454112.doc
Page
Version: 3
04 March 2003
15
Application
The ABAP Application should be set as mentioned in the functional
specification name.
3.2.5
Authorization Group
Used to restrict access to users without a matching authorization group
in their profile. Checks are performed before report execution, and
before access to utility functions, report attributes, and the ABAP
editor.
3.2.6
Logical Database
Assigns the logical database to be evaluated by the program. The
workbench provides access to all logical database programs delivered
by SAP.
3.2.7
From Application
Used in conjunction with the logical database field. The tables
retrieved to access the particular logical database depend upon this
entry.
3.2.8
Screen
This is for report programs only. If a Screen is not specified the system
will create a selection screen based on the logical database (if
specified), the program parameters and select-options. To use an
existing selection screen, enter the version in this field. Versions are
connected to the programming of logical databases. Use the workbench
to analyze logical database screen versions.
3.2.9
Editor Lock
To be set while a program is being created or modified. It allows only
the user ID to set the flag to modify the program. This is to prevent
alteration of a program while a programmer makes modifications to it.
The Editor Lock should not be flagged on.
261454112.doc
Page
Version: 3
04 March 2003
16
3.2.10
3.2.11
3.3
3.3.1
Update programs
All transaction update programs are to offer the user the option of
running the ABAP either in BDC Session or Call Transaction mode,
unless a specific mode or a combination of them like Call Transaction
for all records and BDC Session for failed records is specified in the
Technical Requirement Specification. Ensure that a duplicate record
existence check must be made in every data upload program
3.3.2
Comments
Internal commenting of an ABAP Program is essential for
program maintenance and must be done for all programs.
Informative comments should precede each part of source code
and supplement what can be read from the code itself. This
ABAP documentation must contain references to the initial
specification and changes made subsequently.
ABAP code is fairly self-documenting. However, it is prudent
to provide future programmers with documentation of
purpose, changes, enhancements, additions, and deletions.
Explain the purpose, design, structure and any testing hints at
the top of the program. Include any key decisions and
assumptions made. Maintain a chronological history of
modification notes; with the latest change being the last entry
in the modification log. The documentation block should be
placed at the top of the main program. An overall description
261454112.doc
Page
Version: 3
04 March 2003
17
Zxxxxxxx
* Created by:
________
* Created on:
mm/dd/yyyy.
Version:
n.n
*--------------------------------------------------------------* Modification Log:
* Date
Author
Correction
Description
*29/05/01
Shivapriya
DEV190001
Added
*---------------------------------------------------------------
DevK9000045
DevK9000045
DevK9000045
Or
Begin of DevK9000045
261454112.doc
Page
Version: 3
04 March 2003
18
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
End of DevK9000045
ABAP code should be written modular rather than in line
paragraph or form style.
Complex and large coding structures should be commented
by using a blocked off comment section preceding the
structure.
Example:
******************************************
* This function module formats and posts
* transaction MB01 - Post Goods Receipt
* via CALL transaction
******************************************
CALL FUNCTION POST_GOODS_RECEIPT
EXPORTING
TCODE = W_TCODE
IMPORTING
DYNPROTAB = I_BDC.
3.3.3
Formatting
3.3.3.1
Forms
A large and complex string of coding statements should be broken up
and placed in FORMs to provide easy readability and maintainability.
FORMs are subroutines, which allow a programmer to define a
process once in a program and call that routine from different places
within the program. If a block of code is executed more than once, it
should be placed in a subroutine. This makes the code more
readable, requires less indentation, and is easier to debug since the
debugger can jump through an entire subroutine via a PF key.
261454112.doc
Page
Version: 3
04 March 2003
19
FORM names should begin with F_. This will display all the
program objects together when using Workbench. The rest of the
FORM name should describe what the FORM is doing.
Use the SAP default FORM comment box. To use this feature, code
the PERFORM statement and then double click on the new form
name. The FORM and ENDFORM statements and a default
comment box will be generated at the end of the ABAP. If any
parameters are passed in the PERFORM, comment lines allowing
individual description of these parameters will be generated as well.
With 3.0, the format parameters must be typed using TYPE or LIKE
keywords. This is a new performance feature in 3.0 and also allows
correcting typing errors before runtime.
Pass input parameters as using parameters and output parameters as
CHANGING parameters. The formal parameter does not occupy a
memory of its own. If in doubt, pass the parameters by value.
To avoid shadowing problems, always name your formal parameters
different than the actual parameters.
If Subroutines defined by FORM use/require global variables then
define local fields for use locally within a subroutine and not use
global fields
Example:
*----------------------------------------*
* FORM F_xxxxxxxxxxxxxx
*-----------------------------------------*
* Insert a descriptive text here
261454112.doc
Page
Version: 3
04 March 2003
20
*----------------------------------------*
FORM F_xxxxxxxxxxxxxx
Includes should be used to break down large programs into sections
that can be maintained more easily and to create program sections
that can be shared by several programs. INCLUDE statements
should be commented individually by using the comment indication
*. Code contained within the INCLUDE statement should adhere
to programming standards and naming conventions.
Example:
* Insert a descriptive text to describe the INCLUDE
* INCLUDE xxxxxxxx.
For overall legibility, an ABAP Program should be neatly indented.
The PRETTY PRINTER command (PP typed in the command line)
can be used to indent each nested command structure by 2 positions
with the settings indent and convert to Uppercase.
Statements with multiple objects should be indented and aligned for
clarity.
3.3.3.2
Text Elements
Each ABAP program should have associated text elements and
constants from the source code placed within the Text Elements
section of the ABAP Editor:
261454112.doc
Page
Version: 3
04 March 2003
21
one text for one report header line. All Text Symbols used for
messages should have numbers M01, M02, M03etc.
Example:
WRITE: / TEXT-001.
The advantage of this method is ease of maintainability if
TEXT-001 is coded several times in the program and needs to
be changed.
Formatting Commands
Example:
Correct
WRITE: / 01
xxxxxxx1,
10 xxxxxxx2,
15 xxxxxxx3.
Incorrect
WRITE: / 01
xxxxxxx1, 10 xxxxxxx2, 15
xxxxxxx3.
Use one line per object when defining multiple objects of the
same entity. Describe those objects on that same line.
Example:
Correct
TABLES: T1, description
T2, description
T3. description
Incorrect
TABLES: T1, T2, T3.
Each ABAP command consists of a sentence ending with a
period. SAP allows multiple commands to be on one line;
however, as a standard start each new command on a new
line. This will allow for easier deleting, commenting, and
debugging.
Example:
Correct
261454112.doc
Page
Version: 3
04 March 2003
22
IF W_X = 3
AND W_Y = 2
AND W_Z = 1.
PERFORM.
ENDIF.
Incorrect
IF W_X = 3 AND W_Y =2 AND W_Z = 1
PERFORM.
ENDIF.
3.3.4
261454112.doc
Page
Version: 3
04 March 2003
23
FIELD-GROUPS
FIELDS
FIELD-SYMBOLS
* Event elements
INITIALIZATION
AT SELECTION-SCREEN ON PARAMETERS
AT SELECTION-SCREEN ON BLOCK
AT SELECTION-SCREEN
START-OF-SELECTION
GET
END-OF-SELECTION
TOP-OF-PAGE
END-OF-PAGE
Control elements
TOP-OF-PAGE DURING LINE-SELECTION
AT LINE-SELECTION
AT PFnn
AT USER-COMMAND
Subroutines
FORM / ENDFORM
3.3.5
3.3.5.1
261454112.doc
Page
Version: 3
04 March 2003
24
261454112.doc
Page
Version: 3
04 March 2003
25
Version: 3
04 March 2003
26
the field to the new transaction. Back will return to the original
transaction with all fields populated as they were before leaving
it.
Variants
All screens containing lists should be capable of saving display
variants that may be retrieved by the user in the normal way and
be capable of allowing the user to define a default variant.
All report selection must be capable of creating and retrieving
report selection variants.
Layout
Transactions that will be used extensively must be quick and
easy to use with a minimum of screen changes, button clicks or
keystrokes. Screens should be laid out to present a clear,
uncluttered view with data presented in logical groups within
separate frames.
3.3.5.2.1
Menu Standards
A menu must be defined for each screen that follows the standard
SAP style of menus including all of the appropriate menu
elements.
<object>
Edit
Environment
<object
>
Other
Select
<object all
>
Create Desele
ct all
Got
o
See
belo
w
-----------
Change Select
block
Display Choos
e
Bac
k
View
Extr Environm
as
ent
See See below See
belo
belo
w
w
261454112.doc
Page
System Help
Settin
gs
See
below
Utiliti
es
See
below
Create
session
s
End
session
Appli
cation
Help
SAP
Librar
y
User
Gloss
profile ary
Service ------s
------Version: 3
04 March 2003
27
Copy
Utilitie Relea
s
se
notes
List
------------Workfl SAP
ow
Net
Links
------------Private Feedb
notes
ack
Own
------spool
------request s
Own
Settin
jobs
gs
Short
messag
e
Status
Log off
--------------
--------- Cut
-----Save
Copy
Paste
--------- ------------------Delete
Exit
Insert
line
Delete
line
Sort...
-------------Cancel
261454112.doc
Page
Version: 3
04 March 2003
28
3.3.5.3
261454112.doc
Page
Version: 3
04 March 2003
29
Locking Stages
261454112.doc
Page
Version: 3
04 March 2003
30
Numbering /
Key
External
Internal
External /
Internal
External /
Internal
Process
Create
Create
Change / Delete
Start of Unit
End of Unit
Start of Unit
After record is
selected and delete
button is pressed
261454112.doc
Page
Version: 3
04 March 2003
31
3.3.5.4
COMMIT WORK
3.3.5.5
GUI Status
For each GUI, use SAP defaults proposed by Menu Painter
within Workbench for Menu.
Create a title bar for each screen within a transaction that
identifies what function and area the screen is to be used for.
The standard set of PF Keys should use the SAP defaults
proposed by Menu Painter from Workbench.
261454112.doc
Page
Version: 3
04 March 2003
32
3.3.5.6
Function Code
Function Type
ADD
ADD
CHANGE
CHNG
DELETE
DELT
DISPLAY
DISP
SAVE
SAVE
BACK
BACK
CANCEL
CANC
EXIT
EXIT
CHOOSE
CHSE
FIRST PAGE
P--
PREVIOUS
PAGE
P-
NEXT PAGE
P+
LAST PAGE
P++
PRNT
261454112.doc
Page
Version: 3
04 March 2003
33
Back
Exit
Cancel
Effect
Exits object
component
Exits
task Exits
(application)
processin
g
Jump
target
Returns
previous level
Yes
Save
option(dia
logue
window)
Yes
No
Checks
Yes
Yes
No
Sequence
of
save/chec
k
Example
title of
dialogue
window
Back
Diagnosis
text in
dialogue
window
No diagnosis text
No diagnosis text
Unsaved
data will
be lost
(e.g.)
Example
text in
dialogue
window
Do you want to
post
the
held
document?
Or
Do you want to
post
the
held
document 4712?
Do you want to
post
the
held
document?
Or
Do you want to
post
the
held
document 4712?
Unsaved
data will
be lost.
261454112.doc
Page
--- blank
line --Do you
want to
cancel
the
editing?
Version: 3
04 March 2003
34
Back
Exit
Cancel
(1st line
is
diagnosis
text)
Yes, No
Function
module
popup_to_confirm
_step
popup_to_confirm
_step
popup_to
_confirm
_loss_of
_ data
Action
menu
Goto
<object>
Edit
F-key
F3 (V3)
F15 (V15)
F12
(V12)
261454112.doc
Page
Version: 3
04 March 2003
35
3.3.5.7
Messages
Messages can be used to communicate with users. They are
mostly used for error handling during processing of other user
dialogs
You send messages using the ABAP statement MESSAGE. The
statement specifies the message class, number, and type of the
message. All Message statements supplemented in code with
comment that describes the text of the message.
The message class and number are used to identify the message
in table T100. The message type is one of A, E, I, S, W, or X, .
Message processing depends on the message type specified in
the MESSAGE statement, and the program context in which the
statement occurs.
Message Types
A
Termination
Error
Information
Status
Warning
Exit
261454112.doc
Page
Version: 3
04 March 2003
36
DELETE
Title Delete Processing
Message text - Do you want to delete the records?
TABLE LOCK
Transaction aborted. Unable to Lock the Database Tables (used
for Abort message)
Object required is locked by another user
(used
for Error message)
DATABASE UPDATION
& Record(s) successfully &
(Eg. 1 Record successfully
created)
& Record(s) successfully created
& Record(s) successfully updated
& Record(s) successfully deleted
& Record has already been deleted
& Record(s) not deleted (Eg. Reason code is used in other
tables. Record(s) not deleted)
No changes made
261454112.doc
Page
Version: 3
04 March 2003
37
DATABASE SELECTION
No record(s) found matching the selection criteria
TABLE CONTROL LINE SELECTION
Position the cursor on a valid entry
Select a record from the list
Select a & record from the list & (Eg. Select a Journey record
from the list to allocate)
Multiple selections not allowed
MANDATORY FIELDS
SAP message should come if a field is defined Mandatory (Eg.
Make an entry in all required fields)
Program specific
Please enter & (eg. Please enter Service Group)
Validation Checks
SAP message should come wherever foreign key is defined
through check table.
Program specific
If SAP foreign key is disabled/does not exist then handle
programmatically
eg. Reason code does not exist
Reason Code does not exist for Reason code type
Program Checks
& exists for the & & & (eg. Service Group exists for the Plant,
Reason Code exists for the Reason code type)
Start time is later than end time
From date is later than to date
From date is in past
261454112.doc
Page
Version: 3
04 March 2003
38
3.3.5.8
3.3.5.9
261454112.doc
Page
Version: 3
04 March 2003
39
3.4
ALV Reports
Caution : ALV reports can not be run in background.
In ALV reports use GUI TITLE for setting the title of the
report and GUI STATUS for the menu bar.
Always use data elements for ALV Column headings and
Selection Screen block heading to avoid hard coding.
For ALV Reports, always follow the following instruction for
field catalog:
Y indicates presence of text in respective field label
261454112.doc
Page
Version: 3
04 March 2003
40
Output in
Medium
ALV Report Print
Short text text of
Long text
for field
Preview
of Data Data
of Data
Headin catalog field of ALV
Element Element Element g
colddictxt report
Y
Long Text Long Text
As set (L, M,
Y
Y
Y
S)
Short
Set R Y
Y
Y
Y
Heading
Heading
As set (L, M,
Y
Y
S)
Medium
Always use dictionary structure(s) as per output requirement
of ALV report. This will provide a clean code. Structure
description should say to be used only for the specified
program.
Only a maximum of 9 columns can be sorted in an ALV
Report.
Column heading of ALV report comes from the field label of
data element. The following are four types of field labels
associated with a data element
Short, Medium, Long and Heading
The following rules apply for determining which text will be
selected as field label.
If Heading exists then default column heading will be
Heading text of the field label.
If Heading doesnt exist then default column heading will be
Short text of the field label .
261454112.doc
Page
Version: 3
04 March 2003
41
Core Modifications
Prior to making SAP source code modifications, a Source Code
Change Process must be in place and requirements should be
approved. As a standard, only SAP authorized repairs should be
allowed to the SAP code.
When making modifications to SAP core programs, it is very
important to document the changes made within the program.
Within the comments section at the beginning of the program,
include the following as part of a modification log:
Repair number of the modification (system assigned)
Name/initials of person making the modification
Date
Description of the modification
Example:
*************************************************
***
Program xxxxxxxx
*Description:
*--------------------------------------------------*
*Repair No.
Date
Author Description
*
../../..
*************************************************
**
Within the body of the program, comment every addition of
code or change in code. Include in the comments the repair
261454112.doc
Page
Version: 3
04 March 2003
42
ENDIF.
End of DEVK900088
3.6
261454112.doc
Page
Version: 3
04 March 2003
43
3.7
Smart Forms
The SAP Smart Forms is used for creating and maintaining forms
for mass printing. They replace the SAP script forms, however
SAP script forms will also be supported by SAP in future. SAP
Smart Forms allow you to execute simple modifications to the
form and in the form logic by using simple graphical tools. The
following points should be considered when creating or
maintaining Smart Forms :
A backup of the layout prepared through Smart Form should
be kept in the system with the name y<formname>_bk<nn>
(nn being the sequence no. of the backup). This is important
as version management is not supported for these forms.
The currency field to be printed using Smart Forms should be
defined as a field of the same type in the global definitions.
No hard coding should be done in include text and address
window in Smart Forms.
261454112.doc
Page
Version: 3
04 March 2003
44
4.
4.1
Data Types
All data types used by a program should be first defined to the
ABAP Dictionary as a TYPE-GROUP. One or more TYPEGROUPS can be used by the TYPE-POOLS statement.
With release 3.0 there is a clear distinction between the data type
and the data object:
Data types are declared using the keyword TYPE. Data types
are pure type descriptions. They do not require any storage
space. A data type characterizes the technical properties of all
data objects, which have this type.
Data objects are concrete instances of data types. Each data
object has a particular type and requires all appropriate
storage space. User defined data types can be created using
TYPES statement. They can be either elementary or
structured.
User defined data types allow you to create all application
specific type universally. This structure can be defined
centrally and thus made known to the ABAP programming
environment.
4.2
Data Fields
SAP R/3 Requirements:
261454112.doc
Page
Version: 3
04 March 2003
45
Standards:
All variables should be defined using the type declared in the
TYPE pool.
When custom variables have a corresponding SAP variable, use
the name that reflects that particular SAP data element or field
name. Do not use variable names containing -. as they can be
confused with table fields. Underscores should be used to
separate words contained in variable/constant names. In addition,
make the names descriptive.
For program readability and maintainability, remove defined
fields, which are never referenced, and code, which can never be
logically executed. Whenever possible, the LIKE parameter
should be used to define work fields.
Position Description Values
1-2
Variable
C_
Description
P_
S_
RB_
CB_
PB_
V_
T_
L_
X_
WA_
E_
CL_
CO_
261454112.doc
Page
Meaning
For Constants
For Parameters
For Select-Options
For Radio buttons
For Checkbox
For pushbuttons
For Global Variables
For Internal Tables
For Local Variable
For Types/ Structures
For Work Areas for
Internal Tables (Also for
Layouts in ALV)
For Events
For Classes
For Container
Version: 3
04 March 2003
46
GR_
CI_
R_
Fld_
Cnt_
Flg
3+
4.3
Freely
Definable
For Grid
For Class Instance
For Range
For Field
For Counters
For Flags
use abbreviations for
clear and
concise names.
Abbreviations
When defining Data Fields, use clear and understandable names.
In cases where abbreviations are used, utilize an agreed upon set
of standard abbreviations. It is important that abbreviations are
used consistently in all names.
To determine an abbreviation for words not listed below, strip
out all vowels and insignificant characters. Names, which begin
with a vowel, retain the vowel in the abbreviation. Add vowels
back in when abbreviations for two different names are alike.
Abbreviations will be based on English names.
Name
Customer
Cost
Name
Vendor
Last
First
Middle
Employee
Identification
Quantity
Counter
4.4
Abbreviation
Cus
Cst
Nm
Vnd
Lst
Frst
mdl
Emp
Id
Qty
Cnt
261454112.doc
Page
Version: 3
04 March 2003
47
pic00235.pcx
261454112.doc
Page
Version: 3
04 March 2003
48
5.
ABAP DICTIONARY
When creating a custom table, carefully plan its design and
structure. Define the table fields appropriately. Always place the
key fields starting with MANDT (client) field at the front of the
record layout. Use the SAP database administrator to help design
the table and its attributes, index, and buffer settings.
5.1
Tables
When defining custom tables always place the key fields at the
front of the record structure.
5.1.1
Transparent Tables
When creating custom tables, Transparent Tables should be used
in most cases. A Transparent table is a table with system
structure, which gives an identical structure inside SAP as
outside. Therefore the table can be accessed by both internal and
external applications. All updates to SAP Tables should be
performed within SAP.
5.1.2
Views
For reporting purposes, use VIEW tables to effectively join
related tables that are taking large amounts of time for data
retrieval. A database View is not physically stored, but it is a
table derived from multiple tables. Database Views allow fields
from several tables to be accessed in one view. Generally,
accessing a database view is faster then selecting tables
individually.
With Release 4.X views can be buffered in the same manner as
tables.
5.1.3
Index
The purpose of an Index is to quicken the scanning process when
searching for specific records in a table. An Index is a copy of a
table reduced to particular sorted fields to enable faster access to
needed data.
261454112.doc
Page
Version: 3
04 March 2003
49
261454112.doc
Page
Version: 3
04 March 2003
50
Structures
Identify the fields that are used in constructing a screen in
Dialog program
Create Structures in the Data Dictionary.
Add the fields that are required in the structure. You can copy
the fields contained in a dictionary structures, table or views
with Edit / Include / Insert / Copy components
261454112.doc
Page
Version: 3
04 March 2003
51
Data Elements
A data element defines the description for the field. The
semantic information (description and field labels) is assigned to
the data element along with any on-line documentation. If
possible, use the standard SAP Data Elements such as BUKRS,
BELNR etc.
The data element is the functional name associated with a
domain; e.g., one of the data elements associated with domain
CHAR30 may be ADDRESS. Whenever ADDRESS is entered
as a data element, the characteristics of the domain CHAR30
appear.
5.4
Domains
A domain describes the physical format of the data such as the
type and length of the data. Fields referring to a domain (via the
data elements assigned to them) assumed the data format defined
by the domain.
5.5
261454112.doc
Page
Version: 3
04 March 2003
52
Table Buffering
Database tables can be stored locally on each application server.
Performance time may be improved because reading from the
buffer avoids directly accessing the database. Within SAP, only
POOLED and TRANSPARENT tables allow buffering. The
decision to buffer a table should be made by the SAP Database
Administrator.
Considerations:
Only buffer a table that has read-only accesses made against
it and is referenced frequently.
Only buffer those tables that contain the business and other
transaction processing rules, that are setup during the
implementation of the SAP R/3 system and are changed very
infrequently.
Tables that contain master and transaction data should not be
buffered.
Only buffer tables that are modifiable, if write access occurs
infrequently. Changes to buffered tables get automatically
logged in the database and are transferred to the application
servers at regular intervals. If buffered tables are modified
frequently, the additional processing needed may cancel any
performance gains attained by buffering.
261454112.doc
Page
Version: 3
04 March 2003
53
C(n)
Character strings
CLNT
C(3)
Client
CUKY
C(5)
CURR n, P((n+2)/2)
m, s
DECIMAL m
DEC n,
m, s
P((n+2)/2)
DECIMAL m
DATS
D(8)
FLTP
F(8)
INT1
1-byte integer
INT2
2-byte integer
INT4
4-byte integer
LANG
C(2)
Language key
LRAW
X(n)
LCHR
C(n)
261454112.doc
Page
Version: 3
04 March 2003
54
Description
QUAN n, P((n+2)/2)
m, s
DECIMAL m
RAW n
X(n)
TIMS
T(6)
UNIT
C(n)
VARC n
C(n)
n: no. of
places
m: number of
decimal places.
s: sign flag
Considerations:
When non-standard conversions are needed to display
differently than SAPs internal format or vice-versa, create a
Conversion Exit for the Domain. This should be done by
creating two function modules in the same function group.
one module to convert from display format to internal
format.
the other to convert from internal format to the external
format.
Data types of P and I are treated the same on all SAP
supported platforms.
Note that floating points have an accuracy up to 15 decimal
places on all platforms, and that the rounding behavior may
261454112.doc
Page
Version: 3
04 March 2003
55
TYPE P
DECIMALS 2
VALUE
261454112.doc
Page
Version: 3
04 March 2003
56
6.
6.1
INTERNAL TABLES
An Internal Table is a group of records created at runtime.
It is recommended to define all internal tables using user-defined
data types and without a header line.
Example:
TYPES: Begin of T_definition
Driver like driverduty-driver,
End of T_definition
DATA: I_table TYPE STANDARD table of T_definition.
Considerations:
The initial size addition is similar to the OCCURS parameter
in version 3.X. When the initial size is not known, it makes
more sense to leave it to SAP to determine by specifying
initial size 0.
6.1.1
6.1.1.1
Select Into
When an Internal Table needs to be created directly from one
database table, use the SELECT INTO to fill the Internal Table.
The contents of I_T001 will be replaced by the selected data so a
REFRESH is not needed.
Example:
SELECT * FROM T001 INTO TABLE I_T001.
261454112.doc
Page
Version: 3
04 March 2003
57
Append
Append adds a new entry to an Internal Table. The system does
not check if a record with the same key exists.
Considerations:
As APPEND adds new entries to an Internal Table, duplicate
entries may occur. If the internal table already contains the
number of entries allocated by the system (Initial size 0
addition), the additional entries are rolled to the paging area,
resulting in longer runtimes.
When using Internal Tables with a header line, avoid
unnecessary assignments to the header line. Use statements,
which have an explicit work area.
Example:
More Efficient
APPEND W_TAB TO I_TAB.
Less Efficient
I_TAB = W_TAB.
APPEND I_TAB
261454112.doc
Page
Version: 3
04 March 2003
58
Insert
Use INSERT to add single rows or blocks of rows to an Internal
Table as a specific position.
Example:
INSERT I_TAB INDEX 6.
Considerations:
When a block of lines is to be inserted at a specific position,
use the LINES OF parameter of the INSERT statement.
INSERTing a block of lines is faster than INSERTing one row
at a time during a LOOP. This example will insert rows 3
through 7 from I_TAB1 into I_TAB2 as rows 4, 5, 6, and line
4 from I_TAB2 will become line 7 after the INSERT.
Example:
INSERT LINES OF I_TAB1 FROM 3 TO 5 INTO
I_TAB2 INDEX 4.
261454112.doc
Page
Version: 3
04 March 2003
59
6.1.2
6.1.2.1
Read Table
READ TABLE is used to read a single row from an Internal
Table.
READ TABLE I_TAB is used to read a Internal Table using the
Internal Tables header line as the output area.
READ TABLE I_TAB INTO WA is used to read an Internal
Table and use the work area as the output area.
Considerations:
6.1.2.2
LOOP
LOOP WHERE is faster than LOOP/CHECK because LOOP
WHERE evaluates the specified condition internally.
Example:
More Efficient
*Key access with LOOP WHERE
LOOP AT TAB WHERE K = KVAL.
" ...
ENDLOOP.
Less Efficient
261454112.doc
Page
Version: 3
04 March 2003
60
More Efficient
*Key access with LOOP/CHECK
LOOP AT TAB.
CHECK TAB-K = KVAL.
" ...
ENDLOOP.
Make the comparison operators share a common type; as with
any logical expression, the performance is better if the operands
of a comparison share a common type.
Performance can be further enhanced if the LOOP WHERE is
combined with FROM i1 and/or TO i2.
6.1.2.3
Nested Loops
Performance in reading the internal tables can be enhanced by
using the combination of Read table and Loop statements.
Read table will locate the index of the record and loop
statement can be used with the addition From.
Caution: The nested loop table should be sorted on the basis of
where clause fields. It has to be ensured that sorting a table on a
particular field should not affect the program flow at a
subsequent location in the program flow where a different sort is
expected. Therefore, in such cases the internal table must be
resorted as per fields expected.
Example:
More Efficient
261454112.doc
Page
Version: 3
04 March 2003
61
ENDLOOP.
6.1.2.4
6.1.3
6.1.3.1
Collect
The COLLECT statement scans the Internal Table for an entry
where the default key matches that of the entry in the Work area /
261454112.doc
Page
Version: 3
04 March 2003
62
Version: 3
04 March 2003
63
Modify
Use the MODIFY command to change a line within an Internal
Table
Example:
LOOP AT I_TAB.
MOVE C_INITIALIZE TO I_TAB-INITIALIZE.
MODIFY I_TAB.
ENDLOOP.
6.1.3.3
Delete
Use the DELETE command to delete a row or group of rows
from an Internal Table. When DELETEing a group of rows from
an Internal Table, delete them using a DELETE WHERE clause
instead of a single row at a time during a LOOP, unless other
activity takes place during the LOOP.
Example:
DELETE I_TAB
WHERE WERKS EQ C_0010.
If possible, WHERE should be used together with
FROM...and/or TO ... to enhance performance even more.
Example:
DELETE I_TAB [FROM] [TO] WHERE.
Considerations:
To delete all rows in an Internal Table, use the REFRESH
statement.
When working with Internal Tables, use the FREE command to
release the memory after the Internal Table has served its
purpose and will not be used again.
261454112.doc
Page
Version: 3
04 March 2003
64
261454112.doc
Page
Version: 3
04 March 2003
65
Example:
One-step Approach: READ/INSERT
* I_DEST is filled with 1000 entries
REFRESH I_DEST.
LOOP AT TAB_SRC INTO WA_SRC.
READ TABLE I_DEST WITH KEY K =
TAB_SRC-K BINARY SEARCH.
INSERT WA_SRC INTO I_DEST INDEX SYTABIX.
ENDLOOP.
*Use on small tables (<= 20 rows)
Two-step Approach: APPEND, SORT
* I_DEST is filled with 1000 entries
REFRESH I_DEST.
LOOP AT TAB_SRC INTO WA_SRC.
APPEND WA_SRC TO I_DEST.
ENDLOOP.
SORT TAB_DEST BY K.
*Use on large tables
6.1.5
6.1.5.1
DESCRIBE
DESCRIBE determines the number of entries in an Internal
Table.
Example:
More Efficient
DESCRIBE TABLE I_TAB LINES W_LNE_CNTR
Less Efficient
LOOP AT I_TAB.
W_LNE_CNTR = W_LNE_CNT + 1.
ENDLOOP
6.1.5.2
RANGES
The RANGES statement creates Internal Tables that have the
structure of a SELECT-OPTION table, but the RANGES do not
261454112.doc
Page
Version: 3
04 March 2003
66
261454112.doc
Page
Version: 3
04 March 2003
67
DATA:
END OF I_TAB,.
Considerations when using RANGES:
RANGES are not selection screen fields.
RANGES are not passed to the logical database programs.
RANGES do not support the short form of logical
expressions,
RANGES are to be used in the WHERE clause of OPEN
SQL statements in expressions with the IN parameter.
6.1.5.3
Miscellaneous
More Efficient
APPEND WA_ TO ITAB.
Less Efficient
MOVE WA_ TO ITAB.
APPEND ITAB.
More Efficient
INSERT WA_ INTO ITAB.
Less Efficient
MOVE WA_ TO ITAB.
INSERT ITAB.
261454112.doc
Page
Version: 3
04 March 2003
68
More Efficient
COLLECT WA_ INTO ITAB.
Less Efficient
MOVE WA_ TO ITAB.
COLLECT ITAB.
Use the FREE statement to release the memory allocated to
Internal Tables. The FREE statement should follow the last
statement used to process the data in the table. Use the FREE
statement where you no longer need the internal table in your
program.
As noted above in APPEND, when using Internal Tables with a
header line, avoid unnecessary assignments to the header line.
Use statements that have an explicit work area:
Examples:
When performing control break logic on Internal Tables and
FIELD-GROUPS, make use of the AT NEW, AT END OF,
ON CHANGE OF, and SUM commands. The use of ABAPs
control break commands will provide easier readability and
maintainability versus coding the break logic without the
benefit of the commands. When using the control break logic
statements, one must necessarily use the work area instead of
internal table header.
6.1.6
FIELD GROUPS
SAP R/3 Requirements:
FIELD-GROUPS combines several existing fields together under
one name. Used in conjunction with INSERT, EXTRACT, and
LOOP. Conceptually, it is similar to processing Internal Tables.
Considerations:
FIELD-GROUP are used to build internal tables that have a
common key structure but different arguments. They are
261454112.doc
Page
Version: 3
04 March 2003
69
Example
261454112.doc
Page
Version: 3
04 March 2003
70
Sample Code
set pf-status '24BM_ERR'.
leave to list-processing.
write text-004.
loop at i_return where type = 'E'.
* Data to be displayed
write at / i_return-message
endloop.
6.1.8
261454112.doc
Page
Version: 3
04 March 2003
71
if sy-subrc <> 0.
* Status light not created.
Error Message
endif.
p_w_stat = l_stat.
p_w_icon_stat = l_icon_stat.
endform.
" F_GET_LIGHTS
261454112.doc
Page
Version: 3
04 March 2003
72
6.1.9
261454112.doc
Page
Version: 3
04 March 2003
73
Example
* Get the last used value of plant recid for
plant and date
select max( plntrecid ) into
w_plantid
from /slssv/cplntrec
where plant = p_plant
and lddate = p_date.
w_plantid = w_plantid + 1.
Immediately enqueue w_plantid.
6.1.10
6.1.11
261454112.doc
Page
Version: 3
04 March 2003
74
to ...
ENDFORM.
" abc
IF Comparison
Before doing IF comparisons on elements of different types (i.e.,
numeric to character), move one element to a variable of the
same type as the other element so that you will not experience
unexpected results. While ABAP will automatically convert
261454112.doc
Page
Version: 3
04 March 2003
75
elements of unlike types for you, the end result may not be what
the programmer expects.
When comparing quantity fields, make sure the quantities are in
the same unit of measure. Note that this is normally done by
looking at which field is used NOT by coding in a unit
conversion or validation.
6.2
Examples
Standard - Non-Unique Key, accessed by key or indexing (predominantly by
indexing, also known as Index Tables). When the key is used, the time
increases linearly with the number of table entries.
TYPES: BEGIN OF T_MAT,
DATA: I_MAT TYPE STANDARD
WERKS LIKE MSEGTABLE OF T_MAT
WERKS,
WITH KEY NON-UNIQUE
MATNR LIKE MSEGMATNR
MATNR,
INITIAL SIZE 0,
END OF T_MAT.
WA_MAT TYPE T_MAT.
Sorted - Key is either Unique or Non-Unique, accessed primary by key or
indexing (predominantly by Key). When the key is used, the time is
logarithmic in relation to the number of table entries.
TYPES: BEGIN OF T_MAT,
DATA: I_MAT TYPE SORTED TABLE
WERKS LIKE MSEGOF T_MAT
WERKS,
WITH UNIQUE KEY
MATNR LIKE MSEGWERKS
MATNR,
INITIAL SIZE 10000,
END OF T_MAT.
WA_MAT TYPE T_MAT.
Hashed - Unique Key, accessed only by Key. Response time is constant and
does not depend on the number of entries.
261454112.doc
Page
Version: 3
04 March 2003
76
Version: 3
04 March 2003
77
6.2.1
6.3
261454112.doc
Page
Version: 3
04 March 2003
78
:
:
INITIALIZATION.
* prepare SM35 button
sscrfields-functxt_01 = 'View SM35'. "for key 1
:
:
at selection-screen.
if sscrfields-ucomm = 'FC01'.
D0100-MAPN = PA_GROUP.
SET PARAMETER ID 'MPN' FIELD D0100-MAPN.
CALL TRANSACTION 'SM35'
AND SKIP FIRST SCREEN.
endif.
-------------------------------------------------------------------------------------The limitation to the above code is that max 4(four) function
keys can be added to the selection screen.
6.4
Logical Database
In most cases, it is likely that coding database retrievals with
SELECT statements will prove more efficient than using a
Logical Database (LDB) program. A LDB program reads tables
with nested SELECT loops. The depth of the SELECT into the
LDB hierarchy depends on the GET statement in the ABAP
corresponding to the tables located at the lowest level of the
LDB hierarchy. If a program does not need information from a
superior table in the hierarchy, unnecessary reads will occur.
Before using a LDB, be sure the logic cannot be coded more
efficiently using SELECT.
The Logical Database allows reading of hierarchically related
tables using GET statements. The advantages of the logical
databases are:
Ease of programming
261454112.doc
Page
Version: 3
04 March 2003
79
Version: 3
04 March 2003
80
Subroutines
The three subroutine alternatives are:
FORM routines
Include programs
Call functions
Calling ABAP subroutines can create conflicts between the goals
of transparency, maintainability and performance. In each
individual case, consider the following:
How often is the form called?
How much time is required by the respective module call?
The guideline values for resource consumption:
Subroutine Type
Internal PERFORM
External PERFORM
CALL FUNCTION
CALL DIALOG
261454112.doc
Page
Microseconds
3
20-50
20-100
10,000-150,000
Version: 3
04 March 2003
81
6.4.1
Forms
FORMS are subroutines that allow a programmer to define a
process once in a program and call that routine from different
places within the program or from other programs. A FORM
should be used for large coding blocks. Common sections of
code accessed from several points in an ABAP should also be
put into FORMS.
If a block of code is executed more than once, it should be
placed in a subroutine at the bottom of the code. This makes the
code more readable, requires less indentation, and is easier to
debug since the debugger can jump through an entire subroutine
via a PF key.
For good modularization, the decision of whether or not to
PERFORM a subroutine should be made before the subroutine is
called.
Example:
More Efficient
IF f1 NE 0.
PERFORM sub1.
ENDIF.
FORM sub1.
.
ENDFORM.
Less Efficient
PERFORM sub1.
FORM sub1.
IF f1 NE 0.
EXIT.
ENDIF.
ENDFORM..
Considerations:
Dont use PERFORM<form name>(<program name>)
unnecessarily. Overall runtime will be increased because the
261454112.doc
Page
Version: 3
04 March 2003
82
Includes
An INCLUDE is a section of code which has been separated due
to program size or it is in common use by several programs.
Effective use of includes can reduce development and
maintenance time.
Consideration:
A program that uses include incorporates it at generation time, so
if the include is altered all the programs that use it must be regenerated. SAP has to regenerate if the last update date and the
regeneration date of the program are not the same.
6.4.3
Function Modules
For speed, internal routines are the fastest. Functions should be
used for general routines so maintenance can be performed
collectively. The routines are loaded into a buffer so their first
access is very slow. The most frequently accessed functions are
held sequentially in memory, and as new routines are used the
least frequent routines are dropped.
261454112.doc
Page
Version: 3
04 March 2003
83
Importing
Tables
Exceptions
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
261454112.doc
Page
Version: 3
04 March 2003
84
6.5
SQL
6.5.1
261454112.doc
Page
Version: 3
04 March 2003
85
261454112.doc
Page
Version: 3
04 March 2003
86
ENDSELECT.
6.5.1.2
261454112.doc
Page
Version: 3
04 March 2003
87
6.5.1.3
SELECT
Aggregates
261454112.doc
Page
Version: 3
04 March 2003
88
6.5.1.4
261454112.doc
Page
Version: 3
04 March 2003
89
261454112.doc
Page
Version: 3
04 March 2003
90
LOOP AT I_OBJECTS.
SELECT * FROM TADIR
WHERE PGMID = I_OBJECTS-PGMID
AND OBJECT = I_OBJECTS-OBJECT
AND OJB_NAME = I_OBJECTSOBJ_NAME.
TADIR = INT_OBJECTS.
UPDATE TADIR.
ENDSELECT.
ENDLOOP.
* Less Efficient
6.5.1.6
Column Update
When possible, use column updates instead of single-row
updates to update database tables
Example:
Column update
UPDATE VERI_CLNT
SET FUNCTINT = FUNCTINT + 1
* More Efficient
Single line update
SELECT * FROM VERI_CLNT.
VERI_CLNT-FUNCTINT = VERI_CLNTFUNCTINT + 1.
UPDATE VERI_CLNT.
ENDSELECT.
* Will work, but Less Efficient
6.5.1.7
261454112.doc
Page
Version: 3
04 March 2003
91
Example 1:
Select Into Table
SELECT * FROM T006
INTO TABLE I_T006.
* More Efficient
Select + Append Statement
REFRESH X006.
SELECT * FROM T006 INTO I_T006.
APPEND I_T006.
ENDSELECT.
* More Efficient
As a general rule, use database views or the INTO TABLE
version of a SELECT statement with the addition FOR ALL
ENTRIES IN TABLE ITAB rather than using nested SELECT
statements. The latter (for all entries) is less efficient than using
database views but is more efficient than nested selects. When
using For All Entries in Table ITAB, it must be ensured that
ITAB is not initial.
6.5.1.8
UP TO nn ROWS
The ABAP UP TO nn construct causes as many FETCHs to be
executed until sufficient rows have been returned to satisfy the
nn requirement. When coding a construct of this type, use SQL
Trace to examine the output to see how many records can be
retrieved with a single FETCH and adjust your Initial Size and
UP TO values appropriately. When examining the trace screen,
look for the FETCH xx Array: nnn statement. This gives the
optimum value for the size of the UP TO and Initial Size in the
program
6.5.1.9
6.5.1.9.1
Inner Join
261454112.doc
Page
Version: 3
04 March 2003
92
261454112.doc
Page
Version: 3
04 March 2003
93
Catch / Endcatch
Catch/Endcatch - The CATCH and ENDCATCH statements
allow for the implementation of global exception handling.
CATCH SYSTEM-EXCEPTIONS CONVT_NO_NUMBER = 1
BCD_ZERODIVIDE = 2
OTHERS
= 3.
ENDCATCH.
CASE SY-SUBRC.
WHEN 1.
WRITE: / 'Numeric conversion error.'.
WHEN 2.
WRITE: / 'Divide by zero error.'.
WHEN 3.
WRITE: / 'Unknown run time error has
occurred.'.
ENDCASE.
261454112.doc
Page
Version: 3
04 March 2003
94
Native SQL
The use of native SQL provides the programmer with greater
flexibility but increases the responsibility to produce efficient
code. In addition, native SQL can improve performance but
increases responsibility. Personnel need to be multiskilled as
maintenance becomes more difficult.
Considerations:
The buffering of tables will not be beneficial if Native SQL is
used.
Unlike ABAP OPEN SQL, the programmer needs to be
concerned with the MANDT field. In ABAP OPEN SQL,
WHERE MANDT = is added to the SELECT statement; with
native SQL, the programmer needs to code WHERE
MANDT = :SY-MANDT.
The use of native SQL for INSERT, UPDATE, and DELETE
operations is not recommended for standard SAP tables.
As native SQL directly accesses the underlying database and
bypasses the buffer for SAP buffered tables, native SQL
should only be used for read-only tables.
261454112.doc
Page
Version: 3
04 March 2003
95
String Manipulation
6.6.1
CONCATENATE
Use the CONCATENATE statement instead of programming a
string concatenation.
Example:
Use of the CONCATENATE statement
MOVE Jane TO W_MA.
MOVE Miller TO W_MB.
MOVE New York City TO w_MC.
CONCATENATE Mrs.
w_MA w_MB
from
w_MC INTO CHA SEPARATED BY
SPACE.
Mrs. Jane Miller from New York City is the final
value of CHA
* More Efficient
Moving with Offset
MOVE Jane TO w_MA.
MOVE Miller TO w_MC.
I1 = STRLEN( w_MA ).
I2 = STRLEN( w_MB )
MOVE Mrs. TO W_CHA.
MOVE w_MA TO CHA+5. I1 = I1 + 6.
MOVE w_MB TO CHA+11. 1 = I1 + 12 + 1.
MOVE from TO CHA+I1.I1 = I1 + 5.
MOVE w_MC TO CHA+11.
Mrs. Jane Miller from New York City is the final
value of CHA
* Less Efficient
261454112.doc
Page
Version: 3
04 March 2003
96
DELETING LEADING
Version: 3
04 March 2003
97
Editor line n.
SHIFT W_CLA LEFT DELETING LEADING
SPACE.
* More Efficient
Shifting by SY-FDPOS places
W_CLA contains the sting
Editor line n.
IF W_CLA CN SPACE. ENDIF.
SHIFT W_CLA BY SY-FDPOS PLACES LEFT.
* Less Efficient
6.6.3
SPLIT
Use the SPLIT statement instead of programming a string split.
Example:
Use of the SPLIT statement
* W_CMA contains '(410)-45174-66354312' and shall
be split into
* W_AREA_CD, W_TEL_NBR1, TEL_NBR2
SPLIT W_CMA AT '-' INTO W_AREA_CODE
W_TEL_NBR1
W_TEL_NBR2.
* More Efficient
Use of SEARCH and MOVE with offset
261454112.doc
Page
Version: 3
04 March 2003
98
STRLEN
The ABAP function STRLEN returns the length of a string up to
the last character that is not a space.
Example
* Display the length of the variables w_word1,
w_word2 and w_word3
DATA: W_INT TYPE I,
W_WORD1(20) VALUE 'ABCDE'.
W_WORD2(20).
W_WORD3(20) VALUE ' 4 '.
W_INT = STRLEN( W_WORD1 ). WRITE W_INT.
W_INT = STRLEN( W_WORD2 ). WRITE / W_INT.
W_INT = STRLEN( W_WORD3 ). WRITE / W_INT.
The results are 5 , 0, and 1 respectively.
6.7
FIELD-SYMBOLS
Use the ASSIGN and FIELD-SYMBOLS statements to provide
the powerful functionality of pointers. FIELD-SYMBOLS are
place holders for fields. A FIELD-SYMBOL does not occupy
memory, but points to a position that has been ASSIGNed to the
FIELD-SYMBOL at runtime. After the FIELD-SYMBOL has
261454112.doc
Page
Version: 3
04 March 2003
99
FIELD-
DO.
READ DATASET P_FL_IN INTO INPT_RCRD.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
LENGTH =
INPT_RCRD+POSITION(3).
IF
LENGTH = 0.
EXIT.
ENDIF.
ADD 3
TO POSITION.
ASSIGN INPT_RCRD+POSITION(LENGTH) TO
<ENTRY>.
WRITE <ENTRY>.
IF POSITION >= 3000.
EXIT.
ENDIF.
ENDDO.
Considerations:
As FIELD-SYMBOL references are only established at
runtime, the syntax does not always detect errors such as type
conflicts. This could cause runtime errors or incorrect data
assignments. As of Release 3.0, to avoid the possibility of a
261454112.doc
Page
Version: 3
04 March 2003
100
6.8
General Statements
Logical expressions are evaluated from left to right. The
evaluation is ended when the final result has been established
(elimination or complete inclusion). Therefore, when using
AND or OR operator (in IF, WHERE, etc.), the most likely
elimination criterion should be specified first. The opposite
will be true for negative comparisons and some OR
conditions.
Example:
The following table is to be read with printing of employees from
ABC company in Georgia:
EMPLOYE
E
001
002
003
004
005
006
007
008
009
010
NAME
Doe, J
Doe, M
Jones, A.
Jones, B.
Jones, C.
Jones, D.
Jones, E.
Smith, A.
Smith, B.
Smith, C.
COMPAN
Y
ABC
ABC
XYZ
ABC
ABC
XYZ
ABC
ABC
ABC
ABC
STATE
TX
OK
TX
GA
TX
GA
TX
GA
TX
OK
Less Efficient
IF COMPANY = ABC
AND STATE = GA.
WRITE
ENDIF.
Will work, but will need to evaluate both the company
and state fields for eight of ten records.
261454112.doc
Page
Version: 3
04 March 2003
101
More Efficient
IF STATE = GA
AND COMPANY = ABC.
WRITE
ENDIF.
Will need more time to process, since it can eliminate all
records without STATE = GA and therefore will need
to evaluate both company and state for only 3 records.
Use special operators CO (Contains Only), CA (Contains
Any), CS (Contains String) instead of programming the
operations yourself. If ABAP statements are executed per
character on long strings, CPU consumption can rise
substantially.
Example:
Do-Loop with Field-Symbols
ASSIGN CHA(1) TO <C>.
DO 200 TIMES.
IF <C> = ( OR <C> = ).
.. any actions
EXIT.
ENDIF.
ASSIGN <C>+1 TO <C>.
ENDDO.
1263 microsec
Using the CA Operator
IF CHA(200) CA ().
any actions.
ENDIF.
443 microsec
When testing fields equal to something, use either the
nested IF or the CASE statement. CASE is better for two
reasons. It is easier to read and after about five nested IFs the
performance of the CASE is more efficient.
261454112.doc
Page
Version: 3
04 March 2003
102
Example:
More Efficient
MOVE BSEG TO *BSEG
Less Efficient
MOVE-CORRESPONDING BSEG TO *BSEG
6.9
261454112.doc
Page
Version: 3
04 March 2003
103
261454112.doc
Page
Version: 3
04 March 2003
104
7.
Version: 3
04 March 2003
105
261454112.doc
Page
Version: 3
04 March 2003
106
Appendix
1/ Conversion Process
The purpose of this Appendix is to provide clear guidelines for
building Conversion Programs and Conversion Reporting.
1.
1.1
File Upload
In interface programs, when you upload the data from file to
internal table then all the fields should be character type only
otherwise it may cause a short dump. Once the data is there in
the character fields it is then validated for containing values as
per its required field type. Incorrect records are rejected as errors
and correct records are passed ahead for further processing. This
prevents any short dumps. Also, translate to upper case all
character fields (exclude descriptive text fields) of inbound files
first, and then use them in validations against SAP tables.
1.2
File Transfer
261454112.doc
Page
Version: 3
04 March 2003
i
IN TEXT MODE
Effect: If this addition is used, the contents of the file are
structured in lines. Each time the READ DATASET or
TRANSFER statement are used, the system reads or writes a
single line.
IN BINARY MODE
Effect: The contents of the file are not structured in lines in the
READ DATASET or TRANSFER operations. Instead, they are
input or output as a stream. There is no need to specify the IN
BINARY MODE addition explicitly.
Note
Only one of the additions IN TEXT MODE and IN
BINARY MODE can be used in a single statement.
Mode of upload Mode of opening Result
the data
the file
Binary
Binary mode
# appears as
character in
record
Binary
Text mode
# appears as
character in
record
ASCII
Binary mode
# appears as
character in
record
ASCII
Text mode
Without #.
261454112.doc
Page
a last
each
a last
each
a last
each
Version: 3
04 March 2003
ii
1.3
2.
Conversion Reporting
Each Conversion program should generate the following reports:
1/ Conversion Statistics Report: This is a breakdown of
conversion statistics (ie/ Total number of records in the input file;
total number of records processed; total number of records
containing errors).
2/ Major Error Report: This is a list of all the records, which
contained major errors (ie/ No value for a mandatory field;
incorrect/non SAP Standard value for a mandatory field;
incorrect/non SAP standard value for any field with a check
table). It should also detail records which have failed because
261454112.doc
Page
Version: 3
04 March 2003
iii
Select statements have not been able to return an SAP value (eg/
Purchase Order Conversion will take a legacy system Vendor
number and use it to try to find the SAP Vendor Number).
A page break should exist between these reports. Each of the
conversion programs should use the same Report format.
3.
4.
Conversion Testing
All Custom Conversion ABAPs should be unit tested prior to
being signed off as completed. It is assumed that in cases where
the Conversion process comprises a SAP Standard and a Custom
ABAP ABAP, both will be unit tested. The text file will be
passed through the SAP Standard ABAP, all the way to executing
the BDC Session. Test scripts and data should be provided to
the Conversion functional and technical Designers.
261454112.doc
Page
Version: 3
04 March 2003
iv
2/ EDI Modifications
When modifying SAP supplied EDI function modules, the
following steps should be followed:
1. Copy SAP standard function module
An exact copy of SAPs standard EDI function modules will be
made for those transactions that Novartis will be using. These
copies will keep the same name as the original, but will be
prefixed with Z_CCa ( CC = Country Code, a = application
ID). The name of the function module will serve as the link
back to the SAP original version.
2. Modifications and commenting
Modifications are made directly in the code of the customer
function module. The modification should be commented in such
a way as to allow easy readability and tracking of updates.
Modifications should only include adding lines of code and
commenting out of SAP code, if necessary. SAP standard code
should never be deleted or changed. The modifications should
be commented and marked with a search string as described in
Section 4 above.
3. OSS notes should be applied simultaneously to SAP
standard and custom function modules
This will ensure that both function modules are kept in sync. It
also ensures that the only differences in the two function modules
are the commented modifications made as a result of as GAP.
This will make it easier in the future to identify SAP bugs
independently from the modifications made at Novartis.
The advantages and disadvantages to this method are outlined in
the following table:
Advantages
Ease of code maintenance and
modification
261454112.doc
Page
Disadvantages
SAP lack of support for
customer function modules
Version: 3
04 March 2003
Migration of upgraded
enhancements in SAP standard
function modules to customer
function modules.
Introduction
The purpose of this document is to outline the naming
convention that should be followed for the creation of Transports
for ABAP development jobs in the development environment.
A rigorous naming convention is the cornerstone of effective
version management and change control in an SAP landscape.
The Transport description will allow the technical team to audit /
track / group changes in the system. It will also allow the
technical team to identify and correct errors when they occur.
In short a good naming standard will allow the technical team
and the Basis engineers to better support the project.
It should be noted that the basis team will be instructed not to
move any transports from Development which do not comply
with the naming standard outlined below.
2.
Standard Outline
This section will review some of the main fields of relevance in
the transport, and which are regularly used as a basis for
reporting.
Transport No.
The transport no is automatically assigned by the SAP system to
each CTS.
261454112.doc
Page
Version: 3
04 March 2003
vi
DO3K003428
Text
Valid 3-character prefix e.g. NCC
Dash -
SAP module name (Pick from Functional spec
Dash -
Type of program (Pick from Functional spec name
e.g. CON, REP, etc.) followed by a space
12
Dash -
13.16
Valid sequence number (Prefix 0 to the 3
digit number
obtained from Functional spec name)
17.24
Valid date in YYYYMMDD format
25+
Valid R/3 user id, followed by space, followed by
free form text.
Example:
NCC-FI-CON 000220030121ROUTRAB1 Chart of
Accounts Conversion
261454112.doc
Page
Version: 3
04 March 2003
vii
Description
CATT SCRIPTS
DEDUCTION
MANAGEMENT
DO NOT TRANSPORT!
DEVELOPMENT CLASSES
GLOBAL USER EXIT
NOVARTIS
CONSUMER
CORE
OSS NOTES
US
SECURITY
AND
CONTROLS
US USER EXIT
Note: When creating Transport Requests for any User Exit jobs,
please use the prefix GUE.
The following aspects related to organization of CTS should be
adhered to:
Objects of the same program in one transport request.
Objects for global use in separate request one for each ABAP
object. Create related group of global objects in one request.
261454112.doc
Page
Version: 3
04 March 2003
viii
Program/Transaction Code
Financial Accounting
Financial Accounting
Accounting documents
Assets
Financial Accounting
Financial Accounting
Financial Accounting
RFBIBL00
RAALTD01 (Batch Input)
RAALTD11 (Direct Input)
RFBISA00
RFBIDE00
RFBIKR00
FI-Bank Data
RFBVAT_0
RPUSTD00
Human Resources
Human Resources
Materials Management
Materials Management
Create characteristics
Create classes
RCCTBI01
RCCLBI01
FI-General Ledger
FI-General Ledger
FI-General Ledger
Human Resources
261454112.doc
Page
RFBVCA_0
RFBVD_ _2
RFBVGB_0
RFBVIT_0
RFBVES_0
RFBVCH_0
RPULKT00
RHALTD00
Version: 3
04 March 2003
vi
Business Object
Materials Management
Materials Management
Materials Management
Materials Management
Materials Management
Materials Management
Materials Management
Materials Management
Materials Management
(EH&S)
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Plant Maintenance
Program/Transaction Code
Create classification
Change classification
Material master
Purchase information records
Purchase requisitions
Open purchase order
RCCLBI02
RCCLRI03
RMDATIND
RM06IBI0
RM06BBI0
RM06EEI0 Purchase Order
RM06EEI1 Order
Development
RSTXLITF Long Texts
Reservations
RM07RRES
Stocks (Inventory Management) RM07MMBL
Vendor master
RFBIKR00
Phrases
CG31
Sources
Substances
CG32
CG33
Measuring point
Measurement document
Notifications - general
Functional location
Object link
Equipment
Maintenance plan
Scheduling maintenance plan
Order confirmation
Equipment task list
General maintenance task list
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
RIIBIP00/IBIP
261454112.doc
Page
Version: 3
04 March 2003
vii
Business Object
Program/Transaction Code
Plant Maintenance
RIIBIP00/IBIP
RCSBI010
RCSBI020
RCSBI030
RCSBI040
Production Planning
Demand management
SAP-EIS
RKCFILE0
RV14BTCI
RFBIDE00
RVINVB00
RVAFSS00
261454112.doc
Page
RCPTRA01
RCVBI010
RLPLAT00
RLBEST00
Version: 3
04 March 2003
viii