Академический Документы
Профессиональный Документы
Культура Документы
Table Of Contents.
1. INTRODUCTION............................................................................................................................2
1.1. PURPOSE.....................................................................................................................................2
1.2. SCOPE.........................................................................................................................................2
1.3. AUDIENCE...................................................................................................................................2
1.4. RELATED DOCUMENTS...............................................................................................................2
2. DOCUMENT STRUCTURE..........................................................................................................3
2.1. HEADER SECTION.......................................................................................................................3
2.2. DATA SECTION............................................................................................................................3
2.2.1. Variable Names..................................................................................................................4
2.3. LOGIC SECTION..........................................................................................................................5
2.3.1. Statement Layout...............................................................................................................5
2.3.2. Comments..........................................................................................................................6
2.3.3. Forms And Functions........................................................................................................7
3. REVISIONS......................................................................................................................................9
3.1. IN-HOUSE PROGRAMS...............................................................................................................13
3.2. SAP STANDARD PROGRAMS.....................................................................................................13
3.2.1. Chnge...............................................................................................................................13
3.2.2. Date..................................................................................................................................14
3.2.3. Who..................................................................................................................................14
3.2.4. Reason..............................................................................................................................14
3.2.5. Access Key.......................................................................................................................14
3.2.6. Tracking Changes............................................................................................................14
4. MODULARISATION....................................................................................................................15
4.1. INCLUDE PROGRAMS................................................................................................................15
4.2. FORMS (PROCEDURES).............................................................................................................15
4.3. FUNCTIONS...............................................................................................................................15
4.4. MACROS...................................................................................................................................15
List Of Figures.
Figure 1 - SAP Revision History................................................................................................................9
Figure 2 - SAP Change Report.................................................................................................................13
List Of Tables.
Table 1 - Variable Prefixes.........................................................................................................................4
Table 2 - SAP System Variables By Name...............................................................................................19
Page 1
SAP Procedure
1. Introduction.
1.1. Purpose.
The purpose of this document is to define a standard for programming in ABAP/4. It provides
the standard to which code inspections if implemented should take place. These standards are
designed to ensure:
Consistency in Coding.
Maintainability of Code.
Legibility of Code.
1.2. Scope.
This document addresses programming in ABAP/4 for R/3 3.0e.
1.3. Audience.
This document is intended for all programmers working on Interim Technology UKs SAP
system whether permanent or contract staff, It assumes an understanding of the SAP
environment.
2.
Page 2
SAP Procedure
3. Document Structure.
The structure of an ABAP program shall be as follows:
Header Section
Data Section
Logic Section
Forms Section.
***********************************************************************
*
* Program: ZSO0630
* Title: Order Intake Analysis By Profit Centres
* Analyst: Cecilia Chan
* Programmer: Richard Harper
* Date: 12/05/98
* Doc. Id: 31-10010013-06
*
***********************************************************************
*
* Change History
* Date Reason Who
*
REPORT ZSO0630 Message-Id 38
Line-Count 64(1)
Line-Size 132
No Standard Page Heading.
Constants
Tables
Data
Select-Options and parameters
Field Groups
Field Symbols
Definitions not defined in the SAP data dictionary should be commented as to their use. Eg:
Page 3
SAP Procedure
The variables should be prefixed with a single character and an under score (_). The
single character defines the type of variable:
The second part of the variable name should identify the variable. If the variable is a
copy of a SAP defined variable and has an identical use then this portion of the name
should be the same as the definition. For example a working storage version of
mara-matnr could be defined as w_matnr.
Where possible always declare a variable using the like keyword which associates a
variable definition with a data dictionary item.
Within data definitions (and code blocks), system variables will be used where
required and not the literal value. (eg. Sy-langu instead of E). A list of system
variables is provided in appendix A.
Do not use two underscores within a variable name such as w__count as this is the
convention used in the programs documented in PROC032 'Common Programming
Procedures' to prevent conflict with any user programs.
Apart from that variable names should be clear, meaningful abbreviations of what
they actually represent. Over long variable names (such as w_vatonsales) should be
avoided where the abbreviation (w_vat) is just as easily understood.
Page 4
SAP Procedure
Initialisation
At Selection-Screen
Start-Of-Selection
Get Tables
Get Tables Late
End-Of-Selection
Top-Of-Page
End-Of-Page
At Line-Selection
At Pf-keys
At User-Command
Top-Of-Page During Line Selection
3.3.1.2. Indentation.
Program code should be indented to allow the structure and flow of the
program logic to be easily observed.
Indents should begin at the column of the next word on the line causing the
indentation:
Page 5
SAP Procedure
Loop At Vbak.
Perform Routine1.
EndLoop.
If w_material <> .
Perform ProcessMaterial.
Case w_material.
When 1.
.
.
When 2.
.
.
.
EndCase.
EndIf.
Data declarations should make sure that the type or like reserved words
all line up on the same column as can be seen in section 2.2 above.
3.3.2. Comments.
Code should be commented in useful, meaningful ways. Comments should always
highlight a block of codes functionality. In order to take advantage of ABAPs print
functionality where comments can be highlighted, all comments should begin with
an asterisk in column one, with the actual text starting at the indent level of the code.
To highlight comments even further, a blank comment should be at the top and
bottom of the comment block:
*
* Any Model here ?
*
if w_modelfound = True.
*
* Report Dependant Selection.
*
Clear t_Repdata.
Move-Corresponding vbak to t_repdata.
Case w_repid.
When c_zso0600.
Perform GetOrderDiscount
using vbak-vbeln
Changing w_kzwi6.
*
* Get the change reason.
*
Page 6
SAP Procedure
Wherever possible Forms should be self contained. Any communication with the
outside world should be carried out using formal parameters. Any variables used in
the routine should be declared inside the routine.
3.3.3.1. Local.
The local keyword is used in association with a previously defined global
variable name. The current value of the variable is pushed on the stack at
the start of the routine and pulled from the stack at the end, thus allowing
changes to be made to the variable whilst keeping the changes within the
currently running procedure.
3.3.3.2. Static.
This keyword preserves the value of the declared variable across procedure
calls. This should be used where a value has to be carried across two or
more calls to the procedure. Without using this keyword, the variable
would have to be declared at a higher level. If the use of the variable is
restricted to the current or lower procedures and the value has to be
preserved then this keyword should be used. Again, to preserve
readability of the program.
Forms should be prefixed with the following comment block, also available in
ZBLANK:
*eject
**********************************************************************
*
* Procedure:
*
* Purpose:
*
* Entry:
*
* Exit:
*
* Called By:
*
* Calls:
*
* Modification History:
*
* Date Reason Version Who
*
Form ProcedureName
Tables TableList
...
...
Using ParameterList
...
...
Changing ChangeList.
Page 7
SAP Procedure
Forms should be prefixed with the comment block above, also available in
ZBLANK:
All entries should start in the column after Modification History and can extend for
as many lines as required.
3.3.3.3. Procedure.
This is the name of the form.
3.3.3.4. Purpose.
This entry should details the function of the procedure. The action that it
carries out.
3.3.3.5. Entry.
This entry should list any tables passed to the routine and any Using
variables with their name and function.
It should document any assumptions made by the routine and any reliance
(!!!) on global variables. (See Local/Static above)
3.3.3.6. Exit.
This entry details any variables and their function that are changed by the
routine.
3.3.3.8. Calls.
This entry details the procedures that are called by this routine.
4. Revisions.
Programs tend to be subject to a never ending request for revisions. SAP contains a version
management system that is activated at each transport of the program. Therefore it makes sense to use
this system to track changes to our in-house programs.
Taking the Common SAP Procedures include program ZBOSSINC, the Version manager has this to
report on the Include program:
Page 8
SAP Procedure
This shows that there have been nine transports of the program to the live environment. Previous
versions can be recalled, and differences compared between versions:
Left-hand column:
Report source: ZBOSSINC Version 00008
Request: M01K902911 22.05.1998 RHARPER
Text: ZSO Report series changes.
Right-hand column:
Report source: ZBOSSINC active version
Request: M01K903193 01.06.1998 RHARPER
Text: ZBOSSINC modification/upgrade.
Contents unchanged:
000010 000010 ***INCLUDE ZBOSSINC.
000020 000020 ***********************************************************************
000030 000030 *
... ... ...
000460 000460 Data: w__grouphdr type i, " In group header routine
000470 000470 w__lineprinted type i, " Line printed flag
000480 000480 w__runtotal type i. " Run total rec needed
Page 9
SAP Procedure
Contents unchanged:
000500 000500 ***********************************************************************
000510 000510 *
000520 000520 * macro: Psub.
... ... ...
000740 000740 &1-low &1-high.
000750 000750 EndLoop.
000760 000760 End-Of-Definition.
Contents unchanged:
000780 000780 ***********************************************************************
000790 000790 *
000800 000800 * Procedure: Repheader.
... ... ...
001490 001490 Move False to w__grouphdr.
001500 001500 Move False to w__lineprinted.
001510 001510 ENDFORM.
Contents unchanged:
001520 001530 ***********************************************************************
001530 001540 *
001540 001550 * Procedure: WLine.
... ... ...
002230 002240 write ' ' no-gap.
002240 002250 enddo.
002250 002260 ENDFORM.
Contents unchanged:
002260 002280 ***********************************************************************
002270 002290 *
002280 002300 * Procedure: GroupHdr.
... ... ...
002810 002830 Move false to w__lineprinted.
002820 002840 Endif.
002830 002850 ENDFORM. " Group Header.
Contents unchanged:
002840 002870 ***********************************************************************
002850 002880 *
002860 002890 * Procedure: PrintTitles.
... ... ...
003750 003780 EndWhile.
003760 003790 Endif.
003770 003800 ENDFORM. " PrintTitles
Contents unchanged:
003780 003820 ***********************************************************************
003790 003830 *
003800 003840 * Procedure: Underline.
... ... ...
004020 004060 Move sy-uline to w__repline+w__offset(p_width).
004030 004070 Write / w__repline.
004040 004080 ENDFORM. "UNDERLINE
Page 10
SAP Procedure
Contents unchanged:
004050 004100 ***********************************************************************
004060 004110 *
004070 004120 * Procedure: Tableline.
... ... ...
004290 004340 Perform UnderLine
004300 004350 using ReportTable-StartPos w__maxwidth.
004310 004360 ENDFORM.
Contents unchanged:
004320 004380 ***********************************************************************
004330 004390 *
004340 004400 * Procedure: BuildReport.
... ... ...
005220 005280 endloop.
005230 005290 Append ReportTable.
005240 005300 ENDFORM. "BUILDREPORT.
Contents unchanged:
005250 005320 ***********************************************************************
005260 005330 *
005270 005340 * Procedure: FormatReport.
... ... ...
005940 006010 Modify ReportTable.
005950 006020 Endloop.
005960 006030 ENDFORM. "FORMATREPORT
Contents unchanged:
005970 006050 ***********************************************************************
005980 006060 *
005990 006070 * Procedure: WriteLine
... ... ...
006720 006800 Write sy-vline no-gap.
006730 006810 Move True to w__lineprinted.
006740 006820 EndForm.
Contents unchanged:
006750 006840 ***********************************************************************
006760 006850 *
006770 006860 * Procedure: SetColour
... ... ...
007070 007160 When Col_Group. Format Color Col_Group.
007080 007170 Endcase.
007090 007180 EndForm.
Contents unchanged:
007100 007200 ***********************************************************************
007110 007210 *
007120 007220 * Procedure: WriteCentre.
... ... ...
007340 007440 Move p_text to w__repline+w__offset.
007350 007450 Write /001 w__repline.
007360 007460 ENDFORM.
Page 11
SAP Procedure
Contents unchanged:
007370 007480 ***********************************************************************
007380 007490 *
007390 007500 * Procedure: FindSupplier.
... ... ...
008410 008520 endif.
008420 008530 endif.
008430 008540 ENDFORM. " FINDSUPPLIER
Contents unchanged:
008440 008560 ***********************************************************************
008450 008570 *
008460 008580 * Procedure: GiveLine.
... ... ...
009090 009210 move space to p_text.
009100 009220 endif.
009110 009230 ENDFORM.
Contents unchanged:
009120 009250 ***********************************************************************
009130 009260 *
009140 009270 * Procedure: StripString.
... ... ...
009570 009700 EndWhile.
009580 009710 EndDo.
009590 009720 EndForm.
Contents unchanged:
009610 009740 ***********************************************************************
009620 009750 *
009630 009760 * Procedure: SortRep
... ... ...
010030 010160 EndCase.
010040 010170 Endif.
010050 010180 EndForm.
Contents unchanged:
010070 010200 ***********************************************************************
010080 010210 *
010090 010220 * Procedure: SubTitle
... ... ...
010730 010860 Endif.
010740 010870 Perform WriteCentre using w__subtitle.
010750 010880 EndForm.
Contents unchanged:
010760 010900 ***********************************************************************
010770 010910 *
010780 010920 * Procedure: InitBreak
... ... ...
011190 011330 Move t__cols[] to ReportBreaks-Totals[].
011200 011340 Append ReportBreaks.
011210 011350 EndForm.
Page 12
SAP Procedure
Contents unchanged:
011220 011370 ***********************************************************************
011230 011380 *
011240 011390 * Procedure: Checkbreaks
... ... ...
012240 012390 EndWhile.
012250 012400 EndIf.
012260 012410 EndForm.
Contents unchanged:
012280 012430 ***********************************************************************
012290 012440 *
012300 012450 * Procedure: PrintTotals
... ... ...
013000 013150 Position w__pos.
013010 013160 Write: sy-vline.
013020 013170 EndForm.
Contents unchanged:
013030 013190 ***********************************************************************
013040 013200 *
013050 013210 * Procedure: RunTotals
... ... ...
013500 013660 EndLoop.
013510 013670 Perform TableLine.
013520 013680 EndForm.
Revisions can be retrieved at will with the proviso that they will over write the current version unless it
is copied somewhere else.
In order to maintain readability, lines that should be deleted should be and not commented
out. Lines that are changed should be changed and not copied and commented out. This
maintains readability throughout the code and in any case, the previous version can always be
retrieved if required.
The comments should form a history of the changes made in the program and should contain
the following details:
4.2.1. Chnge
This column should contain a consecutive change number (1 2 3.... etc)
Page 13
SAP Procedure
4.2.2. Date
The date the change commenced
4.2.3. Who
Who is responsible for the change.
4.2.4. Reason
The reason for the change.
To delete a line, place an asterisk in the first column, changing that line into a
comment, again marking that line with Interim change No.
To change a line, copy the line to the clipboard, mark the current line with an
asterisk and Interim change No. Paste the original line back in below the old line
and make the necessary changes. Again, mark the line with Interim change No.
Whilst this is not the way to maintain programs and keep them readable and tidy, this is
apparently the way that Origin maintain programs...... However.
5.
Page 14
SAP Procedure
6. Modularisation.
Programs should be modularised so that effects of changes and damage limitation can be contained.
However, a better way of doing this is to group all the common procedures for an application
into an Include file which is Included in the main program using the Include statement
6.3. Functions.
A Procedure with a value.
6.4. Macros.
These are defined once at the head of the program and are then used as though they are
intrinsic commands within the ABAP language. An example of a macro can be found in
PROC032, PSUB.
Page 15
SAP Procedure
Appendix A
SAP System Variables.
Page 16
SAP Procedure
Page 17
SAP Procedure
Page 18
SAP Procedure
Page 19