Search code examples
abapfunction-module

Why is this structure declaration allowed in a built-in Function Module but not in a new one?


I'm working on a Function Module to assist with dealing with included text with logic embedded. While looking into the way SAP handles SAPScript files and parses the logic I found a structure that is declared as so:

DATA BEGIN OF events OCCURS 100.
      INCLUDE STRUCTURE ITCCA.
DATA: command LIKE BOOLEAN,
      template LIKE BOOLEAN,
      mask LIKE BOOLEAN,
     END OF events.

This obviously works, as I can trace through it while it is running a print program. So I thought I would try a similar structure in my own code but even when I copied the code 1 for 1 like above I get an error during activation. The error is

"BOOLEAN" must be a flat structure. Internal tables, references, 
strings and structures are forbidden as components.

Can someone explain to me why this structure is valid in one program and not mine?


Solution

  • To explain the actual effect: LIKE usually refers to a data object (an actual variable) on the right-hand side, not a data type. As you rightly discovered, once you provide a data object named BOOLEAN, that is used to construct the type. If a data object of that name is not present and you're not within a class or an interface, an obsolete variant of the LIKE statement will be triggered that also takes data types into account, but only allows for certain elements on the right-hand side - namely only flat structured objects or their components. LIKE DATATYPE-BOOLEAN should have worked. As usual, the error message is somewhat less than helpful.