Sei sulla pagina 1di 49

ABAP Standard Coding Rule

ERP Common System


ABAP Standard Coding Rule

7th Edition

Creation Date

2014/01/14

Date Last
Modified

2014/01/14

ABAP Standard Coding Rule

06/02/2016 03:28:54 3/49


Change Log
Ver

Effective Date

1.0

2014/01/14

Publisher

FSU1.BU8 - Technical Team

Changed Contents

New Document

Change Log

06/02/2016 03:28:54 4/49


Change Log
Ver

Effective Date

Publisher

Changed Contents

Change Log

06/02/2016 03:28:54 5/49


ABAP Standard Coding Rule
Revised Sheet Name

Change Management No.

Change Log

06/02/2016 03:28:54 6/49


ABAP Standard Coding Rule
Revised Sheet Name

Change Management No.

Change Log

06/02/2016 03:28:54 7/49

Contents
Initial
initial
initial
initial
Initial

ABAP Standard Codin

Setting
setting
setting
setting
Setting

ALV

Default Line Length for Editor

Screen Item Definition

Set Pretty Printer

Field Name (Column Title)

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

Event Keyword Composition


Subroutine Segmentation

Indent

Subroutine (FORM) Name

Comment

What's Structuration Design

Literal

Standardization of Program Structurat

Specify type
Prohibition Item
Message

Performance

Naming (Variable / Constant)


Print Format

DB Access

Extended Program Check

Internal Table

Modificatgion log
Dynpro
Naming

Modificatgion log

GUI Status

Modification Coment

Screen Item Definition


Method of Using OK Code
Execution Point of User Command

Basic Design

Save Procedure
Sort Procedure of Table Control Data

Screen Definition

Screen Transition (Pattern as Return)

Updata Addon Table

Confirmation Pop-up

Type of Input-output File

the PG Structure of Dynpro Expression from Selection Screen

Authority Check

the Method of Outputting List from Dynpro

Transaction

Function Module
Description Method
Naming (Parameter)

FPT Software

Contents

06/02/2016 03:28:54 8/49

Contents

ABAP Standard Codin

Table Type Parameter

FPT Software

Contents

06/02/2016 03:28:54 9/49


ABAP Standard Coding Rule

on Design
Program Structuration

FPT Software

Contents

06/02/2016 03:28:54 10/49


ABAP Standard Coding Rule

FPT Software

Contents

06/02/2016 03:28:54 11/49

Initial Setting

ABAP Standard Coding Rule

Default Line Length for Editor


Set maximum digit number as 72 as below.
User-Specific Settings
ABAP Editor (SE38/SE80)
MenuUtilities Setting

Check 'Default Line Length'

Set Pretty Printer


Set character type of source code as 'Uppercase' or 'Keyword Uppercase' as below.

Not check 'Convert upper-/lowercase'


(DefaultUppercase)
Or
Check 'Convert upper-/lowercase'
Check 'Uppercase' or 'keyword Uppercase'

Others

FPT Software

Initial Setting

06/02/2016 03:28:54 12/49

Initial Setting

ABAP Standard Coding Rule

Set other setting items as default.

FPT Software

Initial Setting

06/02/2016 03:28:54 13/49

Head Comment

ABAP Standard Coding Rule

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

Enter registered Program ID in uppercase.

Program name

Enter the same name as Program Title

Program Summary

Specification document : Enter Procedure Summary

Completion Date

Completion date (unit test completion date)

Composer

Enter Name'(RSI)' ( 1SPACE between Name & (RSI) )

CodingStandardsVer. the newest version when registered program ID


Development Version Component Version which PG is created
(MenuSystemStatus)
Rewrite as below when
R/3 ENTERPRISE
SAP ECC 5.0

ERP2004

SAP ECC 6.0

ERP2005

Available Condition If there are some limits in running system.

Description place
Report

The beginning of program

Dynpro

The beginning of Modulpool

Function Module

Beneath of the header which is created automatically at the source code tab.

FPT Software

Header Comment

06/02/2016 03:28:55 14/49

Head Comment

ABAP Standard Coding Rule

Declaration Header
Example)
*----------------------------------------------------------------------* Tables Definition
*----------------------------------------------------------------------TABLES: XXXXXXX.

Delete the parts


which is not used

*----------------------------------------------------------------------* Include Definition


*----------------------------------------------------------------------INCLUDE: XXXXXXX.
*----------------------------------------------------------------------* Control Definition
*----------------------------------------------------------------------CONTROLS: TL_XXXX TYPE TABLEVIEW USING SCREEN 999.
*----------------------------------------------------------------------* Type Definition
*----------------------------------------------------------------------TYPES: BEGIN OF TA_XXXX,
XXXX(20) TYPE C,
XXXXX
TYPE XXXX-XXXXX,
END OF TA_XXXX.
*----------------------------------------------------------------------* Work Area Definition
*----------------------------------------------------------------------DATA: WA_XXXX
TYPE TA_XXXX,
BEGIN OF WA_XXXXXX,
XXXXX
TYPE XXXX-XXXXX,
XXXXX
TYPE XXXX-XXXXX,
END
OF WA_XXXXXX.
*----------------------------------------------------------------------* Inner Table Definition
*----------------------------------------------------------------------DATA: IT_XXXX
TYPE TABLE OF TA_XXXX,
IT_XXXXXX
LIKE TABLE OF WA_XXXXXX,
R_XXXX
TYPE RANGE OF XXXX-XXXXX.
*----------------------------------------------------------------------* Variable Definition
*----------------------------------------------------------------------DATA: WK_XXXXX
TYPE XXXX-XXXXX,
FLG_XXXXX
TYPE C.
FIELD-SYMBOLS:
<FS_XXXXX> TYPE X.
*----------------------------------------------------------------------* Constant Definition
*----------------------------------------------------------------------CONSTANTS:
C_XXXXX
TYPE X VALUE 'XXXXXXXXXX'.
*----------------------------------------------------------------------* Selection Screen Definition
*----------------------------------------------------------------------PARAMETERS:
P_XXXXX
TYPE XXXX-XXXXX OBLIGATORY.
SELECT-OPTIONS:
S_XXXXX
FOR XXXX-XXXXX.
*----------------------------------------------------------------------* CLASS Definition
*----------------------------------------------------------------------CLASS CL_XXXX DEFINITION.
PUBLIC SECTION.
FPT Software
METHODS: M_XXXX.
ENDCLASS.

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

ABAP Standard Coding Rule

*----------------------------------------------------------------------CLASS CL_XXXX DEFINITION.


PUBLIC SECTION.
METHODS: M_XXXX.
ENDCLASS.

Event Header
Report
************************************************************************
INITIALIZATION.
************************************************************************
************************************************************************
AT SELECTION-SCREEN.
************************************************************************

Delete the parts


which is not used

************************************************************************
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.
*----------------------------------------------------------------------*-----------------------------------------------------------------------

Only Event Header

Dynpro Template.TXT

Header Comment

*----------------------------------------------------------------------PROCESS BEFORE OUTPUT.


*----------------------------------------------------------------------*-----------------------------------------------------------------------

Head Comment
PROCESS AFTER INPUT.

06/02/2016 03:28:55 16/49


ABAP Standard Coding Rule

*-----------------------------------------------------------------------

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 Header ( Module Header )


*&---------------------------------------------------------------------*
*&
Form xxxxxxxxxxxxx
*&---------------------------------------------------------------------*
*
[1-2-3]Procedure
*----------------------------------------------------------------------*

Subroutine name

Enter FORM name which is called from PERFORM command

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

Description of the procedure

FPT Software

Header Comment

06/02/2016 03:28:55 17/49

Coding

ABAP Standard Coding Rule

Indent
The beginning position is as below.
1st column

Global Date Declaration (TYPES/DATA etc.)

Selection Screen Definition


3th column

Event Keyword

the other procedure description

( Local ( inside FORM ) data declaration etc. )


Operator of AND operation and OR operation is writing

at the same column of the commands.


Shifting 2 columns to the right per the logic

when writing commands (key word).


Example)
*----------------------------------------------------------------------* Variable Definition
*----------------------------------------------------------------------DATA: WK_A TYPE C.
Global Date Declaration
************************************************************************
START-OF-SELECTION.
************************************************************************
Event Keyword
PERFORM MAIN_PROC.
The other procedure
*&---------------------------------------------------------------------*
description
*&
Form MAIN_PROC
*&---------------------------------------------------------------------*
*
[2-1]Main Procedure
*----------------------------------------------------------------------*
FORM MAIN_PROC.
DATA: L_WK_WRITE(2)

TYPE N.

IF ( ( WK_A = C_CHECK
OR
WK_B = C_CHECK )
AND
WK_C = C_CHECK
).

The other procedure


description
The other procedure
description
AND operation
/ OR operation

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)

the other procedure


description
Command (Keyword)

Comment

FPT Software

Coding

06/02/2016 03:28:55 18/49

Coding

ABAP Standard Coding Rule

Can use both Asterisk(*) & double quotation(").


Do not write asterisk when it is not necessary.

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

Use for data selection


Table Work Area
(TABLES command)

for Dynpro Screen Item definition etc.


it is not problem to use.

Internal Table
Definition

Text Symbol

Use OCCURS command to define


internal table.
Use for constant

Use for Screen Item / Report Item

(for message etc.)

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

>< =< => EQ NE

Use below

LT GT LE GE

= <> < > <= >=

ADDSUBSTRACTMULTIPLYDIVIDE

Use below

COMPUTE command

+ - * / MOD **(index)

STOP command

Use CHECK/EXIT command and Flag to

Interruption
Procedure

pass following procedure.

Specify the Condition Literal'JA''J'


of Language Key
Example) WHERE SPRAS = 'J'.

System VariableUse SY-LANGU

0 Division

Example) WHERE SPRAS = SY-LANGU.

0 Division

Because shortdumps happen , if denominator

(Division which denominator is 0)

0 is possible , make an avoid procedure.

Omit ASCENDING / DESCENDING

Attach ASCENDING / DESCENDING


Example)

Sort

SORT IT_TBL

BY

FIELD1 ASCENDING
FIELD2 DESCENDING

TABLES Parameter

Use USING / CHANGING Parameter to

FPT Software
Subroutine
(Parameter Interface)

Coding

06/02/2016 03:28:55 19/49

Coding

ABAP Standard Coding Rule


deliver Table type data

Subroutine
(Parameter Interface)

Deliver by reference(1).

Deliver by value (2) .

Example) USING V_WK_XXX

Example) USING VALUE(V_WK_XXX)

Not define data type

Make sure to specify data type.

Example) USING VALUE(V_WK_XXX).

Example) USING VALUE(V_WK_XXX) TYPE XXXXX.

Local Varible / Fixed Declaration in the logic

Make sure to decalare just under the FORM

Number Definition

line.

Reference Deliver Add the reference of Substantial Parameter to Provisional Parameter,

and change the Substantial Parameter directly.


USING change the parameter the of same with CHANGING.
Value Deliver

Add the value of Substantial Parameter to Provisional Parameter ,


and change the value in the subroutine.
CHAGING : Reflect the changed value to the Substantial Parameter.
USING

: Not reflect the changed value to the Substantial Parameter.

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

When appropriate message is not exist in common message class,


create an new addon message class.
Addon message

When entry message is 1 sentence , not attach '.' .

entry rule

(attach '.' when there are more than 2 sentences).


Message with only '&' is forbidden.

Message type is determinated by purpose.


Message Type

Action

Abnormal End

ROLLBACK is executed and program closes.

Error

Procedure breaks.

Warning

Procedure breaks instantly, press ENTER to continue.

Information

Display in dialog box.


The procedures after command continue as usual.

Status

Display in the next screen.


The procedures after command continue as usual.

Abnormal End (Short Dumps)

The same as type A.


When program ends, short dumps are output.

Naming (Variable / constant)

FPT Software

Coding

06/02/2016 03:28:55 20/49

Coding

ABAP Standard Coding Rule

Attach the below prefix for the variable / constant.

Type
Type

Variable

Constant

Item

Global
Prefix

Local

Example

Prefix

Example

Date Type

TA_

TA_INIT

L_TA

L_TA_VBRK

Table Type Date Type

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

Radio Button Group

RG_

RG_1

Definition /

Radio Button

RB_

RB_CLASS

Object

Check Box

CB_

CB_FILE

Push Button

PB_

PB_START

Tab Strip Control

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

WK_SURYO Right WK_KWMENG

False

C_OR

Constant is named as the meaning.


Example) Constant : TYPE VBAK-AUART VALUE '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

Dont use format which is except from standard as much as possible.


(When use, manage the format by project.)

Extended Program Check


After program making , must execute Extended Program Check.

FPT Software

Coding

06/02/2016 03:28:55 21/49

Coding

ABAP Standard Coding Rule

Error must to be solved , Warning / Message should be solved as much as possible.

Select All Items

FPT Software

Coding

06/02/2016 03:28:55 22/49

Dynpro

ABAP Standard Coding Rule

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

INPUT VALUE SEARCH

F11

SAVE

SAVE

F12

CANC

CANCEL

Shift + F3

END

END

Standard function key (Recommend)


Function Key

Function Code

Function Text

Icon

F2

PICK

Select (DBL Click)

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

Sort in Ascending Order ICON_SORT_UP

Ctrl + Shift + F6

DSRT

Sort in Descending Order ICON_SORT_DOWN

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

Execute and Print

ICON_PRINT

Ctrl + Shift + F9

EXPO

Export

ICON_EXPORT

Ctrl + PAGEUP

P--

The First Page

ICON_FIRST_PAGE

PAGEUP

P-

The Previous Page

ICON_PREVIOUS_PAGE

PAGEDOWN

P+

The Next Page

ICON_NEXT_PAGE

CTRL+PAGEDOWN

P++

The Last Page

ICON_LAST_PAGE

FPT Software

Dynpro

06/02/2016 03:28:55 23/49

Dynpro

ABAP Standard Coding Rule

Screen Item Definition


Use structure for defining screen item.
Merit of using structure
It is possible for using Dic referring option.
The setting of digits is suggested automatically.
When there is a input value (Pulldown List) in the item,
it can show the value which is same as standard type automatically.
Text label of input item is made at the left automatically.
It is appropriate to set item for reference item.
Ex)

Currency item becomes decimal 2 digits as default.


If reference item is setted in advance, item shows as the setting.
Such as, JPY is no decimal, USD is decimal 2 digits.

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.

Method of Using OK Code


When PAI event breaks (input check error etc.),
refer and clear OK_CODE for passing though the subsequent processing normally.
Name Dynpro element type 'OK' as 'OK_CODE'.
Define 'SAVE_OK', referring to SY-UCOMM.

MODULE USER_COMMAND_0100 INPUT.


SAVE_OK = OK_CODE.
CLEAR OK_CODE.

At the beginning of MODULE


'EXIT_COMMAND_xxxx' / 'USER_COMMAND_xxxx',

CASE SAVE_OK.

substitute the value of OK_CODE to SAVE_OK.

WHEN XXX.

Clear the value of OK_CODE.


Hereafter, use SAVE_OK to refer to the function code.

FPT Software

Dynpro

06/02/2016 03:28:55 24/49

Dynpro

ABAP Standard Coding Rule

Execution Point of User Command


Execute user command (USER_COMMAND_xxxx) after item check.

Save Procedure
When press SAVE button, change confirmation is not necessary.
With or without change, execute SAVE procedure with no condition.

Sort Procedure of Table Control Data


SORT command don't control the output data order when the item key is same.
When sort the contents of table control continuously by pressing sort button,
add STABLE option (Keep up the output order as last time) to SORT command.

Screen Transition (Pattern as Return)


The basic is as below, however there is other variety by business requirements.
Back

Button (USER-COMMAND)

Back to the previous screen.


Execute input check in advance.
When the 1st screen, close the program
(Input check is not necessary).

Exit

Button (EXIT-COMMAND)

Cancel Button (EXIT-COMMAND)

Close the program.


Back to the 1st screen.
When the 1st screen, close the program.

Cancel

Previous

Cancel

Screen
END
Previous
Screen

1st Screen
1st Screen
Close

Previous

Cancel

Screen

Check 2nd Screen


2nd Screen

Check 3th Sreen


3th Sreen

Close

Close

Confirmation Pop-up
When BACK/EXIT/CANCEL is pressed on the screen where is a save procedure,

FPT Software

Dynpro

06/02/2016 03:28:55 25/49

Dynpro

ABAP Standard Coding Rule

check wheather there is a change. If there is a change, show confirmation pop-up.


Function Module

POPUP_TO_CONFIRM

Title Line

Message Line

Confirmation The input contents will be lost, is it OK?

Response Yes
No

Response Button
Button1

Yes

Button2

No

Contiue the screen move procedure.


Stop move procedure, back to the previous screen.

the PG Structure of Dynpro expression from Selection Screen


Make the main program as report program (executable report program).

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

Use CALL SCREEN command to move to Dynpro Screen.


Dynpro200
Program type is Report in 'Statement of Naming Standards'.

the Method of Outputting List from Dynpro


In processing of PBO/PAI, execute list output logic,
after using LEAVE TO LIST-PROCESSING command to start list processor.

FPT Software

Dynpro

06/02/2016 03:28:55 26/49

Function Module

ABAP Standard Coding Rule

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

Structure TBL Date Type

Import

I_

IS_

IT_

Export

E_

ES_

ET_

Changing

C_

CS_

CT_

Table

Prohibition

Exception

Unnecessary

Table Type Parameter


Table parameter is forbidden.
When use Table Data (Interal Table) as parameter, referring to table data type structure,
set & use Import/Export/Changing parameter.
Example)

Table Date Type


Structure

FPT Software

Function Modual

06/02/2016 03:28:55 27/49

Function Module

ABAP Standard Coding Rule

Structure

FPT Software

Function Modual

06/02/2016 03:28:55 28/49

ALV

ABAP Standard Coding Rule

Screen Field Definition


Use Structure to define Screen Field.

Field Name (Column Title)


If Field name (Data Element : Field Label) of DB is difficult to understand ,
change the name to an appropriate one.
Example) DB Item Name Name 1

Output Item NameCustomer Number

Don't use the same field Name in a structure.

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

06/02/2016 03:28:55 29/49

ALV

ABAP Standard Coding Rule

FPT Software

ALV

06/02/2016 03:28:55 30/49

SmartForms

ABAP Standard Coding Rule

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_

Line Type HEADER

LI_H(_)

Line Type MAIN

LI_M(_)

Line Type FOOTER

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_

When define plural ones, use (_).

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

06/02/2016 03:28:55 31/49

SmartForms

ABAP Standard Coding Rule

FPT Software

SmartForms

06/02/2016 03:28:55 32/49

Structuration

ABAP Standard Coding Rule

Event Keyword Composition


the order of procedure logic composition is as below.
INITIALIZATION

Initial Procedure

Execute the preprocess, such as


setting the initial value to screen item & etc..

AT SELECTION-SCREEN

Selection Screen
Procedure

START-OF-SELECTION

Main Procedure

END-OF-SELECTION

End Procedure

Execute selection item check , such as


authority check / screen item exist check etc..
Execute main procedure, such as Select / edit date,
output report etc.. Don't delete even if not using.
Execute output procedure,
such as report / file etc. output.

Execute the procedure which right before outputting

TOP-OF-PAGE

New Page Procedure

END-OF-PAGE

Footer Procedure

Execute the procedure which output footer.

AT USER-COMMAND

Input Event

Execute the procedure which at every Input Event.

a new page, such as output the head of report.

Procedure
AT LINE-SELECTION
FORM

Line Selection

Execute the procedure when the line is pressed

Procedure

in the report screen.

Procedure

Procedure which is called by the command PERFORM.

Delete the keyword which not be executed (Exclude START-OF-SELECTION).


Not describe the detail logic right under the event keyword.
(Right under the event keyword, only call the subroutine,
execute the detail procedure in the subroutine.)
Subroutine Segmentation
Divide the subroutine by function unit for reusing.
Subroutine (FORM) Name
Consider the main procedure in the subroutine to be easy to understand.
Make sure the Verb to be in the beginning.
Example)
Initial Procedure

INIT_PROC

Main Procedure

MAIN_PROC

End Procedure

END_PROC

Search Procedure
Internal Table Edit

SELECT_MARA

Individual Table

SELECT_MARA_JOIN

Plural table join/the 1st table name+'_JOIN'

SET_IT_TBL

Procedure
WRITE_HEADER

Output head

Report Output Procedure WRITE_DETAIL

Output Item

WRITE_FOOTER

Output Footer

FPT Software

Structuration

06/02/2016 03:28:55 33/49

Structuration

ABAP Standard Coding Rule

The under is the general explanation materials about structuration.

What's Structuration Design


the Background of Structuration
Program is made just by using Follow Chart & Coding Form in the past.
The structuration is poor, and logic is complicated, coding & changing had a big cost.
And quality was not good.
Structuration design analyzes function to the simple shape
and design the structure of program systematicly.
Structuration design is a design method which make the program be easy to understand.
the Effect of Structuration
A high productivity ( can be managed by module unit).
Easy to maintenance.
Easy to see, easy to understand. The thought of design is easy to understand.
The time of test is short.
What is Module
Module is a unit as which divide the program by top-down function unit.
the Order of Structuration
1. Declare the function of the program ( Function Analyze).
2. Write main function basing on the program & date flow.
3. Combinate the main function and the subsidiary function by top-down approach.

Standardization of Program Structuration


the Basic Structuration
The all programs consist of 3 procedures ( sessions ) as below.

FPT Software

Structuration

06/02/2016 03:28:55 34/49

Structuration

ABAP Standard Coding Rule

Initial Procedure Procedure which is executed before main procedure,


such as open file, set initial value etc..
Main Procedure

The typical procedure of program, such as make report, make file etc..

End Procedure

Procedure which is executed after main procedure,


such as close file etc..

Position in the structural drawing

Program
Program

Initial
Initial
Procedure
Procedure

Main
Main
Procedure
Procedure

End
End
Procedure
Procedure

Basic Procedure Type


Main procedure has 3 types as below.
(Single or combination)

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

2. Control Break Type


execute repeatedly until the condition is (not) met.

Make
Make Report
Report
Procedure
Procedure

1st
1st
Procedure
Procedure

FPT Software

2nd
2nd
Procedure
Procedure

Structuration

06/02/2016 03:28:55 35/49

Structuration

ABAP Standard Coding Rule


1st
1st
Procedure
Procedure

READ
READ
Procedure
Procedure

Execute

2nd
2nd
Procedure
Procedure

only 1 time

Detail
Detail
Procedure
Procedure

When control break condition is met


break 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.

Check control , when it breaks,


Output the contents,
or write the contents to the other file.

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

Execute only 1 time

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

06/02/2016 03:28:55 36/49

Structuration

ABAP Standard Coding Rule

FPT Software

Structuration

06/02/2016 03:28:55 37/49

Performance

ABAP Standard Coding Rule

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

BUDAT >= SY-DATUM

( It is same as the SELECT-OPTIONS for search condition. )


When join table, write the condition item which is except the WHERE command
by the order of FROM / JOIN table.
When the amount of the table is small, select the data in advance together,
and get the data by READ command.
Table such as text table which is expected the repeaded record,
not JOIN the table but select the record in a new SELECT command.
Example) Transaction series
* Select main data
SELECT
T1~KUNNR

INTO TABLE IT_VBAK


FROM VBAK AS T1
JOIN VBAP AS T2 ON
WHERE
.

* Select text data


SELECT KUNNR
NAME1
INTO TABLE IT_KNA1
FROM KNA1
FOR ALL ENTRIES IN IT_VBAK
WHERE KUNNR = IT_VBAK~KUNNR.

LOOP AT IT_VBAK INTO WA_VBAK.

*
Refer the text data from main data
READ TABLE IT_KNA1 INTO WA_KNA1
WITH TABLE KEY KUNNR = WA_KNA1-KUNNR.

ENDLOOP.

Example) Master series


SELECT T1~MATNR
T2~MAKTX
INTO IT_MARA
FROM MARA AS T1
JOIN MAKT AS T2 ON T1~MATNR = T2~MATNR
AND T2~SPRAS = SY-LANGU
WHERE .
The relationship of Master and Name is 1:1.
Because there is not repeated, store the
data to one internal table.
The occasion when key item can be focused on
the specific condition (Language Key),
not use WHERE command, write the condition
at the JOIN command.
Separate the data such as name
which is assumed to be repeated,
from the main internal table, road into
the other internal table when neccesary.

Don't use selection loop SELECTENDSELECT. (Use FOR ALL ENTRIES to select together in advance.)

FPT Software

Performance

06/02/2016 03:28:55 38/49

Performance

ABAP Standard Coding Rule

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. )

FOR ALL ENTRIES


For high performance, use FOR ALL ENTRIES command to only select the data which is necessary.
Example)
SELECT

FOR ALL ENTRIES IN <it_tbl>


WHERE <condition>.

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.

* Delete the repeated data


L_IT_VBAK[] = IT_VBAK[].
SORT L_IT_VBAK BY KUNNR ASCENDING.
DELETE ADJACENT DUPLICATES FROM L_IT_VBAK COMPARING KUNNR.
* Select the text data
SELECT KUNNR
NAME1
NAME2
INTO TABLE IT_KNA1
FROM KNA1
FOR ALL ENTRIES IN L_IT_VBAK
WHERE KUNNR = L_IT_VBAK~KUNNR.

FPT Software

Performance

DELETE ADJACENT DUPLICATES FROM L_IT_VBAK COMPARING KUNNR.


* Select the text data
SELECT KUNNR
NAME1
NAME2
INTO TABLE IT_KNA1
FROM KNA1
FOR ALL ENTRIES IN L_IT_VBAK
WHERE KUNNR = L_IT_VBAK~KUNNR.

Performance

06/02/2016 03:28:55 39/49


ABAP Standard Coding Rule

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

: If there is a repeated data in the entire select datas,


only one data be selected.

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

06/02/2016 03:28:55 40/49

Performance

ABAP Standard Coding Rule

not be proportional to the linear function of the table entries.


( When records are small, the performance is lower than STANDARD TABLE.)
Don't use INDEX for access.
Don't use APPEND command.
Memory usage is bigger than the other types.
It is suitable for direct access( READ command of specifying key) of unique data.
SORT Table
Usually keep the right sorted shape (SORT command is prohibited).
It is OK for either unique key or non-unique.
When key access, binary search is executed in the internal.
The searc time is proportional to the linear function of the table entries.
If key is non-unique, adopt the entry which INDEX is smallest.
It is possible for INDEX access.
When use INDEX to execute INSERT command, it checks if sort order is right.
in this instance the performance is lower than the other types.
When access for SORT table, make sure to use table key.

Applicable condition of each type


The 3 types of internal table is used as the occasions as below.
Use HASH/SORT Table as much as possible.
STANDARD Table
When not execute key access(WHERE READ WITH (TABLE) KEY ).
The number of the records is small.
Impact is big, if use HASHED/SORTED TABLE, when key is changed,
the work of editting is hard .
Example) Only use for the entire entries LOOP(sequential search)
the table for head data.
The table which only execute READ/DELETE command by INDEX.
HASH Table

FPT Software

Performance

06/02/2016 03:28:55 41/49

Performance

ABAP Standard Coding Rule

The occasion except above.


The occasion which unique key can be setted.
(No LOOP command) Only READ procedure is executed.
Example) Material text table
SORT Table
The occasion which except above.
Example) Item data table

Typical example of use


LOOP Internal TBL for Header
LOOP Internal TBL for Item
READ Internal TBL for Text

STANDARD TABLE
SORTED TABLE
HASHED TABLE

ENDLOOP
ENDLOOP

Release the resource


Try not to compress the resource by the data which is not used.
when the internal TBL has not been used, use FREE command to release the resource.

FPT Software

Performance

06/02/2016 03:28:55 42/49

Modificatgion log

ABAP Standard Coding Rule

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

Modification Number : Usually write from the 3rd place.


Modification ModeAdd(ADD) / Modification(MOD) / Delete:(DEL)

FPT Software

Modificatgion log

06/02/2016 03:28:55 43/49


Number : Usually write from the 3rd place.
Modificatgion Modification
log

ABAP Standard Coding Rule

Modification ModeAdd(ADD) / Modification(MOD) / Delete:(DEL)


START / ENDStartSTART / EndEND
* 001(XXX)Start---------------------------------------------separator line : up to the 60th place

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 logic)

When change(add/delete) the logic once more, if it is difficult to understand


by using comment to encircle the target logic only, encirle the previous comment.
Example)
* 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-----------------------------------------------

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

* 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------------------------------------------------

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------------------------------------------------

06/02/2016 03:28:55 44/49

ABAP Standard Coding Rule

If it is difficult to understand
as changing logic only,
comment including the previous comment.

READ TABLE IT_TBL INTO WA_TBL WITH KEY ID = 'DEF'.


* 002(MOD)END------------------------------------------------

FPT Software

Modificatgion log

06/02/2016 03:28:55 45/49

FPT Software

Modificatgion log

06/02/2016 03:28:55 46/49

FPT Software

Modificatgion log

06/02/2016 03:28:55 47/49

understand

previous comment.

FPT Software

Modificatgion log

06/02/2016 03:28:55 48/49

Basic Design

ABAP Standard Coding Rule

Screen Definition
Radio Button
When procedure separates by purpose, use radio button for selection.
Example)
There are plural types of document

Destination of input/output file


seperates by local/server

Output Document

File Path

Receipt Goods
Delivery Goods

Local File

Both

AP Server File

Code input selection which the item is not referred to dictionary


Function Selection

is prohibited.

Function Selection

Please select No.


Insert

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

Logic File Name


Output
Output File Name

Logic File Name


OutputLog File Name

Error File Name

Update Addon Table


When update addon table, make sure to execute exclusion access control (lock the target table & data).

Type of Input-output File


Tab break file is recommended.

Authority Check

FPT Software

Basic Design

06/02/2016 03:28:55 49/49

Basic Design

ABAP Standard Coding Rule

User authority check.

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

Potrebbero piacerti anche