2

我正在尝试使用功能模块REUSE_ALV_FIELDCATALOG_MERGE传递 ddic 中的字段标签以显示在 alv 报告的列标题中。但是,那没有用。

如果我评论该I_STRUCTURE_NAME = 'TY_YNAH_CUS_OBJ_REQ'行,它会给我运行时错误状态

ABAP 程序行比内部表更宽。

但是如果我取消注释,程序仍然无法运行

REPORT YALV_TEST.

        tables sscrfields. 
        type-pools : slis.

        "CREATE STRUCTURE -1 
        TYPES: BEGIN OF TY_YNAH_CUS_OBJ_REQ, 
               REQID TYPE YNAH_REQ_ID, 
               REQUESTOR TYPE YNAH_REQUESTOR,
               BUSINESS_OWNER TYPE YNAH_BUS_OWN,
               FUNCTIONAL_OWNER TYPE YNAH_FUNC_OWN, 
               REQNUM TYPE YNAH_SERVICE_REQ_NUM, 
               PROJECT_ID TYPE YNAH_PRO_ID, 
               SYSTEM_ID TYPE YNAH_SYS_ID, 
               FUNCTIONAL_AREA TYPE YNAH_FUNC_AREA,
               REQUEST_DATE TYPE YNAH_REQ_DATE,
               REQUEST_TIME TYPE YNAH_REQ_TIME,

           END OF TY_YNAH_CUS_OBJ_REQ.

        "defining internal table -2 

        DATA: IT_YNAH_CUS_OBJ_REQ type TABLE OF TY_YNAH_CUS_OBJ_REQ 
         * WA_YNAH_CUS_OBJ_REQ type TY_YNAH_CUS_OBJ_REQ.

        DATA: it_fcat TYPE slis_t_fieldcat_alv ,
         wa_fcat TYPE slis_fieldcat_alv,
         gd_layout TYPE slis_layout_alv.

        SELECTION-SCREEN BEGIN OF BLOCK menu WITH FRAME TITLE text-001.
        SELECT-OPTIONS: s_proid FOR IT_YNAH_CUS_OBJ_REQ-PROJECT_ID.
        PARAMETER p_sysid type TY_YNAH_CUS_OBJ_REQ-SYSTEM_ID.
        SELECTION-SCREEN: BEGIN OF LINE,
        pushbutton 33(8) BUT user-command search. 
        SELECTION-SCREEN END OF LINE. 
        SELECTION-SCREEN END OF BLOCK menu.

        initialization. 
        BUT = 'SEARCH'. END-OF-SELECTION.

        "execute search function when user click search button
        at selection-screen. "after processing user input 
         case SSCRFIELDS.
           when 'SEARCH'.
            SSCRFIELDS-UCOMM = 'ONLI'.
        endcase.

    "fetch data using select-4 START-OF-SELECTION. 

    SELECT * 
    FROM YNAH_CUS_OBJ_REQ "Database 
    INTO CORRESPONDING FIELDS OF TABLE IT_YNAH_CUS_OBJ_REQ "Into internal table 
    WHERE 
       PROJECT_ID in s_proid and 
       SYSTEM_ID eq p_sysid.

        CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' 
        EXPORTING
         I_PROGRAM_NAME = sy-repid
        I_INTERNAL_TABNAME ='TY_YNAH_CUS_OBJ_REQ'
        * I_STRUCTURE_NAME = 'TY_YNAH_CUS_OBJ_REQ'
        * I_CLIENT_NEVER_DISPLAY = 'X'
        I_INCLNAME = sy-repid 
        * I_BYPASSING_BUFFER = 'X' 
        * I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = it_fcat. 
        * EXCEPTIONS 
        * INCONSISTENT_INTERFACE = 1 
        * PROGRAM_ERROR = 2 
        * OTHERS = 3 
        * .
         IF SY-SUBRC <> 0. 
        ** Implement suitable error handling here 
        ENDIF.
4

3 回答 3

3
  1. REUSE_*ALV*功能模块不受支持。我建议切换到CL_SALV_*类。文档更好,有更多示例程序 ( DEMO_SALV_*) 并且您得到支持。
  2. 如果你想获得基于字典的字段描述,你需要一个字典结构(duh)。据我所知,如果您使用 ABAP 级别组装结构类型TYPE ... BEGIN OF ... END OF ...,则各个字段的字典类型首先转换为 ABAP 类型,然后才组装成结构类型。无论如何,原始字段的字典引用丢失了。不要在代码中定义输出表的结构,而是使用字典结构。
于 2015-08-11T06:15:28.627 回答
2

您有一些您可能不知道的错误(SAP 有时非常令人困惑,并且错误消息不透明)。我为您提供了我的一个工作示例,请看一下,尤其是在评论中。

一、数据定义:

TYPE-POOLS slis. "import you need for REUSE_ALV_FIELDCATALOG_MERGE

DATA:
  lt_fieldcat TYPE slis_t_fieldcat_alv,

  BEGIN OF G_IT_MATERIAL occurs 0,
    MATNR LIKE MARA-MATNR,
    MTART LIKE MARA-MTART,
    MAKTX_DE LIKE MAKT-MAKTX,
    MAKTX_FR LIKE MAKT-MAKTX,
    MAKTX_IT LIKE MAKT-MAKTX,
    ERNAM LIKE MARA-ERNAM,
    ERSDA LIKE MARA-ERSDA,
    LAEDA LIKE MARA-LAEDA,
  END OF G_IT_MATERIAL.

直接用 定义本地结构是绝对必要的LIKE,否则解析器REUSE_ALV_FIELDCATALOG_MERGE将找不到它。

选择你的东西:

 SELECT ma~matnr ma~mtart ma~ernam ma~ersda ma~laeda
 de~maktx as maktx_de fr~maktx as maktx_fr it~maktx as maktx_it
 FROM mara as ma
 LEFT JOIN MAKT as de ON de~matnr = ma~matnr AND de~spras = 'DE'
 LEFT JOIN MAKT as fr ON fr~matnr = ma~matnr AND fr~spras = 'FR'
 LEFT JOIN MAKT as it ON it~matnr = ma~matnr AND it~spras = 'IT'
 INTO CORRESPONDING FIELDS OF TABLE g_it_material
      WHERE ...

动态创建字段目录:

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME        = sy-repid

I_INTERNAL_TABNAME    = 'G_IT_MATERIAL'

I_INCLNAME            = sy-repid
CHANGING
ct_fieldcat            = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error          = 2
OTHERS                 = 3.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

现在显示 ALV 网格:

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat   = lt_fieldcat                 "you could also give a structure
"i_structure_name      = 'ZMM_SMATERIAL'    "here instead of the fieldcat
TABLES
t_outtab      = g_it_material
EXCEPTIONS
program_error = 1
OTHERS        = 2.

请注意,解析器还需要 72 个字符的最大行大小。

于 2015-08-14T08:38:17.300 回答
0

结构提供了几种不同的文本组件slis_fieldcat_alv,用作列标签。所选文本取决于当前列宽(其本身通常取决于所显示数据的长度)。确保您相应地更改它们!

通常的技巧是:通过传递I_STRUCTURE_NAME,你得到一个对应于这个 DDIC 结构的字段目录(改变参数ct_fieldcat)。然后,您根据需要修改此内部表,并将修改后的表传递给REUSE_ALV_GRID_DISPLAY.

在我不区分不同大小的文本版本的情况下,我使用以下宏将所有文本字段设置为相同的值。宏需要一个本地工作区ls_fieldcat(线型为ct_fieldcat) and a local string variablelv_text` 才能工作。

define set_field.
* Feld &1 für Anzeigefeld &2 den Wert &3 zuweisen
  ls_fieldcat-&1 = &3.
  modify ct_fieldcat from ls_fieldcat
    transporting &1
    where fieldname cp '&2'.
end-of-definition.

define set_text_direct.
  lv_text = &2.
  set_field seltext_s &1 lv_text.
  lv_text = &2.
  set_field seltext_m &1 lv_text.
  lv_text = &2.
  set_field seltext_l &1 lv_text.
end-of-definition.
于 2015-08-11T09:58:14.733 回答