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: 

numbering rows in ALV report

Former Member
0 Kudos

hi

i have an alv report and i want to number the lines of of the alv table. i created a variablle which give the number to the line- i loop at the alv table and add 1 in each look and give the number to the row but..... when the alv report appers and i want to sort the table the column of row_number is also sorted and the numbers are not in the right order. is ther a way to number the rows and it wont be affected from sorting or filtering the table ?

thanks

2 REPLIES 2

Former Member
0 Kudos

It seems like the line number you're using was located in the Itab that you use for displaying the data. So whenever the itab is sorted or filtered, it wil affect the line number too.

The easiest way to solve your problem is to rearrange the line number when you sort or filter the ALV. Everytime the user sort, filter, double clicking or make another event, it will catch in the event method of the program.

For example, you use the FM REUSE_ALV_GRID_DISPLAY to display the ALV grid like this

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_user_command = 'FORM_USER_COMMAND'

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2

so whenever you click the SORT button for example, the program will go to the FORM_USER_COMMAND.

Your job is to make the FORM_USER_COMMAND, and rearrange the line number of itab in that Form.

Maybe something like this :

FORM_USER_COMMAND

DATA : num TYPE i.

LOOP AT itab.

num = num + 1.

itab-line_number = num.

MODIFY itab TRANSPORTING line_number.

ENDLOOP.

ENDFORM.

Former Member
0 Kudos

Hi,

Firstly, I think you can build a sort table to pass through ALV FM:


data: gt_sort                   type slis_t_sortinfo_alv,
  CLEAR gs_sort.
  gs_sort-spos = '01'.
  gs_sort-fieldname = 'ROW_NUMBER'.
*  gs_sort-tabname = 'ITAB'.
  gs_sort-up = 'X'.
*  gs_sort-level = '1'.
  APPEND gs_sort TO gt_sort.

call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program       = gv_repid
            i_callback_user_command  = pv_user_command
            i_callback_top_of_page   = pv_top_of_page
            i_callback_pf_status_set = pv_pf_status_set
*            I_GRID_TITLE             = SY-TITLE
            is_layout                = gs_layout
            i_save                   = gv_save
*            IT_SPECIAL_GROUPS        = GT_sp_group
*            IT_EXCLUDING             = GT_EXCLUDING[]
            is_variant               = gs_variant
*            IT_EVENTS                = GT_EVENTS[]
*            IT_EVENT_EXIT            = GT_EVENT_EXIT[]
            it_fieldcat              = gt_fieldcat[]
            it_sort                  = gt_sort[] "sort table
       importing
            e_exit_caused_by_caller  = gv_exit_caused_by_caller
            es_exit_caused_by_user   = gs_exit_caused_by_user
       tables
            t_outtab                 = pt_itab.

Then, In your subroutine that assign PF-STATUS to report then exclude Sort up, Sort down and filter button from ALV toolbar.

If you want to align number to left you can attach attribute just to fieldcat:


gs_fieldcat-just = 'L'.

Hope it help.

Thanks,