ARTICLE
Type Checks and Type Compatibility
Overview
1 Field symbols
2 STRUCTURE
3 LIKE
4 INCLUDES
1 Field symbols
If you define the types of field symbols using
FIELD-SYMBOLS <(><)>
STRUCTURE s DEFAULT wa and they are later assigned a data object
wa using ASSIGN wa TO ... ,
in non-Unicode programs both statements are checked to see that wa
is at least as long as s and wa satisfies the
alignment requirements of s at runtime.
2 STRUCTURE
For historical reasons, field symbols and parameters of
subroutines or Function modules
can only be typed with the STRUCTURE addition.
If, in a non-Unicode system, parameters in function modules or
subroutines are typed with FORM form1 USING/CHANGING arg STRUCTURE
s ... or FORM form2 TABLES itab_a STRUCTURE s ... and actual
parameters are passed to them using PERFORM form1 USING/CHANGING
wa or PERFORM form2 USING/CHANGING itab_b , the system also
only checks whether wa or the row type of itab_b is at
least as long as s and wa or whether the row type of
itab_b meets the alignment requirements of s . The same
applies to parameters of function modules that are typed using
STRUCTURE .
In Unicode programs, the following additional rules are checked after
type assignments using STRUCTURE when
assigning data objects - that is, for the DEFAULT addition to the
FIELD-SYMBOLS statement, for
ASSIGN , and when transferring actual
parameters:
If wa or the row type of itab_b is a
flat or deep structure,
the Unicode fragment views of
wa or itab_b must have the same length as that of
s , including closing alignment gaps. The handling of closing
alignment gaps is described in the section
Data Layout of Structures .
If wa is a single field, only the character-type types C, N, D,
or T are allowed and the structure s must be purely
character-type.
3 LIKE
If, in non-Unicode programs, the type of an argument in a function
module was defined using ... LIKE struc , where struc is a
flat structure, the system only checks whether the argument is a flat
structure with the same length during parameter transfer. In Unicode
programs, it also checks whether the fragment views of the current and
formal parameters match.
4 INCLUDES
Furthermore, two structures of which one or both contain
Includes , are only compatible if the
alignment gaps caused by the Include are the same on all platforms. In
the following example, struc1 and struc2 are not
compatible because a further alignment gap occurs in the Unicode system
before the INCLUDE :
BEGIN OF struc1, BEGIN OF struc2, BEGIN OF struc3,
a(1) TYPE X, a(1) TYPE X., b(1) TYPE X,
b(1) TYPE X, INCLUDE struc3. c(1) TYPE C,
c(1) TYPE C, END OF struc2. END OF struc3.
END OF struc1.
Since the type compatibility can differ in a Unicode program and an
non-Unicode program, the type compatibility rules of the calling
program are valid for checking the parameters in a non-Unicode system.
Therefore, if a non-Unicode program calls a Unicode program, the
type compatibility is defined as in the non-Unicode program. Conversely,
the Unicode check is activated if a
Unicode program calls a non-Unicode program.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved