top of page

ABAP Naming Conventions and the "Self-Explanatory Code" Concept

Writer's picture: Hilmi GünayHilmi Günay

Updated: Jan 2

1. Introduction


In software development, especially in large projects, writing maintainable and easily understandable code is a goal for every developer. However, issues like code clutter, incorrect naming, and insufficient documentation can make achieving this goal difficult. This is where "self-explanatory code" and naming conventions come into play.

Self-explanatory code is code that is not only understandable by computers but also easily readable by other developers. Properly named variables, functions, and structures allow a developer to quickly grasp the purpose and logic of the code. In this paper, we will explore the concept of self-explanatory code and naming conventions, explain their impact on project workflows, and provide examples to support these concepts.


2. The "Self-Explanatory Code" Concept


a) What is Self-Explanatory Code?


Self-explanatory code is code that is easily understood not only by computers but also by human developers. The purpose and logic of the code should be clear without needing additional comments or documentation.


b) Why is Self-Explanatory Code Important?


  1. Maintenance: In large projects, code that is easy to understand facilitates faster maintenance.

  2. Debugging: Well-named variables and logical code structures make debugging easier.

  3. Team Communication: In projects involving multiple developers, self-explanatory code improves communication within the team.


c) Challenges Faced by Developers


Developers may encounter situations where modular structures and complex workflows make understanding the code more difficult. In such cases, the readability of the code and minimizing errors are critical to the success of the project. The concepts of self-explanatory code and naming conventions are effective approaches to reducing these challenges.


d) Example Comparison


Let’s illustrate the importance of self-explanatory code with poor and good code examples.


Bad Example:

DATA: x TYPE i,
      y TYPE i.
x = x + y.
WRITE: / x.

Good Example (Self Explanatory Code):

DATA: lv_total_sales TYPE i,         " Total Sales
      lv_current_month_sales TYPE i. " Current Month Sales
lv_total_sales = lv_total_sales + lv_current_month_sales.
WRITE: / lv_total_sales.

In this example, meaningful variable names make the purpose of the code clear.


3. ABAP Naming Conventions


a) What are Naming Conventions?


Naming conventions in ABAP ensure that variables, tables, constants, and other objects are consistently and meaningfully named. These conventions improve code readability and help create a standardized structure in projects.


b) Basic Naming Conventions


While it's impossible to list all naming conventions here, below are some basic conventions for the most commonly used objects:

Object Type

Naming Convention

Explanation

Global Variable

gv_<variable_name>

A variable that is accessible globally throughout the project.

Local Variable

lv_<variable_name>

A variable that is used only within a function or method.

Global Internal Table

gt_<table_name>

A global internal table.

Local Internal Table

lt_<table_name>

A local internal table.

Global Work Area

gs_<work_area_name>

A global (structure) work area (typically used for internal tables).

Local Work Area

ls_<work_area_name>

A local (structure) work area (typically used for internal tables).

Constant

gc_<constant_name>

A global constant.

Input Parameter

iv_<parameter_name>

An input parameter for a function or method.

Output Parameter

ev_<parameter_name>

An output parameter for a function or method.

Changing Parameter

cv_<parameter_name>

A changing parameter for a function or method.

Select Option

s_<select_option_name>

A select option parameter (used with SELECT-OPTIONS).

Note:

These conventions are examples of globally accepted naming standards. However, every organization may define its own internal standards based on project requirements. The key is to maintain consistency throughout the project.


4. The Impact of Self-Explanatory Code and Naming Conventions


Naming conventions support the concept of self-explanatory code by improving the readability and clarity of the code.


Bad Example:

DATA: a TYPE i,
      b TYPE i.
a = a + b.
WRITE: / a.

Good Example:

DATA: lv_quantity TYPE i,       " Quantity
      lv_price TYPE p.          " Price
DATA: lv_total_cost TYPE p.     " Total Cost
lv_total_cost = lv_quantity * lv_price.
WRITE: / lv_total_cost.

Well-named variables clearly indicate the purpose and operation of the code.


5. Common Mistakes and Solutions


a) Short and Meaningless Variable Names


  • Bad Example:

DATA: a TYPE i, b TYPE i.
a = a + b.
WRITE: / a.
  • Issue: Variable names (a, b) are too short and vague.


  • Solution: Use meaningful variable names.

DATA: lv_quantity TYPE i, 
      lv_price TYPE i.
lv_total = lv_quantity * lv_price.
WRITE: / lv_total.

b) Insufficiently Defined User-Defined Object Names


  • Bad Example:

DATA: wa TYPE zcustomer_data.
  • Issue: Short abbreviations like wa are confusing.


  • Solution: Give the object a more descriptive name.

DATA: ls_customer_data TYPE zcustomer_data.

c) Incorrect Data Type Selection


  • Bad Example:

DATA: lv_total TYPE i.
lv_total = '100'.
WRITE: / lv_total.
  • Issue: Assigning a string value ('100') to a numeric variable (i) can cause a type mismatch error.


  • Solution: Use the correct data type.

DATA: lv_total TYPE p LENGTH 10 DECIMALS 2.
lv_total = 100.00.
WRITE: / lv_total.

d) Other Mistakes

  • Short and vague parameter names,

  • Complex internal structures,

  • Excessively abbreviated global variables.


6. Conclusion


Self-explanatory code and naming conventions play a crucial role not only in ABAP projects but in all software development processes. Adopting these conventions improves the readability and maintainability of the code. Developers who use proper naming conventions can make their code more understandable and maintainable, which ultimately enhances the efficiency of the software development process.

17 views0 comments

Recent Posts

See All

Comments


bottom of page