How to use REUSE_ALV_FIELDCATALOG_MERGE function module?

冷暖自知 提交于 2019-12-06 06:31:37
  1. The REUSE_*ALV* function modules are unsupported. I'd suggest switching to the CL_SALV_* classes. The documentation is better, there are more sample programs (DEMO_SALV_*) and you get support.
  2. You need a dictionary structure if you want to get dictionary-based field descriptions (duh). If you assemble a structure type on the ABAP level using TYPE ... BEGIN OF ... END OF ..., as far as I know, the dictionary types for the individual fields are converted to ABAP types first and only then assembled into a structure type. Anyway, the dictionary reference of the original fields is lost. Instead of defining the structure of the output table in your code, use a dictionary structure.
inetphantom

You have some mistakes you might have not known (SAP is very confusing sometimes and not transparent with error-messages). I got for you a working example of mine, have a look on it, especially on the comments.

First, data definition:

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.

It is absolutely necessary that you define your local structure directly with LIKE, otherwise the parser from REUSE_ALV_FIELDCATALOG_MERGE will not find it.

Select your stuff:

 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 ...

Create a field catalog dynamically:

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.

Now display the ALV grid:

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.

Note that the parser also needs a max linesize of 72 chars.

There are several different text components provided by structure slis_fieldcat_alv that are used as column labels. The chosen text depends on the current column width (which itself usually depends on the length of the data displayed). Make sure that you change them all accordingly!

The usual technique is: By passing the I_STRUCTURE_NAME, you get a field catalog corresponding to this DDIC structure (the changing parameter ct_fieldcat). You then modify this internal table according to your needs and pass that modified table to the REUSE_ALV_GRID_DISPLAY.

In cases where I don't distinguish the different-sized text versions, I use the following macros to set all the text fields to the same value. The macros require a local work area ls_fieldcat (with the linetype of ct_fieldcat) and a local string variablelv_text` in order to work.

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!