GENERATE (ABAP Keyword)

GENERATE is a keyword used in SAP ABAP programming.
This tutorial covers its introduction & syntax details.

GENERATE

GENERATE – Generate a
program

Variants

1. GENERATE REPORT
prog.
2. GENERATE SUBROUTINE POOL itab NAME name.

Variant
1
GENERATE REPORT prog.

Additions

1. … MESSAGE f1
2.
… INCLUDE f2
3. … LINE f3
4. … WORD f4
5. … OFFSET f5
6. …
TRACE-FILE f6
7. … DIRECTORY ENTRY f7
8. … WITHOUT
SELECTION-SCREEN

Effect
Generates the program specified in the field
prog . If the program is a report (i.e. a type 1 program), the selection screen
is generated automatically.

The return code value is set as
follows:

SY-SUBRC = 0 Program generated successfully.
SY-SUBRC
<> 0 Unable to generate program.
SY_SUBRC = 4 Syntax error.
SY-SUBRC
= 8 Generation error.
SY-SUBRC = 12 Error when generating selection
screen.

Addition 1
… MESSAGE f1

Effect
When a syntax error
occurs, the error message is stored in this field.

Addition 2

INCLUDE f2

Effect
When a syntax error occurs, the name of the include
program concerned is stored in this field.

Addition 3
… LINE
f3

Effect
When a syntax error occurs, the number of the incorrect line
is stored in this field.

Addition 4
… WORD f4

Effect
When
a syntax error occurs, the incorrect word is stored in this
field.

Addition 5
… OFFSET f5

Effect
When a syntax error
occurs, the position of the incorrect word in the incorrect line is stored in
this field.

Addition 6
… TRACE-FILE f6

Effect
Trace output
is stored in this file. This addition automatically activates the trace
mode.

Addition 7
… DIRECTORY ENTRY f7

Effect
The program
attributes required for checking are taken from the field f4 . This field must
correspond to the structure of the table TRDIR .

Addition 8

WITHOUT SELECTION-SCREEN

Effect
Does not generate the selection
screen.

Variant 2
GENERATE SUBROUTINE POOL itab NAME
name.

Additions

1. … MESSAGE f1
2. … INCLUDE f2
3.
… LINE f3
4. … WORD f4
5. … OFFSET f5
6. … TRACE-FILE
f6

The additions have the same meaning as with GENERATE REPORT . Only the
addition DIRECTORY-ENTRY is not supported with GENERATE SUBROUTINE POOL because
temporary subroutine pools are always generated as type S programs and the
arithmetic flag is taken over from the generating
program.

Effect
Generates a temporary subroutine pool. The source code
for the subroutine pool to be generated is passed on in the internal table itab
. The field name contains the name under which FORM routines can be addressed in
the temporary subroutine pool via external PERFORM .

The return code
value is set as follows:

SY-SUBRC = 0 Generation
successful.
SY-SUBRC <> 0 Generation unsuccessful.
SY_SUBRC = 4
Syntax error.
SY-SUBRC = 8 Generation error.
In contrast to GENERATE
REPORT , the source code is passed on in an internal table with GENERATE
SUBROUTINE POOL , not read from the database. The load version generated is not
written to the database but held in main memory only.

Notes
Temporary
subroutine pools belong to the runtime context of the generating program, i.e.
to the roll area of the internal mode from which the generation is performed.
They may therefore be addressed only within this context, i.e. the generated
FORM routines can only be called from within the generating mode.
Up to 36
temporary subroutine pools can currently be managed for each roll
area.

GENERATE – Generate a screen

GENERATE
DYNPRO h f e m ID g.
…MESSAGE F1 …LINE F2 …WORD
F3.

Additions

1. … OFFSET f4
2. … TRACE-FILE
f5

Effect
Generates the screen specified in the field g .
Here, the
source code is taken from the structure h and the internal tables f , e and m .
The field h (screen header) should correspond to the structure D020S , the
internal table f (field list) to the structure D021S , the internal table e
(flow logic) to the structure D022S and the internal table m (matchcode
information) to the structure D023S .

If a syntax error occurs, the error
message is stored in the field f1 .

If a syntax error occurs, the number
of the incorrect line is stored in the field f2 .
By reading the return code
value, you can determine whether this line refers to the flow logic or the field
list.

If a syntax error occurs, the incorrect word is stored in the field
f3 .

The return code value is set as follows:

SY-SUBRC = 0 The
screen was generated.
SY-SUBRC <> 0 The screen could not be
generated.
SY_SUBRC = 4 The error is in the flow logic.
SY-SUBRC = 8 The
error is in the field list.

Addition 1
… OFFSET
f4

Effect
If a syntax error occurs, the position of the incorrect word
is output in this field.

Addition 2
… TRACE-FILE
f5

Effect
Stores performance data in this file. This addition
automatically switches on the trace mode.