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: 

Group/ Sort in ALV using OOPS

ricky_shaw
Contributor
0 Kudos

Hi Experts,

I am using ALV control USING OOPS on my screen output.

I need to sort/group the output by a field such that the field will not appear ONCE and the items reated to that will appear as

they are.

ex:

MATNR ITEMS DESC AMOUNT -->field catalog

abc 10 glass 10.0

20 black met 20.0

30 sulfa 30.0

abc 40 moldie 40.0

50 black met 11.0

60 sulfa 33.0

I have developed the ALV grid using OOPS.

Please suggest.

Thanks,

Ricky

13 REPLIES 13

Former Member
0 Kudos

Hi Ricky,

Refer to the links...

http://wiki.sdn.sap.com/wiki/display/ABAP/ALVGridReport-withObjectOrientedSALVClasses

http://wiki.sdn.sap.com/wiki/display/ABAP/OBJECTORIENTEDALV+Guide

0 Kudos

Hi NAresh,

This is NOT working for me.

In my case the field (say MATNR) that i want to group by is at a 2nd position in the output.

In the first position i have a check box. Is that causing NOT to group by/sort.

Please suggest.

Thanks

Ricky.

Former Member
0 Kudos

Ricky,

such that the field will not appear ONCE and the items reated to that will appear as they are .... I suppose you mean that you want to sort but you don't want to merge the same values..


gt_sort-SPOS = 01.
gt_sort-FIELDNAME = 'AENAM'.
gt_sort-up = 'X'.
append gt_sort.

ls_layout-NO_MERGING = 'X'.

CALL METHOD lo_alv->set_table_for_first_display
   EXPORTING
     i_structure_name              = 'MARA'
     IS_LAYOUT                     = ls_layout
  CHANGING
     it_outtab                     = gt_mara
     it_fieldcatalog               = gt_fcat
     it_sort                       = gt_sort[]
*    it_filter                     =
  EXCEPTIONS
.............

I don't understand what you wanted to show with the data example you posted, let me know if I misunderstand your question/

BR,

Diwakar

0 Kudos

Hi,

Its simple.

I want the Matnr to appear once but the items have to appear as they are.(Similar to what shown in the 2nd link that Naresh Patel posted). definitely i dont want to merge the items.

Any clues?

Should the field that i want to sort need to be in 1st position or that doesn' t matter, I have check box as the 1st field.

Thanks

0 Kudos

Ricky,

Sorry, But I am confused, you seem to be writing 2 diff statements.

 such that the field will *not* appear ONCE

I want the Matnr to appear once

-


Anyways, items (other fields) will remain as it is unless you change them specifically.

Suppose you want to sort by MATNR now, fill gt_sort.

gt_sort-SPOS = 01.

gt_sort-FIELDNAME = 'AENAM'.

gt_sort-up = 'X'.

append gt_sort.

Now, you want to merge MATNR or not, can be controlled by below parameter.

ls_layout-NO_MERGING = 'X'.

So, what is not working for you ? I believe order of field should not matter.

BR,

Diwakar

0 Kudos

Diwakar,

I want the MATNR to appear once.

MATNR ITEMS DESC AMOUNT -->field catalog

My current output: (columns may be mis aligned)

Matnr1 10 glass 10.0

Matnr1 20 black met 20.0

Matnr1 30 Batteries 30.0

Matnr2 40 glass 40.0

Matnr2 50 black met 50.0

Matnr2 60 Batteries 60.0

DESIRED OUTPUT : I want the desired output as below:

Matnr1 10 glass 10.0

20 black met 20.0

30 Batteries 30.0

Matnr2 40 glass 40.0

50 black met 50.0

60 Batteries 60.0

But this MATNR is at column# 2. NOT the first field in the output. 1st column has checkbox.

Pls suggest

Ricky

0 Kudos

hi,

Plz refer below link for OOALV.

/thread/492162 [original link is broken]

0 Kudos

Rick, this looks pretty basic. You can display the grid, mark coluimns MATNR with the mouse, click SORT ascending icon, save (and transport) as default layout variant

Or:

If MATNR appears in all rows, it is not SORTED. Or you use NO_MERGING in layout, then sorted columns will not merge.

Try

lt_sort-SPOS = 1.
lt_sort-FIELDNAME = 'MATNR'.
lt_sort-up = 'X'.
append lt_sort.

and pass it to IT_SORT parameter. That's it.

Regards,

Clemens

0 Kudos

Hi Clemens,

Yes this is basic stuff.

But i lost the grouping & also Zebra display when i placed a check box on my ALV grid using.lvc_s_fcat-checkbox = 'X'.

Its quite surprsing to see such an impact after placing a checkbox.

Any suggestions please?

Thanks

Ricky

0 Kudos

Ricky,

I tested with first column as 'Checkbox' field. Sorting, grouping (2nd field), zebra all seem to be Working well for me.

Can you please paste your relevant code ?

Do you have some CELL as Editable in the Grid, Grouping might get impacted due to that, but Zebra should still work fine.

BR,

Diwakar

0 Kudos

Hi Diwakar,

Yes. I have the same Checkbox field as EDITABLE in the field catalog.

IF i have that Check Box column (CELL) as Editable, both grouping & ZEBRA display are effected.

I have marked the layout-zebra = 'X' & passed the same in Set_table_first_display method.

Sample code of my field catalog declaration check box:


 data :gs_layout             type lvc_s_layo,
 gs_fieldcat           type lvc_s_fcat.

  gs_fieldcat-fieldname = 'PROCESS'.
  gs_fieldcat-inttype = 'C'.
  gs_fieldcat-coltext = 'Process'.
  gs_fieldcat-checkbox = 'X'.
  gs_fieldcat-edit = 'X'.
  gs_fieldcat-outputlen = 3.
  append gs_fieldcat to gt_fieldcat.
  clear  gs_fieldcat.

Any suggestions please..?

Thanks

Ricky

0 Kudos

Ricky,

For Grouping, I had encountered this earlier (No grouping on sorted field if any cell in the grid is editable) and not sure we have a solution for this.

For Zebra, it should work Fine. Please check your code carefully that there is no miss-out. The colour changes for zebra lining when any column is Editable, so might be you are not carefully analysing it. Open in 2 parallel sessions, with 1 having layout-zebra = 'X' and otherwithout it and you should be able to Notice some difference in the Grid for Sure.

BR,

Diwakar

0 Kudos

Hi Diwakar,

No. Its NOT working. Its NOT showing ZEBRA lines atleast .

This is what my code is:

data: gs_layout type lvc_s_layo.

 gs_layout-zebra = 'X'.

  call method r_grid->set_table_for_first_display
    exporting
      is_variant           = w_variant
      i_save               = 'A'
      i_default            = 'X'
      is_layout            = gs_layout
*     it_toolbar_excluding = it_exclude
    changing
      it_outtab        = it_final 
      it_sort          = t_sort
      it_fieldcatalog      = gt_fieldcat.

Any suugestions pls?

Thanks

Ricky