ABAP Keyword Documentation →  ABAP − Reference →  program editing →  Dynamic Program Editing →  Source Code → 

SYNTAX-CHECK  Syntax Diagram

Short Reference

Syntax

SYNTAX-CHECK FOR itab MESSAGE mess LINE lin WORD wrd
                [PROGRAM prog] [DIRECTORY ENTRY dir]
                 [WITH CURRENT SWITCHSTATES]
                                     [error_handling].

Extras:

1. ... PROGRAM prog

2. ... DIRECTORY ENTRY dir

3. ... WITH CURRENT SWITCHSTATES

Effect

This statement executes a syntax check on the content of the internal table itab. The internal table itab must be a standard table without secondary table keys with a character-like row type.

If the internal table does not contain syntactically correct ABAP source code, then:

The additions PROGRAM and DIRECTORY ENTRY are used to set the attributes for the syntax check. The WITH CURRENT SWITCHSTATES addition specifies which switch configuration is used for the syntax check. The other error_handling additions can be used to identify other attributes of the first syntax error.

System Fields

sy-subrc Meaning
0 The internal table itab contains a syntactically correct ABAP program.
4 The internal table itab does not contain a syntactically correct ABAP program.
8 A runtime error occurred in the syntax check.

If a runtime error occurs during the syntax check (sy-subrc has the value 8), a database rollback is executed in the usual manner. As usual, the short dump of the runtime error can be found in ABAP Dump Analysis.

If the internal addition ID is specified with ERR, the value 6 can also occur for sy-subrc.

Note

It is not required to execute the SYNTAX-CHECK statement directly before GENERATE SUBROUTINE POOL or GENERATE REPORT, because the syntax check is always performed when these statements are executed.

Addition 1

... PROGRAM prog

Addition 2

... DIRECTORY ENTRY dir

Effect

These additions are used to specify the program attributes used for the syntax check.

In non-Unicode programs, at least one of these two additions must be specified and this is also recommended in Unicode programs. If neither PROGRAM nor DIRECTORY ENTRY is specified, the system uses executable program as the default program type. General default values are then assigned to the the remaining program attributes. If both additions PROGRAM and DIRECTORY ENTRY are specified, the program attributes are determined by the structure dir.

Notes

Example

Syntax check for source code in itab. By reading the attributes of the current program from the database TRDIR into the structure dir, these can be used after DIRECTORY ENTRY. When the dir-uccheck component is set, the first syntax check is executed in the same way as for non-Unicode programs and the second as for Unicode programs. The first syntax check does not find an error in a non-Unicode system and detects the error when the program is not Unicode-enabled. The second syntax check always identifies the error when the BYTE or CHARACTER MODE addition is missing from the DESCRIBE statement.

DATA: itab TYPE STANDARD TABLE OF string,
      mess TYPE string,
      lin  TYPE i,
      wrd  TYPE string,
      dir  TYPE trdir.

APPEND 'PROGRAM test.'                  TO itab.
APPEND 'DATA dat TYPE d.'               TO itab.
APPEND 'DATA len TYPE i.'               TO itab.
APPEND 'DESCRIBE FIELD dat LENGTH len.' TO itab.

SELECT SINGLE *
       FROM trdir
       INTO dir
       WHERE name = sy-repid.

dir-uccheck = ' '.

SYNTAX-CHECK FOR itab MESSAGE mess LINE lin WORD wrd
             DIRECTORY ENTRY dir.

IF sy-subrc = 4.
  MESSAGE mess TYPE 'I'.
ENDIF.

dir-uccheck = 'X'.

SYNTAX-CHECK FOR itab MESSAGE mess LINE lin WORD wrd
             DIRECTORY ENTRY dir.

IF sy-subrc = 4.
  MESSAGE mess TYPE 'I'.
ENDIF.

Example

See also Program Generation.

Addition 3

... WITH CURRENT SWITCHSTATES

Effect

This addition causes the syntax check to use the switch configuration of the Switch Framework, in the state it had when the current transaction was called. Without the addition, the switch configuration valid when the statement is executed is used.




Continue
SYNTAX-CHECK - error_handling
SYNTAX-CHECK - Internal Additions