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: 

ALV Grid - get_filters( )

Former Member
0 Kudos
2,704

Hey you ALV-Gurus!

I have the following problem:

I display an internal table in an ALV Grid using the newer version CL_SALV_TABLE.

Now I have the problem that I have to rebuild my internal table according to the table which is currently displayed in the ALV, so that means if the user changes the sorting of the ALV-table, my internal table must be sorted the same way etc. I already got the sorting to work, but here's my next problem.... THE FILTERS!

To get a current representation of the ALV-table I surely have to delete the rows from my internal table, which are currently filtered out, and this seems like a huge hurdle ...

Here is my current code (not working):


data lr_filters type ref to cl_salv_filters.          " filter reference
data lt_filter type salv_t_filter_ref.                  " Filter Table
data  ls_filter type salv_s_filter_ref.                " Filter Row
data  lt_selopt type salv_t_selopt_ref.            " Select-Option-Table
data  ls_selopt type ref to cl_salv_selopt.       " Select-Option-Row
data  lv_col_name type string.                      " Name of column

" get filters
    lr_filters = mr_alv->get_filters( ).
    lt_filter = lr_filters->get( ).
    
    " filter table according to ALV-Filters
    loop at lt_filter into ls_filter.
      lt_selopt = ls_filter-r_filter->get( ).
      lv_col_name = ls_filter-columnname.

*      first attempt: try to define ranges with the given data, not possible
*      data lt_filter_range type range of table_to_filter_type-(lv_col_name).
*      data ls_filter_range like line of lt_filter_range.

*     second attempt: try to delete rows from table with dynamic mapping, not possible
      delete gt_dunn_copy where (lv_col_name) not in lt_selopt.

      loop at lt_selopt into ls_selopt.
         " here you can use ls_selopt->get_high( ),   ->get_low( ),   ->get_sign( ) etc ....
   
           " third attempt: NO MORE IDEAS 😞 ....

      endloop.
    endloop.

I hope anyone of you has an idea how to handle this. I really can't understand why SAP didn't implement an easy way to get the currently displayed data of the ALV back, I would need that functionality that often and so I always have to programm a workaround, but also this seems sometimes not to work because of dynamic limitations of ABAP .... Sorry, I'm used to other programming languages and I am somehow dissapointed of ABAP (Objects) ...

So, I hope somebody can help me, if my problem isn't clear don't hesitate to ask,

thanks in advance,

regards Matthias

11 REPLIES 11

Former Member
0 Kudos
383

anybody got an idea?

Former Member
0 Kudos
383

What about saving the report layout and then using the newly saved layout once you have rebuilt your new internal table.

It's just a thought.

Cheers

J

Former Member
0 Kudos
383

I'm sorry but I can't really figure out what you mean. Is is possible to get the current ALV-state with the help of the layout?

regards Matthias

0 Kudos
383

When you first execute a report you are able to use a predefined report layout. Or once the report has been displayed to the screen you can change the display and say the laout as a report layout.

What I'm trying to suggest is that having filtered the data you save behind the scene a report layout of how you want the data to be displayed so that when you refresh the dat haveing made changes you call back the report layout that you had just saved.

Hopefully this makes more sense.

J

0 Kudos
383

Try this way

1. Keep a new column in the i_output table called SEQNO its nothing but sy-tabix. and fill it up.

2. Copy i_output table into i_output_t


   i_output_t[] = i_output[].

3. Create filtered records in the i_output_t table by using all SELOPT variable values .


   delete i_output_t where matnr in s_matnr. 
   delete i_output_t where matkx in s_matkx.
   .....
   .....
   delete i_output_t where kunnr in s_kunnr.

4. Now your i_output_t table contains filtered values and then add entries from i_output_t into filter( Create filter for field SEQNO with i_output_t values into FILTER LOW values )


  loop at i_output_t
  gr_filter = gr_table->get_filters( ).
  gr_filter->clear( ).
  v_glow = i_output_t-seqno.
  grg_filter->add_filter( columnname = "SEQNO'
         low = v_glow ).

  endloop,

a®s

Edited by: a®s on Jul 10, 2008 9:40 AM

0 Kudos
383

@ a@s:

That's approximately the way I wanted to do it ... but points 3 + 4 seem somehow needless in my eyes, I would just write

delete it_outtab where field NOT IN sel_opt.

and then the filters would be applied to my internal table.

But the problem is, I always keep my programs as dynamic as possible and I want the code to work for each table, so I DON' T know how the columns are named ... I can only get the name using

ls_filter-columnname.

But then ABAP doesn't allow me to create ranges with dynamic type ...

@ Julie Wallner:

Thanks for the tip, but I am using the class CL_SALV_TABLE and not CL_GUI_ALV_GRID ...

0 Kudos
383

1. I think you select options are not dynamic . in that case from I_OUTPUT_T table delete all records that not part of your select options, that means you will get a filtered records in the I_OUTPUT_T table.

2. You are making the filter only for SEQNO from I_OUTPUT table.

say for example

in I_OUTPUT table


SEQNO       MATNR
1           A       
2           B
3           C 
4           D
5           E
6           F

in I_OUTPUT_T table you have


SEQNO       MATNR
1           A       
2           B
6           F 

Here you are filtering for SEQNO in I_OUTPUT table using values

1

2

6

PS You can make the SEQNO field in the HIDE mode

May this will help you out

Former Member
0 Kudos
383

unfortunately that's not what I want, I'll try to explain it better ...

basically according to some limitations of the ALV-intern export-function I have to write my own "Export to CSV" - functionality. Therefore the data in the internal table, which is displayed in an ALV, must be exact at the same state like the data which is currently displayed in the ALV-Grid. So if the user applies a filter, also the data in the internal table, which per default stores all the data, must be updated to storing only the filtered data.

When the user now presses my button "export", the data in the internal table is sorted the way the ALV is sorted and the columns which are currently marked as invisible are deleted from the structure (surely just operating on a copy, to be able to get back to initial state). This both works fine, but the next step is to filter the data according to the ALV-filters which are applied, and that's my problem....

regards

Matthias

0 Kudos
383

If you are on ECC6.0 there is the functionality to download the data exactly as it is displayed to the screen. have a look at FM ALV_DATA_EXPORT this is found in K_KKB_LIST_DISPLAY

Maybe that will help.

J

Former Member
0 Kudos
383

Thanks a®s, I can now imagine what you want to do, but there's still one big problem ...

your point 3 was:

3. Create filtered records in the i_output_t table by using all SELOPT variable values .

delete i_output_t where matnr in s_matnr. 
   delete i_output_t where matkx in s_matkx.
   .....
   .....
   delete i_output_t where kunnr in s_kunnr.

But this point is still not possible in that way. At the programming time, I DO NOT know the name of the columns, so I can't write such a delete-command because I don't know which columns I should consider for filtering my table.

I somehow have to write such code with dynamic values, in my example (ls_filter-columnname) must be used instead of a fixed columnname, but I don't know how to write that because ABAP always reports me a(n) (syntax-)error ... Hope you understand what I'm trying to say.

regards Matthias

0 Kudos
383

finally I got it to work ... I was stuck thinking about using dynamic data types, but then I realized I can instead use datatype string which can store each data, and then it worked!

Thanks for all the hints and tips!

regards