What is the ABAP program Structure?

ABAP programs are mostly responsible for data processing within the different blocks of an application program. i.e. program cannot create as a single unit however program should divide into smaller modules that are assigned to individual blocks.

Each module (set of statements) in the program is called as a processing block. The set of processing blocks gets executed when we run the program. The processing blocks cannot be nested. A processing block contains a set of ABAP statements.

The following diagram shows the structure of an ABAP program –

SAP ABAP Program Structure

Each ABAP program consists of below two parts -

  • Header section
  • Declaration Part for Global Data, Classes and Selection Screens
  • Processing Blocks container

Header section –

Header section contains the detailed information about the program. Header section is standard template that is generated when we create the program and it is editable. The ABAP program first statement starts with PROGRAM or REPORT. The header section is mandatory.

The first statement automatically inserted by system when creating a program –

  • For module pools – PROGRAM <program-name>
  • For executable pools – REPORT <report-name>

Declaration Part for Global Data, Classes and Selection Screens –

Declaration part for global data, classes, and selection screens is the first part of ABAP program. This part consists of – all declaration statements. i.e. declaration statements for global data, all selection screen definitions, all class definitions, and declaration statements in procedures (methods, subroutines, function modules).

Processing Blocks Container –

Processing block container of an ABAP program contains all processing blocks for the program.

The ABAP program is combination of different processing blocks. Each processing block contains the business logic and its declaration. The processing blocks of ABAP programs are –

  • Dialog Modules
  • Event blocks for selection screens
  • Event blocks for lists
  • Event blocks for executable programs/Reports
  • Subroutines
  • Function Modules
  • Methods
  • All ABAP statements (except the declarative statements in the declaration part)

Let us discuss them one by one in detail -

What is Dialog module?

Dialog module is used to code a business logic that relates to screens flow. Dialog modules can be called from the screen flow logic/screen command logic.

Dialog modules are coded in between the MODULE and ENDMODULE statements.

Fields should have same name on both dialog screen and related ABAP program and data can be passed between the matching named fields in the program.

What is Event block for selection screens?

A selection screen is a type of dialog. The different events in a selection screen like PAI, PBO, user input is controlled by a selection screen processor. The selection screen processor controls the flow logic of the selection screen.

What is Event block for Lists?

Lists are special screens that outputs arranged data. We can create list in any processing block of an ABAP program using a set of commands such as WRITE, NEW-PAGE and so on. The list processor displays the list on the screen and handles user actions within lists. The list processor controls the flow logic of the list.

What is Event block for Executable Programs (Reports)?

Runtime environment controls the execution of program (type 1). Type 1 programs are event driven.

What is Subroutines?

A subroutine is a reusable section of code. We can define subroutines in any ABAP program and can call subroutines using the PERFORM statement from ABAP programs. Subroutines are defined using the FORM statement and coded in between FORM…ENDFORM statement.

What is Function Modules?

Function modules are external functions with a well-defined interface. We can call function modules from ABAP programs using the CALL FUNCTION statement.

Function modules are defined using the FUNCTION statement and coded in between FUNCTION...ENDFUNCTION statement.

What is Method?

Methods define the functions of classes in ABAP Objects. Methods have a defined interface. We can call methods from ABAP programs using the CALL METHOD statement.

Methods are defined using the METHOD statement and coded in between the METHOD…ENDMETHOD statement.

What is the ABAP Statement?

The ABAP statements that are not part of declaration part is called as source code.

The ABAP program source code consists of comments and ABAP statements. The ABAP statements and comments can be discussed in further chapters.

What are the Naming conventions for ABAP programs?

Below are some rules for naming ABAP programs -

  • An ABAP program name can be in between 1 and 30 characters long.
  • Program name cannot contain any of the characters - Period (.), comma (,), space (), parentheses (), apostrophe (‘), inverted commas ("), equals sign (=), asterisk (*), accented characters or German umlauts (à, é, ø etc.), percentage signs (%), or underscores (_).
  • User defined programs should start with “Y” or “Z”.
  • Program should not start with "A" or "X" that are reserved for SAP Programs.

What are the requirements to create a program in real time?

  • Program name – Every user-defined program should start with “Y” or “Z”. Check the naming standards in the project and get the name approved from the client or business analyst.
  • Program Type – Once the name approved, understand the type of program suitable for. The available program types are – executable program, include program, module pool, function group, subroutine pool, interface pool, class pool, type pool or XSLT program.
  • Package – Each requirement is scheduled to certain release in the real time project. Each release has its set of packages (may be one or more than one). Check with the lead for appropriate package and assign the package while saving the program.

What are the characteristics of ABAP program?

  • ABAP statements begins with an ABAP keyword and ends with a period(.).
  • The words (keywords, variables, operators etc.) are always separated by at least one space. If words have more than one space in between, it will be considered as one.
  • ABAP statement can be more than one line long however it is not recommended. ABAP supports a single line contain more than one ABAP statement.
  • There are no rules for ABAP statement starting position or indentation. ABAP statement can start in any column of the line.
  • ABAP statement can be in any case (i.e. either lower case or upper case). Both are considered as same and no differentiation between upper and lower case for keywords, additions, and operands.
  • ABAP program is only case sensitive while comparison.