ABAP Standard Coding Rule (7th Edition)
ABAP Standard Coding Rule (7th Edition)
ABAP Standard Coding Rule (7th Edition)
7th Edition
Creation Date
2014/01/14
Date Last
Modified
2014/01/14
Effective Date
1.0
2014/01/14
Publisher
Changed Contents
New Document
Change Log
Effective Date
Publisher
Changed Contents
Change Log
Change Log
Change Log
Contents
Initial
initial
initial
initial
Initial
Setting
setting
setting
setting
Setting
ALV
Others
Amount/Quantity Item
Header Comment
SmartForms
Standard Template
Naming
Program Header
Layout Definition
Declaration Header
Internal Procedure
Event Header
Subroutine Header ( Module Header )
Structuration
Coding
Indent
Comment
Literal
Specify type
Prohibition Item
Message
Performance
DB Access
Internal Table
Modificatgion log
Dynpro
Naming
Modificatgion log
GUI Status
Modification Coment
Basic Design
Save Procedure
Sort Procedure of Table Control Data
Screen Definition
Confirmation Pop-up
Authority Check
Transaction
Function Module
Description Method
Naming (Parameter)
FPT Software
Contents
Contents
FPT Software
Contents
on Design
Program Structuration
FPT Software
Contents
FPT Software
Contents
Initial Setting
Others
FPT Software
Initial Setting
Initial Setting
FPT Software
Initial Setting
Head Comment
Standard Template
When creating a program, it is necessary to copy the each
Header Comment from the attached file at the right.
Standard Template.txt
Program Header
Example)
*----------------------------------------------------------------------*
* Program ID :ZXXXX999
* Program Name:
*
* Program Summary:
*
* Creation Date : YYYY/MM/DD
Created byRyoka Tarou(RSI)
* Coding Standards Version 7
* Development Version:SAP ECC 6.0
* Available Condition:Only Availabe for SAP ECC 6.0 Server
*----------------------------------------------------------------------*
* Ryoka Systems Inc.
* (C) Copyright Ryoka Systems Inc.
* All Rights Reserved
*----------------------------------------------------------------------*
REPORT ZXXXX999 NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 65
MESSAGE-ID ZPKZ001.
Program ID
Program name
Program Summary
Completion Date
Composer
ERP2004
ERP2005
Description place
Report
Dynpro
Function Module
Beneath of the header which is created automatically at the source code tab.
FPT Software
Header Comment
Head Comment
Declaration Header
Example)
*----------------------------------------------------------------------* Tables Definition
*----------------------------------------------------------------------TABLES: XXXXXXX.
Header Comment
*----------------------------------------------------------------------PARAMETERS:
P_XXXXX
TYPE XXXX-XXXXX OBLIGATORY.
SELECT-OPTIONS:
S_XXXXX
FOR XXXX-XXXXX.
06/02/2016 03:28:55 15/49
*-----------------------------------------------------------------------
Head Comment
* CLASS Definition
Event Header
Report
************************************************************************
INITIALIZATION.
************************************************************************
************************************************************************
AT SELECTION-SCREEN.
************************************************************************
************************************************************************
START-OF-SELECTION.
************************************************************************
************************************************************************
END-OF-SELECTION.
************************************************************************
************************************************************************
TOP-OF-PAGE.
************************************************************************
************************************************************************
END-OF-PAGE.
************************************************************************
************************************************************************
AT USER-COMMAND.
************************************************************************
************************************************************************
AT LINE-SELECTION.
************************************************************************
Dynpro
*----------------------------------------------------------------------PROCESS BEFORE OUTPUT.
*----------------------------------------------------------------------*----------------------------------------------------------------------PROCESS AFTER INPUT.
*----------------------------------------------------------------------*----------------------------------------------------------------------FPT Software
PROCESS ON HELP-REQUEST.
*----------------------------------------------------------------------*-----------------------------------------------------------------------
Dynpro Template.TXT
Header Comment
Head Comment
PROCESS AFTER INPUT.
*-----------------------------------------------------------------------
Program Header
*----------------------------------------------------------------------PROCESS ON HELP-REQUEST.
*-----------------------------------------------------------------------
Declaration Header
*----------------------------------------------------------------------PROCESS ON VALUE-REQUEST.
*-----------------------------------------------------------------------
Subroutine Header
are copied from
standard template.
Delete the parts
which is not used
Subroutine name
Item No. of Detail Spec. Enter the Item No. of Structure Chart on Detail Spec.
(When there is no item No. , omit the Item No..)
Procedure Summary
FPT Software
Header Comment
Coding
Indent
The beginning position is as below.
1st column
Event Keyword
TYPE N.
IF ( ( WK_A = C_CHECK
OR
WK_B = C_CHECK )
AND
WK_C = C_CHECK
).
CASE WK_TYPE.
WHEN C_TYPE_I.
L_WK_WRITE = 1.
WHEN C_TYPE_M.
L_WK_WRITE = 2.
WHEN OTHERS.
ENDCASE.
ENDIF.
READ TABLE IT_TBL INTO WA_TBL WITH KEY NO = L_WK_WRITE.
IF ( SY-SUBRC = 0 ).
TRANSFER WA_TBL TO P_FLNM.
ENDIF.
ENDFORM.
" MAIN_PROC
Shift 2 columns
Command (Keyword)
Comment
FPT Software
Coding
Coding
Literal
Use as you like.
When the literal is used in more than 1 time, or maybe modificated, use the constant preferably.
Specify type
When define Selection Screen & Varible etc. ,
refer to dictionary and define the type as much as possible.
Prohibition Item
Prohibiton Item
Substitution Plan
Reference of SELECT-OPTIONS
Internal Table
Definition
Text Symbol
Example)
Selection Screen : Comment / Block Title
Report : Report Title / Item Title
Use assignment operator (=)
MOVE command
Variable
Substitution
Relevant Operator
Arithmetic Operator
Example) MOVE A TO B.
Example) B = A.
MOVE-CORRESPONDING
Use below
LT GT LE GE
ADDSUBSTRACTMULTIPLYDIVIDE
Use below
COMPUTE command
+ - * / MOD **(index)
STOP command
Interruption
Procedure
0 Division
0 Division
Sort
SORT IT_TBL
BY
FIELD1 ASCENDING
FIELD2 DESCENDING
TABLES Parameter
FPT Software
Subroutine
(Parameter Interface)
Coding
Coding
Subroutine
(Parameter Interface)
Deliver by reference(1).
Number Definition
line.
Message
Use message of addon common message class (ZPKZ001) as much as possible.
Use defined unified message in common procedures.
Refer to common
message
definition document
entry rule
Action
Abnormal End
Error
Procedure breaks.
Warning
Information
Status
FPT Software
Coding
Coding
Type
Type
Variable
Constant
Item
Global
Prefix
Local
Example
Prefix
Example
Date Type
TA_
TA_INIT
L_TA
L_TA_VBRK
TTA_
TTA_VBAK
L_TTA_
L_TTA_VBAP
Work Area
WA_
WA_ECMCT
L_WA_
L_WA_ECMCT
Interal Table
IT_
IT_BDCDATA
L_IT_
L_IT_BDCDATA
Range
R_
R_KUNNR
L_R_
L_R_MANDT
Varible
WK_
WK_RESULT
L_WK_
L_WK_DYN
Count Variable
CNT_
CNT_TOTAL
L_CNT_
L_CNT_ERROR
Flag Variable
FLG_
FLG_OPEN
L_FLG_
L_FLG_OPEN
Field Symbol
FS_
<FS_VALUE>
L_FS
<L_FS_TAB>
Constant
C_
C_DATE
L_C_
L_C_DATE
Parameter
P_
P_BUKRS
Select Option
S_
S_BELNR
Block name
BL_
BL_1
Screen Item
RG_
RG_1
Definition /
Radio Button
RB_
RB_CLASS
Object
Check Box
CB_
CB_FILE
Push Button
PB_
PB_START
TS_
TS_1
Table Control
TL_
TL_1
Subroutine /
Subroutine /
V_
V_WA_VBAP
Provisional
Provisional Parameter
Prefix
according to V_Date Type
Parameter
OK_CODE' / 'SAVE_OK' used in Dynpro are not possible to attach prefix as a exception.
Variable is named from directionary name for which is facility to calculate origin data.
Example) Varialbe : TYPE VBAP-KWMENG
False
False
C_OR
Right C_AUART1
Print Format
Report format ( Report Size in 1 page)
X_58_170
Width
use the standard format in SAP Print Setting.
X_65_132
Recommend
X_65_255
X_65_80
Length
Recommend X_90_120
58 Row
170 Column
65 Row
132 Column
65 Row
255 Column
65 Row
80 Column
90 Row
120 Column
FPT Software
Coding
Coding
FPT Software
Coding
Dynpro
Naming
Naming Rule of DYNPRO No. / GUI Title / GUI Status refer to 'Statement of Naming Standards'.
GUI Status
Menu
Set up function key at the point which is correspond to the standard of menu bar.
Function Key / Function Code (OK Code) / Function Text / Icon
The function key which is used as SAP standard
Function Key
Function Code
Function Text
ENTER
ENTER
ENTER
F1
HELP
HELP
F3
BACK
BACK
F4
INPV
F11
SAVE
SAVE
F12
CANC
CANCEL
Shift + F3
END
END
Function Code
Function Text
Icon
F2
PICK
ICON_SELECT_DETAIL
F5
INST
Create
ICON_CREATE
F6
UPDT
Change
ICON_CHANGE
F7
DISP
Display
ICON_DISPLAY
F8
EXEC
Execute
ICON_EXECUTE_OBJECT
F9
SALL
Select ALL
ICON_SELECT_ALL
Shift + F6
RALL
Deselect All
ICON_DESELECT_ALL
Ctrl + Shift + F5
ASRT
Ctrl + Shift + F6
DSRT
Ctrl + F9
INLI
Insert Row
ICON_INSERT_ROW
Ctrl + F10
DELI
Delete Row
ICON_DELETE_ROW
Ctrl + Shift + F1
SWCH
Display / Change
ICON_TOGGLE_DISPLAY_CHANGE
Shift + F2
DELT
Delete
ICON_DELETE
Ctrl + P
PRIN
ICON_PRINT
Ctrl + Shift + F9
EXPO
Export
ICON_EXPORT
Ctrl + PAGEUP
P--
ICON_FIRST_PAGE
PAGEUP
P-
ICON_PREVIOUS_PAGE
PAGEDOWN
P+
ICON_NEXT_PAGE
CTRL+PAGEDOWN
P++
ICON_LAST_PAGE
FPT Software
Dynpro
Dynpro
When refer to internal table, it needs to search and set the value above,
construct the program by yourself.
When press help button, avoid showing the incomprehensible message.
When user press the help button at the item which is made by the internal table,
it may show the message as 'There is no text'.
When the item is made by structure, because there is attribute in the each item,
the problem as above don't occurs.
CASE SAVE_OK.
WHEN XXX.
FPT Software
Dynpro
Dynpro
Save Procedure
When press SAVE button, change confirmation is not necessary.
With or without change, execute SAVE procedure with no condition.
Button (USER-COMMAND)
Exit
Button (EXIT-COMMAND)
Cancel
Previous
Cancel
Screen
END
Previous
Screen
1st Screen
1st Screen
Close
Previous
Cancel
Screen
Close
Close
Confirmation Pop-up
When BACK/EXIT/CANCEL is pressed on the screen where is a save procedure,
FPT Software
Dynpro
Dynpro
POPUP_TO_CONFIRM
Title Line
Message Line
Response Yes
No
Response Button
Button1
Yes
Button2
No
Report
Insert the Dynpro object (from 2nd Dynpro Screen) to the report program.
(Don't use the constitution which call Selection Screen from ModulePoolPG.)
Dynpro100
FPT Software
Dynpro
Function Module
Description Method
When use CALL FUNCTION to define function module, Pattern insertion is recommended.
When use function module which with exception procedure, certainly make sure that they are effective.
Don't use Function Module which Release Date is blank (Not released) as much as possible.
(Refer the release information at the attribute tab)
Naming (Parameter)
Attach under prefix to parameter.
Parameter
Prefix
Usual
Import
I_
IS_
IT_
Export
E_
ES_
ET_
Changing
C_
CS_
CT_
Table
Prohibition
Exception
Unnecessary
FPT Software
Function Modual
Function Module
Structure
FPT Software
Function Modual
ALV
Amount/Quantity Item
When there is a amount or quantity item, make them to refer CURRENCY or QFIELDNAME.
Make Currency / Unit of quantity in the structure, make amount / quantity refer to them.
Set Currency / Quantity Unit for the amount / quantity item in the field catalog.
CURRENCY
Currency
QFIELDNAME
Quantity Unit
FPT Software
ALV
ALV
FPT Software
ALV
SmartForms
Naming
Parameter
Attach prefix to the parameter(addon) as same as Function Module.
Node
Attach under prefix to node.
Node
Prefix
Page
PA_
Main Window
MW_
Sub Window
W_
Table
TA_
LI_H(_)
LI_M(_)
LI_F(_)
Cell
C_
Line
L_
Text
TX_
Address
AD_
Graphic
GR_
Template
TM_
Folder
FO_
Alternative
IF_
Loop
LP_
Program Lines
PG_
Command
CO_
the Others
When define global declaration / control logic, follow the 'ABAP Standard Coding Rule'.
Layout Definition
Don't define window in every item, gather & define them as a Template in a certain level.
Internal Procedure
Considering the serviceability, don't do complicated procedure in the SmartForms as much as possible.
(Do editing data in the original program in advance.)
FPT Software
SmartForms
SmartForms
FPT Software
SmartForms
Structuration
Initial Procedure
AT SELECTION-SCREEN
Selection Screen
Procedure
START-OF-SELECTION
Main Procedure
END-OF-SELECTION
End Procedure
TOP-OF-PAGE
END-OF-PAGE
Footer Procedure
AT USER-COMMAND
Input Event
Procedure
AT LINE-SELECTION
FORM
Line Selection
Procedure
Procedure
INIT_PROC
Main Procedure
MAIN_PROC
End Procedure
END_PROC
Search Procedure
Internal Table Edit
SELECT_MARA
Individual Table
SELECT_MARA_JOIN
SET_IT_TBL
Procedure
WRITE_HEADER
Output head
Output Item
WRITE_FOOTER
Output Footer
FPT Software
Structuration
Structuration
FPT Software
Structuration
Structuration
The typical procedure of program, such as make report, make file etc..
End Procedure
Program
Program
Initial
Initial
Procedure
Procedure
Main
Main
Procedure
Procedure
End
End
Procedure
Procedure
1. Sequential Type
Execute the low rank module repeatedly.
Make
Make
File
File
READ
READ
Procedure
Procedure
Read file
Detail
Detail
Procedure
Procedure
Write to file
Make
Make Report
Report
Procedure
Procedure
1st
1st
Procedure
Procedure
FPT Software
2nd
2nd
Procedure
Procedure
Structuration
Structuration
READ
READ
Procedure
Procedure
Execute
2nd
2nd
Procedure
Procedure
only 1 time
Detail
Detail
Procedure
Procedure
Execute repeatedly
READ
READ
Procedure
Procedure
Control
Control Break
Break
Procedure
Procedure
Detail
Detail
Procedure
Procedure
Break
Break
Procedure
Procedure
Break
Break
Procedure
Procedure
Break
Break
Procedure
Procedure
ororis executed.
Example)
LOOP AT IT_BSEG INTO WA_BSEG.
AT FIRST.
PERFORM WRITE_COVER.
END AT.
AT NEW BUKRS.
PERFORM WIRTE_HEADER.
END AT.
PERFORM
WRITE_DETAIL.
AT END OF BUKRS.
PERFORM WRITE_FOOTER.
END AT.
ENDLOOP.
3. Matching Type
Just after loading some data, load the other data, match up the two records by a key.
The main requestion of the PG
Make
Make Report
Report
Procedure
Procedure
1st
1st
Procedure
Procedure
Master
Master READ
READ
Procedure
Procedure
Transaction
Transaction
READ
READ
Procedure
Procedure
When
When only
only
master
master
2nd
2nd
Procedure
Procedure
Execute repeatedly
When
When macthed
macthed
When
When only
only
transaction
transaction
(Mst=Trn)
(Mst>Trn)
(Mst<Trn)
FPT Software
Structuration
Structuration
FPT Software
Structuration
Performance
DB Access
Make the times of table access as small as possible.
Use INDEX at the conditon of WHERE command as possible.
( If not use INDEX, program read the all records one by one for searching the target record.
The performance is very bad. )
When use INDEX at the condition of WHERE command,
write the item by directionary order from the first INDEX item.
( When there is a omission or the order is different,
INDEX search is only effective for the higher rank which is correct.)
When use NOT/LIKE, IS INITIAL operator to the INDEX item at theWHERE
WHERE
command,
NOT BUDAT < SY-DATUM
index search is unworking. Use other operator as possible.
WHERE
*
Refer the text data from main data
READ TABLE IT_KNA1 INTO WA_KNA1
WITH TABLE KEY KUNNR = WA_KNA1-KUNNR.
ENDLOOP.
Don't use selection loop SELECTENDSELECT. (Use FOR ALL ENTRIES to select together in advance.)
FPT Software
Performance
Performance
When use non-unique condition to select one record, use option UP TO 1 ROWS, not use SELECT SINGLE.
(in this instance, you can use selection loop.)
ORDER By command is sorting while roading, it becomes load.
When there are great number of records, not use ORDER BY as possible.
When INDEX is necessary for ADDON table, discuss & set in the project.
When INDEX is necessary for SAP standard table, discuss with application staff,
and subbmit to BASIS term.
( One INDEX takes over 10%~20% volume of the table data, new addition needs plenty of discussion. )
Attention
When <it_tbl> is no data, option FOR ALL ENTRIES is ignored, all entries are loaded in.
Before FOR ALL ENTRIES command, make sure to chech if there is any data in the <it_tbl>.
Use FOR ALL ENTRIES command when there is any data in the <it_tbl>.
Repeated data is destroyed from the result setting.
( When stored internal table is setted as unique, if there are repeated datas in key unit,
the procedure breaks.)
Data type and length must be same between database table and internal table items.
ORDER BY / (Operator in the condition)LIKE / BETWEEN / IN are not used concurrently.
If there are repeated data on the internal table for condition,
delete the repeated datas inadvance for decreasing the select records from database.
Example)
DATA L_IT_VBAK
LIKE IT_VBAK.
FPT Software
Performance
Performance
Depending on the definition of the internal table key, the movement is different.
Unique Key
: When there is a repeated data in the key item, shortdumps error break out.
Non-Unique
Internal Table
There are 3 types of internal table, the characteristics of each is as below.
STANDARD Table
Key is non-unique.
When key access, sequential search is executed in the internal.
(Use INDEX for key access as much as possible.)
The searc time is proportional to the linear function of the table entries.
When use READ command, use BINARY SEARCH command to
execute binary search as much as possible.
(on this occasion, it need define non-unique key & sort by key item in advance.)
It is suitable for LOOPENDLOOOP command.
HASH Table
Key must be unique.
When key access, hush search is executed in the internal.
The searc time stays constant,
FPT Software
Performance
Performance
FPT Software
Performance
Performance
STANDARD TABLE
SORTED TABLE
HASHED TABLE
ENDLOOP
ENDLOOP
FPT Software
Performance
Modificatgion log
Modificatgion log
Start record after system integration test.
When Add / Modify / Delete program, attach number.
Adopt sequence number from '001' by the number of support times.
New log is added under the old log.
Example)
*----------------------------------------------------------------------*
* Program ID :XXXXXXXXXX
* Program Name:
*
* Program Summary:
*
* Completion Date : YYYY/MM/DD
ComposerRyoka Tarou(RSI)
* Coding Standards Version 7
* Development Version:SAP ECC 6.0
* Available Condition:Only Availabe for SAP ECC 6.0 Server
*----------------------------------------------------------------------*
* Ryoka Systems Inc.
* (C) Copyright Ryoka Systems Inc.
* All Rights Reserved
*----------------------------------------------------------------------*
* Modification Number : 001
* Modification Date : YYYY/MM/DD
Change by : Ryoka Hanako(RSI)
* Modification Content :
*
*----------------------------------------------------------------------*
* Modification Number : 002
* Modification Date : YYYY/MM/DD
Change by : Ryoka Ichiro(RSI)
* Modification Content :
*
*----------------------------------------------------------------------*
REPORT ZXXXX999 NO STANDARD PAGE HEADING
LINE-SIZE 140
LINE-COUNT 51
MESSAGE-ID ZPKZ001.
Modification Coment
Attach comment right before or after the line for add / change / delete.
* 001(XXX)START----------------------------------------------
Change start
* 001(XXX)END------------------------------------------------
Change end
FPT Software
Modificatgion log
Not delete the unnecessary logic by which change or delete, cancel out as a comment.
Example)
* 001(ADD)START---------------------------------------------CHECK NOT ( WK_D = C_CHECK ).
* 001(ADD)END------------------------------------------------
Add
IF ( WK_A = C_CHECK
OR
WK_B = C_CHECK ).
CASE WK_TYPE.
* 001(MOD)Start---------------------------------------------*
WHEN C_TYPE_I.
WHEN C_TYPE_S.
* 001(MOD)END-----------------------------------------------L_WK_WRITE = 1.
WHEN C_TYPE_M.
L_WK_WRITE = 2.
* 001(DEL)Start---------------------------------------------*
WHEN C_TYPE_U.
*
L_WK_WRITE = 3.
* 001(DEL)END-----------------------------------------------WHEN OTHERS.
ENDCASE.
Modification
(Cancel out
the existing logic)
Delete
(Cancel out
ENDIF.
The existing
modification line
Change
Pattern 1
* 001(MOD)START---------------------------------------------* READ TABLE IT_TBL INTO WA_TBL WITH KEY NO = L_WK_WRITE.
* 002(MOD)START---------------------------------------------* READ TABLE IT_TBL INTO WA_TBL WITH KEY NO = L_WK_WRITE
*
ID = 'ABC'.
READ TABLE IT_TBL INTO WA_TBL WITH KEY ID = 'DEF'.
* 002(MOD)END-----------------------------------------------* 001(MOD)END------------------------------------------------
FPT Software
Modificatgion log
Modificatgion log
Pattern 2
* 002(MOD)START---------------------------------------------** 001(MOD)START---------------------------------------------** READ TABLE IT_TBL INTO WA_TBL WITH KEY NO = L_WK_WRITE.
* READ TABLE IT_TBL INTO WA_TBL WITH KEY NO = L_WK_WRITE
*
ID = 'ABC'.
** 001(MOD)END------------------------------------------------
If it is difficult to understand
as changing logic only,
comment including the previous comment.
FPT Software
Modificatgion log
FPT Software
Modificatgion log
FPT Software
Modificatgion log
understand
previous comment.
FPT Software
Modificatgion log
Basic Design
Screen Definition
Radio Button
When procedure separates by purpose, use radio button for selection.
Example)
There are plural types of document
Output Document
File Path
Receipt Goods
Delivery Goods
Local File
Both
AP Server File
is prohibited.
Function Selection
Change
Display
Delete
Insert
Change
Display
Delete
Specify File
Make sure setting up the F4 search function(file specify dialog) to the local file name item.
Define format/text as below to the server file name item.
Input
Logic File Name
Input File Name
Input
Log
Authority Check
FPT Software
Basic Design
Basic Design
Transaction
When there are plural functions such as Insert/Change/Delete, register transaction by function unit,
seperate procedure in the program. (Don't set up selection button on the initial screen)
FPT Software
Basic Design