Skip to Content
author's profile photo Former Member
Former Member

How to set the structure of the ALV due to RTTS

Hey experts I have the following code:

TABLES: zbr_t_kniznice.

DATA: it_component TYPE cl_abap_structdescr=>component_table .

DATA: st_component LIKE LINE OF it_component .

DATA : it_tabdescr TYPE abap_compdescr_tab,

wa_tabdescr TYPE abap_compdescr.

DATA:

it_fields TYPE TABLE OF dfies,

wa_fields TYPE dfies.

DATA: r_data_tab TYPE REF TO data,

r_data_str TYPE REF TO data,

wa_fieldcat TYPE lvc_s_fcat,

it_fieldcat TYPE lvc_t_fcat.

IF <table> IS NOT ASSIGNED.

st_component-name = 'KNIZNICA'.

st_component-type ?= cl_abap_elemdescr=>describe_by_data( zbr_t_kniznice-nazov ).

APPEND st_component TO it_component.

st_component-name = 'ID_KNIHY'.

st_component-type ?= cl_abap_elemdescr=>describe_by_data( zbr_t_knihy-id_knihy ).

APPEND st_component TO it_component.

st_component-name = 'ZANER'.

st_component-type ?= cl_abap_elemdescr=>describe_by_data( zbr_t_kategorie-nazov ).

APPEND st_component TO it_component.

st_component-name = 'VYDAVATELSTVO'.

st_component-type ?= cl_abap_elemdescr=>describe_by_data( zbr_t_vydavatels-obchodne_meno ).

APPEND st_component TO it_component.

st_component-name = 'JAZYK'.

st_component-type ?= cl_abap_elemdescr=>describe_by_data( zbr_t_kniznice-id_kniznice ).

APPEND st_component TO it_component.

CALL FUNCTION 'DDIF_FIELDINFO_GET'

EXPORTING

tabname = 'zbr_t_knihy'

TABLES

dfies_tab = it_fields

EXCEPTIONS

not_found = 1

internal_error = 2

OTHERS = 3.

LOOP AT it_fields INTO wa_fields.

CHECK wa_fields-fieldname(2) NE 'ID'.

CHECK wa_fields-fieldname NE 'MANDT'.

st_component-name = wa_fields-fieldname.

st_component-type ?= cl_abap_elemdescr=>describe_by_name( wa_fields-rollname ).

APPEND st_component TO it_component .

ENDLOOP.

TRY.

ob_abap_structdescr = cl_abap_structdescr=>create( it_component ).

CATCH cx_sy_struct_creation .

ENDTRY.

TRY.

ob_abap_tabledescr = cl_abap_tabledescr=>create( ob_abap_structdescr ).

CATCH cx_sy_table_creation .

ENDTRY.

CREATE DATA: r_data_tab TYPE HANDLE ob_abap_tabledescr ,

r_data_str TYPE HANDLE ob_abap_structdescr .

ASSIGN r_data_tab->* TO <table>.

ASSIGN r_data_str->* TO <wa_table>.

My outtab is <table>. I want to display it in ALV, but I don't know how to set the structure of the ALV in CALL METHOD r_grid2->set_table_for_first_display. Can you help me with it? Can I use the it_component for it? If yes how? Should I create an fieldcatalog? How can I get the requiered datas from it_component to my fieldcatalog? I would need the exact code, because I'm lost a lot. Thank you.

Regards,

Robert

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 24, 2014 at 12:34 PM

    I've already found an article which helps me

    ALV fieldcatalog - create for ANY table using RTTS - Code Gallery - SCN Wiki

    exactly this part of the code:

    lr_typedescr ?= -type.

    if lr_typedescr->is_ddic_type( ) = 'X'.

    lr_elemdescr ?= -type.

    ls_dfies = lr_elemdescr->get_ddic_field( sy-langu ).

    ls_fieldcat-tabname = ls_dfies-tabname.

    ls_fieldcat-fieldname = -name.

    ls_fieldcat-scrtext_l = ls_dfies-scrtext_l.

    ls_fieldcat-scrtext_m = ls_dfies-scrtext_m.

    ls_fieldcat-scrtext_s = ls_dfies-scrtext_s.

    ls_fieldcat-reptext = ls_dfies-reptext.

    ls_fieldcat-domname = ls_dfies-domname.

    ls_fieldcat-rollname = ls_dfies-rollname.

    ls_fieldcat-intlen = ls_dfies-intlen.

    ls_fieldcat-outputlen = ls_dfies-outputlen.

    ls_fieldcat-decimals = ls_dfies-decimals.

    ls_fieldcat-datatype = ls_dfies-datatype.

    ls_fieldcat-inttype = ls_dfies-inttype.

    ls_fieldcat-rollname = ls_dfies-rollname.

    ls_fieldcat-convexit = ls_dfies-convexit.

    ls_fieldcat-f4availabl = ls_dfies-f4availabl.

    else.

    ls_fieldcat-intlen = lr_typedescr->length.

    ls_fieldcat-inttype = lr_typedescr->type_kind.

    ls_fieldcat-fieldname = -name.

    endif.

    but thank you for everyone 😉

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2014 at 08:05 PM

    Hi,

    You already use tabname 'zbr_t_knihy' . you can give the same in structure name.

    Regards,

    K.S.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      You can declare types with all the fields that you have and declare a table(say t_alv) wrt to the types

      declare lv_struct type dd02l-name and pass t_alv to lv_struct and pass this lv_struct to i_structure name . Please check this.

      Hope this helps.

      Regards,

      K.S.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.