3
votes

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?

2
Where did you find the original code? - vwegert
It is a part of the STXC Function Group. I did find some information about this after I posted this question. It seems that with LIKE I would have to define the BOOLEAN type myself but if I used TYPE then it would use the dictionary value for BOOLEAN. Not sure why they decided to define it themselves in their original code? - JRSofty

2 Answers

3
votes

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.

0
votes

It seems during my initial investigation I missed a declaration for the BOOLEAN type. In the STXC function group SAP decided to declare their own variable for boolean in a different include file like this:

data: boolean(1) type c.

I had originally assumed that they were doing this with the dictionary defined type which has a similar name and is a 1 character long string. What I also found is that if I were to change my structure declaration like this:

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

My code would be valid because it would then be using the dictionary defined value. So either I have to add a declaration for my own definition of boolean so that I can use the LIKE keyword or I have to use the TYPE keyword to use the dictionary definition.