Warning: Undefined variable $saptab in /customers/b/9/9/trailsap.com/httpd.www/abap-statements/index.php on line 46
Get Example source ABAP code based on a different SAP table
Warning: Undefined variable $prev in /customers/b/9/9/trailsap.com/httpd.www/abap-statements/index.php on line 62
Standard SAP Help for SCAN
SCAN ABAP Code Snippet • SCAN ABAP_STATEMENT_INT
ABAP_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 ABAP_STATEMENT_INT • TOKENS INTO SCAN ABAP-SOURCE (internal) • STATEMENTS INTO SCAN ABAP-SOURCE (internal)
ABAP_VARIANT_1 SCAN ABAP-SOURCE itab1 ...TOKENS INTO itab2 ...STATEMENTS INTO itab3.
ABAP_ANY_SEQUENCE
ABAP Addition 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 ABAP Code Snippet 13 ... WITH TYPE-POOLS 14 ... WITH LIST TOKENIZATION 15 ... PRESERVING IDENTIFIER ESCAPING 16 ... WITHOUT TRMAC ABAP Code Snippet ABAP Code Snippet 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
What does it do? 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 without secondary keys.
The token table itab2 must be a standard table without secondary keys 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 ( ABAP Code Snippetmacros) 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 Fieldssy-subrcMeaning 0Source code table is not empty, contains no errors, and is broken down into tokens. 1Source code table is not empty and is broken down into tokens, but at least one include program does not exist (can occur only in co ABAP Code Snippet 2Source code table itab1 is empty or a blank row range was selected (applies to the additions FROM and TO). 4Scanner detects error in source code. 8Other 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: TYPEType of token with possible values:
I (identifier) S (string, i.e. character literal) L (list, enclosed in parentheses) C (comment) B (beginning of a list) D (separator (divider) between list elements) E (end of a list)
Types B, D, and E can only appear if the addition WITH LIST TOKENIZATION is specified. ROWNumber of row where token occurs or where it begins (>= 1) COLOffset of first character of token relative to start of row (>= 0) STRCharacter string forming the token.
If the structure STOKEN is specified, three more fields are filled and the following must be noted: STRThe character string forming the token contains only the first part if the character string is longer than 30. LENLength of the token OVFLOverflow 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) OFF1Offset 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.
Components of the Structure SSTMNT
The fields of the structure SSTMNT, and thus the columns of the statement table itab3, have the following meaning: TYPEType of statement with possible values:
E (Native SQL statement between EXEC SQL and ENDEXEC) ABAP Code Snippet ABAP Code SnippetABAP Code Snippet T (TYPE-POOLS pool) V (TYPE-POOLS pool, pool does not exist) 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) A (method call in short form) K (other ABAP key word) N (blank statement) P (comment between statements) S (comment within statements) U (unknown, non-blank statement) LEVELIndex of source code unit in the level table itab specified after LEVELS INTO (>= 1, if level table specified, otherwise 0). STRUCIndex of the statement in the structure table itab specified after STRUCTURES INTO (0 if the structure table is not specified or the structure in which the statement occurs could not be constructed). FROMIndex of first token of statement in the token table itab2 (FROM = TO + 1, if the statement consists only of the end marker (comma or period)) TOIndex of last token of statement in the token table itab2 (the end marker of the statement no longer counts as a token) NUMBERStatement counter in a source code unit. Covers all statements, regardless of how many are actually selected (in cases where a key word table itab is specified after KEYWORDS FROM) PREFIXLENNumber of tokens before the colon (with chained statements >= 1, otherwise 0) COLONROWRow number of colon (with chained statements >= 1, otherwise 0) COLONCOLColumn number of colon (with chained statements >= 0, otherwise 0) TERMINATOR End marker of a statement (normally a period or a comma, but SPACE in the case of embedded Native SQL statements and internal macro definitions) TROWRow number of the end marker (>= 1, if TERMINATOR <(><<)>> SPACE, otherwise 0) TCOLColumn position of the end marker (>= 0, if TERMINATOR <(><<)>> SPACE, otherwise 0) ENHMTIndex in the enhancement table of type SENHMT, if the statement was enhanced or originates completely from an enhancement implementation. If addition ENHANCEMENTS INTO itab is not specified, this value is always 0.
RESET M2
Latest notes:When macro calls are expanded, no position specifications are available. The corresponding fields in the token table itab2 and in the statement table itab3 are then set to 0. Unlike in the usual syntax check, the following are not treated as errors: Comma without preceding colon (the comma then acts as an end marker), Open chained statement sequence at end of source code, i.e. the last statement is closed by a comma, not by a period, Open statement at end of source code, i.e. the last statement is closed neither by a period nor by a comma. To enable errors to be analyzed without the program being modified, ABAP Code Snippet and OFFSET must be specified to gather information about the error in question.
• FROM SCAN ABAP-SOURCE (internal) • TO SCAN ABAP-SOURCE (internal)
ABAP AdditionABAP Addition
What does it do? 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 specification of the source code table itab1.
RESET M2
Latest notes:When using the start specification n1, use the addition WITHOUT TRMAC to ensure that there are no unnecessary database accesses to the table TRMAC. The end specification n2 is treated as 'soft', i.e. a statement that begins on a line <(><<)>= n2, but ends only on a line > n2, is returned completely.
If the end specification n2 splits a chained statement, only the split part up to the next comma is returned completely, not the entire chained statement up to the next period. Negative line specifications are not allowed and produce a runtime error. A line specification of 0 amounts essentially to no specification. If n1 > number of rows in source code table, the scanner is not called (sy-subrc = 2). If n1 > n2 and n2 > 0, the scanner is not called (sy-subrc = 2).
• KEYWORDS FROM SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? Does not return all statements, only those specified in the key word table itab.
If the key word table is empty (i.e. it contains 0 rows), all the statements are selected.
The rows of the key word table are treated 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 key words EXEC_SQL or DEFINE_MACRO can be specified. It makes no difference whether the statements EXEC or DEFINE occur as well. NativeSQL 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 key word table contains a blank row, blank statements are also selected.
• LEVELS INTO SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? Stores details about each edited source code unit (source code table itab1 itself, expanded ABAP Code Snippet definitions) in the level table itab.
ABAP Code SnippetWITH 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: TYPEType of source code unit with possible values:
P (program) D (internal DEFINE macro) R (macro from table TRMAC) NAMEName of source code unit (name of include program, macro name) DEPTHCurrent nesting depth of source code unit (>= 1) LEVELIndex of superior (i.e. including or calling) source code unit in the level table (>= 1, if DEPTH >= 2, otherwise 0) STMNTIndex of superior (i.e. including or calling) statement in the statement table (>= 1, if DEPTH >= 2, otherwise 0) FROMIndex of first statement of source code unit in the statement table (>= 1) TOIndex of last statement of source code unit in the statement table (>= 1)
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.
Latest notes: Enhancements of type E are saved as normal includes in the level table.
• STRUCTURES INTO SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? 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: TYPEType of 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 (jump command) D (structured declaration) E (event) S (sequence of statements with simple structures) STMNT_TYPEThe statement type of the beginning of the structure. The values are listed in the type pool SCAN in structure SCAN_STRUC_STMNT_TYPE. KEY_STARTFlags whether the start of the structure is described semantically ('X' if there is a special statement, otherwise ' '). KEY_ENDFlags whether the end of the structure is described semantically ('X' if there is a special statement, otherwise ' '). STMNT_FROMIndex of the first statement of the structure in the statement table itab3. STMNT_TOIndex of the last statement of the structure in the statement table itab3. STRUC_FROMIndex of the first substructure of the structure in structure table itab. STRUC_TOIndex of the last substructure of the structure in structure table itab. BACKIndex of the structure in the structure table itab that contains the structure as a substructure (0 if the structure is the root structure of a structure tree).
• OVERFLOW INTO SCAN ABAP-SOURC (internal)E
ABAP Addition
What does it do? 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 SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? Breaks down each token t = a+b(c) according to the logic of the RSYN key word 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 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.
• WITH DECLARATIONS SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? Returns all declarative statements and all statements with inline declarations.
• WITH BLOCKS SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? Returns all statements that define a processing block or a statement block.
• WITH COMMENTS SCAN ABAP-SOURCE (internal)
ABAP Addition
What does it do? 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 ABAP Coding Look at the following program fragment. The prefixed numbers are the indexes of the tokens. 1 * An example 2 * with scattered comments 6 MOVE 3 * inserted comment 1 7 X 4 * inserted comment 2 8 TO 9 Y 5 * inserted comment 3