简体   繁体   English

OCCURS 0 和 TYPE STANDARD TABLE 有什么区别

[英]What is the difference between OCCURS 0 and TYPE STANDARD TABLE

I am new to ABAP, and I am creating ALV using FM 'REUSE_ALV_FIELDCATALOG_MERGE' and 'REUSE_ALV_GRID_DISPLAY'.我是 ABAP 的新手,我正在使用 FM 'REUSE_ALV_FIELDCATALOG_MERGE' 和 'REUSE_ALV_GRID_DISPLAY' 创建 ALV。

It is working when I defined internal table IT_MARD using obsolete occurs 0 definition.当我使用过时发生 0定义定义内部表IT_MARD时,它正在工作。 But I am getting Exception condition "NO_FIELDCATALOG_AVAILABLE" raised, when I defined internal table using type standard table .但是,当我使用type standard table定义内部表时,出现异常条件“NO_FIELDCATALOG_AVAILABLE”。 Could you please explain difference between these two definition and why it is not working in the latter case.您能否解释一下这两个定义之间的区别以及为什么它在后一种情况下不起作用。 The following is the code.以下是代码。

REPORT  ztest_fieldcatalog3.
TYPE-POOLS:slis.
*Semi Automatic Fieldcatalog Generation.
*DATA: BEGIN OF IT_MARD OCCURS 0,
*        MATNR LIKE MARD-MATNR,
*        WERKS LIKE MARD-WERKS,           ""
*        LGORT LIKE MARD-LGORT,
*        PSTAT LIKE MARD-PSTAT,
*      END OF IT_MARD.

TYPES: BEGIN OF ty_mard,
        matnr type mard-matnr,
        werks type mard-werks,
        lgort type mard-lgort,
        pstat type mard-pstat,
      END OF ty_mard.

DATA: IT_MARD TYPE STANDARD TABLE OF ty_mard.


"Use function module create  Fieldcat.
DATA:l_program TYPE sy-repid VALUE sy-repid.

DATA:i_fieldcat TYPE slis_t_fieldcat_alv.

SELECT matnr
       werks
       lgort
       pstat
  FROM mard
  INTO CORRESPONDING FIELDS OF TABLE it_mard
  UP TO 100 ROWS.


CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  EXPORTING
    i_program_name     = l_program
    i_internal_tabname = 'IT_MARD'
    i_inclname         = l_program
    i_bypassing_buffer = 'X'
  CHANGING
    ct_fieldcat        = i_fieldcat[].
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.


"Call ALV and pass fieldcatalog and data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program = l_program
    it_fieldcat        = i_fieldcat
  TABLES
    t_outtab           = it_mard.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

The difference is that OCCURS creates a table with a header line, while TYPE STANDARD TABLE OF does not (unless you explicitly tell it to).不同之处在于OCCURS创建了一个带有标题行的表格,而TYPE STANDARD TABLE OF则没有(除非您明确告诉它)。 I suppose that the function module is able to guess the structure from a table with a header line, but not a table without a header line.我想功能模块能够从带有标题行的表中猜测结构,但不能从没有标题行的表中猜测结构。 My suggestions would be to我的建议是

  1. use a data dictionary structure instead of a local structure - it's easier to maintain and extend later on and使用数据字典结构而不是局部结构 - 以后更容易维护和扩展
  2. don't use the REUSE function modules, but check the CL_SALV_* classes instead since they are officially supported and have a much cleaner API不要使用 REUSE 功能模块,而是检查 CL_SALV_* 类,因为它们受到官方支持并且具有更清晰的 API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM