SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → program editing → Dynamic Program Editing → Source Code → Internal Statements for Source Code Processing →SCAN
This statement is for internal use only.
It must not be used in application programs.
Variants:
1. SCAN ABAP-SOURCE itab1 ...TOKENS INTO itab2
...STATEMENTS INTO itab3.
2. SCAN AND CHECK ABAP-SOURCE itab1 ...RESULT INTO itab2.
SCAN ABAP-SOURCE itab1 ...TOKENS INTO itab2
...STATEMENTS INTO itab3.
Parts marked with " ..." are interchangeable
Extras:
1. ... FROM n1
2. ... TO
n2
3. ... KEYWORDS FROM itab
4. ... LEVELS INTO itab
5. ... STRUCTURES INTO itab
6. ... OVERFLOW INTO c1
7. ... WITH ANALYSIS
8. ... WITH DECLARATIONS
9. ... WITH BLOCKS
10. ... WITH COMMENTS
11. ... WITH PRAGMAS pragmas
12. ... WITH INCLUDES [IMPLEMENTATIONS FROM itab]
13. ... WITH TYPE-POOLS
14. ... WITH LIST TOKENIZATION
15. ... PRESERVING IDENTIFIER ESCAPING
16. ... WITHOUT TRMAC
17. ... [INCLUDE] PROGRAM FROM c2
18. ... INCLUDE INTO c3
19. ... MESSAGE INTO c4
20. ... WORD INTO c5
21. ... LINE INTO n3
22. ... OFFSET INTO n4
23. ... WITH EXPLICIT ENHANCEMENTS [IMPLEMENTATIONS FROM itab]
24. ... WITH IMPLICIT ENHANCEMENTS [IMPLEMENTATIONS FROM itab]
25. ... ENHANCEMENT OPTIONS INTO itab
26. ... ENHANCEMENTS INTO itab
27. ... WITH INACTIVE ENHANCEMENTS
28. ... FRAME PROGRAM FROM c2
29. ... REPLACING itab
Effect
Breaks down the ABAP source code in the source code table itab1 into tokens
according to the rules of the ABAP scanner. The tokens are written – one per row – to
the token table itab2. The source code to be broken down need not necessarily
be contained in an internal table. It can be specified in any character-like field. In particular, fields
of the type STRING can be used. However, this variant only makes sense if the program to be broken down
does not contain any comments. When an internal table is specified, itab1 must be a standard table.
The token table itab2 must be a standard table and have the structure
STOKES. If the addition WITH ANALYSIS is specified, the token table must have the extended structure STOKESX.
(For reasons of downward compatibility, STOKEN and STOKEX can still be used. The main difference is
that in the new structures the character string which makes up the token is typed with reference to
the data type string. With the structures STOKEN and STOKEX, a C field of length 30 and an OVERFLOW area are used instead.)
Normally, comments are filtered out and subordinate source code units
(include programs, called
macros) are ignored. These semantics
can be modified by using the additions WITH COMMENTS and WITH ANALYSIS.
In addition to classifying the source code by token, the scanner organizes the tokens themselves
into statements (using the colon-comma logic to form chained statements) and the statement table itab3 contains a statement description on each row. Here, a three-part
chained statement
"a: b, c1 c2, d." produces three entries "a b,",
"a c1 c2,", and "a d." in the statement table itab3.
The statement table itab3 must be a standard table without secondary keys and have the structure SSTMNT.
The statement classification characters colon, comma, and period are not written to the token table
itab2. Instead, the table itab3 contains details
about the position of a colon or the type (comma or period) and position of the end marker in the statement description.
System Fields
sy-subrc | Meaning |
0 | Source code table is not empty, contains no errors, and is broken down into tokens. |
1 | Source code table is not empty and is broken down into tokens, but at least one include program does not exist (can occur only in connection with the addition WITH INCLUDES). |
2 | Source code table itab1 is empty or a blank row range was selected (applies to the additions FROM and TO). |
4 | Scanner detects error in source code. |
8 | Other error or runtime error in scanner. |
If a runtime error occurs in the scanner (sy-subrc has the value 8), a database rollback is executed as usual.
Components of the Structure STOKES
The fields of the structure STOKES, and thus the columns of the token table itab2, have the following meaning:
If the structure STOKEN is specified, three more fields are filled and the following must be noted:
Components of the Structure SSTMNT
The fields of the structure SSTMNT, and thus the columns of the statement table itab3, have the following meaning:
Notes
... FROM n1
... TO n2
Effect
Breaks down the source code table itab1 into tokens not from start to finish, but only from row n1 to row n2.
The additions FROM n1 and TO n2 must, in this order, follow the specified source code table itab1.
Notes
... KEYWORDS FROM itab
Effect
Does not return all statements, only those specified in the keyword table itab.
If the keyword table is empty (hence it contains 0 rows), all the statements are selected.
The rows of the keyword table are handled as a character field. It must be a standard table without secondary keys.
To select a Native SQL
statement or a macro definition, the pseudo keywords EXEC_SQL or DEFINE_MACRO can be specified. It makes
no difference whether the statements EXEC or DEFINE
occur as well. Native SQL statements and macro definitions are returned as one statement (of type E or M even if the expansion of a macro definition produces more than one statement.
If the keyword table contains a blank row, blank statements are also selected.
... LEVELS INTO itab
Effect
Stores details about each edited source code unit (source code table itab1 itself, expanded
include programs, expanded macro definitions) in the level table itab.
Specify a level table only with the additions WITH INCLUDES or WITH IMPLICIT ENHANCEMENTS.
The level table itab must have the structure SLEVEL. It must be a standard table without secondary keys.
The fields of the structure SLEVEL (and consequently the columns of the level table itab) have the following meaning:
If the source code unit contains include programs or macro calls, the row range [FROM, TO] in the statement table also covers the statements in subordinate source code units.
Note
Enhancements of type E are saved as normal includes in the level table.
... STRUCTURES INTO itab
Effect
Details of the construction of the source code table itab1 are written to the structure table itab.
The structure tableitab must have the structure SSTRUC. It must be a standard table without secondary keys.
The fields in SSTRUC (which are also the columns of structure table itab) have the following meanings:
If the program that is executed for the statement has incorrect syntax, the behavior is undefined.
... OVERFLOW INTO c1
Effect
This addition is only allowed and required if the token table itab2 has the structure STOKEN or STOKEX.
If a token is too large to be stored in the token table in the field STR, it is placed in the overflow
area c1. The offset of the token in the overflow area then lies in the token table in the field OFF1.
... WITH ANALYSIS
Effect
Breaks down each token t = a+b(c) according to the logic of the RSYN keyword ANALYSIS into its three components a, b, and c.
Offset and length of components a, b and, c are stored in the fields LEN1, OFF2, LEN2, OFF3, and LEN3 in the token table. (The offset of OFF1 is always 0 and therefore not required.)
If the addition WITH ANALYSIS is specified, the token table itab2
must have the structure STOKESX, so that the fields LEN1, OFF2, LEN2, OFF3 and LEN3 are available.
If the token table has the structure STOKEX, the following must be noted:
If the whole token exists
in the token table, the offsets specified are relative to the start of the token. If the token is in
the overflow area c1, the offsets specified are relative to the start of the overflow area.
... WITH DECLARATIONS
Effect
Returns all declarative statements and all statements with inline declarations.
... WITH BLOCKS
Effect
Returns all statements that define a processing block or a statement block.
... WITH COMMENTS
Effect
Also returns comments, with each individual comment representing a token. Also writes entries for each
cohesive block to the table itab3. Here, a distinction is made between comments
within statements and comments at program level. In itab3, an entry for a comment within a statement always comes before the statement containing the comment.
Example
Look at the following program fragment. The prefixed numbers are the indexes of the tokens.
SCAN then enters the following values for the components TYPE,
FROM and TO (in this order from left to right) into itab3.
'P' | 1 | 2 | |
'S' | 3 | 5 | |
'K' | 6 | 9 |
Note
If the addition WITH COMMENTS is used, the table itab2 must have the row type STOKES or STOKESX.
... WITH PRAGMAS pragmas
Effect
This addition returns all relevant pragmas for each statement before the first correct token of the statement but after a block of comments collected using the addition WITH COMMENTS. pragmas expects a data object of the type c with length 1, usually containing the value "*". Other values are intended for and recognized by special test tools.
A block of pragmas is combined in the statement table under the statement type "G". In this way, the block order is for a statement which contains comments and matching pragmas "S-G-K".
Pragmas which are not determined for ABAP Compiler are searched for in the TRPRAGMA database table.
Illegal (for example, unknown or lexically incorrect) pragmas are processed in the same way as legal
pragmas, that is, they are summarized in a block preceding the actual statement (ID "G"). This corresponds to the behavior of the scanner in the compiler.
... WITH INCLUDES [IMPLEMENTATIONS FROM itab]
Effect
Also breaks down subordinate source code units (include programs, called macros) into tokens.
In addition, source code plug-ins of explicit and implicit
enhancement options
which may exist are automatically inserted in the source code to be split. The optional addition
IMPLEMENTATIONS FROM itab can be used to limit the number of inserted enhancements to the number
specified in itab. If itab is empty, any enhancements are ignored. itab must be a standard table without secondary keys.
Notes
... WITH TYPE-POOLS
Effect
This addition has the same effect as the WITH INCLUDES addition, except that with the former, include programs belonging to
type groups are broken down into tokens.
... WITH LIST TOKENIZATION
Effect
Tokens of the form (a1, a2, a3) are not returned as tokens but broken down into the elementary components.
... PRESERVING IDENTIFIER ESCAPING
Effect
By default, exclamation marks before names (identifiers) are deleted. Exclamation marks can be used to distinguish between names and keywords. This addition prevents their deletion.
... WITHOUT TRMAC
Effect
If a statement does not start with an ABAP keyword or with a DEFINE macro,
the system does not check whether this is a TRMAC macro, but assumes that
the statement is unknown. (Unknown statements are flagged in the statement table itab3 with a U in the field TYPE.)
To avoid unnecessary database accesses to the table TRMAC, the addition
WITHOUT TRMAC should be used whenever it is assumed that the source code
being scanned contains unknown statements. Unknown statements are particularly likely to occur if the
addition FROM n1 is used, because the scanner does not start at the beginning of the source code, but from a specified point.
Note
If WITHOUT TRMAC is used with WITH INCLUDES,
TRMAC macros are not expanded because the system does not recognize them as subordinate source code units.
... [INCLUDE] PROGRAM FROM c2
... INCLUDE INTO c3
... MESSAGE INTO c4
... WORD INTO c5
... LINE INTO n3
... OFFSET INTO n4
Effect
The above additions have the same effect as the corresponding additions in the statement SYNTAX-CHECK: c2 is an input field for a program name to be assigned to the source code, while the fields c3, c4, c5, n3, and n4 are output fields in case an error occurs.
In Release 7.00, the addition PROGRAM FROM was renamed as INCLUDE
PROGRAM FROM to clarify the difference between the master program and the split source code unit.
If the addition is used in its previous form PROGRAM FROM, it sets the master program and the source code text unit to be scanned at the same time.
To be able to analyze errors without modifying programs, use the additions INCLUDE
INTO, MESSAGE INTO, WORD INTO, LINE
INTO and OFFSET INTO. These provide information about the errors which have occurred.
... WITH EXPLICIT ENHANCEMENTS [IMPLEMENTATIONS FROM itab]
Effect
When WITH EXPLICIT ENHANCEMENTS is specified, the existing source code plug-ins for explicit enhancement points are automatically inserted into the split source code.
The optional addition IMPLEMENTATIONS FROM can limit the number of inserted
enhancements to the number specified in itab. If itab is empty, any enhancements are ignored.
... WITH IMPLICIT ENHANCEMENTS [IMPLEMENTATIONS FROM itab]
Effect
When WITH IMPLICIT ENHANCEMENTS is specified, the existing source code plug-ins for implicit enhancement points are automatically inserted into the split source code.
The optional addition IMPLEMENTATIONS FROM can limit the number of inserted
enhancements to the number specified in itab. If itab is empty, any enhancements are ignored.
... ENHANCEMENT OPTIONS INTO itab
Effect
Details about the enhancement points that exist in the source code unit that is being edited are stored in the description table itab. It therefore only makes sense to specify an enhancement table together with additions WITH INCLUDES, WITH EXPLICIT ENHANCEMENTS, or WITH IMPLICIT ENHANCEMENTS.
The level table itab must be a standard table without a secondary key and must have the row structure SEOPTN whose fields have the following meaning:
Notes
... ENHANCEMENTS INTO itab
Effect
Details of the enhancement implementations in the source code that is being edited are saved in the enhancement table itab. It therefore only makes sense to specify an enhancement table together with additions WITH INCLUDES, WITH EXPLICIT ENHANCEMENTS, or WITH IMPLICIT ENHANCEMENTS.
The enhancement table itab must be a standard table without secondary keys and have the row structure SENHMT, whose fields have the following meaning:
Notes
... WITH INACTIVE ENHANCEMENTS
Effect
This addition is only possible with ENHANCEMENTS INTO. If WITH
INACTIVE ENHANCEMENTS is specified as well, deactivated or overwritten enhancement implementations
are respected. For these, the values "e" and "f" are stored instead of "E" and "F" in the TYPE column of the itab enhancement table.
... FRAME PROGRAM FROM c2
Effect
Using this addition, the master program is specified to the source code unit to be split. This is necessary, especially for inserting source code plug-ins correctly.
Note
In the case of the master program, remember that even when this addition of the statement SCAN
is specified, it is not edited at the same time. The statement SCAN always
edits only the passed source code and possibly the included type groups or include programs. To edit
an include program in its context, the master program must be passed itself. Here, any non-relevant
include programs can be hidden using the addition REPLACING. As an alternative
to the use of REPLACING, a mock master program, which constructs the correct context for include programs to be edited but remains empty the rest of the time, is also possible.
... REPLACING itab
Effect
Individual INCLUDE statements can be overridden by specifying an internal table of type SREPTAB. If itab contains an entry "INCL" in column name, the statement INCLUDE incl does not read the include INCL. Instead the source code from column itab-source is inserted.
It has the same effect as the addition REPLACING of the internal statement SYNTAX-CHECK FOR PROGRAM. However, the entry itab-trdir is ignored.
itab must be a standard table without secondary keys.
SCAN AND CHECK ABAP-SOURCE itab1 ...RESULT INTO itab2.
Parts marked with " ..." are interchangeable
Extras:
1. ... PROGRAM FROM c1
2. ... INCLUDE INTO c2
3. ... MESSAGE INTO c3
4. ... WORD INTO c4
5. ... LINE INTO n1
6. ... OFFSET INTO n2
Effect
Checks the syntax of the program in table itab1. This check writes all information
collected about the program, such as statement structures, statements, tokens, data objects, or types,
to the variable result. Here, result must have the type SYSCH_RESULT, defined in the
type group SYSCH.
... PROGRAM FROM c1
... INCLUDE INTO c2
Addition 3
... MESSAGE INTO c3
Addition 4
... WORD INTO c4
Addition 5
... LINE INTO n1
Addition 6
... OFFSET INTO n2
Effect
The above additions have the same effect as the corresponding additions in the statement
SYNTAX-CHECK: c1 is an input field for a program
name to be assigned to the source code, the fields c2, c3, c4, n1, and n2 are output fields, used when errors occur.
To enable errors to be analyzed without the program being modified, the additions INCLUDE,
MESSAGE, WORD, LINE, and OFFSET must be specified to gather information about the error in question.
Handleable Exceptions
CX_SY_SCAN_SOURCE_TOO_WIDE