INCLUDE 中的声明在主程序中不被识别

Declaration in INCLUDE is not recognized in main program

我正在编写一份报告,其中包含大量数据结构和许多子字段。为了避免让我的代码混乱,我将它外包给了一个 Include,它直接包含在 REPORT 语句之后,后面是 DATA 定义。

现在我的问题是:当使用 INCLUDE 中定义的类型作为我的变量的数据类型时,ABAP 编译器说该类型未定义。即使代码完成显示我使用 Eclipse 时点击 Strg+Space 时包含的类型。

包括:

*&---------------------------------------------------------------------*
*& 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 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.

在这种情况下,类型 first_long_datastructure“未定义”。当我将包含文件的内容粘贴到我的源代码文件中并删除不必要的包含语句时,编译器不再抱怨了。

要防止这种奇怪的行为,请遵循以下准则:

  • 将所有数据声明放入一个包含中。
  • 名称包括..._TOP
  • 将 REPORT 语句放入 TOP include。

所以主程序看起来像:

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

TOP 包含如下所示:

REPORT Z...

* Data declarations...