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: 

Read fields details in Saved ALV (SALV Classes)Layout

0 Kudos

Hi All,

I have developed an ALV report in which I download the data in excel with coloured cells for total and subtotals. Now the requirement is that If user saves some ALV layout and passes the same on the selection screen then only those many fields should be downloaded that are there in the saved ALV layout.

Report is OOPs based and for ALV I have used SALV classes. I tried searching on SDN but all the links I have found do talk about ALV developed using CL_GUI_ALV_GRID.

Regards,

Antim Parmar

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Do you mean you're using CL_SALV_TABLE class?

If it's so, you can use the method GET_COLUMNS in order to get how the columns are set

Max

9 REPLIES 9

Former Member
0 Kudos

Hi

Do you mean you're using CL_SALV_TABLE class?

If it's so, you can use the method GET_COLUMNS in order to get how the columns are set

Max

0 Kudos

Thanks sir for your reply.

I am using the class you mentioned. I am using GET_COLUMNS method but it gives all the fields irrespective of the layout selected with VISIBLE = X and TECHNICAL = ' '. I read on SDN that these are fields which decide which all fields are hidden while displaying ALV grid.

Regards,

Antim Parmar

0 Kudos

Hi Antim,

in the SALV object model you do not have direct access to the VISIBLE and TECHNICAL fields but you can check it using methods

DATA:
  lo_columns        TYPE REF TO cl_salv_columns_list,
  lo_column_table   TYPE REF TO cl_salv_column_table.
FIELD-SYMBOLS:
  <column>          TYPE LINE OF salv_t_column_ref.

lo_columns = gr_salv->get_columns( ).
lt_column_ref = lo_columns->get( ).
LOOP AT lt_column_ref ASSIGNING <column>.
  IF <column>-r_column->get_visible( ) = abap_true.
    write: / <column>-columnname, 'is visible'.
  ENDIF
ENDLOOP.

This code may help you with the concept. TECH works accordingly.

Though I don't know what's it all about.

Regards

Clemens

0 Kudos

Hi Clemens,

I am able to extract the fieldcat usnig the code you specified in the thread

But it has NO_OUT and TECH fields as blank for all the fields so how will I be able to decide as to what all fields are there in ALV layout selected on the selection screen.

Regards,

Antim Parmar

0 Kudos

Hi Antim,

actually this was a hint given by keshav. I posted the method to get the field catalog mainly because there are still too many developers left over who create a field catalog manually and wonder why they get dumps.

Did you already try the methods I suggested in my answer in this thread?

Probably the columns object information is not applied to the field catalog before display.

Actually, in the user layout you may also have filters applied. This should be taken into account. Compare code and discussion in [SALV Table 15 u2013 Show Count of Displayed Rows|http://help-abap.zevolving.com/2011/09/salv-15-show-count-of-displayed-rows/].

Happy coding!

Regards

Clemens

0 Kudos

Below is the code for this.

LO_COLUMNS = G_TABLE->GET_COLUMNS( ). " -


Get column details for all the fields

LO_AGGREGATIONS = G_TABLE->GET_AGGREGATIONS( ). " -


Get AGGREGATIONS

RT_FCAT = CL_SALV_CONTROLLER_METADATA=>GET_LVC_FIELDCATALOG(

R_COLUMNS = LO_COLUMNS

R_AGGREGATIONS = LO_AGGREGATIONS ). " -


Get the default field catalog

IS_LAYOUT-ZEBRA = 'X'. " -


Set layout properties

LS_VARIANT-REPORT = 'ZPP_ROOFING'. " -


Set variant properties

LS_VARIANT-HANDLE = ''.

LS_VARIANT-LOG_GROUP = ''.

LS_VARIANT-VARIANT = P_LAYOUT.

CALL FUNCTION 'LVC_VARIANT_SELECT' " -


Call FM to get the fields details with hidden details

EXPORTING

I_DIALOG = ' '

I_USER_SPECIFIC = 'X'

I_DEFAULT = ' '

IT_DEFAULT_FIELDCAT = RT_FCAT

IMPORTING

ET_FIELDCAT = RT_FCAT

ES_LAYOUT = IS_LAYOUT

CHANGING

CS_VARIANT = LS_VARIANT

EXCEPTIONS

WRONG_INPUT = 1

FC_NOT_COMPLETE = 2

NOT_FOUND = 3

PROGRAM_ERROR = 4

DATA_MISSING = 5

OTHERS = 6.

IF SY-SUBRC <> 0.

  • Implement suitable error handling here

ENDIF.

  • Method called to create dynamic internal table on the basis of field catalog created above

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = RT_FCAT "field catalog appended above

IMPORTING

EP_TABLE = DY_TABLE. "Dynamic internal table which will be created

*Create dynamic work area and assign to FS

ASSIGN DY_TABLE->* TO <DYN_TABLE>.

CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.

*Variables declared to insert column heading in the dynamic internal table created

ASSIGN DY_LINE->* TO <DYN_WA>.

this is how it is achieved..!!

Former Member
0 Kudos

Hi Antim,

I don't really get it... you mean you want to only download the data by selecting a layout and whitout showing the grid?

Or is this an issue while using standard ALV download functions?

Kr,

Manu.

0 Kudos

Hi Manu,

Actaully I have to download the data even before I display the grid based on the Layout selected by the user on the selection screen. So if there are 50 fields and user saved a layout with 20 fields then he wants the ability to download these many fields by selecting file path and ALV layout on the selection screen itself.So if I can get the fields details based on the saved ALV layout . I can prepare a dynamic internal table and download the same in excel file.

Regards,

Antim Parmar

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi,

I am referring a thread posted by Clemens few months back.

where in he has used cl_salv_controller_metadata=>get_lvc_fieldcatalog to get the field catalog details.

I think this can help you.

Kesav