SYNTAX-CHECK ( SAP ABAP Keyword)

SYNTAX-CHECK is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.

SYNTAX-CHECK

Basic form
SYNTAX-CHECK FOR itab …MESSAGE f …LINE g …WORD h.

Additions

1. … PROGRAM f1
2. … INCLUDE f2
3. … OFFSET f3
4. … TRACE-TABLE t1
5. … DIRECTORY ENTRY f4
6. … REPLACING f5
7. … FRAME ENTRY f6
8. … MESSAGE-ID f7
9. … ID tabid TABLE itab

Effect
Syntax check for programs

The
program code is taken from the internal table itab . If a syntax error
is detected during the check, the fields f , g and h are filled as
follows: – f contains the error message text – g contains the program
line where the error occurred – h contains the incorrect word in the
program

Example
f and h are declared as text fields and g as a whole number (integer).

DATA: f(240),
g TYPE I,
h(72).

The return code value is set as follows:

SY-SUBRC = 0 The program contains no syntax errors.
SY_SUBRC = 4 The program contains syntax errors.
SY-SUBRC = 8 Other errors hav occurred.

Addition 1
… PROGRAM f1

Effect
Specifies a program name

If
the addition DIRECTORY ENTRY is missing, the program name is used to
determine the program attributes required for the check, e.g.:
– include or program – the logical database
The field f1 is meant to contain the field attributes of SY-REPID .

Addition 2
… INCLUDE f2

Effect
If there is a syntax error, this field contains the name of the include program where the error occurred.
The field f2 is meant to contain the field attributes of SY-REPID .

Addition 3
… OFFSET f3

Effect
If there is a syntax error, this field contains the position of the incorrect word in the incorrect line.
The field f3 should be declared as a whole number (integer).

Addition 4
… TRACE-TABLE t1

Effect
Trace
output is stored in this table. To switch trace output on or off during
program checks, you use the SYNTAX-TRACE ON and SYNTAX-TRACE OFF
statements.

Addition 5
… DIRECTORY ENTRY f4

Effect
The
program attributes required for the check are taken from the field f4
which must correspond to the structure of the table TRDIR .

Addition 6
… REPLACING f5
The field f5 is meant to contain the field attributes of SY-REPID .

Effect
The
program code placed in the internal table is an include, not the main
program. Therefore, it is the main program specified under PROGRAM
which is to be checked. If this program contains an include name f5 ,
the contents of the internal table should be taken into account instead.
You should use this addition only with PROGRAM .

Addition 7
… FRAME ENTRY f6

Effect
The
main program attributes required for the check (e.g. logical database,
program type) are taken from the field f6 . f6 should have the
structure of the table TRDIR .

Addition 8
… MESSAGE-ID f7

Effect
If a syntax error occurs, the field f7 contains the relevant message key which has a structure similar to the table TRMSG .

Addition 9
… ID tabid TABLE itab

Effect
Returns syntax check information. tabid contains the type of information written to the internal table itab .
For
correction proposals ( ID ‘CORR’ ), the type group SLIN must be
included, for other information the tyep group SYNT . Both these type
groups contain the necessary type specifications.
Please do not use this addition. It is intended only for internal use!
tabid
outputs the following information from the program code: ID ‘MSG ‘ …
warning messages ID ‘CORR’ … correction proposals ID ‘SYMB’ …
technical symbol table dump ID ‘DATA’ … data objects from the program
ID ‘DPAR’ … data object parameters ID ‘TYPE’ … type objects from
the program ID ‘FOTY’ … type objects used by FORM routines ID ‘FUTY’
… type objects used by function modules ID ‘TYCH’ … components of
type objects ID ‘CROS’ … referenced data objects ID ‘STR ‘ …
identifiers ID ‘FORM’ … FORM routines ID ‘FPAR’ … FORM parameters
ID ‘PERF’ … PERFORM calls ID ‘APAR’ … PERFORM parameters ID ‘FUNC’
… function modules ID ‘FFPA’ … function module parameters ID ‘CALL’
… CALL FUNCTION calls ID ‘FAPA’ … CALL FUNCTION parameters ID
‘HYPH’ … data objects with a hyphen in the name ID ‘INCL’ …
includes in the program

——————————————————————————

SYNTAX-CHECK

Basic form
SYNTAX-CHECK FOR DYNPRO h f e m …MESSAGE f1 …LINE f2
…WORD f3.

Additions
1. … OFFSET f1
2. … TRACE-TABLE t1

Effect
Syntax check for screen

The
screen description is taken from the field string h and the internal
tables f , e and m . The field string h (screen header) should
correspond to the structure D020S , the internal table f (field list)
to the structure D021S , the internal table e (flow logic) to the
structure D022S and the internal table m (matchcode information) to the
structure D023S .
Example

DATA: DHEAD LIKE D020S, “screen header
DFIELDS LIKE D021S OCCURS 20, “field list
DFLOWL LIKE D022S OCCURS 20, “flow logic
MCINFO LIKE D023S OCCURS 20. “matchcode information

If a syntax error is detected during the check, the fields f1 , f2 and f3 are filled as follows:
– f1 contains the error message text
– f2 contains the screen line where the error occurred
– f3 contains the incorrect word in the screen

The return code value is set as follows:

SY-SUBRC = 0 The screen contains no syntax errors.
SY_SUBRC = 4 The screen contains syntax errors.

Addition 1
… OFFSET f1

Effect
When a systax error occurs, this field contains the position of the incorrect word in the incorrect line.

Addition 2
… TRACE-TABLE t1

Effect
Any trace output is stored in this table. Trace output is automatically switched on when you specify this addition.