How to create an LLL based on a dynamic structure?

Asked

Viewed 4,388 times

9

I’m trying to expedite processes since several times we need generate reports in Alvs.

The idea is to get the metadata of a structure ( Field Name, Domain, Descriptive ) and thus generate the fieldcat in the ALV creation function and in the sequence manage to fill it.

Ex.:

Through the fields of the structure would fill the skeleton table.

CLEAR gs_s_fcat.
gs_s_fcat-fieldname = fieldname. " Nome do campo da Estrutura
gs_s_fcat-outputlen = size.      " O tamanho do conteúdo
gs_s_fcat-tabname   = table.     " Tabela
gs_s_fcat-coltext   = header.    " Texto do cabeçalho
gs_s_fcat-col_pos   = index.     " Índice da coluna
gs_s_fcat-emphasize = style.     " Estilo, cores e etc.
APPEND gs_s_fcat TO gt_t_fcat.

Calling the generic table creation.

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
  i_style_table             = 'X'
  it_fieldcatalog           = gt_t_fcat
IMPORTING
  ep_table                  = gt_generic_table
EXCEPTIONS
  generate_subpool_dir_full = 1
  OTHERS                    = 2.

{...} - Fill a field-Symbol with the same structure and use it on the display

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
  i_buffer_active          = 'X'
  i_callback_program       = sy-repid
  is_layout                = gs_layout
  it_fieldcat              = gt_t_fcat
TABLES
  t_outtab                 = <fs_table>
EXCEPTIONS
  program_error            = 1
  OTHERS                   = 2.

Ideas?

  • 1

    It will not be easy to find someone who can answer, but the question is interesting. It is likely that you need to bring experts in the subject to the site :)

  • 1

    It’s true @bigown, we need more abapers' :)

  • I’ve done something similar. I know there’s a table that stores the fields of the tables and structures but I can’t remember what it was. I found on google DD03L and DD03T, maybe these are.

2 answers

4


I found some different ways to get the detail of structure fields.

By the assistance class method as below:

tabela_de_detalhe ?= cl_abap_typedescr=>describe_by_name( 'NOME_ESTRUTURA' ).

and the one I thought best for my purposes, the function to follow.

CATSXT_GET_DDIC_FIELDINFO

The end result was like this:

Variables duly declared.

**---------------------------------------------------------------------*
**     Tabelas internas                                                *
**---------------------------------------------------------------------*
  DATA: lt_fields   TYPE ddfields,
        lt_fcat     TYPE lvc_t_fcat,
        lt_fcat_alv TYPE slis_t_fieldcat_alv.
**---------------------------------------------------------------------*
**     Estrutura                                                       *
**---------------------------------------------------------------------*
  DATA: ls_fcat     TYPE lvc_s_fcat,
        ls_fields   LIKE LINE OF lt_fields,
        ls_fcat_alv LIKE LINE OF lt_fcat_alv.
*----------------------------------------------------------------------*
*      Variaveis                                                       *
*----------------------------------------------------------------------*
  DATA: lv_index  TYPE i.

The call of the function that returns the detail of the submitted structure.

   CALL FUNCTION 'CATSXT_GET_DDIC_FIELDINFO'
    EXPORTING
      im_structure_name = structure_name
    IMPORTING
      ex_ddic_info      = lt_fields
    EXCEPTIONS
      failed            = 1
      OTHERS            = 2.

  IF sy-subrc <> 0.
    RAISE structure_not_found.
  ENDIF.

Now we need to direct this information to the table that will keep the ALV skeleton.

LOOP AT lt_fields INTO ls_fields.

    CLEAR: ls_fcat.

    lv_index = lv_index + 1.

    MOVE-CORRESPONDING:  ls_fields to ls_fcat_alv,
                         ls_fields to ls_fcat.

    IF ls_fields-scrtext_m IS NOT INITIAL.
      ls_fcat-coltext   = ls_fields-scrtext_m.
    ELSEIF ls_fields-scrtext_l IS NOT INITIAL.
      ls_fcat-coltext   = ls_fields-scrtext_l.
    ELSEIF ls_fields-scrtext_s IS NOT INITIAL.
      ls_fcat-coltext   = ls_fields-scrtext_s.
    ELSEIF ls_fields-fieldtext IS NOT INITIAL.
      ls_fcat-coltext   = ls_fields-fieldtext.
    ENDIF.

    ls_fcat_alv-seltext_l = ls_fcat-coltext.

    ls_fcat-col_pos   = lv_index.
    ls_fcat-key       = ls_fields-keyflag.

    APPEND: ls_fcat to lt_fcat,
            ls_fcat_alv to lt_fcat_alv.
ENDLOOP.

Obs.:

  • I chose the function CATSXT_GET_DDIC_FIELDINFO for returning me beyond the column name the descriptive, domain information, source table and the like.

  • I purposely maintained two structures to lt_fcat and the lt_fcat_alv, the first will serve for the construction of the dynamic table and another for the exhibition of ALV.

I hope I helped, hugs.

1

A ABAP here to try to help. I don’t know if you still face this problem, but a possible solution would be to use the new ALV classes. The simplest one ever builds the ALV without asking you to specify the fields (FIELDCAT). Just pass the internal table and the rest it already does, as the example below:

REPORT z_teste_brl.

DATA t_t000 TYPE TABLE OF t000 WITH DEFAULT KEY.

SELECT * FROM t000 INTO TABLE t_t000.

DATA o_alv TYPE REF TO cl_salv_table.

CALL METHOD cl_salv_table=>factory
  IMPORTING
    r_salv_table = o_alv
  CHANGING
    t_table      = t_t000.

o_alv->display( ).

To make it dynamic, you can change the above program to something like this:

REPORT z_teste_brl.

PARAMETER tn TYPE dd02l-tabname OBLIGATORY.

DATA table_name TYPE string.
table_name = tn.

DATA line_type_native TYPE REF TO cl_abap_typedescr.
CALL METHOD cl_abap_typedescr=>describe_by_name
  EXPORTING
    p_name         = table_name
  RECEIVING
    p_descr_ref    = line_type_native
  EXCEPTIONS
    type_not_found = 1
    OTHERS         = 2.

CHECK sy-subrc IS INITIAL.

DATA line_type TYPE REF TO cl_abap_structdescr.
line_type ?= line_type_native.

DATA table_type TYPE REF TO cl_abap_tabledescr.
table_type = cl_abap_tabledescr=>create( p_line_type = line_type
                                         p_table_kind = cl_abap_tabledescr=>tablekind_std ).

DATA internal_table TYPE REF TO data.
CREATE DATA internal_table TYPE HANDLE table_type.

FIELD-SYMBOLS <internal_table> TYPE STANDARD TABLE.
ASSIGN internal_table->* TO <internal_table>.

SELECT * FROM (tn) INTO TABLE <internal_table>.

DATA o_alv TYPE REF TO cl_salv_table.

CALL METHOD cl_salv_table=>factory
  IMPORTING
    r_salv_table = o_alv
  CHANGING
    t_table      = <internal_table>.

o_alv->display( ).

Simple, huh? I hope I helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.