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: 

grouping alv output

Former Member
0 Kudos
105

Hello,

which attribut is the rigth one to groupinh the output of aly grid

regards

ertas

1 ACCEPTED SOLUTION

Former Member
0 Kudos
80

Pl. refer the lines marked in bold in this prog.

REPORT z_demo_alv_sort_2.

TABLES : vbak.

TYPE-POOLS: slis. " ALV Global types

SELECT-OPTIONS :

s_vkorg FOR vbak-vkorg, " Sales organization

s_kunnr FOR vbak-kunnr, " Sold-to party

s_vbeln FOR vbak-vbeln. " Sales document

SELECTION-SCREEN SKIP.

SELECTION-SCREEN : BEGIN OF LINE, COMMENT 1(35) v_1 FOR FIELD p_page.

PARAMETERS p_page RADIOBUTTON GROUP optn.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE, COMMENT 1(35) v_2 FOR FIELD p_ligne.

PARAMETERS p_ligne RADIOBUTTON GROUP optn.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE, COMMENT 1(35) v_3 FOR FIELD p_nthng.

PARAMETERS p_nthng RADIOBUTTON GROUP optn.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN :

SKIP, BEGIN OF LINE,COMMENT 5(27) v_4 FOR FIELD p_max.

PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

DATA:

BEGIN OF gt_vbak OCCURS 0,

vkorg LIKE vbak-vkorg, " Sales organization

kunnr LIKE vbak-kunnr, " Sold-to party

vbeln LIKE vbak-vbeln, " Sales document

audat LIKE vbak-audat, " Document date

END OF gt_vbak.

----


INITIALIZATION.

v_1 = 'New page at ''Sales Org.'' break'.

v_2 = 'Underline at ''Sales Org.'' break'.

v_3 = 'Nothing'.

v_4 = 'Maximum of records to read'.

----


START-OF-SELECTION.

PERFORM f_read_data.

PERFORM f_display_data.

----


  • Form f_read_data

----


FORM f_read_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak

FROM vbak

UP TO p_max ROWS

WHERE kunnr IN s_kunnr

AND vbeln IN s_vbeln

AND vkorg IN s_vkorg.

ENDFORM. " F_READ_DATA

----


  • Form f_display_data

----


FORM f_display_data.

  • Macro definition

DEFINE m_fieldcat.

add 1 to ls_fieldcat-col_pos.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = 'VBAK'.

append ls_fieldcat to lt_fieldcat.

END-OF-DEFINITION.

DEFINE m_sort.

add 1 to ls_sort-spos.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

ls_sort-group = &2.

append ls_sort to lt_sort.

END-OF-DEFINITION.

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,

ls_layout TYPE slis_layout_alv,

ls_grid_settings TYPE lvc_s_glay.

*

ls_grid_settings-top_p_only = 'X'.

m_fieldcat 'VKORG'.

m_fieldcat 'KUNNR'.

m_fieldcat 'VBELN'.

m_fieldcat 'AUDAT'.

IF p_page = 'X'.

m_sort 'VKORG' '*'. " Sort by vkorg + Page break

ELSEIF p_ligne = 'X'.

m_sort 'VKORG' 'UL'. " Sort by vkorg + Underline

ELSE.

m_sort 'VKORG' ' '. " Sort by vkorg

ENDIF.

m_sort 'KUNNR' ' '. " Sort by kunnr

m_sort 'VBELN' ' '. " Sort by vbeln

ls_layout-colwidth_optimize = 'X'.

ls_layout-zebra = 'X'.

ls_layout-cell_merge = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-cprog

i_callback_top_of_page = 'TOP_OF_PAGE'

is_layout = ls_layout

i_grid_settings = ls_grid_settings

it_fieldcat = lt_fieldcat

it_sort = lt_sort

TABLES

t_outtab = gt_vbak.

ENDFORM. " F_DISPLAY_DATA

----


  • FORM top_of_page *

----


FORM top_of_page. "#EC CALLED

ULINE.

WRITE : sy-title(65) CENTERED, 'Page :' , sy-pagno .

ULINE.

ENDFORM.

Regards,

Joy.

Edited by: Joyjit Ghosh on Jun 19, 2008 2:26 PM

2 REPLIES 2

Former Member
0 Kudos
81

Pl. refer the lines marked in bold in this prog.

REPORT z_demo_alv_sort_2.

TABLES : vbak.

TYPE-POOLS: slis. " ALV Global types

SELECT-OPTIONS :

s_vkorg FOR vbak-vkorg, " Sales organization

s_kunnr FOR vbak-kunnr, " Sold-to party

s_vbeln FOR vbak-vbeln. " Sales document

SELECTION-SCREEN SKIP.

SELECTION-SCREEN : BEGIN OF LINE, COMMENT 1(35) v_1 FOR FIELD p_page.

PARAMETERS p_page RADIOBUTTON GROUP optn.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE, COMMENT 1(35) v_2 FOR FIELD p_ligne.

PARAMETERS p_ligne RADIOBUTTON GROUP optn.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE, COMMENT 1(35) v_3 FOR FIELD p_nthng.

PARAMETERS p_nthng RADIOBUTTON GROUP optn.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN :

SKIP, BEGIN OF LINE,COMMENT 5(27) v_4 FOR FIELD p_max.

PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

DATA:

BEGIN OF gt_vbak OCCURS 0,

vkorg LIKE vbak-vkorg, " Sales organization

kunnr LIKE vbak-kunnr, " Sold-to party

vbeln LIKE vbak-vbeln, " Sales document

audat LIKE vbak-audat, " Document date

END OF gt_vbak.

----


INITIALIZATION.

v_1 = 'New page at ''Sales Org.'' break'.

v_2 = 'Underline at ''Sales Org.'' break'.

v_3 = 'Nothing'.

v_4 = 'Maximum of records to read'.

----


START-OF-SELECTION.

PERFORM f_read_data.

PERFORM f_display_data.

----


  • Form f_read_data

----


FORM f_read_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak

FROM vbak

UP TO p_max ROWS

WHERE kunnr IN s_kunnr

AND vbeln IN s_vbeln

AND vkorg IN s_vkorg.

ENDFORM. " F_READ_DATA

----


  • Form f_display_data

----


FORM f_display_data.

  • Macro definition

DEFINE m_fieldcat.

add 1 to ls_fieldcat-col_pos.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = 'VBAK'.

append ls_fieldcat to lt_fieldcat.

END-OF-DEFINITION.

DEFINE m_sort.

add 1 to ls_sort-spos.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

ls_sort-group = &2.

append ls_sort to lt_sort.

END-OF-DEFINITION.

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,

ls_layout TYPE slis_layout_alv,

ls_grid_settings TYPE lvc_s_glay.

*

ls_grid_settings-top_p_only = 'X'.

m_fieldcat 'VKORG'.

m_fieldcat 'KUNNR'.

m_fieldcat 'VBELN'.

m_fieldcat 'AUDAT'.

IF p_page = 'X'.

m_sort 'VKORG' '*'. " Sort by vkorg + Page break

ELSEIF p_ligne = 'X'.

m_sort 'VKORG' 'UL'. " Sort by vkorg + Underline

ELSE.

m_sort 'VKORG' ' '. " Sort by vkorg

ENDIF.

m_sort 'KUNNR' ' '. " Sort by kunnr

m_sort 'VBELN' ' '. " Sort by vbeln

ls_layout-colwidth_optimize = 'X'.

ls_layout-zebra = 'X'.

ls_layout-cell_merge = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-cprog

i_callback_top_of_page = 'TOP_OF_PAGE'

is_layout = ls_layout

i_grid_settings = ls_grid_settings

it_fieldcat = lt_fieldcat

it_sort = lt_sort

TABLES

t_outtab = gt_vbak.

ENDFORM. " F_DISPLAY_DATA

----


  • FORM top_of_page *

----


FORM top_of_page. "#EC CALLED

ULINE.

WRITE : sy-title(65) CENTERED, 'Page :' , sy-pagno .

ULINE.

ENDFORM.

Regards,

Joy.

Edited by: Joyjit Ghosh on Jun 19, 2008 2:26 PM

Former Member
0 Kudos
80

Hi,

There is one parameter IT_SORT we have to pass to the ALV's function module .

Giving you a sample code in which you will find how data grouping is done as material wise.

********************************************************************

*&----


*

*& Report ZSAND_SUBTOTAL *

*& *

&----


*& *

*& *

&----


REPORT ZSAND_SUBTOTAL LINE-COUNT 65 .

*&----


*& Report ZALV_LIST

*&

*&----


*&

*&

*&----


TABLES : mseg.

TYPE-POOLS : slis.

DATA : BEGIN OF itab OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

line_color(4) TYPE c,

END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

line_color(4) TYPE c,

END OF itab1.

data: it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

DATA: it_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader.

data: var1(1).

DATA var2.

data:mytabix like sy-tabix.

data:wtab1 like line of itab,

wtab2 like line of itab.

DATA : t_fcat TYPE slis_t_fieldcat_alv,

t_eve TYPE slis_t_event,

t_subtot TYPE slis_t_sortinfo_alv,

subtot LIKE LINE OF t_subtot,

wa_fcat LIKE LINE OF t_fcat,

gd_layout TYPE slis_layout_alv.

DATA : gt_menge LIKE mseg-menge,

st_menge LIKE mseg-menge.

data:it_extab type SLIS_t_EXTAB,

wa_extab like line of it_extab.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : doc FOR mseg-mblnr.

SELECTION-SCREEN : END OF BLOCK blk1.

START-OF-SELECTION.

PERFORM build_cat USING t_fcat.

PERFORM build_layout.

PERFORM build_eve.

perform fill_sort.

PERFORM get_data.

PERFORM display.

*&----


*& Form build_cat

*&----


*text

*----


*-->TEMP_FCAT text

*----


FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MBLNR'.

wa_fcat-seltext_m = 'Material Doc.'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-seltext_m = 'Material'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-seltext_m = 'Plant'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-seltext_m = 'Quantity'.

wa_fcat-do_sum = 'Y'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

ENDFORM. "build_cat

*&----


*& Form build_eve

*&----


*text

*----


FORM build_eve.

DATA : wa_eve TYPE slis_alv_event.

data:mytabix type sy-tabix.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_eve

EXCEPTIONS

list_type_wrong = 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.

READ TABLE t_eve into wa_eve WITH KEY name = slis_ev_top_of_page.

*INTO wa_eve.

IF sy-subrc = 0.

mytabix = sy-tabix.

MOVE 'TOP_OF_PAGE' TO wa_eve-form.

append wa_eve to t_eve.

*modify t_eve from wa_eve index mytabix transporting form.

ENDIF.

READ TABLE t_eve into wa_eve WITH KEY name = slis_ev_end_of_page.

*INTO wa_eve.

IF sy-subrc = 0.

mytabix = sy-tabix.

MOVE 'END_OF_PAGE' TO wa_eve-form.

append wa_eve to t_eve.

*modify t_eve from wa_eve index mytabix transporting form.

ENDIF.

ENDFORM. "build_eve

*&----


*& Form build_layout

*&----


*text

*----


FORM build_layout.

*gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-info_fieldname = 'LINE_COLOR'.

gd_layout-subtotals_text = 'SUBTOTAL'.

*gd_layout-totals_text = 'TOTAL'.

gd_layout-EDIT = 'X'.

ENDFORM. " BUILD_LAYOUT

*&----


*& Form get_data

*&----


*text

*----


FORM get_data.

SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF

TABLE itab

WHERE mblnr IN doc.

SORT itab BY mblnr.

sort itab by mblnr matnr.

read table itab into wtab1 index 1.

mytabix = 1.

loop at itab into wtab2 from 2.

if wtab1-mblnr = wtab2-mblnr and wtab1-matnr = wtab2-matnr.

wtab1-menge = wtab1-menge + wtab2-menge.

modify itab from wtab1 index mytabix.

else.

modify itab from wtab1 index mytabix.

clear wtab1.

mytabix = sy-tabix.

move wtab2 to wtab1.

endif.

clear wtab2.

endloop.

delete ADJACENT DUPLICATES from itab comparing mblnr matnr.

ENDFORM. "get_data

*&----


*& Form display

*&----


*text

*----


FORM display.

*

wa_extab-fcode = '&ETA'.

append wa_extab to it_extab.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = 'ZSAND_SUBTOTAL'

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USERCOMMAND'

  • I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = gd_layout

IT_FIELDCAT = t_fcat

IT_EXCLUDING = it_extab

  • IT_SPECIAL_GROUPS =

IT_SORT = it_sortcat

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = t_eve[]

  • IT_EVENT_EXIT = 'BUILD_EVE'

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = itab

  • 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.

ENDFORM. "display

*

**&----


***& Form top_of_page

*&----


*

*text

*----


FORM top_of_page.

if var1 is initial.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_header

I_LOGO = 'HR_LOGO'

  • I_END_OF_LIST_GRID =

.

var1 = 'X'.

endif.

ENDFORM. "top_of_page

FORM end_of_page.

if var2 is initial.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_header

I_LOGO = 'HR_LOGO'

  • I_END_OF_LIST_GRID =

.

var2 = 'X'.

endif.

ENDFORM. "top_of_page

&----


*& Form fill_sort

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fill_sort .

wa_sort-spos = 1.

wa_sort-fieldname = 'MBLNR'.

wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

wa_sort-spos = 2.

wa_sort-fieldname = 'MATNR'.

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

endform. " fill_sort

FORM status USING rt_extab TYPE slis_t_extab.

set pf-status 'ZSTANDARD'.

endform.

form USERCOMMAND USING R_UCOMM type sy-ucomm

rselfield type slis_selfield .

set parameter id 'MAT' field rselfield-value .

call transaction 'MM03' and skip first screen.

endform.

***********************************************************************

I hope this program will help you in many aspect as this contains many fuctionality.

Help children of U.N World Food Program by rewarding points and encourage others to answer your queries.