"Inline declaration is not possible in this position" 在方法参数中

"Inline declaration is not possible in this position" in a method parameter

下面的代码给出了这个错误:

The inline declaration "DATA(LV_DESKTOP)" is not possible in this position.

  CALL METHOD cl_gui_frontend_services=>get_desktop_directory
    CHANGING
      desktop_directory = data(lv_desktop). "Declaring in method

您不能在方法调用中使用带有 CHANGINGEXPORTING 类型参数的内联声明。

ABAP documentation没有明确说,只是明确提到IMPORTINGRECEIVING类型的参数可以使用内联声明,有一些限制,没说什么关于其他两种类型。

进行了广泛的讨论 here and here

方法调用的可能内联声明示例:

cl_gui_frontend_services=>FILE_GET_ATTRIBUTES
    EXPORTING
      filename = `C:\test.txt`
    IMPORTING
      readonly = DATA(readonly) ).
cl_ixml=>create(
    RECEIVING
      rval = DATA(ixml) ).

关于EXPORTINGCHANGING,你必须处理旧声明。示例:

DATA lv_desktop TYPE string.
cl_gui_frontend_services=>get_desktop_directory(
    CHANGING
      desktop_directory = lv_desktop ).