12-03-2008 10:38 PM
Hi friends,
I have developed a report in OOP. Fieldcatalog was built manually and cl_gui_alv_grid was used. My report function ok, i. e. ALV listing is OK. Because I developed in OOP, I do not want to develop fieldcatalog manually.
Can someone give me the method to use to develop my fieldcatelog exporting my ITAB. I mean the OOP of FM Reuse_alv_fieldcatalog_merge.
I have tried FM LVC_FIELDCATALOG_MERGE, but since I did not create a structure (because I do not want to use structure) rather an ITAB so I coded like this:
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_INTERNAL_TABNAME = ITAB
CHANGING
CT_FIELDCAT = IT_FIELDCAT
Problem: fieldcatslog "it_fieldcat" was not successfuly created.
What do I need? I just need a method in OOP which I would pass my ITAB onto and method should deliver fieldcatalog just as the FM Reuse_alv_fieldcatalog_merge does.
Hope I have made some sense.
Blacky.
12-03-2008 11:19 PM
You may convert the old manual fieldcatalog to the new oop/lvc one, look at this wiki [Creating LVC fieldcatalog Using Internal table through SLIS fieldcatalog |https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/creatingLVCfieldcatalogUsingInternaltablethroughSLISfieldcatalog&showChildren=true] or you may define your internal table without using local type (see thread .
Regards
12-03-2008 10:50 PM
You can use the classs - CL_BUBAS_APPL_LOG and method GET_FIELDCATALOG for this.
Thanks,
Srinivas
12-03-2008 11:19 PM
You may convert the old manual fieldcatalog to the new oop/lvc one, look at this wiki [Creating LVC fieldcatalog Using Internal table through SLIS fieldcatalog |https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/creatingLVCfieldcatalogUsingInternaltablethroughSLISfieldcatalog&showChildren=true] or you may define your internal table without using local type (see thread .
Regards
09-17-2013 11:03 AM
Here an example of a Fieldcat that can be build via any type of data. Create a Utility method for it.
DDIC Structure ZCLS_ALV_OUTPUT
T_COLOR | LVC_T_SCOL | 0 | 0 | ALV control: Table for cell coloring | |
COLOR | Z_DE_COLOR | CHAR | 4 | 0 | ALV control: Field for line coloring |
T_STYLE | LVC_T_STYL | 0 | 0 | ALV Control: Style Table for Cells | |
S_DROPDOWN | LVC_S_DROP | 0 | 0 | ALV Control: Dropdown List Boxes | |
EDIT | XFELD | CHAR | 1 | 0 | Checkbox |
OIF_MVC | ZIF_MVC | 0 | 0 | Generic - Default actions in MVC based programs | |
OR_DREF | DATA | 0 | 0 |
Utility method:
Importing | IS_FCAT | TYPE LVC_S_FCAT OPTIONAL | ALV control: Field catalog |
Importing | IV_DDIC_OBJECT | TYPE ANY OPTIONAL | FREE use of DDIC structure |
Importing | IS_DATA | TYPE ANY OPTIONAL | Any structure |
Importing | IT_DATA | TYPE ANY TABLE OPTIONAL | Any data table |
Importing | IOR_DREF | TYPE REF TO DATA OPTIONAL | Any data reference |
Returning | VALUE( RT_FCAT ) | TYPE LVC_T_FCAT | Field Catalog for List Viewer Control |
Exception | NO_STRUCTURE | ||
Exception | INVALID_TYPE |
METHOD build_fieldcat.
DATA:
ls_fcat TYPE lvc_s_fcat,
lo_structdescr TYPE REF TO cl_abap_structdescr,
lo_typedescr TYPE REF TO cl_abap_typedescr,
ltr_data TYPE REF TO data,
lsr_data TYPE REF TO data,
lt_dfies TYPE dfies_tab,
lsr_dfies TYPE REF TO dfies.
FIELD-SYMBOLS: <lt_data> TYPE STANDARD TABLE,
<ls_data> TYPE ANY,
<lv_ele> TYPE ANY.
* Full structure input
IF is_fcat IS NOT INITIAL.
APPEND is_fcat TO rt_fcat.
* DDIC struct of table name
ELSEIF iv_ddic_object IS NOT INITIAL.
CREATE DATA lsr_data TYPE (iv_ddic_object).
rt_fcat = build_fieldcat( ior_dref = lsr_data ).
* Fill Table name
ls_fcat-tabname = iv_ddic_object.
MODIFY rt_fcat FROM ls_fcat
TRANSPORTING tabname WHERE tabname = space.
* Any data structure
ELSEIF is_data IS SUPPLIED.
GET REFERENCE OF is_data INTO lsr_data.
rt_fcat = build_fieldcat( ior_dref = lsr_data ).
* Any data table
ELSEIF it_data IS SUPPLIED.
GET REFERENCE OF it_data INTO ltr_data.
rt_fcat = build_fieldcat( ior_dref = ltr_data ).
* Data reference
ELSEIF ior_dref IS BOUND.
* Get reference type
lo_typedescr ?=
cl_abap_typedescr=>describe_by_data_ref( ior_dref ).
* CASE lo_typedescr->kind.
* WHEN cl_abap_typedescr=>kind_elem. " field
*
* WHEN cl_abap_typedescr=>kind_struct. " structure
* lo_structdescr ?=
* cl_abap_structdescr=>describe_by_data_ref( ior_dref ).
* lor_struc = ior_dref.
*
* WHEN cl_abap_typedescr=>kind_table. " table
* ASSIGN ior_dref->* TO <lt_data>.
* CREATE DATA lor_struc LIKE LINE OF <lt_data>.
* lo_structdescr ?=
* cl_abap_structdescr=>describe_by_data_ref( lor_struc ).
* ENDCASE.
CASE lo_typedescr->type_kind.
WHEN cl_abap_typedescr=>typekind_struct1 OR
cl_abap_typedescr=>typekind_struct2. " structure
lo_structdescr ?=
cl_abap_structdescr=>describe_by_data_ref( ior_dref ).
lsr_data = ior_dref.
WHEN cl_abap_typedescr=>typekind_table. " table
ASSIGN ior_dref->* TO <lt_data>.
CREATE DATA lsr_data LIKE LINE OF <lt_data>.
lo_structdescr ?=
cl_abap_structdescr=>describe_by_data_ref( lsr_data ).
ENDCASE.
** Get fields in table
lt_dfies = cl_salv_data_descr=>read_structdescr( lo_structdescr ).
* Build Field catalog
LOOP AT lt_dfies REFERENCE INTO lsr_dfies.
ls_fcat-fieldname = lsr_dfies->fieldname.
ls_fcat-ref_field = lsr_dfies->reffield.
ls_fcat-ref_table = lsr_dfies->reftable.
* Set technical - by fieldname
* This are the fields from include structure ZCLS_ALV_OUTPUT
* or fields that were declared as reference
IF lsr_dfies->datatype = 'REF' OR "reference
ls_fcat-fieldname = 'T_COLOR' OR
ls_fcat-fieldname = 'COLOR' OR "pointer: layout-info_fname
ls_fcat-fieldname = 'T_STYLE' OR
ls_fcat-fieldname = 'S_DROPDOWN' OR
ls_fcat-fieldname = 'EDIT' OR
ls_fcat-fieldname = 'NODE_KEY' OR
ls_fcat-fieldname = 'RELATKEY'.
ls_fcat-tech = abap_true.
ELSE.
IF lsr_dfies->precfield IS NOT INITIAL.
IF lsr_dfies->datatype = 'CURR'.
ls_fcat-cfieldname = lsr_dfies->precfield.
ELSEIF lsr_dfies->datatype = 'QUAN'.
ls_fcat-qfieldname = lsr_dfies->precfield.
ENDIF.
ENDIF.
ls_fcat-outputlen = lsr_dfies->outputlen.
ls_fcat-dd_outlen = lsr_dfies->outputlen.
IF lsr_dfies->convexit IS NOT INITIAL.
CONCATENATE '==' lsr_dfies->convexit INTO ls_fcat-edit_mask.
ENDIF.
ls_fcat-rollname = lsr_dfies->rollname.
ls_fcat-f4availabl = lsr_dfies->f4availabl.
ls_fcat-mac = lsr_dfies->mac.
ls_fcat-rollname = lsr_dfies->rollname.
ls_fcat-domname = lsr_dfies->domname.
ls_fcat-intlen = lsr_dfies->leng.
ls_fcat-intlen = lsr_dfies->intlen.
ls_fcat-decimals = lsr_dfies->decimals.
ls_fcat-datatype = lsr_dfies->datatype.
ls_fcat-inttype = lsr_dfies->inttype.
ls_fcat-scrtext_s = lsr_dfies->scrtext_s.
ls_fcat-scrtext_m = lsr_dfies->scrtext_m.
ls_fcat-scrtext_l = lsr_dfies->scrtext_l.
IF lsr_dfies->datatype = 'CURR' OR
lsr_dfies->datatype = 'QUAN'.
ls_fcat-no_sign = abap_false.
ELSE.
ls_fcat-no_sign = lsr_dfies->sign.
ENDIF.
ls_fcat-lowercase = lsr_dfies->lowercase.
ls_fcat-f4availabl = lsr_dfies->f4availabl.
ls_fcat-checktable = lsr_dfies->checktable.
ls_fcat-key = lsr_dfies->keyflag.
* Set No-Sum field
IF ls_fcat-datatype <> 'CURR' AND
ls_fcat-datatype <> 'QUAN'.
ls_fcat-no_sum = abap_true.
ENDIF.
* Set technical - by rollname
IF ls_fcat-rollname = 'MANDT' OR
ls_fcat-rollname = '/BSAR/DE_TSTMP_FROM' OR
ls_fcat-rollname = '/BSAR/DE_TSTMP_TO' OR
ls_fcat-rollname = '/BSAR/DE_CRETSTMP' OR
ls_fcat-rollname = '/BSAR/DE_CHATSTMP'.
ls_fcat-tech = abap_true.
ENDIF.
* Set checkbox
IF ls_fcat-domname = 'CHECKBOX' OR
ls_fcat-domname = 'XFELD'.
ls_fcat-checkbox = abap_true.
ENDIF.
* Set Icon
IF ls_fcat-domname = 'ICON'.
ls_fcat-icon = abap_true.
ls_fcat-just = 'C'. "Center
ENDIF.
ENDIF.
* Save column as record
APPEND ls_fcat TO rt_fcat. CLEAR ls_fcat.
ENDLOOP.
IF sy-subrc = 1.
RAISE no_structure.
ENDIF.
** Build fcat -- An other way to build, but without F4 shlp info
* data:
* lo_descr_elem TYPE REF TO cl_abap_elemdescr,
* ls_comp TYPE abap_compdescr,
* lv_type TYPE dom_ref,
* lv_name TYPE ddobjname,
* lv_tabix TYPE sytabix,
* ls_dd04v TYPE dd04v,
* CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
** Get reference in structure format
* ASSIGN lor_struc->* TO <ls_data>.
*
* LOOP AT lo_structdescr->components INTO ls_comp.
* CLEAR ls_fcat.
* ls_fcat-col_pos = lv_tabix = sy-tabix.
* ls_fcat-fieldname = ls_comp-name.
* ls_fcat-inttype = ls_comp-type_kind.
* ls_fcat-intlen = ls_comp-length.
* ls_fcat-decimals = ls_comp-decimals.
*
** Set technical - by fieldname
* IF ls_fcat-fieldname = 'T_COLOR' OR
* ls_fcat-fieldname = 'T_STYLE' OR
* ls_fcat-fieldname = 'S_DROPDOWN' OR
* ls_fcat-fieldname = 'EDIT' OR
* ls_fcat-fieldname = 'OIF_MVC' OR "Ref to implem. class
* ls_fcat-fieldname = 'OR_DREF'. "Ref to data record
* ls_fcat-tech = abap_true.
*
* ELSE.
* ASSIGN COMPONENT ls_comp-name OF STRUCTURE <ls_data>
* TO <lv_ele>.
*
* lo_typedescr = cl_abap_elemdescr=>describe_by_data( <lv_ele> ).
* CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
* lo_descr_elem ?= lo_typedescr.
* lv_type = lo_descr_elem->absolute_name.
** type defintion like : \TYPE=....
* SHIFT lv_type BY 6 PLACES.
* CALL FUNCTION 'DDIF_DTEL_GET'
* EXPORTING
* name = lv_type
* state = 'A'
* langu = sy-langu
* IMPORTING
* dd04v_wa = ls_dd04v.
*
* MOVE-CORRESPONDING ls_dd04v TO ls_fcat.
* IF ls_fcat-reptext IS INITIAL.
* ls_fcat-reptext =
* ls_fcat-scrtext_s =
* ls_fcat-scrtext_m =
* ls_fcat-scrtext_l = ls_comp-name.
* ENDIF.
* ENDCATCH.
* IF sy-subrc = 1.
* RAISE invalid_type.
* ENDIF.
*
** Set technical - by rollname
* IF ls_fcat-rollname = 'MANDT' OR
* ls_fcat-rollname = '/BSAR/DE_TSTMP_FROM' OR
* ls_fcat-rollname = '/BSAR/DE_TSTMP_TO' OR
* ls_fcat-rollname = '/BSAR/DE_CRETSTMP' OR
* ls_fcat-rollname = '/BSAR/DE_CHATSTMP'.
* ls_fcat-tech = abap_true.
* ENDIF.
* ENDIF.
*
** Set checkbox
* IF lv_type = 'CHECKBOX' OR lv_type = 'XFELD'.
* ls_fcat-checkbox = abap_true.
* ENDIF.
*
** Save record
* APPEND ls_fcat TO rt_fcat.
* ENDLOOP.
* ENDCATCH.
* IF sy-subrc = 1.
* RAISE no_structure.
* ENDIF.
ENDIF.
ENDMETHOD.