Application Development and Automation 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 only

Grouping and Page Break in ALV using Function Modules

Former Member
0 Likes
1,451

Hi all,

I am trying to develop an ALV Report that will be grouped by vendor, some vendor information to be displayed on header. And, after each vendor;s records there should be a page break.

It should be something like this:

Vendor Number: 00012345454

Vendor Name: ABC Technologies, Inc

Vendor Country: USA

Item....Price...... Descriptopm

123....100,00......this is description

124....120.00......this is another description

PAGE BREAK

Vendor Number: 000123456545

Vendor Name: My Bank

Vendor Country: USA

Item....Price..... Descriptopm

223....32,00......this is my description

224....120.00......this is another description

Can anybody give some sample code for it ? I have tried a few codes from web, but they are not working.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,090

Hi,

Please look these sample program:

BALVBT01: Testprogram ALV: Block list

BALVBT02: Testprogram ALV: Block list without block modules

But I'm not sure about page-break.

Regards,

9 REPLIES 9
Read only

Former Member
0 Likes
1,091

Hi,

Please look these sample program:

BALVBT01: Testprogram ALV: Block list

BALVBT02: Testprogram ALV: Block list without block modules

But I'm not sure about page-break.

Regards,

Read only

Former Member
0 Likes
1,090

Hi,

Try the following:

1. Build your sorting criteria. Pass this to ALV FM.

gs_sort-fieldname = 'VENDOR'.

gs_sort-group = '*'. "new page

gs_sort-up = 'X'.

APPEND gs_sort TO gt_sort.

2. Add event group level change. Pass this to ALV FM

gs_event-name = 'GROUPLEVEL_CHANGE'.

gs_event-form = 'GROUPLEVEL_CHANGE'.

APPEND gs_event TO gt_event.

Inside the form, retrieve your vendor details.

FORM grouplevel_change USING gs_lineinfo
                             gs_groups TYPE kkblo_grouplevels.

  DATA: l_index     TYPE i.

  IF gs_groups-level = 1.
    l_index = gs_groups-index_to + 1.
    READ TABLE gt_display INDEX l_index  INTO gw_display.    
  ENDIF.

3. In the event top-of-page, display vendor details using write statements. For the first record, your structure (gw_display) will be blank, read from your data table first

 FORM top_of_page.

  IF gw_display IS INITIAL.
    READ TABLE gt_display INDEX 1 INTO l_display.
    IF sy-subrc = 0.
      WRITE: / l_display-vendor
    ENDIF.
  ELSE.
    WRITE: / gw_display-vendor.
    CLEAR: gw_display.
  ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'SET_STATUS'
      i_callback_user_command  = 'USER_COMMAND'
      is_layout                = gs_layout
      it_fieldcat              = gt_fcat[]
      it_sort                  = gt_sort[]
      i_save                   = 'A'
      it_events                = gt_event
    TABLES
      t_outtab                 = gt_display[]
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

Hope this helps.

Read only

0 Likes
1,090

Thanks nene,

Your reply seems to be what I want. The only thing is I need Grid Display, I will be implementing your solution today. If you have anything else to share please comment.

Thanks.

Read only

0 Likes
1,090

Hi,

For some reason the event grouplevel_change is not called on group change, I am using is_sort-group = '*' and everthing else. The even top_of_page is called properly, I tried to add some other events and their form routines same as top_of_page but none is working for me, do you know what the issue might be?

Thanks.

Read only

0 Likes
1,090

Did you manage to find a solution? What are you passing in the sort fieldname, it should be a fieldname from your display table. I find it strange, the suggested solution works for me.

Read only

0 Likes
1,090

Infact I had find the solution, I removed the tabname field from code altogether and it worked fine.

Read only

0 Likes
1,090

Hi Nene,

I have the same kind of requirement i.e I have grouped my alv according to a field (fieldname = vbeln). Now I want to display the vbeln of the particular group as the header of the group.

I have seen the code u have posted.

Please tell me whether u r using the function "REUSE_ALV_EVENTS_GET".

I am new to ABAP and in all my alv reports I have used the above function to trigger new events like top-of-page.

Regards,

TROZAN.

Read only

0 Likes
1,090

Hi Trozan,

Hope this is not so late. If I understand your requirement correctly, you want to display VBELN only in the header. This may not be the best solution. See if it works. Try to hide VBELN column and write it in the header (top of page).

REUSE_ALV_EVENTS_GET will not do the actual event trigger, it only gives the list of events that you can use.

Regards,

nEnE

Read only

Former Member
0 Likes
1,090

The problem was I the tabname field, I removed it from code and then I could get what I wanted.