首页 > 解决方案 > INCLUDE 中的声明在主程序中不被识别

问题描述

我正在编写一份报告,其中包含许多具有许多子字段的数据结构。为了避免弄乱我的代码,我将它外包给了一个 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 “未定义”。当我将包含文件的内容粘贴到我的源代码文件中并删除不必要的包含语句时,编译器不再抱怨了。

标签: typesincludeabap

解决方案


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

  • 将所有数据声明放入一个包含中。
  • 将其命名为 ..._TOP
  • 将 REPORT 语句放入 TOP 包含中。

所以主程序将如下所示:

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

TOP 包含将如下所示:

REPORT Z...

* Data declarations...

推荐阅读