主程序不识别INCLUDE中的声明

问题描述

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

解决方法

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

  • 将所有数据声明放入一个include。
  • 命名为包括..._ TOP
  • 将REPORT语句放入TOP include。

因此主程序将如下所示:

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

TOP包含将如下所示:

REPORT Z...

* Data declarations...