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 sort/group disfunction ?!

Former Member
0 Kudos

Hi there,

I'm a bit helpless because of the sort/group function my ALV should do. Current situation is that I'm using an CL_GUI_ALV_GRID.


CALL METHOD gr_config_alv_1_2->set_table_for_first_display
    EXPORTING
      is_layout                     = ls_layout
    CHANGING
      it_sort                       = sort_table
      it_outtab                     = config_1_2_table
      it_fieldcatalog               = cat_config_fieldcat_alv
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.

So you can see that I'm using it_sort to tell the ALV how to sort the it_outtab. [Result looks like this|http://fabianvogt.com/alv_1.jpg].

What the it_sort does is sorting the it_outtab ASCENDING for the coloum "GRP" (display-name: "Bezugstyp"). So far so good...But I know that CL_GUI_ALV_GRID normally does some kind of grouping by merging cells with the same content. [This would look like that|http://fabianvogt.com/alv_2.jpg].

In my case it does not work and I don't have any idea why. I searched the CLASS for a hint or maybe an attribute which has to be filled/flagged to do this kind of grouping.

Looking forword to your help!

1 ACCEPTED SOLUTION

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Try this way :

lt_sort type lvc_t_sort

ls_sort-fieldname = 'FIELDNAME' .

ls_sort-spos = '1' .

ls_sort-up = 'X' .

APPEND ls_sort TO lt_sort .

Also check the attribute : MT_SPECIAL_GROUPS

12 REPLIES 12

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Try this way :

lt_sort type lvc_t_sort

ls_sort-fieldname = 'FIELDNAME' .

ls_sort-spos = '1' .

ls_sort-up = 'X' .

APPEND ls_sort TO lt_sort .

Also check the attribute : MT_SPECIAL_GROUPS

0 Kudos

Hi Sandeep,

sorry I forgot to add the following lines in my first post. I already did what you told me.


 DATA: sort_line      TYPE lvc_s_sort,
       sort_table     TYPE lvc_t_sort.

* Ausgabe-Tabelle sortieren/gruppieren
  sort_line-spos      = '1'.
  sort_line-fieldname = 'GRP'.
  sort_line-up        = 'X'.
  sort_line-group     = 'UL'.
  APPEND sort_line TO sort_table.

And this does not take any effect...

Now I'm checking the attribute MT_SPECIAL_GROUPS ... maybe this is the solution i'm searching.

0 Kudos

Hello,

* Ausgabe-Tabelle sortieren/gruppieren
  sort_line-spos      = '1'.
  sort_line-fieldname = 'GRP'.
  sort_line-up        = 'X'.
  sort_line-group     = 'UL'.
  APPEND sort_line TO sort_table.

I'm surprised why this shouldn't work? Did you check the program 'BCALV_TEST_GRID'? There is a block for "Cloumn Sorting", just check it out.

BR,

Suhas

0 Kudos

Hi everyone!

I've checked BCALV_TEST_GRID. Basically they do it the same way I'm trying. I found out that I have the possibility to set ls_layout-no_merging to control, whether cells with the same content are merged or not. By default no_merging is set SPACE, so the cells should be merged - NOT in my case.

Even if I set no_merging = ' ' (SPACE) manually, the merging won't be done.

Running out ouf ideas ...

NEWS:

I did some kind of a workaround, in my opinion even a nicer way to realize my purpose. So take a look at what I did right now:

(take a look at the screenshots in my previous posts for your better understanding)

- The old 'GRP' field (old content: 'B',' K', 'M') is now filled with 'Belegbezug', 'Kundenbezug', 'Materialbezug' and is set NO_OUT (fieldcatalogue).

- I insterted a field called 'CNT' type I, which i use to create Totals/Subtotals.

- NO_TOTLINE = 'X' (Layout) --> total line is not shown; only subtotals

- TOTALS_BEF (Layout) --> subtotals are placed on top

[So this is what I got now|http://fabianvogt.com/alv3.jpg]. Much better than before!!!

My only problem is now, that the 'CNT' coloum looks pretty ugly and has no function except doing the sum thing.

I tried to make it invisible using the fieldcatalogue (NO_OUT / TECH), but then the total lines disappear 😕

Any suggestions?

Edited by: Fabian Vogt on Oct 4, 2010 4:35 PM

0 Kudos

Hello Fabian,

Is this behavior specific to your ALV or for all the ALVs?

Last ditch effort, try initialising the ALV buffers Relevant programs are: BCALV_BUFFER_DELETE, BALVBUFDEL.

BR,

Suhas

0 Kudos

Hi Suhas,

this behaviour is not specific to my ALV. I also tried it at the program BCALV_TEST_GRID...same issue 😕

Thanks for your hint with the ALV Buffers. I'm going to practice a bit with that topic later today ... dont even have an idea what this is about yet.

Best Regards ... see you tomorrow

0 Kudos

Hi Fabian,

You can try these options.

In the fieldcatalog, make it as Key field and put no_out = 'X'. (try both or Individually).

Loop at pt_fieldcat into ls_fcat.

CASE ls_fcat-fieldname.

WHEN 'B'.

ls_fcat-key = 'X'.

ls_fcat-no_out = 'X'.

MODIFY pt_fieldcat FROM ls_fcat.

ENDLCASE.

ENDLOOP.

and in the layout choose the below options. Keep sel_mode as 'B' in the layout and try other 2 feilds individually also.

FORM set_layout .

gs_layout-no_totline = 'X'.

gs_layout-smalltitle = 'X'.

gs_layout-sel_mode = 'B'.

ENDFORM. " set_layout

This should definitely solve your problem.

You might have tried this. But make sure spos is in 2 digits, so it should be '01' instead of '1'.

FORM do_sort .

gs_sort-spos = '01'.

gs_sort-fieldname = 'B'.

gs_sort-subtot = 'X'.

gs_sort-up = 'X'.

APPEND gs_sort TO gt_sort.

gs_sort-spos = '02'.

gs_sort-fieldname = 'K'.

gs_sort-subtot = 'X'.

gs_sort-up = 'X'.

APPEND gs_sort TO gt_sort.

ENDFORM. " do_sort

Thanks

Lakshmi

Edited by: Lakshmi Narayana L on Oct 6, 2010 5:25 AM

0 Kudos

Hi Lakshmi,

thanks for your post, but I think you did not understand my problem.

If you look at the screenshot in my previous post, you will see that I don't use the sorting/grouping anymore, thanks for that tip anyway.

The way I took now, is to realize my purpose by summing an "help"-field (called 'CNT') to create sub-total-lines (even a nicer way than the sorting function). 'B', 'K', 'M' (also old) were contents of my field 'Bezugstyp' and not coloums - this is what I understood from your post.

So please keep in mind: My actual problem is that I have to make a coloum invisible, which is summed up. Current reaction on making it invisible: no total-lines any more.

BR

Fabian

0 Kudos

In your new design, If you the count of what you need, than you can concatenate that value along with your column content - E.g. 'Belegbezug - 13', 'Kundenbezug - 4', and so on... But, I guess, you need to keep on updating the value if you have Filters available in your ALV.

As you mentioned earlier in one of your post that merging while sorting is also not function in the standard program BCALV_TEST_GRID than it might be a problem with your GUI. I would suggest to check that program on other colleague's PC.

Regards,

Naimesh Patel

Edited by: Naimesh Patel on Oct 6, 2010 8:45 AM

0 Kudos

Hi Naimesh,

thought about your suggestion and in my opinion this won't work, because SAP is only able to create totals for columns with data-type INT. If I concatenate e.g. 'Belegbezug' and '13' to 'Belegbezug - 13' - as you suggested - the totals won't be created.

Changed my plan now, and switched the control I'm going to use! Now I'm trying to realise my purpose with CL_GUI_ALV_TREE. (combines a tree with an ALV - as the name already says). Advantage of my change will probably be: No more need of creating total lines --> I can manage the 'top levels' by creating folders.

What do you think?

BR Fabian

Former Member
0 Kudos

Hi Fabian,

While creating layout, you should try to do this.

ls_layout-no_merging = SPACE.

0 Kudos

Hi KhuShi,

please read the entire thread before posting! Your answer is not necessary anymore.

Thanks anyway...