SCAN

SCAN <Syntax Diagram

Incompatible changes or further developments may occur at any time without warning or notice.

1. SCAN ABAP-SOURCE itab1 TOKENS INTO itab2
STATEMENTS INTO itab3.
2. SCAN AND CHECK ABAP-SOURCE itab1 ...RESULT INTO itab2.


Variant 1

SCAN ABAP-SOURCE itab1 ... TOKENS INTO itab2
...STATEMENTS INTO itab3.


1. ... FROM n1
2. ... TO n2
3. ... KEYWORDS FROM itab4
4. ... LEVELS INTO itab5
5. ... STRUCTURES INTO itab6.
6. ... OVERFLOW INTO c1
7. ... WITH ANALYSIS
8. ... WITH COMMENTS
9. ... WITH INCLUDES
10. ... WITHOUT TRMAC
11. ... PROGRAM FROM c2
12. ... INCLUDE INTO c3
13. ... MESSAGE INTO c4
14. ... WORD INTO c5
15. ... LINE INTO n3
16. ... OFFSET INTO n4

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 line - to the token table itab2 .

The token table itab2 must have the structure STOKEN. (If you specify the addition WITH ANALYSIS, the token table must have the extended structure STOKEX.)

Normally, comments are filtered out and subordinate source code units (included programs, called macros) are ignored. If you want to include these items, use 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 chain records - and the statement table itab3 contains a statement description on each line. Here, a three-part chain record "a: b, c1 c2, d." results in three entries "a b,", "a c1 c2," and "a d." in the statement table itab3.

The statement table itab3 must 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.

The

return code

is set as follows:

SY-SUBRC = 0:

Source code table is not empty, contains no errors and is broken down into tokens.

SY-SUBRC = 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).

SY-SUBRC = 2:

Source code table itab1 is empty or a blank line range was selected (applies to the additions FROM and TO).

The fields of the structure STOKEN, and thus the columns of the token table itab2, have the following meaning:

TYPE Type of token with possible values:

I (Identifier)
S (String, i.e. character literal)
L (List, enclosed in parentheses)
C (Comment)

ROW Number of line where token occurs or where it begins (>= 1)

COL Offset of first character of token relative to start of line (>= 0)

LEN Length of token

STR Character string forming the token (or just first part)

OVFL Overflow flag for field STR with the following possible values:

SPACE (no overflow, token fits completely in field STR)
X (overflow, either not resolved (no overflow area specified) or token fits in overflow area c1))
O (overflow of token and overflow of overflow area c1)

OFF1 Offset in overflow area, if

token does not fit completely in field STR and
an overflow area c1 is specified and
token fits completely in overflow area c1.

The fields of the structure SSTMNT, and thus the columns of the statement table itab3, have the following meaning:

TYPE Type of statement with the following possible values:

E (Native SQL statement between EXEC SQL and
ENDEXEC)
I (INCLUDE prog)
J (INCLUDE prog, prog does not exist, can
occur only in connection with the addition
WITH INCLUDES)
R (Call a macro from table TRMAC)
D (Call a macro internally defined with DEFINE)
M (Macro definition between DEFINE and
END-OF-DEFINITION)
C (COMPUTE statement, sometimes without
COMPUTE as first token)
K (Other ABAP/4 key word)
N (Blank statement)
U (Unknown, non-blank statement)

LEVEL Index of source code unit in the level table itab5 (>= 1, if level table specified, otherwise 0).

STRUC Index of the statement in the structure table itab6 (0 if the structure table is not specified or the structure in which the statement occurs could not be constructed).

FROM Index of first token of statement in the token table itab2

TO Index of last token of statement in the token table itab2 (the end marker of the statement no longer counts as a token)

NUMBER Statement counter in a source code unit. Covers all statements, regardless of how many are actually selected - in cases where a key word table itab4 is specified

PREFIXLEN Number of tokens before the colon (with chain statements >= 1, otherwise 0)

COLONROW Line number of colon (with chain statements >= 1, otherwise 0)

COLONCOL Column position of colon (with chain statements >= 0, otheriwse 0)

TERMINATOR End marker of a statement (normally a period or a comma, but SPACE in the case of native SQL statements and internal macro definitions)

TROW Line number of end marker (>= 1, if TERMINATOR <> SPACE, otherwise 0)

TCOL Column position of end marker (>= 0, if TERMINATOR <> SPACE, otherwise 0)

When expanding macro calls, no position specifications are available. The relevant fields in the token table itab2 and in the statement table itab3 are then set to 0.

Effect

Breaks down the source code table itab1 into tokens not from start to finish, but only from line n1 to line n2.

The additions FROM n1 and TO n2 must, in this order, follow the specification of the source code table itab1.

When using the start specification n1, use the addition WITHOUT TRMAC to ensure that there are no unnecessary database accesses to the table TRMAC.

Effect

Does not return all statements, only those specified in the key word table itab4.

If the key word table is empty (i.e. it contains 0 lines), all the statements are selected.

The lines of the key word table are treated as a character field.

To select a native SQL statement or a macro definition, you can specify the pseudo key words EXEC_SQL or DEFINE_MACRO. 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 results in more than one statement.

If the key word table contains a blank line, blank statements are also selected.

Effect

Stores details about each edited source code unit (source code table itab1 itself, expanded include programs, expanded macro definitions) in the level table itab5.

Specification of a level table makes sense only with the addition WITH INCLUDES.

The level table itab5 must have the structure SLEVEL.

The fields of the structure SLEVEL - and consequently the columns of the level table itab5 have the following meaning:

TYPE Type of source code unit with the following possible values:

P (Program)
D (Internal DEFINE macro)
R (Macro from table TRMAC)

NAME Name of source code unit (name of include program, macro name)

DEPTH Current nesting depth of source code unit (>= 1)

LEVEL Index of superior (i.e. included or called) source code unit in the level table (>= 1, if DEPTH >= 2, otherwise 0)

STMNT Index of superior (d.h. included or called) statement in the statement table (>= 1, if DEPTH >= 2, otherwise 0)

FROM Index of first statement of source code unit in the statement table (>= 1)

TO Index of last statement of source code unit in the statement table (>= 1)

If the source code unit contains include programs or macro calls, the line range [FROM, TO ] in the statement table also covers the statements in subordinate source code units.

Effect

Details of the construction of the source text table are given in the structure table itab6.

The structure table itab6 must have the structure SSTRUC.

The fields in SSTRUC (which are also the columns of structure table itab6) have the following meanings:

TYPE Type of the structure with possible values:
P (Beginning of the source code)
R (Subroutine)
M (Macro, EXEC SQL)
I (Loop)
A (Case distinction)
C (Condition in a case distinction)
J (Goto command)
D (Structured declaration)
E (Event)
S (Follow-on from simple structured statement)

STMNT_TYPE

The statement type of the beginning of the structure. The values are listed in the type pool SCAN in structure SCAN_STRUC_STMNT_TYPE.

KEY_START

Flags whether the start of the structure is described semantically ('X' if there is a special statement, otherwise blank).

KEY_END

Flags whether the end of the structure is described semantically ('X' if there is a special statement, otherwise blank).

STMNT_FROM

Index of the first statement of the structure in the statement table itab3.

STMNT_TO

Index of the last statement of the structure in the statement table itab3.

<STRUC_FROM

Index of the first substructure of the structure in structure table itab6.

STRUC_TO

Index of the last substructure of the structure in structure table itab6.

BACK

Index of the structure in the structure table itab6 that contains the structure as a substructure (0 if the structure is the root structure of a structure tree).

Effect

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.

Effect

Breaks down each token t = a+b(c) according to the logic of the RSYN key word >ANALY into its three components a, b and c.

Offset and length of components a, b and c are stored in the fields OFF1, LEN1, OFF2, LEN2, OFF3 and LEN3 in the token table.

If you specify the addition WITH ANALYSIS, the token table itab2 must have the structure STOKEX, so that the fields LEN1, OFF2, LEN2, OFF3 and LEN3 are available.

If the whole token exists in the token table, the offset specifications are relative to the token start. If the token is in the overflow area c1 , the offset specifications are relative to the start of the overflow area.

Effect

Returns comments also, with each individual comment representing a token.

Note

The addition ... WITH COMMENTS is unfortunately not supported at present!

Effect

Also breaks down subordinate source code units (included programs, called macros) into tokens.

You should normally combine the addition WITH INCLUDES with the addition LEVELS INTO itab5.

If (at least) one included program does not exist, SY-SUBRC is set to 1 and the relevant INCLUDE statement is flagged in the statement table itab3 by the statement type J (instead of I), but the breakdown process continues. The level table itab5 contains no entry for include programs that do not exist.

Effect

If a statement begins neither with an ABAP/4 key word nor with a DEFINE macro, the system does not check whether this is a TRMAC macro, but assumes an unknown statement. (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, you should use the addition WITHOUT TRMAC whenever you assume that the source code to be scanned contains unknown statements. Unknown statements are particularly likely to occur if you use the addition FROM n1, because the scanner does not start at the beginning of the source code, but from a specified point.

Note

If you use WITHOUT TRMAC with WITH INCLUDES, TRMAC macros are not expanded because the system does not recognize them as subordinate source code units.

Effect

The above additions have the same meaning as those for the SYNTAX-CHECK statement: 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.

To be able to analyze errors without modifying programs, use the additions INCLUDE, MESSAGE, WORD, LINE and OFFSET. These provide information about the errors which have occurred.

Variant 2

SCAN AND CHECK ABAP-SOURCE itab1 ...RESULT INTO itab2.

Parts marked with " ..." are interchangeable

Effect

The syntax of the program in table itab1 is checked. During the check, all of the information from the program, such as statement structures, statements, tokens, data objects, types and do on are placed into the result field. This field must have the type SYSCH_RESULT, which is defined in type group SYSCH. You must therefore declare type group SYSCH in your program using a TYPE-POOLS statement.

Effect

The above additions have the same effect as the corresponding additions in the 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 you to analyze errors without having to modify the program, you should specify the INCLUDE, WORD, LINE and OFFSET additions for the information about the error that occurred.