well code Abap

<This documents will explain to the beginners in ABAP that how we can make our code more structured and standardized so that it can become more Interactive. However coding standards are made by SAP Professionals, but the target of this document is to make aware  to  the persons who is new in Technology .Hope this document will share the things well .  >

<

Coding Standards:

1.1    Name of report

While naming the ABAP program, make sure that the Program starts with Z or Y (for all programs created in the Training environment). These are called the Namespaces and if required different namespaces will be provided during the real time project work.

1.2    Program description and modification log

An overall description of the program along with the modification log must be given at the top of all the Program, SAP Script, Print Program, Dialog Program, BDC and all other programs. It should have the following format: *********************************************************

* Author's name       :

* Date written        :

* Program description :

*

*********************************************************

* Modification #      :

* Date of modification:

* Programmer          : Name of person modifying code

* Description         : description of the modification

*********************************************************

1.3    Includes

The program includes, type pools must be enclosed between two comment lines as shown below: ****** START OF INCLUDES **************************

INCLUDE ZFUGLSTR.

****** END OF INCLUDES ****************************

1.4    Data declaration section

All the global data must be defined here. They must be enclosed between two comment lines as follows:  ****** START OF DATA DECLARATION ******************

****** END OF DATA DECLARATION ******************** All the items in this section must follow the following sequence: Tables declaration

Type definition

Parameters

Select-options

Constants

Variables

Internal tables

1.4.1     Table definition

Define SAP tables used in the program as with a brief description of the table. Example:

TABLES     : EKKO,                  "Purchasing Document Header   

             EKPO.                  "Purchasing Document Line Items

1.4.2    Type definition

User defined non-elementary types must be prefixed with TY_Example:

TYPES:    BEGIN OF TY_MYTYPE,

              NAME (10) TYPE C,

          NUMBER    TYPE I,

          END OF TY_MYTYPE.

1.4.3    Parameters

SAP R/3 limits the number of characters in parameter name up to 8. Standard

Parameters must be prefixed with P_. Example:

PARAMETER: P_NAME TYPE C. Note: The explanation for the parameter can be given in text element.

1.4.4    Select-options

SAP R/3 limits the number of characters in select-options name up to 8. Standard

 For the SELECTION-SCREEN Parameters use the following.

Select Options                      SO_

Parameters                            P_

Radio Buttons                      R_

Check boxes                         CH_

Pushbuttons                          PB_  Example:

SELECT-OPTIONS: SO_NAME FOR ZVEND-NAME. Note: The explanation for the select-options can be given in text element.

1.4.5    Constants

Standard

Constants must be prefixed with C_. Example:

CONSTANTS: C_NO_OF_COLS_IN_EXCEL TYPE I VALUE 12.

1.4.6    Variables

Standard

The first character of the variable must indicate the scope of the variable.

G - for global variable

L - for local variable The second character of the variable must indicate the type of the variable.

C   Character

N   Numeric Text

I     Integer

P    Packed

F    Floating Point

H   Hex

D   Date

T   Time

O   OLE object

S    Structure (any other non-elementary type) The third character must be an underscore.  The rest of the characters must indicate the purpose of the variable.  Example:

A global variable that holds the document date of financial document can be declared as following:

DATA: GD_DOCUMENT_DATE TYPE D.

1.4.7     Flags

Standard

Declaration of Flags should always start with F_.

Example:

DATA: F_FLAG TYPE C VALUE 'X'.

1.4.8     Ranges

Declaration of Ranges should start with RA_ and Local ranges should be declared as LRA_

1.4.9     Counters

Declaration of Counters / Accumulators should start with CNT_

Example:

DATA: CNT_Counter1 TYPE I.

1.4.10     Field-Groups

Declaration of FIELD-GROUPS should start with FG_

1.4.11     Field-Symbols

Declaration of FIELD-SYMBOLS should start with FS_

Example:

DATA: <FS_T> TYPE ANY.

1.4.12     Type Reference Declaration.

All objects with the declaration TYPE REF TO should start with LO_

1.4.13     Internal tables

Standard

Internal tables must be named with the prefix GT_ for Global tables and LT_ for Local Tables. Example:

DATA: GT_CUSTOMER LIKE ZCUST OCCURS 0 WITH HEADER LINE.

1.5    Work Area

It is always better to use a Work Area for a Table instead of creating a table with a Header Line and using that.

Work areas can be created globally as well as we can use Local Work Areas. Please make sure that there is proper and valid clearing of the Work Areas before they are used in the program.

Global Work Areas should always start with WA_

Local Work Areas should always start with LWA_

Example:

DATA: WA_CUSTOMER TYPE TYPE_CUSTOMER_TABLE.

1.6     Main program logic


The main program logic must be enclosed between the following comment lines:

1.       All ABAP programs must be structured. Forms must be used.

  ****** START OF MAIN LOGIC ************************

****** END OF MAIN LOGIC **************************

1.7    Comments and Indentation

Proper comments are to be written to explain the logic used in the code and the flow of the program. The data declarations should also be explained with the elements Description.

The pretty printer option in the ABAP/4 workbench editor's menu option must be used to indent the code properly. Also note Pretty Printer should always be used only when the code is developed.

Please refrain from using Pretty Printer on the Objects that are already created, which are being modified by you.

Line width should not exceed 72 Characters.

1.8     Attributes

Proper Program Attributes should be maintained even if it is a test program. SE38 -> GOTO -> Attributes. Or from the attributes screen that comes at the time of program Creation.

1.9     Proper Creation and usages of Include files.

XXX_TOP Include              - Used for all the declarations

XXX_F01 Include               - Used for the Subroutines and the Functions

XXX_D01 Include              - Used for writing the Selection Screen parameters

XXX_I01 Include                - Used for the PAI Module in Dialog Program

XXX_O01 Include              - Used for the PBO Module in the Dialog Program.

In the above includes XXX is the Program name, that is calling the Includes.
 


REPORT ZTEST.

* Program Header

DEFING ABAP DATA OBJECTS

TABLES AND DDIC STRUCTURES


              * Declaring SAP transparent tables
                TABLES : xxxxx.               

                * Declaring custom transparent tables
                TABLES : xxxxx.               

                * Declaring SAP structures
TABLES : BGR00,....

INTERNAL TABLES AND PROGRAM STRUCTURES



                * Declaring program structures

* DECLARING Internal Tables
               

DATA VARIABLES


* Declaring Counters and summing items
DATA : C_COUNT_RECORDS TYPE I

* Declaring Work variables
DATA : W_AMOUNT(6) TYPE P DECIMALS 2.

CONSTANTS


* Declaring Constants
CONSTANTS :

INCLUDES


* Declaring INCLUDES
INCLUDE xxxxxx.
INCLUDE

SELECTION-SCREEN : Parameters, Select-Options, ...


* Defining Selection Screen
                SELECTION-SCREEN: .....
                PARAMETERS :
                SELECT-OPTIONS

MAIN PROGRAM


INITIALIZATION.
Initializing Global variables, menu surface, batch-input structures

AT SELECTION-SCREEN.
            Parameter, Select-Option Input Control
Input, Output File Opening

START-OF-SELECTION
GET  xxxxx.
                Reading and controling data
                Converting, processing Data (conversion, calculation, sorting, summing)               Creating OutPut Files
               
END-OF-SELECTION.
                Reporting Data
            Reporting Errors, Warnings
                Closing Files

PAGE HEADER, PAGE FOOTER


TOP-OF-PAGE.
            Defining the standard Page Header (BHDGD)

END-OF-PAGE
            Defining Page Footer

INTERACTIVE LIST EVENTS


AT PFnn.
              Instructions executed every time the function key PFnn is activated

AT USER-COMMAND.
              Instructions executed every time a user command is activated (OK code, ..)

AT LINE-SELECTION.
              Instructions executed every time a line is selected

FORMS


FORM F000-xxxxxxx.
ENDFORM

FORM F999-xxxxxxxx.
ENDFORM.


>


***The Report Program Events should always be called in the following order.
 §  INITIALIZATION
§  AT SELECTION-SCREEN OUTPUT
§  AT SELECTION SCREEN ON VALUE-REQUEST
§  AT SELECTION SCREEN ON HELP-REQUEST
§  AT SELECTION SCREEN ON <parameter>
§  AT SELECTION-SCREEN
§  START-OF-SELECTION
§  GET <node>
§  END-OF-SELECTION
§  TOP-OF-PAGE
§  TOP-OF-PAGE DURING LINE-SELECTION
§  END-OF-PAGE
§  AT LINE-SELECTION
§  AT USER-COMMAND
§  FORM

§  ENDFORM
***Performance tips specifically with Internal Tables:
 Ø  It must be Cleared / Refreshed wherever necessary.
Ø  APPEND to be used instead of COLLECT.
Ø  Usage of Memory ID should be minimal & freed immediately after use.
Ø  CLEAR the Header Line / Work Area after the APPEND statement.
Ø  CLEAR Header Line after DELETE statement.
 

2. Performance Measures.
 2.1 Use Proper Text Elements instead of Hard-coding the text.
  Example:
WRONG
Write: 'This is wrong'.
 CORRECT
Write: text-t02.  "Text-t02 contains 'This is Wrong'
 

2.2 Use CHECK Statements at all required places as we can avoid unnecessary processing of code.

 Example:
 SELECT name age FROM EMPL INTO TABLE gt_main_table
WHERE age = 25.
 Check gt_main_table[] is not initial.
 Other select queries.......
 

2.3 No Select Statement within a LOOP Statement.

 Example:
 LOOP AT gt_main_table INTO wa_main_table.
                SELECT ...
ENDLOOP.

 

2.4 Avoid calling of Function Modules within a LOOP Statement.

 Example:
 LOOP AT gt_main_table INTO wa_main_table.
                CALL FUNCTION 'GENERATE_NUMBERS'.
                .........
ENDLOOP.
  
2.5 Use the Keyword SPACE instead of  ' '.
 Example:
IF CC_text = SPACE.  " Instead of ' '.
ENDIF.
    
 2.6 Every SELECT, READ, DELETE, INSERT, APPEND, MODIFY Statement should have a SY-SUBRC Check.
 Example:
SELECT name age FROM EMPL INTO TABLE gt_main_table
WHERE age = 25.
 IF sy-subrc NE 0.
                WRITE text-t04.                  "t04 - Error.
ENDIF.
  2.7 Even if SY-SUBRC check is not required there should be an empty SY-SUBRC Check.
 Example:
SELECT name age FROM EMPL INTO TABLE gt_main_table
WHERE age = 25.
 IF sy-subrc NE 0.
                "Empty Sy-subrc Check.
ENDIF.
  
2.8 Tables should be SORTED before a READ Statement. READ Statements are better performed when done on a Table with the BINARY SEARCH option used.
 Example:
 Sort gt_main_table by Name.
 READ TABLE gt_main_table INTO wa_main_table WITH KEY name = 'TEST' BINARY SEARCH.
 IF sy-subrc NE 0.
                WRITE text-t04.                  "t04 - Error.
ENDIF.
  
2.9 The ERROR, WARNING, INFORMATION MESSAGES should NOT be Hard Coded.
 Example:
WRONG:
MESSAGE 'This is correct' TYPE E.
 CORRECT
MESSAGE text-t05 TYPE E.

 

Note: Other people's articles

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园建设方案旨在通过融合先进技术,如物联网、大数据、人工智能等,实现校园的智能化管理与服务。政策的推动和技术的成熟为智慧校园的发展提供了基础。该方案强调了数据的重要性,提出通过数据的整合、开放和共享,构建产学研资用联动的服务体系,以促进校园的精细化治理。 智慧校园的核心建设任务包括数据标准体系和应用标准体系的建设,以及信息化安全与等级保护的实施。方案提出了一站式服务大厅和移动校园的概念,通过整合校内外资源,实现资源共享平台和产教融合就业平台的建设。此外,校园大脑的构建是实现智慧校园的关键,它涉及到数据中心化、数据资产化和数据业务化,以数据驱动业务自动化和智能化。 技术应用方面,方案提出了物联网平台、5G网络、人工智能平台等新技术的融合应用,以打造多场景融合的智慧校园大脑。这包括智慧教室、智慧实验室、智慧图书馆、智慧党建等多领域的智能化应用,旨在提升教学、科研、管理和服务的效率和质量。 在实施层面,智慧校园建设需要统筹规划和分步实施,确保项目的可行性和有效性。方案提出了主题梳理、场景梳理和数据梳理的方法,以及现有技术支持和项目分级的考虑,以指导智慧校园的建设。 最后,智慧校园建设的成功依赖于开放、协同和融合的组织建设。通过战略咨询、分步实施、生态建设和短板补充,可以构建符合学校特色的生态链,实现智慧校园的长远发展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值