Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Building fieldcatalog based on internal table

0 Likes
2,794

Hello,

I do the following to build a fieldcatalog from a table p_table.

form get_structure.

  data : idetails type abap_compdescr_tab,
         xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table and build fieldcatalog.

  ref_table_des ?=  cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[] = ref_table_des->components[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
  endloop.



endform.

What I do not get is, when I have an internal table

l_tab_fields

with certain columns of table p_table and only want those columns included in the fieldcatalog - how to achieve this ?

Thanks in advance,

Clemens

Hello,

I do the following to build a fieldcatalog from a table p_table.

form get_structure.

  data : idetails type abap_compdescr_tab,
         xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table and build fieldcatalog.

  ref_table_des ?=  cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[] = ref_table_des->components[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
  endloop.



endform.

What I do not get is, when I have an internal table

l_tab_fields

with certain columns of table p_table and only want those columns included in the fieldcatalog - how to achieve this ?

Thanks in advance,

Clemens

8 REPLIES 8
Read only

Former Member
0 Likes
2,060

Hi Clemens,

Are you using OO ALV or Classical ALV?

Classical ALV:

Use function module REUSE_ALV_FIELDCATALOG_MERGE and pass the I_PROGRAM_NAME as your program name and I_INTERNAL_TABNAME as the itnernal table on whose structure you want to build the field catalog. Incase you want to restrict the number of columns, you can delete the columns (which are internal table rows in generated field catalog) from the fieldcat table.

Hope this helps.

Regards,

Aditya

Read only

0 Likes
2,060

Thank you!

I now have:

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
         I_PROGRAM_NAME         = 'Y_D042439_A1S_2'
         I_INTERNAL_TABNAME     = l_tab_fields
*         I_STRUCTURE_NAME       =
*         I_CLIENT_NEVER_DISPLAY = 'X'
*         I_INCLNAME             =
*         I_BYPASSING_BUFFER     =
*         I_BUFFER_ACTIVE        =
     CHANGING
          CT_FIELDCAT            = ifc
*    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.

With

l_tab_fields

containing the columns i want to include.

When compiling, i get a runtime error / dump saying that the fm call was wrong and that under i_internal_tabname are certain datatypes allowed only.

I defined

l_tab_fields

as

  l_tab_fields TYPE ty_table_struct OCCURS 0.

and

BEGIN OF ty_table_struct,
      FIELDNAME   TYPE DD03L-FIELDNAME, " Tabellenname
      DDTEXT      TYPE DD04T-DDTEXT,    " Kurztext
      checkbox,
     END OF ty_table_struct.

.

I feel that there is maybe only a minor mistake somewhere in but i just cant find it. any idea ?

thanks, clemens

Read only

0 Likes
2,060

Hi,

I think you should give the <b>name</b> of the table 'L_TAB_FIELDS' rather than the table itself for the parameter I_INTERNAL_TABNAME.

Best regards,

Guillaume

Read only

p291102
Active Contributor
0 Likes
2,060

Hi,

Herewith i am sending the sample ALV report for your issue.

REPORT YMS_ALVDEMO .

TYPE-POOLS : SLIS.

TABLES : QALS.

DATA : BEGIN OF T_OUT OCCURS 0,

MATNR LIKE QALS-MATNR, "MATERIAL

WERK LIKE QALS-WERK, "PLANT

ART LIKE QALS-ART, "Inspaction Lot Type

OBJNR LIKE QALS-OBJNR, "Object Number

END OF T_OUT.

DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

I_LAYOUT TYPE SLIS_LAYOUT_ALV,

GS_LAYOUT TYPE LVC_S_LAYO,

G_REPID TYPE SY-REPID,

LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

SELECT-OPTIONS:S_PRFLOS FOR QALS-PRUEFLOS.

INITIALIZATION.

G_REPID = SY-REPID.

I_LAYOUT-ZEBRA = 'X'.

I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

START-OF-SELECTION.

PERFORM FETCH_DATA.

END-OF-SELECTION.

PERFORM FILL_FIELDCAT.

PERFORM DISPLAY_ALV.

&----


*& Form FETCH_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FETCH_DATA .

SELECT MATNR WERK ART OBJNR

FROM QALS

INTO TABLE T_OUT

WHERE PRUEFLOS IN S_PRFLOS.

ENDFORM. " FETCH_DATA

&----


*& Form FILL_FIELDCAT

&----


  • text

----


FORM FILL_FIELDCAT .

REFRESH I_FIELDCAT[].

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = G_REPID

I_INTERNAL_TABNAME = 'T_OUT'

I_INCLNAME = G_REPID

CHANGING

CT_FIELDCAT = I_FIELDCAT[]

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

ENDFORM. " FILL_FIELDCAT

&----


*& Form display_alv

&----


  • text

----


FORM DISPLAY_ALV .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = G_REPID

IS_LAYOUT = I_LAYOUT

IT_FIELDCAT = I_FIELDCAT[]

TABLES

T_OUTTAB = T_OUT

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ENDFORM. " display_alv

Thanks,

Sankar M

Read only

guillaume-hrc
Active Contributor
0 Likes
2,060

Hi,

The ALV renders only the columns that are contained into the field catalog.

Thus, if you want to restrict the columns, you can write things like :

FIELD-SYMBOLS: <fs_tab_field>  TYPE ANY,
                 <fs>                TYPE ANY.

READ TABLE l_tab_fields INDEX 1 ASSIGNING <fs_tab_field>.
CHECK sy-subrc = 0.

LOOP AT idetails INTO xdetails.
    ASSIGN COMPONENT xdetails-name OF STRUCTURE <fs_tab_field> TO <fs>.
    IF sy-subrc = 0. 
      xfc-fieldname = xdetails-name .
      xfc-datatype  = xdetails-type_kind.
      xfc-inttype   = xdetails-type_kind.
      xfc-intlen    = xdetails-length.
      xfc-decimals  = xdetails-decimals.
      append xfc to ifc. 
   ENDIF.
ENDLOOP.

Best regards,

Guillaume

Read only

0 Likes
2,060

hi guillaume,

i tried as you suggested but i get a dump/runtime error stating that fieldlist LT_GENTAB is empty.

i debugged the whole - my l_tab_fields contains the fields.

what happened ?

clemens

Read only

0 Likes
2,060

Hi,

Could you show us the code please.

I guess LT_GENTAB is your field catalog. It should be populated with the information you got from the LOOP ... ENDLOOP

Best regards,

Guillaume

Read only

0 Likes
2,060

Hi,

the coding is as follows:



form get_structure.
  FIELD-SYMBOLS: <fs_tab_field>  TYPE ANY,
                           <fs> TYPE ANY.

  data : idetails type abap_compdescr_tab,
         xdetails type abap_compdescr.



  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table and build fieldcatalog.

  ref_table_des ?=  cl_abap_typedescr=>describe_by_name( p_table ).

  idetails[] = ref_table_des->components[].

* l_tab_fields contains all the fields i want to show up in alv

  READ TABLE l_tab_fields INDEX 1 ASSIGNING <fs_tab_field>.




 CHECK sy-subrc = 0.


  loop at idetails into xdetails.
    clear xfc.
IF sy-subrc = 0. 

    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
endif.
  endloop.




endform.

As i said - the fieldcatalog seems to be empty.

thanks for your help!