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: 

Hotspot in ALV BLOCK LIST

Former Member
0 Kudos
352

Hi,

i want to create a drill down report using ALV BLOCK LIST.I have created a form named USER COMMAND and set as i_calback_user command parameter in REUSE_ALV_BLOCK_LIST_INIT function.But when i clicks on the grid,it won't display the subreport.Please help me to solve this problem

regards,

Ajas P Thomas

SAP ABAP Consultant

3 REPLIES 3

santhosh_patil
Contributor
0 Kudos
125

Hi,

Please paste the coding part for form user command

---Patil

Former Member
0 Kudos
125

Hi

See the sample code for ALV Block list and doa ccordingly

REPORT YMS_BLOCKLISTALV .

TYPE-POOLS: slis. " ALV Global types

SELECTION-SCREEN :

SKIP,

BEGIN OF LINE,

COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED

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

SELECTION-SCREEN END OF LINE.

DATA:

  • 1st Table

BEGIN OF gt_kna1 OCCURS 0, " Data displayed

kunnr LIKE kna1-kunnr, " Customer number

ernam LIKE kna1-ernam, " Name of Person who Created

erdat LIKE kna1-erdat, " Creation date

name1 LIKE kna1-name1, " Name 1

END OF gt_kna1,

  • 2nd Table

BEGIN OF gt_mara OCCURS 0,

ernam LIKE mara-ernam, " Name of Person who Created

matnr LIKE mara-matnr, " Material number

ersda LIKE mara-ersda, " Creation date

brgew LIKE mara-brgew, " Gross weight

END OF gt_mara,

  • 3rd Table

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

netwr LIKE vbak-netwr, " Net Value of the Sales Order

waerk LIKE vbak-waerk, " SD document currency

END OF gt_vbak.

----


INITIALIZATION.

v_1 = 'Maximum of records to read'.

----


START-OF-SELECTION.

  • Read data

SELECT * FROM kna1

UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_kna1.

SELECT * FROM mara

UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_mara.

SELECT * FROM vbak

UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE gt_vbak.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = sy-cprog

i_callback_user_command = 'USER_COMMAND'.

PERFORM list_append TABLES gt_kna1

USING '1'

'GT_KNA1'.

PERFORM list_append TABLES gt_mara

USING '2'

'GT_MARA'.

PERFORM list_append TABLES gt_vbak

USING '3'

'GT_VBAK'.

PERFORM f_list_display.

----


  • FORM USER_COMMAND *

----


FORM user_command USING i_ucomm LIKE sy-ucomm

is_selfield TYPE slis_selfield. "#EC CALLED

CASE i_ucomm.

WHEN '&IC1'. " Pick

CASE is_selfield-tabname.

WHEN 'GT_MARA'.

WHEN 'GT_KNA1'.

WHEN 'GT_VBAK'.

READ TABLE gt_vbak INDEX is_selfield-tabindex.

IF sy-subrc EQ 0.

  • Sales order number

SET PARAMETER ID 'AUN' FIELD gt_vbak-vbeln.

  • Display Sales Order

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

ENDIF.

ENDCASE.

ENDCASE.

ENDFORM. " USER_COMMAND

----


*/div>

  • Form list_append

----


FORM list_append TABLES ut_table

USING u_no TYPE char1

u_tabname TYPE slis_tabname.

  • Macro definition

DEFINE m_fieldcat.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = &2.

append ls_fieldcat to lt_fieldcat.

END-OF-DEFINITION.

DEFINE m_sort.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

append ls_sort to lt_sort.

END-OF-DEFINITION.

DATA :

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog

ls_sort TYPE slis_sortinfo_alv,

lt_sort TYPE slis_t_sortinfo_alv. " Sort table

DATA:

lt_events TYPE slis_t_event,

ls_event TYPE slis_alv_event,

ls_layout TYPE slis_layout_alv.

ls_layout-group_change_edit = 'X'.

ls_layout-colwidth_optimize = 'X'.

ls_layout-zebra = 'X'.

ls_layout-detail_popup = 'X'.

ls_layout-get_selinfos = 'X'.

ls_layout-max_linesize = '200'.

CASE u_no.

WHEN '1'.

  • Build field catalog and sort table

m_fieldcat 'KUNNR' 'KNA1'.

m_fieldcat 'ERNAM' 'KNA1'.

m_fieldcat 'ERDAT' 'KNA1'.

m_fieldcat 'NAME1' 'KNA1'.

m_sort 'KUNNR'.

WHEN '2'.

m_fieldcat 'MATNR' 'MARA'.

m_fieldcat 'ERNAM' 'MARA'.

m_fieldcat 'ERSDA' 'MARA'.

m_fieldcat 'BRGEW' 'MARA'.

m_sort 'MATNR'.

WHEN '3'.

m_fieldcat 'VBELN' 'VBAK'.

m_fieldcat 'VKORG' 'VBAK'.

m_fieldcat 'KUNNR' 'VBAK'.

m_fieldcat 'NETWR' 'VBAK'.

m_fieldcat 'WAERK' 'VBAK'.

m_sort 'VBELN'.

ENDCASE.

IF u_no CA '13'.

MOVE 'TOP_OF_PAGE' TO ls_event-name.

CONCATENATE 'TOP_OF_PAGE' u_no INTO ls_event-form.

APPEND ls_event TO lt_events.

ELSE.

MOVE 'TOP_OF_LIST' TO ls_event-name.

CONCATENATE 'TOP_OF_LIST' u_no INTO ls_event-form.

APPEND ls_event TO lt_events.

ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

it_fieldcat = lt_fieldcat

is_layout = ls_layout

i_tabname = u_tabname

it_events = lt_events

it_sort = lt_sort

  • i_text =

TABLES

t_outtab = ut_table

EXCEPTIONS

program_error = 1

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

ENDFORM. " LIST_APPEND

----


  • Form f_list_display

----


FORM f_list_display.

DATA ls_print TYPE slis_print_alv.

ls_print-no_print_selinfos = 'X'. " Display no selection infos

ls_print-no_print_listinfos = 'X'. " Display no listinfos

ls_print-reserve_lines = 2. " Lines reserved for end of page

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

EXPORTING

i_interface_check = ' '

is_print = ls_print

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. " F_LIST_DISPLAY

----


  • FORM top_of_page1 *

----


FORM top_of_page1. "#EC CALLED

PERFORM top_of_page.

ENDFORM.

----


  • FORM top_of_page3 *

----


FORM top_of_page3. "#EC CALLED

PERFORM top_of_page.

ENDFORM.

----


  • FORM top_of_page *

----


FORM top_of_page.

ULINE.

WRITE : sy-uname, sy-title(56) CENTERED, sy-datum.

ULINE.

ENDFORM.

----


  • FORM top_of_list2 *

----


FORM top_of_list2. "#EC CALLED

WRITE 'TOP OF LIST2'.

ENDFORM.

                            • END OF PROGRAM Z_ALV_LIST_BLOCK ***********************

REPORT ZKEERTHI_ALV3 LINE-COUNT 100 .

&----


*& tables declaration

&----


tables: mara.

&----


*& type-pools declaration

&----


type-pools: slis.

&----


*& data declaration

&----


data: g_repid type sy-repid.

DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "mara

WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA : IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV, "makt

WA_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.

DATA : IT_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV, "marc

WA_FIELDCAT2 TYPE SLIS_FIELDCAT_ALV.

DATA: GT_PRINT TYPE SLIS_PRINT_ALV,

WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

XS_EVENT TYPE SLIS_ALV_EVENT,

GT_XEVENTS TYPE SLIS_T_EVENT,

GT_YEVENTS TYPE SLIS_T_EVENT,

GT_ZEVENTS TYPE SLIS_T_EVENT,

WA_SORT TYPE SLIS_SORTINFO_ALV,

IT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA: BEGIN OF it_mara occurs 0,

MATNR LIKE MARA-MATNR,

MTART LIKE MARA-MTART,

MATKL LIKE MARA-MATKL,

MEINS LIKE MARA-MEINS,

NTGEW LIKE MARA-NTGEW,

END OF it_mara.

DATA: BEGIN OF IT_MAKT occurs 0,

MATNR LIKE MAKT-MATNR,

SPRAS LIKE MAKT-SPRAS,

MAKTX LIKE MAKT-MAKTX,

MAKTG LIKE MAKT-MAKTG,

END OF IT_MAKT.

DATA: BEGIN OF IT_MARC occurs 0,

MATNR LIKE MARC-MATNR,

WERKS LIKE MARC-WERKS,

LADGR LIKE MARC-LADGR,

MTVFP LIKE MARC-MTVFP,

dispr LIKE marc-dispr,

dismm LIKE marc-dismm,

dispo LIKE marc-dispo,

END OF IT_MARC.

&----


*& initialisation

&----


initialization.

g_repid = sy-repid.

&----


*& selection screen

&----


selection-screen begin of block b with frame title text-001.

select-options: s_matnr for mara-matnr,

s_mtart for mara-mtart.

selection-screen end of block b.

&----


*& start of selection

&----


start-of-selection.

perform get_maradetails.

perform get_maktdetails.

perform get_marcdetails.

&----


*& Form get_maradetails

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_maradetails .

select matnr

mtart

matkl

meins

ntgew from mara

into table it_mara

where matnr in s_matnr and

mtart in s_mtart.

ENDFORM. " get_maradetails

&----


*& Form get_maktdetails

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_maktdetails .

select matnr

spras

maktx

maktg from makt into table it_makt

for all entries in it_mara

where matnr = it_mara-matnr..

ENDFORM. " get_maktdetails

&----


*& Form get_marcdetails

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_marcdetails .

select matnr

werks

ladgr

mtvfp

dispr

dismm

dispo from marc

into table it_marc

for all entries in it_mara

where matnr = it_mara-matnr.

ENDFORM. " get_marcdetails

&----


*& end of selection

&----


END-OF-SELECTION.

perform sort_list.

perform modify_fieldcat.

PERFORM EVENT_LIST.

PERFORM BLOCK_LIST.

&----


*& Form modify_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM modify_fieldcat .

clear wa_fieldcat.

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-TABNAME = 'IT_MARA'.

WA_FIELDCAT-SELTEXT_L = 'MATERIAL NUM'.

WA_FIELDCAT-COL_POS = 1.

WA_FIELDCAT-OUTPUTLEN = 18.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MTART'.

WA_FIELDCAT-TABNAME = 'IT_MARA'.

WA_FIELDCAT-SELTEXT_L = 'MAT TYPE'.

WA_FIELDCAT-COL_POS = 2.

WA_FIELDCAT-OUTPUTLEN = 5.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MATKL'.

WA_FIELDCAT-TABNAME = 'IT_MARA'.

WA_FIELDCAT-SELTEXT_L = 'MAT GROUP'.

WA_FIELDCAT-COL_POS = 3.

WA_FIELDCAT-OUTPUTLEN = 10.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MEINS'.

WA_FIELDCAT-TABNAME = 'IT_MARA'.

WA_FIELDCAT-SELTEXT_L = 'UNIT'.

WA_FIELDCAT-COL_POS = 4.

WA_FIELDCAT-OUTPUTLEN = 5.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'NTGEW'.

WA_FIELDCAT-TABNAME = 'IT_MARA'.

WA_FIELDCAT-DO_SUM = 'X'.

WA_FIELDCAT-SELTEXT_L = 'QUANTITY'.

WA_FIELDCAT-COL_POS = 5.

WA_FIELDCAT-OUTPUTLEN = 15.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-FIELDNAME = 'MATNR'.

WA_FIELDCAT1-TABNAME = 'IT_MAKT'.

WA_FIELDCAT1-SELTEXT_L = 'MATERIAL NUM'.

WA_FIELDCAT1-COL_POS = 1.

WA_FIELDCAT1-OUTPUTLEN = 18.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-FIELDNAME = 'SPRAS'.

WA_FIELDCAT1-TABNAME = 'IT_MAKT'.

WA_FIELDCAT1-SELTEXT_L = 'LANGUAGE'.

WA_FIELDCAT1-COL_POS = 2.

WA_FIELDCAT1-OUTPUTLEN = 2.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-FIELDNAME = 'MAKTX'.

WA_FIELDCAT1-TABNAME = 'IT_MAKT'.

WA_FIELDCAT1-SELTEXT_L = 'MAT DESC'.

WA_FIELDCAT1-COL_POS = 3.

WA_FIELDCAT1-OUTPUTLEN = 40.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-FIELDNAME = 'MAKTG'.

WA_FIELDCAT1-TABNAME = 'IT_MAKT'.

WA_FIELDCAT1-SELTEXT_L = 'GRP DESC'.

WA_FIELDCAT1-COL_POS = 4.

WA_FIELDCAT1-OUTPUTLEN = 40.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'MATNR'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'MATERIAL NUM'.

WA_FIELDCAT2-COL_POS = 1.

WA_FIELDCAT2-OUTPUTLEN = 18.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'WERKS'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'PLANT'.

WA_FIELDCAT2-COL_POS = 2.

WA_FIELDCAT2-OUTPUTLEN = 4.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'LADGR'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'LOAD GRP'.

WA_FIELDCAT2-COL_POS = 3.

WA_FIELDCAT2-OUTPUTLEN = 4.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'MTVFP'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'GRP CHK'.

WA_FIELDCAT2-COL_POS = 4.

WA_FIELDCAT2-OUTPUTLEN = 4.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'DISPR'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'MRP PROFILE'.

WA_FIELDCAT2-COL_POS = 5.

WA_FIELDCAT2-OUTPUTLEN = 4.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'DISMM'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'MRP TYPE'.

WA_FIELDCAT2-COL_POS = 6.

WA_FIELDCAT2-OUTPUTLEN = 4.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

WA_FIELDCAT2-FIELDNAME = 'DISPO'.

WA_FIELDCAT2-TABNAME = 'IT_MARC'.

WA_FIELDCAT2-SELTEXT_L = 'MRP CON'.

WA_FIELDCAT2-COL_POS = 7.

WA_FIELDCAT2-OUTPUTLEN = 4.

APPEND WA_FIELDCAT2 TO IT_FIELDCAT2.

CLEAR WA_FIELDCAT2.

ENDFORM. " modify_fieldcat

&----


*& Form BLOCK_LIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BLOCK_LIST .

CLEAR WA_LAYOUT.

WA_LAYOUT-ZEBRA = 'X'.

WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

I_CALLBACK_PROGRAM = G_REPID

I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'user_command'.

  • IT_EXCLUDING =

.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

I_TABNAME = 'IT_MARA'

IT_EVENTS = GT_XEVENTS

IT_SORT = IT_SORT

  • I_TEXT = ' '

TABLES

T_OUTTAB = IT_MARA

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

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

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT1

I_TABNAME = 'IT_MAKT'

IT_EVENTS = GT_YEVENTS

  • IT_SORT =

  • I_TEXT = ' '

TABLES

T_OUTTAB = IT_MAKT

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

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

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT2

I_TABNAME = 'IT_MARC'

IT_EVENTS = GT_ZEVENTS

  • IT_SORT =

  • I_TEXT = ' '

TABLES

T_OUTTAB = IT_MARC

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

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

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

IS_PRINT = GT_PRINT

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

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

&----


*& Form EVENT_LIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM EVENT_LIST .

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

XS_EVENT-FORM = 'XTOP_OF_PAGE'.

APPEND XS_EVENT TO GT_XEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_END_OF_PAGE.

XS_EVENT-FORM = 'XEND_OF_PAGE'.

APPEND XS_EVENT TO GT_XEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_TOP_OF_LIST.

XS_EVENT-FORM = 'XTOP_OF_LIST'.

APPEND XS_EVENT TO GT_XEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_END_OF_LIST.

XS_EVENT-FORM = 'XEND_OF_LIST'.

APPEND XS_EVENT TO GT_XEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_END_OF_PAGE.

XS_EVENT-FORM = 'YEND_OF_PAGE'.

APPEND XS_EVENT TO GT_YEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

XS_EVENT-FORM = 'YTOP_OF_PAGE'.

APPEND XS_EVENT TO GT_YEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_TOP_OF_LIST.

XS_EVENT-FORM = 'YTOP_OF_LIST'.

APPEND XS_EVENT TO GT_YEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_END_OF_LIST.

XS_EVENT-FORM = 'YEND_OF_LIST'.

APPEND XS_EVENT TO GT_YEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_END_OF_PAGE.

XS_EVENT-FORM = 'ZEND_OF_PAGE'.

APPEND XS_EVENT TO GT_ZEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

XS_EVENT-FORM = 'ZTOP_OF_PAGE'.

APPEND XS_EVENT TO GT_ZEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_TOP_OF_LIST.

XS_EVENT-FORM = 'ZTOP_OF_LIST'.

APPEND XS_EVENT TO GT_ZEVENTS.

CLEAR XS_EVENT.

XS_EVENT-NAME = SLIS_EV_END_OF_LIST.

XS_EVENT-FORM = 'ZEND_OF_LIST'.

APPEND XS_EVENT TO GT_ZEVENTS.

CLEAR XS_EVENT.

ENDFORM. " EVENT_LIST

FORM XTOP_OF_PAGE.

WRITE:/ 'TOP OF PAGE FOR MARA'.

ENDFORM.

FORM YTOP_OF_PAGE.

WRITE:/ 'TOP OF PAGE FOR MAKT'.

ENDFORM.

FORM ZTOP_OF_PAGE.

WRITE:/ 'TOP OF PAGE FOR MARC'.

ENDFORM.

FORM XEND_OF_PAGE.

WRITE:/ 'END OF PAGE FOR MARA'.

ENDFORM.

FORM YEND_OF_PAGE.

WRITE:/ 'END OF PAGE FOR MAKT'.

ENDFORM.

FORM ZEND_OF_PAGE.

WRITE:/ 'END OF PAGE FOR MARC'.

ENDFORM.

FORM XTOP_OF_LIST.

WRITE:/ 'TOP OF LIST FOR MARA'.

ENDFORM.

FORM YTOP_OF_LIST.

WRITE:/ 'TOP OF LIST FOR MAKT'.

ENDFORM.

FORM ZTOP_OF_LIST.

WRITE:/ 'TOP OF LIST FOR MARC'.

ENDFORM.

FORM XEND_OF_LIST.

WRITE:/ 'END OF LIST FOR MARA'.

ENDFORM.

FORM YEND_OF_LIST.

WRITE:/ 'END OF LIST FOR MAKT'.

ENDFORM.

FORM ZEND_OF_LIST.

WRITE:/ 'END OF LIST FOR MARC'.

ENDFORM.

&----


*& Form sort_list

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sort_list .

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'MTART'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'MATKL'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

ENDFORM. " sort_list

Reward points for useful Answers

Regards

Anji

Former Member
0 Kudos
125

hi,

check the below coding:

REPORT Zsr_ALV_HIERSEQ_LIST.

TYPE-POOLS: SLIS. " ALV Global types

----


CONSTANTS :

C_X VALUE 'X',

C_GT_VBAP TYPE SLIS_TABNAME VALUE 'GT_VBAP',

C_GT_VBAK TYPE SLIS_TABNAME VALUE 'GT_VBAK'.

----


SELECTION-SCREEN :

SKIP,

BEGIN OF LINE,COMMENT 5(27) V_1 FOR FIELD P_MAX. "#EC NEEDED

PARAMETERS P_MAX(02) TYPE N DEFAULT '10' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN :

SKIP, BEGIN OF LINE,COMMENT 5(27) V_2 FOR FIELD P_EXPAND. "#EC NEEDED

PARAMETERS P_EXPAND AS CHECKBOX DEFAULT C_X.

SELECTION-SCREEN END OF LINE.

----


TYPES :

  • 1st Table

BEGIN OF TY_VBAK,

VBELN TYPE VBAK-VBELN, " Sales document

KUNNR TYPE VBAK-KUNNR, " Sold-to party

NETWR TYPE VBAK-NETWR, " Net Value of the Sales Order

ERDAT TYPE VBAK-ERDAT, " Creation date

WAERK TYPE VBAK-WAERK, " SD document currency

EXPAND TYPE XFELD,

END OF TY_VBAK,

  • 2nd Table

BEGIN OF TY_VBAP,

VBELN TYPE VBAP-VBELN, " Sales document

POSNR TYPE VBAP-POSNR, " Sales document

MATNR TYPE VBAP-MATNR, " Material number

NETWR TYPE VBAP-NETWR, " Net Value of the Sales Order

WAERK TYPE VBAP-WAERK, " SD document currency

END OF TY_VBAP.

----


DATA :

  • 1st Table

GT_VBAK TYPE TABLE OF TY_VBAK,

  • 2nd Table

GT_VBAP TYPE TABLE OF TY_VBAP.

----


INITIALIZATION.

V_1 = 'Maximum of records to read'.

V_2 = 'With ''EXPAND'' field'.

----


START-OF-SELECTION.

  • Read Sales Document: Header Data

SELECT VBELN KUNNR NETWR WAERK ERDAT

FROM VBAK

UP TO P_MAX ROWS

INTO CORRESPONDING FIELDS OF TABLE GT_VBAK.

IF NOT GT_VBAK[] IS INITIAL.

  • Read Sales Document: Item Data

SELECT VBELN POSNR MATNR NETWR WAERK

FROM VBAP

INTO CORRESPONDING FIELDS OF TABLE GT_VBAP

FOR ALL ENTRIES IN GT_VBAK

WHERE VBELN = GT_VBAK-VBELN.

ENDIF.

PERFORM F_DISPLAY.

----


  • Form F_DISPLAY

----


FORM F_DISPLAY.

  • Macro definition

DEFINE M_FIELDCAT.

LS_FIELDCAT-TABNAME = &1.

LS_FIELDCAT-FIELDNAME = &2.

LS_FIELDCAT-REF_TABNAME = &3.

LS_FIELDCAT-CFIELDNAME = &4. " Field with currency unit

APPEND LS_FIELDCAT TO LT_FIELDCAT.

END-OF-DEFINITION.

DEFINE M_SORT.

LS_SORT-TABNAME = &1.

LS_SORT-FIELDNAME = &2.

LS_SORT-UP = C_X.

APPEND LS_SORT TO LT_SORT.

END-OF-DEFINITION.

DATA:

LS_LAYOUT TYPE SLIS_LAYOUT_ALV,

LS_KEYINFO TYPE SLIS_KEYINFO_ALV,

LS_SORT TYPE SLIS_SORTINFO_ALV,

LT_SORT TYPE SLIS_T_SORTINFO_ALV," Sort table

LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,

LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV." Field catalog

LS_LAYOUT-GROUP_CHANGE_EDIT = C_X.

LS_LAYOUT-COLWIDTH_OPTIMIZE = C_X.

LS_LAYOUT-ZEBRA = C_X.

LS_LAYOUT-DETAIL_POPUP = C_X.

LS_LAYOUT-GET_SELINFOS = C_X.

IF P_EXPAND = C_X.

LS_LAYOUT-EXPAND_FIELDNAME = 'EXPAND'.

ENDIF.

  • Build field catalog and sort table

M_FIELDCAT C_GT_VBAK 'VBELN' 'VBAK' ''.

M_FIELDCAT C_GT_VBAK 'KUNNR' 'VBAK' ''.

M_FIELDCAT C_GT_VBAK 'NETWR' 'VBAK' 'WAERK'.

M_FIELDCAT C_GT_VBAK 'WAERK' 'VBAK' ''.

M_FIELDCAT C_GT_VBAK 'ERDAT' 'VBAK' ''.

M_FIELDCAT C_GT_VBAP 'POSNR' 'VBAP' ''.

M_FIELDCAT C_GT_VBAP 'MATNR' 'VBAP' ''.

M_FIELDCAT C_GT_VBAP 'NETWR' 'VBAP' 'WAERK'.

M_FIELDCAT C_GT_VBAP 'WAERK' 'VBAP' ''.

M_SORT C_GT_VBAK 'KUNNR'.

M_SORT C_GT_VBAP 'NETWR'.

LS_KEYINFO-HEADER01 = 'VBELN'.

LS_KEYINFO-ITEM01 = 'VBELN'.

LS_KEYINFO-ITEM02 = 'POSNR'.

  • Dipslay Hierarchical list

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-CPROG

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IS_LAYOUT = LS_LAYOUT

IT_FIELDCAT = LT_FIELDCAT

IT_SORT = LT_SORT

I_TABNAME_HEADER = C_GT_VBAK

I_TABNAME_ITEM = C_GT_VBAP

IS_KEYINFO = LS_KEYINFO

TABLES

T_OUTTAB_HEADER = GT_VBAK

T_OUTTAB_ITEM = GT_VBAP

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. " F_LIST_DISPLAY

----


  • Form USER_COMMAND *

----


FORM USER_COMMAND USING I_UCOMM TYPE SY-UCOMM

IS_SELFIELD TYPE SLIS_SELFIELD. "#EC CALLED

DATA LS_VBAK TYPE TY_VBAK.

CASE I_UCOMM.

WHEN '&IC1'. " Pick

CASE IS_SELFIELD-TABNAME.

WHEN C_GT_VBAP.

WHEN C_GT_VBAK.

READ TABLE GT_VBAK INDEX IS_SELFIELD-TABINDEX INTO LS_VBAK.

IF SY-SUBRC EQ 0.

  • Sales order number

SET PARAMETER ID 'AUN' FIELD LS_VBAK-VBELN.

  • Display Sales Order

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

ENDIF.

ENDCASE.

ENDCASE.

ENDFORM. " USER_COMMAND

                                    • END OF PROGRAM Z_ALV_HIERSEQ_LIST ******************