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 can we remove the repetation values in field & display as one .

Former Member
0 Kudos

Dear Freinds,

i have developed a custom development relating to a salarly report based on the orgunit, the output is coming however i have one doubt in alv output.

right now my internal table data having data as follows : (iam giving only some fields)

orgunit orgdesc Empno Empname

70000905 Human Resources 7056 Richard

70000905 Human Resources 7057 Reymond Jain

70000905 Human Resources 7058 Maria Gulz

70000905 Human Resources 7061 Jacob

now in my output i dont want to have the orgunit value 70000905 and orgdesc (human resources) shouldnt not be repeated . is there any option in ALV where we I can use in

the field cat ( any parameter) where i can set that we can make the orgid as one and remove the repeation.(iam using alv grid function module).

Please help me in this regard

Regards

Syamla

1 ACCEPTED SOLUTION

former_member386202
Active Contributor
0 Kudos

Hi,

Before displaying sort ur internal table.

refer this code.

&----


*& Form sub_display_data

&----


  • text

----


FORM sub_display_data .

*--To sort the output through material number

DATA : lwa_sort TYPE slis_sortinfo_alv.

DATA : lit_sort TYPE slis_t_sortinfo_alv.

*--Pass the values to the table

lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '1'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = 'X'. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '2'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '3'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

wa_layout-colwidth_optimize = 'X'.

IF NOT it_final2[] IS INITIAL.

*--Call the function module to display the ALV report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = wa_layout

i_callback_program = v_repid

it_fieldcat = it_fieldcat1[]

i_default = c_chk

i_save = c_save

it_sort = lit_sort

TABLES

t_outtab = it_final2

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE.

*--Message No data found

MESSAGE i888 WITH text-017.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " sub_display_data

Regards,

Prashant

5 REPLIES 5

former_member386202
Active Contributor
0 Kudos

Hi,

Before displaying sort ur internal table.

refer this code.

&----


*& Form sub_display_data

&----


  • text

----


FORM sub_display_data .

*--To sort the output through material number

DATA : lwa_sort TYPE slis_sortinfo_alv.

DATA : lit_sort TYPE slis_t_sortinfo_alv.

*--Pass the values to the table

lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '1'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = 'X'. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '2'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '3'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

wa_layout-colwidth_optimize = 'X'.

IF NOT it_final2[] IS INITIAL.

*--Call the function module to display the ALV report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = wa_layout

i_callback_program = v_repid

it_fieldcat = it_fieldcat1[]

i_default = c_chk

i_save = c_save

it_sort = lit_sort

TABLES

t_outtab = it_final2

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE.

*--Message No data found

MESSAGE i888 WITH text-017.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " sub_display_data

Regards,

Prashant

0 Kudos

Dear Prashant,

I got the solution as per the logic given by you thanks allot for the help.

Regards

syamala.

Former Member
0 Kudos

Hi syamala,

use the standard alv functionality of sort ascending on all fields of ALV to achieve this.

Regards,

Kasinath Babu.

Former Member
0 Kudos

Hi Syamala,

do like this before displaying the ALV output

 DATA: it_sortcat   TYPE TABLE OF slis_sortinfo_alv,
        wa_sort      TYPE slis_sortinfo_alv.

  wa_sort-spos      = 1.
  wa_sort-fieldname = 'ORGUNIT'.
  APPEND wa_sort TO it_sortcat.
  CLEAR wa_sort.

  wa_sort-spos      = 2.
  wa_sort-fieldname = 'ORGDESC'.
  APPEND wa_sort TO it_sortcat.
  CLEAR wa_sort.

 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      i_callback_top_of_page  = 'TOP-OF-PAGE'
      it_fieldcat             = git_fieldcatalog[]
      it_sort                 = it_sortcat
      i_callback_user_command = c_user_command
      i_save                  = c_save
    TABLES
      t_outtab                = git_data
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.         " IF sy-subrc <> 0.

<b>Reward points for helpful answers</b>

Satish

Former Member
0 Kudos

Hi Syamala,

you can use the sort table option in the ALV.

**- Sorting based on the fields.

CLEAR wa_sort.

wa_sort-spos = 1.

wa_sort-fieldname = "field1".

APPEND wa_sort TO i_sort.

CLEAR wa_sort.

wa_sort-spos = 2.

wa_sort-fieldname = "field2".

APPEND wa_sort TO i_sort.

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

it_toolbar_excluding = i_excl_func

is_variant = wa_variant

i_save = c_a

is_layout = pwa_layout

CHANGING

it_outtab = pi_final[]

it_fieldcatalog = pi_fieldcat[]

<b> it_sort = pi_sort[]</b>

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

Reward If Useful.

Regards,

Chitra