The information contained herein is subject to change without notice
Coding Standards Speaker name : Anuradha GRao Title, HP : Coding Standards Date : 9/15/2014 HP Confidential Coding Standards 2 Introduction
1. This document explains the standards of coding while handling different type of objects.
2. This helps in understanding the standards of coding used in HP.
9/15/2014 HP Confidential Coding Standards 3 SAP ABAP Dictionary Naming Conventions Standard
9/15/2014 HP Confidential Coding Standards 4 Naming Conventions
ABAP Dictionary naming conventions have been defined for each of the following object types:
Table Structure View Append Structure Field Data Element Domain Lock Object Search Help Secondary Index BAPI Fields 9/15/2014 HP Confidential Coding Standards 5
Current site code usage in HP:
G = Global 1 = EMEA 2 = PRMO 3 = NA 4 = NA Rep 7 = AP 8 = AP Rep 9 = EMEA Rep
9/15/2014 HP Confidential Coding Standards 6 Database Table
Format:
Zyxn Z = Fixed text for custom object designation y = Site code x = Alpha characters based on the standard abbreviations of the key fields n = Optional numeric counter if necessary to make the object name unique
Examples:
Z1DFCHRFMD Default Characteristics Per Reference Model ZGBLDCNORN Billing Document Number Ranges 9/15/2014 HP Confidential Coding Standards 7
Structure
Format:
ZyS_xn Z = Fixed text for custom object designation y = Site code S_ = Fixed text for structure designation x = Alphanumeric characters referring to the primary table name on which the structure is based. If it is based on multiple tables or not based on a table, then provide the abbreviation of a meaningful name by using the Standard Abbreviation List. n = Optional numeric counter if necessary to make the object name unique
Examples:
ZGS_KNA1 for standard SAP table KNA1 Z1S_BWRFMD BW Reference Models 9/15/2014 HP Confidential Coding Standards 8 View
A view is a virtual table that logically relates to one or more tables. That is, the data of a view is not actually physically stored, but derived from one or more other tables. A view can be tailored to the needs of a specific application, making it possible to directly access specific data.
Format:
ZyV_xn Z = Fixed text for custom object designation y = Site code V_ =Fixed text for view designation x = Name of the view based on primary key of table n = Optional numeric counter if necessary to make the object name unique
Examples:
ZGV_KNA1 for standard SAP table KNA1 ZGV_KNA101 for standard SAP table KNA1 9/15/2014 HP Confidential Coding Standards 9 Append Structure
An Append Structure is used to extend a standard SAP table with custom fields. It is not a separate dictionary object like a Structure, but is defined/maintained only through the table definition screen. The primary advantage of using an Append Structure is that it is protected from being overwritten when the system is upgraded. Therefore, after an upgrade the fields in an Append Structure are added to the new standard tables, thereby maintaining any custom extensions that may have been added to SAP standard tables.
Format:
During the process of creating an Append Structure, the system proposes a default name. The current standard is to accept the proposed name.
Examples:
ZAVBAK 9/15/2014 HP Confidential Coding Standards 10 Field
It is important to note that a field is not an object in the ABAP Dictionary. It has no associated description, but it provides the link between a table and a data element, which contains a description. The data element provides the link to a domain, which contains the physical characteristics of the field.
Format: ZZx ZZ = Fixed text for custom object designation x = Alphanumeric Characters from data element Custom Table Field x = Alphanumeric Characters from data element
Examples: Table type Field name Data element Domain SAP ZZWERKS WERKS WERKS Custom WERKS WERKS WERKS SAP ZZDELFLAG ZZGDELFL ZZGFLA Custom DELFLAG ZZ1DELFL ZZ1FLAG 9/15/2014 HP Confidential Coding Standards 11 Data Element
A Data Element stores field descriptions. All fields assigned to a data element will have the same description. Data Elements also store the domain name which contain the physical characteristics of a field ZZyx
Format:
ZZ = Fixed text for custom object designation y = Site code x = Alpha characters based on the standard abbreviations of the Data Element description
Examples:
ZZ7ORHDSTCD Order Hold Status Code ZZGATTGNO Asset Tag Number 9/15/2014 HP Confidential Coding Standards 12 Data Element Supplement
Data Element Supplements are used to create screen-specific documentation for a field. This documentation will be displayed when help is requested for that screen-specific field
Format:
Data Element Supplement Names must be a number equal to 9000 or greater.
Example: N/A
9/15/2014 HP Confidential Coding Standards 13 Domain
A Domain stores physical characteristics of a field; i.e., Data Type, Length, and Range of Values, Validation Table are defined for a Domain.
Format:
ZZyx ZZ = Fixed text for custom object designation y = Site code x = Alpha characters based on the standard abbreviations of the Domain description
Examples:
ZZ7ORHSTCD Order Hold Status Code ZZGAPOPCTY APO Procurement Type 9/15/2014 HP Confidential Coding Standards 14 Lock Object
Lock Objects prevent two or more users from simultaneously accessing the same logical unit of data. Locks on the data are set or released by calling certain function modules in an ABAP program. These functions are automatically generated during the creation of the lock objects. Lock objects must be defined in the ABAP Dictionary.
Format:
Ext E = Fixed text for Lock Object designation x = Name of the custom table (including the Z and site code) t = Lock type E = Exclusive and Cumulative S = Shared X = Exclusive
Examples:
EZ3TSLSORDX for a lock object for the table Z3TSLSORD 9/15/2014 HP Confidential Coding Standards 15 Search Help
Help views are used to output additional information when the online help system is called.
Format:
Zyx Z = Fixed text for custom object designation y = Site code x = Name of the standard object the Search Help is based on
Format for Custom Tables / Objects x x = Name of the custom object the Search Help is based on.
Examples:
ZGKNA1 for SAP standard table KNA1 Z3TFGFCST for custom table Z3TFGFCST 9/15/2014 HP Confidential Coding Standards 16 Secondary Index
The function of an index is to speed up the retrieval of data from a table. An index is usually created on specific fields on the table based on the retrieval search criteria.
Format:
Zn Z = Custom Designation n = A Number from 1-9
Examples:
Z1 Z2 9/15/2014 HP Confidential Coding Standards 17 BAPI Fields
BAPIs are interfaces for Business Objects. Together with the Business Objects, BAPIs define and document the interface standard at the business level. BAPI fields are merely fields within a structure in the ABAP Dictionary. A BAPI structure is used to pass data to and from a BAPI function module. Because the structure has visibility outside of SAP, it makes sense to use meaningful descriptive names for the structure fields.
Format:
Program BAPIFELD, offered in SAP 4.6, generates English defaults for external BAPI structures. The recommended default values should be used when creating BAPI related structures.
Examples: N/A
9/15/2014 HP Confidential Coding Standards 18 SAP ABAP Program Documentation Standard 9/15/2014 HP Confidential Coding Standards 19 Source Code Documentation
Source code documentation is intended to help the IT support and development teams understand the technical implementation of a program. At some point in time, someone else will more than likely need to understand your source code in order to modify its behavior. Source code documentation helps:
Improve the readability of the program Reduce the time required to understand the source code Document relevant thoughts, concerns, assumptions, and intentions that are not self evident
The standard components of this documentation are:
A standardized comment block with a revision history General source code comments General FORM documentation SAP Exit documentation (Userexit / Function Exit) Programming conventions / guidelines 9/15/2014 HP Confidential Coding Standards 20 Programming Conventions
Readability of the source code can be improved dramatically by following certain standard programming conventions and style guidelines as follows: Type 1 (executable) programs should be arranged in the following generally accepted sequence:
Report statement Table declarations Data declarations Data INCLUDES Selection screen definition Initialization At selection-screen Top-of-page, End-of-page At line-selection, At user-command Start-of-selection End-of-selection Forms Form INCLUDES 9/15/2014 HP Confidential Coding Standards 21 Copying Custom Program Standard 9/15/2014 HP Confidential Coding Standards 22 Custom Program Cloning Procedures
Cloning a program is never the preferred solution. Occasionally, we simply cannot change the original program to meet new requirements. But, the last thing we want to do is clone a program that is a known performance problem. Before cloning any program, determine if the original has ever been identified as a performance issue. If the program has been modified for performance reasons, determine if the current program runs efficiently. Checking the current program's database utilization will confirm how well or poorly the clone will perform.
Guidelines
Here are some guidelines to follow: Modify the custom program if the modifications are simple, and apply globally or can be parameterized. Copy the program if significant functional changes are being implemented. Do not modify or copy the program if only a fraction of the functionality is needed. In this case, start from scratch and create a custom program that is performance efficient. 9/15/2014 HP Confidential Coding Standards 23 Security for Custom SAP Programs Standard 9/15/2014 HP Confidential Coding Standards 24 Early Planning For Security
It is necessary to plan early for security and to incorporate security needs at the start of development work. The concepts of who the users are, what data groups of users are allowed access (or not allowed access), and the field values that should be checked in the ABAPs must all be considered.
As the business owner of the business process, they are responsible to define this business groups and users. 9/15/2014 HP Confidential Coding Standards 25 Authorization Check Objects
Custom development work should not reference any SAP delivered authorization objects. SAP Authorization objects are linked to SAP interpretation of the business processes. Thus, using an SAP delivered authorization object may inadvertently result in allowing access when SAP changes the interpretation of the object. In addition, custom programs which use SAP delivered authorization objects may also be affected if the authorization object is changed or deleted in future releases. However, there may be exceptions 9/15/2014 HP Confidential Coding Standards 26 Programming Authority-Checks
All custom ABAP programs and reports must address the need for security. Some reports may not need to have an authority check if they do not display sensitive data. Corporate guideline for Handling and Managing HPs Information Assets, http://legal.hp.com/linkpub/chart.pdf, should be followed. Document required special handling should have an authorization check. This check allows Security Administration 9/15/2014 HP Confidential Coding Standards 27 Securing Transaction Codes
Security authorization group includes t-code for all programs. T-code can be a custom t-code or generated when program is added to the report tree. Therefore, all programs should be secured by t-code. This is the preferred way to protect custom report.
When a user enters a transaction at the command line, a check is executed to test user access. This check object is usually one of the same objects referenced in the program. Whereas programming authority-checks allows for checks during run-time, securing access at the transaction code level prevents a user from even starting the program. The user will not even be able to display the first screen.
However, security access at this level does not check access if a CALL TRANSACTION in another program is done to this one. 9/15/2014 HP Confidential Coding Standards 28 Development Steps Identify the field and values that are to be checked in the ABAP program. Fields and values check are defined by the business processes as defined by business owner. Past practices of linking the program attributes authorization group to user security is not used. Document the field and values required for this object to Security Administration. Security Administration then creates the object with the fields defined by the developer and notifies the developer of the authorization object name. Security Administration will create a user to test the object with.
Validate the authorization checks with the test user for that object. This must be a joint effort between Security Administration and the developer. Different values in the authorization need to be checked in order to determine if all possible values are controlled by the program. Once the testing and the object is ready for implementation, it will be transport to production. Inform the appropriate application module team of the authorization objects so that it can be incorporated into programs and reports.
9/15/2014 HP Confidential Coding Standards 29 Custom Data Element Documentation 9/15/2014 HP Confidential Coding Standards 30 Process
CMODGotoText EnhancementsData ElementsNew DE Cust. Docu.
Customer Documentation Pop-Up screen appears. Enter the data element name and press green check.
Document Maintenance: Initial Screen. Hit the DISPLAY button (or CREATE if no documentation exists).
If DISPLAY was pressed, hit the CHANGE<>DISPLAY button. Enter the following tags and text into new lines below any existing documentation text:
U1 &data element name& AS U1 &USE& AS U1 &EXAMPLE& BL 9/15/2014 HP Confidential Coding Standards 31 Examples for data element ZP_STCLAS *
U1 & ZP_STCLAS & AS Status Classification U1 &USE& AS Code indicating classification of the part by HP P into a group AS according to the part's activity and acceptability. AS &EXAMPLE& BL 0 = (code no longer used; was 'Unclassified Part') BL 1 = First level choice BL 2 = Second level choice BL 3 = Third level choice BL 4 = Not recommended for new designs BL 5 = All production usage discontinued BL 6 = Void part number BL # = Code not applicable BL ? = Not yet coded 9/15/2014 HP Confidential Coding Standards 32 SAP 4.6 Custom Development Class and Program Object Naming Standard 9/15/2014 HP Confidential Coding Standards 33 Development Classes
Used to specify the transport layer for all included objects Used to secure development access via S_DEVELOP authorization object Used as nodes in the Application Hierarchy (transaction SE81) Used as an object listing mechanism in the ABAP Workbench Can easily transport all objects in a development class
9/15/2014 HP Confidential Coding Standards 34 Development Class Convention: ZYXWWWWWWWW_B Code Description Examples Z Fixed code for object ownership Z = Custom development Y Fixed code that defines the site code origin G = Global 1 = EMEA 3 = NA 7 = AP X Fixed code that defines object type R = Report E = Enhancements C = Conversions I = Interfaces M = Modifications(copies of SAP programs, or includes inside SAP programs userexits, function exits, etc.) W Variable length application component from the SAP delivered application component hierarchy or reasonable equivalent.
The application component is usually 4-8 characters. The first two characters typically identify the base level application (FI, SD, MM). Additional levels are usually 2 or 3 characters each. The complete code usually consists of 2-3 component levels. FIAA = Asset Accounting FIAROI = Accounts Receivable\Open Items FIARDU = Accounts Receivable\Dunning FIARCR = Accounts Receivable\Correspondence SDCM = Credit Management SDEDI = IDoc interfaces for EDI SDSLSSO = Sales\Sales Orders SDPR = Pricing and Conditions LOLIS = Logistics Information System LOMM = Material Master LOPDM = Product Data Management MMPURPO = Purchasing\Purchase Orders LESHP = Shipping _B Optional underscore and short description / acronym. Used for identifying partner systems, or significant blocks of development created for specific business solutions. HERT, BACKPLANE, PIT, SMART_ATP 9/15/2014 HP Confidential Coding Standards 35 Example Development Classes
Category Development Class Description Reports ZGRFIAROI Z1RSDPR Global A/R ageing reports EMEA SD pricing reports Interfaces Z3ILESHP_HEART ZGISDPR_CPL NA shipping interfaces for HEART Global pricing interfaces for CPL Conversions ZGCSDSLSSO Z7CFIAPOI Global Sales order conversions AP FI A/P conversions Enhancements ZGESDOC Z1ESDPR Z3EFIARDU Global Sales enhancements for output determination EMEA Sales enhancements for pricing NA Finance enhancements for A/R dunning 9/15/2014 HP Confidential Coding Standards 36 Object Type Convention Explanation Examples Executable programs (Non-IM3 development) da d = Development class a = Description Z3RSDPR_OPENITEMS ZGRFIAR_OVER90DAYS Z3ILESHP_HEART_DELIVERIE S Current & Future Executable program includes bcnn b = main program name c = TOP for gobal data O for output modules I for input modules F for form routines nn = two digit number for O, I, and F Z3RSDPR_OPENITEMSTOP Z3RSDPR_OPENITEMSO01 Z3RSDPR_OPENITEMSI01 Z3RSDPR_OPENITEMSF01 Current & Future Module pool SAPMdnn SAPM = fixed prefix d = development class nn = 2 digit number SAPMZGECSSE01 Current & Future Module pool includes Mdnntnn M = fixed prefix dnn = module pool suffix tnn = TOP, Onn, Inn, Fnn (e.g. SAPs internal convention) MZECSSE01TOP MZECSSE01O01 MZECSSE01I01 MZECSSE01F01 Current & Future Program Objects
9/15/2014 HP Confidential Coding Standards 37 Transaction code dnn Best practice is to use the same suffix as corresponding module pool. When impractical, the format Zyb may be used, where: Z = Custom development y = Site code b = Short description In addition, system generated tcodes names are also permitted. ZGECSSE01 Function Group dnn d = development class nn = 2 digit number ZGELESHP01 Current & Future Future Function Module Zy_b Z = Custom development y = Site code b = Short description ZG_SERIAL_NUMBER_STATUS Z3_IDOC_OUTPUT_ZORDERS2 Current & Future Layout Set Zyxx_b_c Z = Custom development y = Site code xx = Application area b = Org code, region code, or country identifier c = Document type Z1SD_NA_BILLING_DOCUMENT Current & Future Contd. 9/15/2014 HP Confidential Coding Standards 38 Classes ZyCL_b Z = Custom development y = Site code CL = Class identifier B = Short description Z3CL_IM_C_CALC_BADI Business objects new Zyxxxxnn Z = Custom development y = Site code xxxx = SAP application component nn = 2 digit number Z3MMIM0001 Business objects custom SAP subtype Zyb Z = Custom development y = Site code b = SAP Business object ZGBUS2032 Contd. 9/15/2014 HP Confidential Coding Standards 39 Local Date and Local Time Usage Standard 9/15/2014 HP Confidential Coding Standards 40 The SAP run time values for system date (SY-DATUM) and system time (SY-UZEIT) are set by the application server system date and time. The SAP run time values for local date (SY-DATLO) and local time (SY-TIMLO) are calculated as an offset from system time, based on the time zone specified in the user master. If no time zone is specified, then the local date and time will be identical to the system date and time
Use SY-DATLO and SY-TIMLO for all application specific dates and times. This would include such things as (but not limited to); document date, posting date, shipping date, billing date, requested date, material availability date, effective date - all sorts...pricing, exchange rates, sales status, etc.
Only use SY-DATUM and SY-UZEIT for system level functions where, for example, you must maintain the integrity of the sequence of events. This would include such things as (but not limited to); document creation date, document change date, program execution time, date and time stamps used in file names, etc. 9/15/2014 HP Confidential Coding Standards 41 SAP Reporting Tree Standard 9/15/2014 HP Confidential Coding Standards 42 As of 4.6 upgrade, this report tree is attached to the standard SAP area menu (S000) via an enhancement area menu (ZREPTREE).
Non compliant area menus on ESG Americas :
Z9M1 Corporate Contracts Administrator Menu Z9MN Corporate Contracts Main Menu (attached to SAP ME00) ZB2B B2B Management ZCBT Backplane Interface ZCSO Report Selections ZCSO_1 Report Selections (backup copy) ZCSO_1_1 Report Selections (backup copy) 9/15/2014 HP Confidential Coding Standards 43 There are 3 types of Area menus enhancement to SAP menu requires a repair to SAP Name of object should be the Development Class (w/o optional extension) with underscore and SAP area menu attached to Example: Z3MSO_S000
Only one attachment to SAP per functional area and only one owner for changes Sub menu of other HP area menu Maintained with SE43 Name of object should be the Development Class (w/o optional extension) with underscore and 4 digit number controlled by enhancement area menu owner. Example: Z3ESO_0001 Freestanding menu that works like a Tcode Not available on menu tree Name of object should conform to Tcode naming convention with underscore and MENU Naming conflicts between Tcode and Area menu will always resolve to the Tcode Example: Z3ESO01_MENU 9/15/2014 HP Confidential Coding Standards 44 Restricted ABAP Coding Standard 9/15/2014 HP Confidential Coding Standards 45 The following ABAP keywords are not to be used in any custom program on any production SAP system, with the exception of controlled objects or 3rd party software interfaces with the appropriate approvals:
INSERT REPORT DELETE REPORT
The following ABAP keyword may only be used in any custom program on any production system following review and approval:
GENERATE SUBROUTINE POOL 9/15/2014 HP Confidential Coding Standards 46 Restricted Use of Dynamic ABAP
Dynamically generated ABAP can be a very powerful and useful tool when used properly, and it can compromise the integrity of data, security, and the entire system when used improperly. For this reason, all use of dynamic ABAP must be reviewed and approved before it is moved into production.
The following uses of dynamically generated ABAP programs are not allowed:
Generic table maintenance - Any program that generates maintenance screens for non-specific SAP Dictionary tables.
Non-template based programs - Any program that is generated from non-permanently stored code templates.
9/15/2014 HP Confidential Coding Standards 47 Fusion SAP Filename and Directory Standard 9/15/2014 HP Confidential Coding Standards 48 File Naming Convention
This convention is based on the interface naming convention through position 8. Positions 10 through 13 have been added for this file naming convention to provide unique, sequentially numbered files for each interface program. Base filename and sequence are separated by a dot. File Naming Convention Z0MI01AA.0001 Description Examples Entity (from table Z010E) Z0 R/3 Application Module M Direction I 2 digit sequence number 01 2 character sequence AA Dot . 4 digit file extension 0001 9/15/2014 HP Confidential Coding Standards 49 Logical File Name Standard
The following example illustrates the logical path and logical file naming convention for the PRS projects CPL price data extract files. Logical File Path Naming Convention ZPRS_CPL_REPORTS_PATH Description Examples Custom development Z Project ID PRS Free Form CPL_REPORTS_PATH Logical File Naming Convention ZPRS_CPL_REPORTS Description Examples Custom development Z Project ID PRS Free Form CPL_REPORTS 9/15/2014 HP Confidential Coding Standards 50 Function module FILE_GET_NAME is used to automatically return directory path for a file: call function 'FILE_GET_NAME' exporting client = sy-mandt logical_filename = 'ZPRS_CPL_REPORTS' operating_system = sy-opsys importing file_name = file_name exceptions file_not_found = 1 others = 2.
Example:
The returned value file_name is the physical path that was assigned to the logical path. You concatenate this physical path with your file name to establish the full path.
Example of a physical path assigned to a logical path: /opt/z9/<SYSID>/PRS/<FILENAME> Where <SYSID> and <FILENAME> are variables. 9/15/2014 HP Confidential Coding Standards 51 Contd
Non-IM/3 program:
Imported file name from FILE_GET_NAME function: /opt/z9/QA2/PRS/. Concatenate /opt/z9/QA2/PRS/ with filename to get the full path /opt/z9/QA2/PRS/filename.
IM/3 program:
Imported file name from FILE_GET_NAME function: /opt/z9/QA2/PRS/filename
9/15/2014 HP Confidential Coding Standards 52 ESG 4.6 SAP Modification Standard 9/15/2014 HP Confidential Coding Standards 53 This standard consists of four sections:
1. Usage of the Note Assistant 2. Usage of the Modification Assistant 3. Source Code Comment Requirements 4. External Documentation Requirements
9/15/2014 HP Confidential Coding Standards 54 Thank You