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: 

regarding alv logic

MohitSingh
Product and Topic Expert
Product and Topic Expert
0 Kudos
245

Hi all iam making blocked alv programe.

In the below code if i want to display in Second block the list of Material Types with No. of materials in each type than what should be the approach for this logic.

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_mara ,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

END OF ty_mara ,

BEGIN OF ty_makt ,

matnr TYPE makt-matnr,

maktx TYPE makt-maktx,

END OF ty_makt ,

BEGIN OF ty_final ,

mtart TYPE mara-mtart,

matnr TYPE mara-matnr,

maktx TYPE makt-maktx,

record TYPE i ,

END OF ty_final ,

BEGIN OF records,

records TYPE i,

END OF records.

DATA no TYPE i.

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

*************************INTERNAL TABLES******************************

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

DATA: it_mara TYPE TABLE OF ty_mara ,

it_makt TYPE TABLE OF ty_makt ,

it_final TYPE TABLE OF ty_final ,

it_fieldcat TYPE slis_t_fieldcat_alv,

it_events TYPE slis_t_event ,

it_fieldcat1 TYPE slis_t_fieldcat_alv,

it_records TYPE TABLE OF records.

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

*************************WORK AREAS***********************************

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

DATA: wa_mara TYPE ty_mara ,

wa_makt TYPE ty_makt ,

wa_final TYPE ty_final ,

wa_fieldcat TYPE slis_fieldcat_alv,

wa_layout TYPE slis_layout_alv ,

wa_events TYPE slis_alv_event ,

wa_fieldcat1 TYPE slis_fieldcat_alv,

wa_records TYPE records.

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

**************************VARIABLES***********************************

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

DATA: v_mtart TYPE mara-mtart, "#EC NEEDED

v_repid TYPE sy-repid ,

v_text TYPE string .

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

**************************CONSTANTS***********************************

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

CONSTANTS: c_zrh(4) TYPE c VALUE 'zrh' ,

c_x(1) TYPE c VALUE 'X' ,

c_02(2) TYPE c VALUE '02' ,

c_04(2) TYPE c VALUE '04' ,

c_06(2) TYPE c VALUE '06' ,

c_mtart(5) TYPE c VALUE 'MTART' ,

c_matnr(5) TYPE c VALUE 'MATNR' ,

c_maktx(5) TYPE c VALUE 'MAKTX' ,

c_it_final(8) TYPE c VALUE 'IT_FINAL' ,

c_mara(4) TYPE c VALUE 'MARA' ,

c_makt(4) TYPE c VALUE 'MAKT' ,

c_l(1) TYPE c VALUE 'L' ,

c_user_command(12) TYPE c VALUE 'USER_COMMAND' ,

c_alv_user_command(16) TYPE c VALUE 'ALV_USER_COMMAND',

c_top_of_page(11) TYPE c VALUE 'TOP_OF_PAGE' ,

c_alv_top_of_page(15) TYPE c VALUE 'ALV_TOP_OF_PAGE' ,

c_end_of_list(11) TYPE c VALUE 'END_OF_LIST' ,

c_alv_end_of_list(15) TYPE c VALUE 'ALV_END_OF_LIST' .

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

************************INITIALIZATION********************************

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

INITIALIZATION.

  • Initialize MTART at the selection screen

PERFORM initialize_mtart.

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

*********************SELECTION SCREEN*********************************

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

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

DATA p_mtart TYPE mara-mtart.

SELECT-OPTIONS: imtart FOR p_mtart.

SELECTION-SCREEN END OF BLOCK blk1.

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

*********************AT SELECTION SCREEN******************************

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

AT SELECTION-SCREEN.

  • Validate MTART entered at the selection screen.

PERFORM validate_mtart.

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

**********************START-OF-SELECTION******************************

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

START-OF-SELECTION.

  • Select all the required data

PERFORM select_data.

  • Prepare final table

PERFORM populate_final_tab.

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

**********************END-OF-SELECTION********************************

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

END-OF-SELECTION.

  • Prepare ALV settings for display

PERFORM prepare_settings.

  • Display ALV Report

PERFORM display_report.

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

**********************SUBROUTINES*************************************

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

&----


*& Form initialize_mtart

&----


  • Subroutine to Initialize MTART at the selection screen.

----


FORM initialize_mtart .

p_mtart = c_zrh.

ENDFORM. " initialize_mtart

&----


*& Form validate_mtart

&----


  • This subroutine is to validate MTART entered at the

  • selection screen.

----


FORM validate_mtart .

SELECT SINGLE mtart

FROM t134

INTO v_mtart

WHERE mtart IN imtart.

  • If not found display error message

IF sy-subrc <> 0.

  • MESSAGE e014 WITH text-002.

ENDIF.

ENDFORM. " validate_mtart

&----


*& Form select_data

&----


  • This subroutine selects all the required data

----


FORM select_data .

SELECT matnr

mtart

FROM mara

INTO TABLE it_mara

WHERE mtart IN imtart.

IF sy-subrc <> 0.

  • MESSAGE i014 WITH text-003.

LEAVE LIST-PROCESSING.

ELSE.

SORT it_mara BY matnr.

SELECT matnr

maktx

FROM makt

INTO TABLE it_makt UP TO 20 ROWS

FOR ALL ENTRIES IN it_mara

WHERE matnr = it_mara-matnr

AND spras = sy-langu .

IF sy-subrc <> 0.

  • MESSAGE i014 WITH text-004.

LEAVE LIST-PROCESSING.

ELSE.

SORT it_mara BY mtart.

SORT it_makt BY matnr.

ENDIF.

ENDIF.

ENDFORM. " select_data

&----


*& Form populate_final_tab

&----


  • This subroutine prepares final internal table.

----


FORM populate_final_tab .

LOOP AT it_mara INTO wa_mara.

CLEAR wa_final.

CLEAR wa_makt.

READ TABLE it_makt INTO wa_makt

WITH KEY matnr = wa_mara-matnr

BINARY SEARCH.

IF sy-subrc = 0.

wa_final-mtart = wa_mara-mtart.

wa_final-matnr = wa_mara-matnr.

wa_final-maktx = wa_makt-maktx.

APPEND wa_final TO it_final.

ENDIF.

ENDLOOP.

  • DATA : v_lines TYPE i.

  • DESCRIBE TABLE it_final LINES v_lines.

**WRITE:/ 'Total lines = ', v_lines.

*

  • wa_records-records = v_lines.

LOOP AT it_final INTO wa_final.

no = no + 1.

ENDLOOP.

wa_records-records = no.

APPEND wa_records TO it_records.

ENDFORM. " populate_final_tab

&----


*& Form prepare_settings

&----


  • This subroutine prepares ALV settings for display

----


FORM prepare_settings .

  • Prepare layout

CLEAR wa_layout.

wa_layout-zebra = c_x.

  • Prepare fieldcat

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = c_02.

wa_fieldcat-fieldname = c_mtart.

wa_fieldcat-tabname = c_it_final.

wa_fieldcat-ref_fieldname = c_mtart.

wa_fieldcat-ref_tabname = c_mara.

wa_fieldcat-ddictxt = c_l.

wa_fieldcat-seltext_l = text-005.

wa_fieldcat-seltext_m = text-005.

wa_fieldcat-seltext_s = text-005.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = c_04.

wa_fieldcat-fieldname = c_matnr.

wa_fieldcat-tabname = c_it_final.

wa_fieldcat-ref_fieldname = c_matnr.

wa_fieldcat-ref_tabname = c_mara.

wa_fieldcat-ddictxt = c_l.

wa_fieldcat-seltext_l = text-006.

wa_fieldcat-seltext_m = text-006.

wa_fieldcat-seltext_s = text-006.

wa_fieldcat-hotspot = c_x.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = c_06.

wa_fieldcat-fieldname = c_maktx.

wa_fieldcat-tabname = c_it_final.

wa_fieldcat-ref_fieldname = c_maktx.

wa_fieldcat-ref_tabname = c_makt.

wa_fieldcat-ddictxt = c_l.

wa_fieldcat-seltext_l = text-007.

wa_fieldcat-seltext_m = text-007.

wa_fieldcat-seltext_s = text-007.

APPEND wa_fieldcat TO it_fieldcat.

  • records field cat

wa_fieldcat1-col_pos = c_04.

wa_fieldcat1-fieldname = 'RECORDS'.

wa_fieldcat1-tabname = 'RECORDS'.

wa_fieldcat1-seltext_m = 'NO OF RECORDS MATERIAL WISE TYPE LIST'.

APPEND wa_fieldcat1 TO it_fieldcat1.

  • Prepare Events table.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events

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.

SORT it_events BY name.

CLEAR wa_events.

READ TABLE it_events INTO wa_events

WITH KEY name = c_user_command

BINARY SEARCH.

IF sy-subrc = 0.

wa_events-form = c_alv_user_command.

MODIFY it_events

FROM wa_events

INDEX sy-tabix

TRANSPORTING form.

ENDIF.

CLEAR wa_events.

READ TABLE it_events INTO wa_events

WITH KEY name = c_top_of_page

BINARY SEARCH.

IF sy-subrc = 0.

wa_events-form = c_alv_top_of_page.

MODIFY it_events

FROM wa_events

INDEX sy-tabix

TRANSPORTING form.

ENDIF.

CLEAR wa_events.

READ TABLE it_events INTO wa_events

WITH KEY name = c_end_of_list

BINARY SEARCH.

IF sy-subrc = 0.

wa_events-form = c_alv_end_of_list.

MODIFY it_events

FROM wa_events

INDEX sy-tabix

TRANSPORTING form.

ENDIF.

ENDFORM. " prepare_settings

&----


*& Form display_report

&----


  • This subroutine calls FM to display report

----


FORM display_report .

CLEAR v_repid.

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • IT_EXCLUDING =

.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

is_layout = wa_layout

it_fieldcat = it_fieldcat

i_tabname = 'it_FINAL'

it_events = it_events

  • IT_SORT =

  • I_TEXT = ' '

TABLES

t_outtab = it_final

  • 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 = 'TY_FINAL'

it_events = it_events

  • IT_SORT =

  • I_TEXT = ' '

TABLES

t_outtab = it_records

  • 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 = it_final

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

&----


*& Form alv_user_command

&----


  • This subroutine handles user command

----


FORM alv_user_command USING v_cmd TYPE sy-ucomm

wa_selfield TYPE slis_selfield. "#EC * "#EC

CLEAR wa_final.

READ TABLE it_final INTO wa_final

INDEX wa_selfield-tabindex.

CLEAR v_text.

CONCATENATE text-008

wa_final-matnr

INTO v_text

SEPARATED BY space.

  • Display to user which material he/she has clicked

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

titel = text-009

textline1 = v_text

start_column = 25

start_row = 6.

ENDFORM. "alv_user_command.

&----


*& Form alv_top_of_page

&----


  • This subroutine writes top of page

----


FORM alv_top_of_page. "#EC CALLED

FORMAT COLOR COL_HEADING.

ULINE AT /1(80).

WRITE:/1 sy-vline,

2 text-010,

9 sy-datum,

80 sy-vline.

WRITE:/1 sy-vline,

2 text-011,

9 sy-uzeit,

40 text-012,

80 sy-vline.

WRITE:/1 sy-vline,

2 text-013,

9 sy-uname,

80 sy-vline.

ULINE AT /1(80).

FORMAT COLOR OFF.

ENDFORM. "alv_top_of_page.

&----


*& Form alv_end_of_list

&----


  • This subroutine writes end of list

----


FORM alv_end_of_list. "#EC CALLED

FORMAT COLOR COL_HEADING.

ULINE AT /1(80).

WRITE:/1 sy-vline,

2 text-014,

12 no,

80 sy-vline.

ULINE AT /1(80).

FORMAT COLOR OFF.

ENDFORM. "alv_end_of_list.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
216

hi,

can u explain what u exactly want?

and i answered ur earlier question so if it got solved than please reward points and close that question.

Message was edited by:

Dhwani shah

6 REPLIES 6

Former Member
0 Kudos
217

hi,

can u explain what u exactly want?

and i answered ur earlier question so if it got solved than please reward points and close that question.

Message was edited by:

Dhwani shah

MohitSingh
Product and Topic Expert
Product and Topic Expert
0 Kudos
216

Hi dhwani,

In first alv block iam material type material no and material decsription .so in second alv block if i want to display the no of each material type such as if on selection screen iam choosing range from coup to dien than the second block should display no of records of type and of type dien.

I hope you be getting what iam trying to explain.

0 Kudos
216

ok

so if i have given range of material type in which only two type of material coming than u want to display total number of materials of tha two type?

means like,

FERT 5

FHMI 1

like this?

MohitSingh
Product and Topic Expert
Product and Topic Expert
0 Kudos
216

Hi dhwani,

yes what u r saying thats what i want.

0 Kudos
216

hi,

here it is.

&----


*& Report ZTEST_DS

*&

&----


*&

*&

&----


REPORT ztest_ds.

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_mara ,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

END OF ty_mara ,

BEGIN OF ty_makt ,

matnr TYPE makt-matnr,

maktx TYPE makt-maktx,

END OF ty_makt ,

BEGIN OF ty_final ,

mtart TYPE mara-mtart,

matnr TYPE mara-matnr,

maktx TYPE makt-maktx,

record TYPE i ,

END OF ty_final ,

BEGIN OF records,

records TYPE i,

END OF records.

DATA no TYPE i.

*************************INTERNAL TABLES******************************

DATA : it_mara TYPE TABLE OF ty_mara ,

it_makt TYPE TABLE OF ty_makt ,

it_final TYPE TABLE OF ty_final ,

it_fieldcat TYPE slis_t_fieldcat_alv,

it_events TYPE slis_t_event ,

it_fieldcat1 TYPE slis_t_fieldcat_alv,

it_records TYPE TABLE OF records WITH HEADER LINE.

*************************WORK AREAS***********************************

DATA : wa_mara TYPE ty_mara ,

wa_makt TYPE ty_makt ,

wa_final TYPE ty_final ,

wa_fieldcat TYPE slis_fieldcat_alv,

wa_layout TYPE slis_layout_alv ,

wa_events TYPE slis_alv_event ,

wa_fieldcat1 TYPE slis_fieldcat_alv,

wa_records TYPE records.

**************************VARIABLES***********************************

DATA : v_mtart TYPE mara-mtart, "#EC NEEDED

v_repid TYPE sy-repid ,

v_text TYPE string .

<b>DATA : BEGIN OF i_rec OCCURS 0,

mtart TYPE mara-mtart,

record TYPE i,

END OF i_rec.

DATA : BEGIN OF i_rec_col OCCURS 0,

mtart TYPE mara-mtart,

record TYPE i,

END OF i_rec_col.</b>

**************************CONSTANTS***********************************

CONSTANTS : c_zrh(4) TYPE c VALUE 'zrh' ,

c_x(1) TYPE c VALUE 'X' ,

c_02(2) TYPE c VALUE '02' ,

c_04(2) TYPE c VALUE '04' ,

c_06(2) TYPE c VALUE '06' ,

c_mtart(5) TYPE c VALUE 'MTART' ,

c_matnr(5) TYPE c VALUE 'MATNR' ,

c_maktx(5) TYPE c VALUE 'MAKTX' ,

c_it_final(8) TYPE c VALUE 'IT_FINAL' ,

c_mara(4) TYPE c VALUE 'MARA' ,

c_makt(4) TYPE c VALUE 'MAKT' ,

c_l(1) TYPE c VALUE 'L' ,

c_user_command(12) TYPE c VALUE 'USER_COMMAND' ,

c_alv_user_command(16) TYPE c VALUE 'ALV_USER_COMMAND',

c_top_of_page(11) TYPE c VALUE 'TOP_OF_PAGE' ,

c_alv_top_of_page(15) TYPE c VALUE 'ALV_TOP_OF_PAGE' ,

c_end_of_list(11) TYPE c VALUE 'END_OF_LIST' ,

c_alv_end_of_list(15) TYPE c VALUE 'ALV_END_OF_LIST' .

************************INITIALIZATION********************************

INITIALIZATION.

  • Initialize MTART at the selection screen

PERFORM initialize_mtart.

*********************SELECTION SCREEN*********************************

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

DATA p_mtart TYPE mara-mtart.

SELECT-OPTIONS: imtart FOR p_mtart.

SELECTION-SCREEN END OF BLOCK blk1.

*********************AT SELECTION SCREEN******************************

AT SELECTION-SCREEN.

  • Validate MTART entered at the selection screen.

PERFORM validate_mtart.

**********************START-OF-SELECTION******************************

START-OF-SELECTION.

  • Select all the required data

PERFORM select_data.

  • Prepare final table

PERFORM populate_final_tab.

**********************END-OF-SELECTION********************************

END-OF-SELECTION.

  • Prepare ALV settings for display

PERFORM prepare_settings.

  • Display ALV Report

PERFORM display_report.

**********************SUBROUTINES*************************************

&----


*& Form initialize_mtart

&----


  • Subroutine to Initialize MTART at the selection screen.

----


FORM initialize_mtart .

p_mtart = c_zrh.

ENDFORM. " initialize_mtart

&----


*& Form validate_mtart

&----


  • This subroutine is to validate MTART entered at the

  • selection screen.

----


FORM validate_mtart .

SELECT SINGLE mtart

FROM t134

INTO v_mtart

WHERE mtart = p_mtart.

  • If not found display error message

IF sy-subrc <> 0.

  • MESSAGE e014 WITH text-002.

ENDIF.

ENDFORM. " validate_mtart

&----


*& Form select_data

&----


  • This subroutine selects all the required data

----


FORM select_data .

SELECT matnr

mtart

FROM mara

INTO TABLE it_mara

WHERE mtart IN imtart.

IF sy-subrc <> 0.

  • MESSAGE i014 WITH text-003.

LEAVE LIST-PROCESSING.

ELSE.

SORT it_mara BY matnr.

SELECT matnr

maktx

FROM makt

INTO TABLE it_makt UP TO 20 ROWS

FOR ALL ENTRIES IN it_mara

WHERE matnr = it_mara-matnr

AND spras = sy-langu .

IF sy-subrc <> 0.

  • MESSAGE i014 WITH text-004.

LEAVE LIST-PROCESSING.

ELSE.

SORT it_mara BY mtart.

SORT it_makt BY matnr.

ENDIF.

ENDIF.

ENDFORM. " select_data

&----


*& Form populate_final_tab

&----


  • This subroutine prepares final internal table.

----


FORM populate_final_tab .

LOOP AT it_mara INTO wa_mara.

CLEAR wa_final.

CLEAR wa_makt.

READ TABLE it_makt INTO wa_makt

WITH KEY matnr = wa_mara-matnr

BINARY SEARCH.

IF sy-subrc = 0.

wa_final-mtart = wa_mara-mtart.

wa_final-matnr = wa_mara-matnr.

wa_final-maktx = wa_makt-maktx.

APPEND wa_final TO it_final.

ENDIF.

ENDLOOP.

LOOP AT it_final INTO wa_final.

no = no + 1.

ENDLOOP.

  • wa_records-records = no.

  • it_records-records = no.

  • APPEND it_records.

<b> LOOP AT it_final INTO wa_final.

i_rec-mtart = wa_final-mtart.

i_rec-record = 1.

APPEND i_rec.

ENDLOOP.

LOOP AT i_rec.

MOVE-CORRESPONDING i_rec TO i_rec_col.

COLLECT i_rec_col.

ENDLOOP.</b>

ENDFORM. " populate_final_tab

&----


*& Form prepare_settings

&----


  • This subroutine prepares ALV settings for display

----


FORM prepare_settings .

  • Prepare layout

CLEAR wa_layout.

wa_layout-zebra = c_x.

  • Prepare fieldcat

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = c_02.

wa_fieldcat-fieldname = c_mtart.

wa_fieldcat-tabname = c_it_final.

wa_fieldcat-ref_fieldname = c_mtart.

wa_fieldcat-ref_tabname = c_mara.

wa_fieldcat-ddictxt = c_l.

wa_fieldcat-seltext_l = text-005.

wa_fieldcat-seltext_m = text-005.

wa_fieldcat-seltext_s = text-005.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = c_04.

wa_fieldcat-fieldname = c_matnr.

wa_fieldcat-tabname = c_it_final.

wa_fieldcat-ref_fieldname = c_matnr.

wa_fieldcat-ref_tabname = c_mara.

wa_fieldcat-ddictxt = c_l.

wa_fieldcat-seltext_l = text-006.

wa_fieldcat-seltext_m = text-006.

wa_fieldcat-seltext_s = text-006.

wa_fieldcat-hotspot = c_x.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = c_06.

wa_fieldcat-fieldname = c_maktx.

wa_fieldcat-tabname = c_it_final.

wa_fieldcat-ref_fieldname = c_maktx.

wa_fieldcat-ref_tabname = c_makt.

wa_fieldcat-ddictxt = c_l.

wa_fieldcat-seltext_l = text-007.

wa_fieldcat-seltext_m = text-007.

wa_fieldcat-seltext_s = text-007.

APPEND wa_fieldcat TO it_fieldcat.

<b>wa_fieldcat1-col_pos = c_04.

wa_fieldcat1-fieldname = 'MTART'.

wa_fieldcat1-tabname = 'I_REC_COL'.

wa_fieldcat1-seltext_m = 'Material Type'.

APPEND wa_fieldcat1 TO it_fieldcat1.

  • records field cat

wa_fieldcat1-col_pos = c_04.

wa_fieldcat1-fieldname = 'RECORD'.

wa_fieldcat1-tabname = 'I_REC_COL'.

wa_fieldcat1-seltext_m = 'NO OF RECORDS MATERIAL WISE TYPE LIST'.

APPEND wa_fieldcat1 TO it_fieldcat1.</b>*

Prepare Events table.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events

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.

SORT it_events BY name.

CLEAR wa_events.

READ TABLE it_events INTO wa_events

WITH KEY name = c_user_command

BINARY SEARCH.

IF sy-subrc = 0.

wa_events-form = c_alv_user_command.

MODIFY it_events

FROM wa_events

INDEX sy-tabix

TRANSPORTING form.

ENDIF.

CLEAR wa_events.

READ TABLE it_events INTO wa_events

WITH KEY name = c_top_of_page

BINARY SEARCH.

IF sy-subrc = 0.

wa_events-form = c_alv_top_of_page.

MODIFY it_events

FROM wa_events

INDEX sy-tabix

TRANSPORTING form.

ENDIF.

CLEAR wa_events.

READ TABLE it_events INTO wa_events

WITH KEY name = c_end_of_list

BINARY SEARCH.

IF sy-subrc = 0.

wa_events-form = c_alv_end_of_list.

MODIFY it_events

FROM wa_events

INDEX sy-tabix

TRANSPORTING form.

ENDIF.

ENDFORM. " prepare_settings

&----


*& Form display_report

&----


  • This subroutine calls FM to display report

----


FORM display_report .

CLEAR v_repid.

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • IT_EXCLUDING =

.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

is_layout = wa_layout

it_fieldcat = it_fieldcat

i_tabname = 'it_FINAL'

it_events = it_events

  • IT_SORT =

  • I_TEXT = ' '

TABLES

t_outtab = it_final

  • 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 = 'TY_FINAL'

it_events = it_events

  • IT_SORT =

  • I_TEXT = ' '

TABLES

<b> t_outtab = i_rec_col</b>

  • 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 = it_final

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

&----


*& Form alv_user_command

&----


  • This subroutine handles user command

----


FORM alv_user_command USING v_cmd TYPE sy-ucomm

wa_selfield TYPE slis_selfield. "#EC * "#EC

CLEAR wa_final.

READ TABLE it_final INTO wa_final

INDEX wa_selfield-tabindex.

CLEAR v_text.

CONCATENATE text-008

wa_final-matnr

INTO v_text

SEPARATED BY space.

  • Display to user which material he/she has clicked

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

titel = text-009

textline1 = v_text

start_column = 25

start_row = 6.

ENDFORM. "alv_user_command.

&----


*& Form alv_top_of_page

&----


  • This subroutine writes top of page

----


FORM alv_top_of_page. "#EC CALLED

FORMAT COLOR COL_HEADING.

ULINE AT /1(80).

WRITE:/1 sy-vline,

2 text-010,

9 sy-datum,

80 sy-vline.

WRITE:/1 sy-vline,

2 text-011,

9 sy-uzeit,

40 text-012,

80 sy-vline.

WRITE:/1 sy-vline,

2 text-013,

9 sy-uname,

80 sy-vline.

ULINE AT /1(80).

FORMAT COLOR OFF.

ENDFORM. "alv_top_of_page.

it will solve ur problem.

reward if useful.

Former Member
0 Kudos
216

HI

<b> 2 lists in ALV</b>

REUSE_ALV_BLOCK_LIST_APPEND

REUSE_ALV_BLOCK_LIST_DATA_GET

REUSE_ALV_BLOCK_LIST_DATA_SET

REUSE_ALV_BLOCK_LIST_DISPLAY

REUSE_ALV_BLOCK_LIST_HS_APPEND

REUSE_ALV_BLOCK_LIST_INIT

REUSE_ALV_BLOCK_LIST_REFRESH

REUSE_ALV_BLOCK_STATUS_GET

Check this sample one

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
* I_CALLBACK_PF_STATUS_SET = 'STAN'
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
.
G_LAYOUT-NO_INPUT = 'X'.
G_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
G_LAYOUT-TOTALS_TEXT = 'TOTALS'(255).
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = G_LAYOUT
IT_FIELDCAT = FIELDCAT[]
I_TABNAME = 'I_VBAP1'
IT_EVENTS = G_EVENTS
* IT_SORT I_TEXT = text-001
TABLES
T_OUTTAB = I_VBAP1[]
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.

LOOP AT I_VBAP1.
IF SY-TABIX = 1.
MOVE-CORRESPONDING I_VBAP1 TO I_VBAP2.
APPEND I_VBAP2.
I_VBELN = I_VBAP1-VBELN.
ELSEIF I_VBAP1-VBELN = I_VBELN.
MOVE-CORRESPONDING I_VBAP1 TO I_VBAP2.
APPEND I_VBAP2.
I_VBELN = I_VBAP1-VBELN.
ENDIF.

on change of i_vbap1-vbeln.
IF SY-TABIX > 1.

i_vbap3[] = i_vbap2[].
I_vbeln = i_vbap1-vbeln.
endif.
ENDon.
if not i_vbap3[] is initial.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = G_LAYOUT
IT_FIELDCAT = FIELDCAT[]
I_TABNAME = 'I_VBAP2'
IT_EVENTS = G_EVENTS
* IT_SORT I_TEXT = text-001
TABLES
T_OUTTAB = I_VBAP2[]
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
GT_PRINT-RESERVE_LINES = 2.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
IS_PRINT = gt_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.
clear i_vbap3.
refresh i_vbap3.
REFRESH I_VBAP2.
clear i_vbap2.
MOVE-CORRESPONDING I_VBAP1 TO I_VBAP2.
APPEND I_VBAP2.

endif.
ENDLOOP.
GT_PRINT-RESERVE_LINES = 2.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
IS_PRINT = gt_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.

Regards

Pavan