Radinator
Radinator

Reputation: 1088

Declaration in INCLUDE is not recognized in main program

I am writing a report that contains a lot of datastructures with many subfields. To avoid cluttering my code I outsourced it to a Include which is included directly after the REPORT statement, followed by the DATA definitions.

Now my problem: when using a type defined in the INCLUDE as datatype for my variables the ABAP compiler says that the type is not defined. Even when the codecompletion shows me the types from the include when hitting Strg+Space when using Eclipse.

include:

*&---------------------------------------------------------------------*
*& Include          Z_MY_REPORT01_INCLUDE
*&---------------------------------------------------------------------*
types:
    begin of first_long_datastructure,
        field01 type string,
        field02 type string,
        ....
        fieldnn type string,
    end of first_long_datastructure,
    
    begin of second_long_datastructure
        field01 type string,
        field02 type string,
        ...
        fieldnn type string,
    end of second_long_datastructure.

report:

*&---------------------------------------------------------------------*
*& Report Z_MY_REPORT01
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_MY_REPORT01.

include Z_MY_REPORT01_INCLUDE.

data:
    lt_first_long_ds    type    first_long_datastructure,
    lt_second_long_ds   type    second_long_datastructure,
    lv_counter          type    i.

In this case the type first_long_datastructure "is not defined". When I paste the content of the include file in my sourcecodefile and remove the unnescessary include statement, the compiler is not complaining anymore.

Upvotes: 2

Views: 1825

Answers (1)

József Szikszai
József Szikszai

Reputation: 5071

To prevent this kind of strange behaviour follow these guidelines:

  • Put all your data declarations into one include.
  • Name this include ..._TOP
  • Put the REPORT statement into the TOP include.

So the main program will look like:

INCLUDE z..._top.
INCLUDE z..._F01.
...

The TOP include will look like:

REPORT Z...

* Data declarations...

Upvotes: 4

Related Questions