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: 

Sortinf of ALV grid and merging of the columns

Former Member
0 Kudos

I have an ALV display like this.

LIFNR MATNR

C1000 12345

C1000 12345

C2000 12345

C2000 12345

C2000 12678

C2000 12679

Here, I need merging of the columns and is working properly as

C1000 12345

-


C2000 -


> (Here no MATNR repeated at present)

-


12678

-


-


But, Evenif LIFNR changes from C1000 to C2000, MATNR is not getting repeated at that time because MATNR value is 12345 itself. I want the MATNR 12345 to be repeated again when the row LIFNR changes from C1000 to C2000.

I want the display to be

C1000 12345

-


-


C2000 12345

-


-


12678

-


-


Please help me..

10 REPLIES 10

former_member188685
Active Contributor
0 Kudos

Hi,

build the sort table based on LIFNR , don't make it dependent on lifnr, matnr.

do it onlt for LIFNR, then it will come.

sort-fieldname = 'LIFNR'.

remove the matnr from sort criteria.

Regards

vijay

Former Member
0 Kudos

HI Ratheesh

I think you have sorted based on both LIFNR and MATNR.

sort it only using LIFNR then it will work

regards

kishore

Former Member
0 Kudos

Hi,

Sort the table on LIFNR alone.

Regs,

Venkat Ramanan

Former Member
0 Kudos

former_member188685
Active Contributor
0 Kudos

hi

your sort table should be like this..


DATA: LT_SORT TYPE SLIS_T_SORTINFO_ALV.
  DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.

  CLEAR LS_SORT.
  LS_SORT-FIELDNAME = 'LIFNR'.
  LS_SORT-SPOS      = 1.
  LS_SORT-UP        = 'X'.
* ls_sort-subtot    = 'X'.
  APPEND LS_SORT TO LT_SORT.

[code]*  CLEAR LS_SORT.
*  LS_SORT-FIELDNAME = 'MATNR'.
*  LS_SORT-SPOS      = 2.
*  LS_SORT-UP        = 'X'.
* ls_sort-subtot    = 'X'.
*  APPEND LS_SORT TO LT_SORT

.[/code]

comment the bold one and try..

Regards

vijay

Former Member
0 Kudos

Hi,

In order to display an ALV report with specific columns already sorted by default you can build a

sort catalogue.

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_sort.htm

Let us know if your problem is solved

Best Regards,

Anjali

Former Member
0 Kudos

Hi,

Sort the internal table on LIFNR alone, it should work.

(OR)


FORM prepare_sort_table CHANGING pt_sort TYPE lvc_t_sort . 
  DATA ls_sort TYPE lvc_s_sort . 
  ls_sort-spos = '1' . 
  ls_sort-fieldname = 'LIFNR' .
  ls_sort-up = 'X' . "A to Z 
  ls_sort-down = space .
  APPEND ls_sort TO pt_sort . 
ENDFORM.

Pass this pt_sort in export parameter.

Regs,

Venkat Ramanan

Message was edited by: Venkat Ramanan Natarajan

Former Member
0 Kudos

Hello All,

Thank u very much for the comments u have put.

But, I can't sort it based on LIFNR only beacuse I want MATNR also to be sorted and grouped. Only thing is that whenevr LIFNR changes, eventhogh same MATNR occurs, I need the MATNR to be repeated.

0 Kudos

Hi,

if you group them LIFNR, MATNR then for any change in lifnr, or for any change in MATNR it will trigger.

but if you sort only based on matnr then the output will be like this..

linr matnr ....

1234 abctest

abctest

cdctest

1235 abctest

cdctest

Regards

vijay

former_member188685
Active Contributor
0 Kudos

Hi,

it is triggering for me, even lifnr changes the same matnr repeating see this example.(copy+paste the code)

REPORT  ZTEST_ALV1                              .
TYPE-POOLS: SLIS.
DATA:
  LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
  LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
  LT_SORT     TYPE SLIS_T_SORTINFO_ALV,
  LS_SORT     TYPE SLIS_SORTINFO_ALV.

DATA: BEGIN OF ITAB OCCURS 0,
       LIFNR LIKE LFA1-LIFNR,
       MATNR LIKE MARA-MATNR,
      END OF ITAB.
ITAB-LIFNR = 'C1000'.
ITAB-MATNR = '12345'.
APPEND ITAB.
CLEAR ITAB.

ITAB-LIFNR = 'C1000'.
ITAB-MATNR = '12678'.
APPEND ITAB.
CLEAR ITAB.
ITAB-LIFNR = 'C2000'.
ITAB-MATNR = '12345'.
APPEND ITAB.
CLEAR ITAB.
ITAB-LIFNR = 'C2000'.
ITAB-MATNR = '12345'.
APPEND ITAB.
CLEAR ITAB.
ITAB-LIFNR = 'C2000'.
ITAB-MATNR = '12678'.
APPEND ITAB.
CLEAR ITAB.
ITAB-LIFNR = 'C2000'.
ITAB-MATNR = '12679'.
APPEND ITAB.
CLEAR ITAB.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  EXPORTING
    I_PROGRAM_NAME         = SY-REPID
    I_INTERNAL_TABNAME     = 'ITAB'
    I_INCLNAME             = SY-REPID
  CHANGING
    CT_FIELDCAT            = LT_FIELDCAT
  EXCEPTIONS
    INCONSISTENT_INTERFACE = 1
    PROGRAM_ERROR          = 2
    OTHERS                 = 3.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LS_SORT-FIELDNAME = 'LIFNR'.
LS_SORT-UP        = 'X'.

APPEND LS_SORT TO LT_SORT.
CLEAR LS_SORT.
LS_SORT-FIELDNAME = 'MATNR'.
LS_SORT-UP        = 'X'.
APPEND LS_SORT TO LT_SORT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    IT_FIELDCAT = LT_FIELDCAT
    IT_SORT     = LT_SORT
  TABLES
    T_OUTTAB    = ITAB.

Regards

Vijay