Type Checks and Type Compatibility
For historical reasons, the types of field symbols and parameters in subroutines or function modules can be defined with the STRUCTURE addition.
FIELD-SYMBOLS <fs> STRUCTURE s DEFAULT wa and they are later assigned a data object wa using ASSIGN wa TO <fs> ... , in a NUP both statements are checked to see if wa is at least as long as s and wa satisfies the alignment requirements of s at runtime.
- If the types of field symbols are defined using
- If parameters in function modules or subroutines are defined using FORM form1 USING/CHANGING arg STRUCTURE s ... or FORM form2 TABLES itab_a STRUCTURE s ... and the parameters are passed actual parameters using PERFORM form1 USING/CHANGING wa or PERFORM form2 USING/CHANGING itab_b, the NUP also only checks if wa or the line type of itab_b is at least as long as s and wa or the line type of itab_b satisfies the alignment requirements of s. The same is true for function module parameters whose types are defined with STRUCTURE.
The following extra rules are checked in a UP after defining the type with STRUCTURE when assigning data objects, i.e. for the DEFAULT addition in the FIELD-SYMBOLS statement, for ASSIGN and when passing actual parameters.
- If wa or the line type of itab_b is a flat or deep structure, the length of s must be the same for the Unicode fragment views of wa or of itab_b and s.
- If wa is a single field, only the character-types C, N, D or T are allowed and the structure s must have character-type only.
- If the type of an argument in a function module was defined with ... LIKE struc, where struc is a flat structure, the NUP only checks if the argument is a flat structure with the same length when the parameters are passed. In the UP, it also checks that the fragment views of the current and formal parameters are the same.
- 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 US before the INCLUDE:
BEGIN OF struc1,TYPE X,
b(1) TYPE X,
c(1) TYPE C,
END OF struc1.
BEGIN OF struc2,
a(1) TYPE X.
END OF struc2.
BEGIN OF struc3,
b(1) TYPE X,
c(1) TYPE C,
END OF struc3.
Since the type compatibility can differ in a UP and an NUP, the type compatibility rules of the calling program are valid in an NUS for checking the parameters. This means that if an NUP calls a UP, the type compatibility is defined as in the NUP. Conversely, the Unicode check is activated if a UP calls an NUP.
Use the categories used in the Dictionary when using these types with Structure Enhancements.