3

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
JRSofty
  • 1,216
  • 1
  • 24
  • 49
  • Where did you find the original code? – vwegert Jan 10 '17 at 10:30
  • 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 Jan 10 '17 at 10:38

2 Answers2

3

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.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • 1
    Thanks for the explaination. As a newcomer to SAP and ABAP I'm finding lots of little gotchas in understanding how it all works. – JRSofty Jan 10 '17 at 11:19
  • 2
    Learn to live with it - that feeling won't go away any time soon :-) – vwegert Jan 10 '17 at 11:26
0

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.

JRSofty
  • 1,216
  • 1
  • 24
  • 49