Application Development 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: 

How To Field Symbols

Former Member
0 Kudos

Hello!

I created a Z structure for an ALV report, but my report has some dynamic Columns, so I need to expand the Z structure dynamicly.

Im trying to create an internal table, and I try adding a fieldsymbol inside...but I think my code wont work.

please help...

Check this out...

field-symbols: <c1> type string.

TYPES:

BEGIN OF ty_caract.

types: cuobj TYPE inob-cuobj,

atwrt TYPE ausp-atwrt,

<c1>.

INCLUDE STRUCTURE zXXX.

TYPES END OF ty_caract.

DATA: ti_caract TYPE ty_caract OCCURS 0 WITH HEADER LINE.

10nks in advance,,,

Gabriel

1 ACCEPTED SOLUTION

Former Member
0 Kudos

There is no need to use a field symbol.

Build the structure to contain all of the various variations.

Hide the fields that you do not currently need using the field catalog.

-


Which technique are you using to disply the ALV?

In the following example, I am using tables without headers and a work area.

Tables without headers are required in th OO context.

If using CL_GUI_ALV_GRID:

You need to have a field catalog declared of type

DATA: i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,

w_fieldcat TYPE lvc_s_fcat.

When you initially set up the field catalog, you cann set hidden fields:

w_fieldcat-fieldname = 'FIELDNAME'.

w_fieldcat-col_pos = 1. "Field sequence

w_fieldcat-outputlen = 5.

w_fieldcat-scrtext_l = 'My Long Field Text'.

w_fieldcat-scrtext_s = 'Short Text'.

etc

<b> w_fieldcat-no_out = 'X'. " This forces the field to be hidden/no output</b>

then

APPEND w_fieldcat TO i_fieldcat. "Append when making a new entry to the field catalog

-


If you need to subsequently modify things, you can change the field catalog.

First, you may need to retrieve the field catalog, in case it may have been changed. This is up to you.

There is a method in CL_GUI_ALV_GRID

GET_FRONTEND_FIELDCATALOG

Assuming you have an ALV grid object created named "alv_obj" and a table of type LVC_T_FCAT, you can call the method as follows:

CALL METHOD alv_obj->get_frontend_fieldcatalog
  IMPORTING
    ET_FIELDCATALOG = i_fieldcat.

READ TABLE i_fieldcat into w_fieldcat WITH KEY fieldname = 'FIELDNAME'.
IF sy-subrc = 0.
  w_fieldcat-no_out      = 'X'.       " This forces the field to be hidden/no output   

or 

  w_fieldcat-no_out      = space.   " This forces the field to be visible  

  MODIFY i_fieldcat FROM w_fieldcat.
ENDIF.

You can then refresh the table display using method

CALL METHOD alv_obj->set_frontend_fieldcatalog
  EXPORTING
    it_fieldcatalog = i_fieldcat.

-


If using SALV, do the following to hide a field named FIELDNAME:

Assuming you have declared various constants you need, e.g.:

CONSTANTS: gc_true        TYPE sap_bool VALUE 'X',
           gc_false       TYPE sap_bool VALUE ' '.

  DATA: lr_columns          TYPE REF TO cl_salv_columns_table,
            lr_column           TYPE REF TO cl_salv_column_table.

  lr_columns = gr_table->get_columns( ).

You can do the following:

  TRY.
      lr_column ?= lr_columns->get_column( 'FIELDNAME' ).
      lr_column->set_visible( gc_false ).
    CATCH cx_salv_not_found.                            "#EC NO_HANDLER
  ENDTRY.

3 REPLIES 3

former_member194669
Active Contributor
0 Kudos

HI,

I think your code will not work.

Please check this thread

aRs

marcelo_ramos
Active Contributor
0 Kudos

Hi,

try this way.

DATA: l_table TYPE REF TO data.
DATA: l_line   TYPE REF TO data.

DATA: lt_fieldcatalog TYPE lvc_t_fcat.
 
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
  
FIELD-SYMBOLS: <table> TYPE REF TO data.
FIELD-SYMBOLS: <line> TYPE REF TO data.
  
" 1st
ls_fieldcatalog-fieldname = 'CARRID'.
ls_fieldcatalog-inttype = 'C'. 
APPEND ls_fieldcatalog TO lt_fieldcatalog.
 
ls_fieldcatalog-fieldname = 'CONNID'.
ls_fieldcatalog-inttype = 'N'.
APPEND ls_fieldcatalog TO lt_fieldcatalog.
 
"2nd create a dynamic table
CALL METHOD cl_alv_table_create=>create_dynamic_table
     EXPORTING
       it_fieldcatalog = lt_fieldcatalog
     IMPORTING
       ep_table = l_table
     EXCEPTIONS
       generate_subpool_dir_full = 1
       OTHERS = 2
		.
IF sy-subrc is initial.

"Create a internal table 
ASSIGN l_table->* TO <table>.

"Create a work area
CREATE DATA l_line LIKE LINE OF <table>. 

ASSIGN l_line->*  TO <line>.

...

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    it_fieldcat_lvc = lt_fieldcatalog
    ...
  TABLES
    t_outtab        = <table>.
    ....

ENDIF.

Regards.

Marcelo Ramos

Former Member
0 Kudos

There is no need to use a field symbol.

Build the structure to contain all of the various variations.

Hide the fields that you do not currently need using the field catalog.

-


Which technique are you using to disply the ALV?

In the following example, I am using tables without headers and a work area.

Tables without headers are required in th OO context.

If using CL_GUI_ALV_GRID:

You need to have a field catalog declared of type

DATA: i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,

w_fieldcat TYPE lvc_s_fcat.

When you initially set up the field catalog, you cann set hidden fields:

w_fieldcat-fieldname = 'FIELDNAME'.

w_fieldcat-col_pos = 1. "Field sequence

w_fieldcat-outputlen = 5.

w_fieldcat-scrtext_l = 'My Long Field Text'.

w_fieldcat-scrtext_s = 'Short Text'.

etc

<b> w_fieldcat-no_out = 'X'. " This forces the field to be hidden/no output</b>

then

APPEND w_fieldcat TO i_fieldcat. "Append when making a new entry to the field catalog

-


If you need to subsequently modify things, you can change the field catalog.

First, you may need to retrieve the field catalog, in case it may have been changed. This is up to you.

There is a method in CL_GUI_ALV_GRID

GET_FRONTEND_FIELDCATALOG

Assuming you have an ALV grid object created named "alv_obj" and a table of type LVC_T_FCAT, you can call the method as follows:

CALL METHOD alv_obj->get_frontend_fieldcatalog
  IMPORTING
    ET_FIELDCATALOG = i_fieldcat.

READ TABLE i_fieldcat into w_fieldcat WITH KEY fieldname = 'FIELDNAME'.
IF sy-subrc = 0.
  w_fieldcat-no_out      = 'X'.       " This forces the field to be hidden/no output   

or 

  w_fieldcat-no_out      = space.   " This forces the field to be visible  

  MODIFY i_fieldcat FROM w_fieldcat.
ENDIF.

You can then refresh the table display using method

CALL METHOD alv_obj->set_frontend_fieldcatalog
  EXPORTING
    it_fieldcatalog = i_fieldcat.

-


If using SALV, do the following to hide a field named FIELDNAME:

Assuming you have declared various constants you need, e.g.:

CONSTANTS: gc_true        TYPE sap_bool VALUE 'X',
           gc_false       TYPE sap_bool VALUE ' '.

  DATA: lr_columns          TYPE REF TO cl_salv_columns_table,
            lr_column           TYPE REF TO cl_salv_column_table.

  lr_columns = gr_table->get_columns( ).

You can do the following:

  TRY.
      lr_column ?= lr_columns->get_column( 'FIELDNAME' ).
      lr_column->set_visible( gc_false ).
    CATCH cx_salv_not_found.                            "#EC NO_HANDLER
  ENDTRY.