SYNTAX-CHECK

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 for the content of the internal table itab. The internal table itab must be a standard table with character-like row type.

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

Use additions PROGRAM and DIRECTORY ENTRY to set the attributes of the syntax check. The addition WITH CURRENT SWITCHSTATES specifies which switch configuration is used for the syntax check. Use the other additions error_handling to detect 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 contains an ABAP program with syntax errors.
8 Other errors occurred.

Note

The execution of the statement SYNTAX-CHECK directly before GENERATE SUBROUTINE POOL or GENERATE REPORT is not required, because the syntax check is always executed when using these statements.

Addition 1

... PROGRAM prog

Addition 2

... DIRECTORY ENTRY dir

Effect

Use these additions to determine the program attributes used for the syntax check.

In Non-Unicode programs, you should, and in Unicode programs, you must specify one of these two additions. If you use neither PROGRAM nor DIRECTORY ENTRY, the system assumes an executable program as the program type. The other program attributes are then set to general standard values. If both additions PROGRAM and DIRECTORY ENTRY are specified, the program attributes are determined by the structure dir.

Notes

Example

Syntax check for a source code in itab. When importing the properties of the current program from the database TRDIR into the structure dir, it can be used after the DIRECTORY ENTRY. When setting the component dir-uccheck, the first syntax check is executed in the same way as for non-Unicode programs and the second one 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 finds the error when the addition BYTE or CHARACTER MODE is missing in the statement DESCRIBE.

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.

Addition 3

... WITH CURRENT SWITCHSTATES

Effect

This addition specifies that the syntax check is executed with the same switch settings of the switch framework as for the execution of the statement GENERATE SUBROUTINE POOL - that is, the same switch configuration that existed when the current transaction was called is used.

Without the addition, the switch configuration valid at the time of the statement execution is used.

Note

Without the addition, the syntax check is executed as for every implicit or explicit compilation of ABAP programs. For the explicit compilation, the internal statement GENERATE REPORT is used.