09-23-2014 8:06 PM
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
09-24-2014 1: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
09-23-2014 9:05 PM
Hi,
You already use tabname 'zbr_t_knihy' . you can give the same in structure name.
Regards,
K.S.
09-23-2014 10:07 PM
Yeh, but I have populated the <table> with some other fields as you can see, so the 'zbr_t_knihy' is not good as structure name.
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.
09-24-2014 9:38 AM
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.
09-24-2014 1: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