In the following program we have used ALV block list approach for some materials and their description.
REPORT zsr_test NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPE-POOLS: slis.
DATA: wa_fcat TYPE slis_fieldcat_alv,
it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat2 TYPE slis_fieldcat_alv,
it_fcat2 TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv,
wa_event TYPE slis_alv_event,
it_event TYPE slis_t_event.
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
END OF ty_mara.
DATA: wa_mara TYPE ty_mara,
it_mara TYPE TABLE OF ty_mara.
TYPES: BEGIN OF ty_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.
DATA: wa_makt TYPE ty_makt,
it_makt TYPE TABLE OF ty_makt.
INITIALIZATION.
PARAMETERS p_mtart TYPE mtart.
SELECT-OPTIONS s_ersda FOR sy-datum.
START-OF-SELECTION.
PERFORM get_mara.
PERFORM field_catalog.
PERFORM alv_events.
PERFORM alv_display.
*&---------------------------------------------------------------------*
*& Form GET_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_mara .
SELECT matnr ersda ernam mtart matkl
FROM mara INTO TABLE it_mara
WHERE ersda IN s_ersda
AND mtart = p_mtart.
IF sy-subrc = 0.
SELECT matnr maktx
FROM makt INTO TABLE it_makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND spras = sy-langu.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM field_catalog .
DATA lv_col TYPE i VALUE 0.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_l = 'Material'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ERSDA'.
wa_fcat-seltext_l = 'Created On'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-seltext_l = 'Created By'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MTART'.
wa_fcat-seltext_l = 'Type'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MATKL'.
wa_fcat-seltext_l = 'Group'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
CLEAR lv_col.
lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MATNR'.
wa_fcat2-seltext_l = 'Material'.
APPEND wa_fcat2 TO it_fcat2.
CLEAR wa_fcat2.
lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MAKTX'.
wa_fcat2-seltext_l = 'Material Description'.
APPEND wa_fcat2 TO it_fcat2.
CLEAR wa_fcat2.
wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_events .
wa_event-form = 'TOP'.
wa_event-name = 'TOP_OF_PAGE'.
APPEND wa_event TO it_event.
CLEAR wa_event.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-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_fcat
i_tabname = 'MARA'
it_events = it_event
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_mara
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout
it_fieldcat = it_fcat2
i_tabname = 'MAKT'
it_events = it_event
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_makt
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_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
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form TOP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top .
WRITE:/ 'Blocked ALV Report - 2 Blocks' COLOR 3.
ENDFORM.
Output is as follows.
Selection Screen
Required Output
REPORT zsr_test NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPE-POOLS: slis.
DATA: wa_fcat TYPE slis_fieldcat_alv,
it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat2 TYPE slis_fieldcat_alv,
it_fcat2 TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv,
wa_event TYPE slis_alv_event,
it_event TYPE slis_t_event.
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
END OF ty_mara.
DATA: wa_mara TYPE ty_mara,
it_mara TYPE TABLE OF ty_mara.
TYPES: BEGIN OF ty_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.
DATA: wa_makt TYPE ty_makt,
it_makt TYPE TABLE OF ty_makt.
INITIALIZATION.
PARAMETERS p_mtart TYPE mtart.
SELECT-OPTIONS s_ersda FOR sy-datum.
START-OF-SELECTION.
PERFORM get_mara.
PERFORM field_catalog.
PERFORM alv_events.
PERFORM alv_display.
*&---------------------------------------------------------------------*
*& Form GET_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_mara .
SELECT matnr ersda ernam mtart matkl
FROM mara INTO TABLE it_mara
WHERE ersda IN s_ersda
AND mtart = p_mtart.
IF sy-subrc = 0.
SELECT matnr maktx
FROM makt INTO TABLE it_makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND spras = sy-langu.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM field_catalog .
DATA lv_col TYPE i VALUE 0.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_l = 'Material'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ERSDA'.
wa_fcat-seltext_l = 'Created On'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-seltext_l = 'Created By'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MTART'.
wa_fcat-seltext_l = 'Type'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
lv_col = 1 + lv_col.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'MATKL'.
wa_fcat-seltext_l = 'Group'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
CLEAR lv_col.
lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MATNR'.
wa_fcat2-seltext_l = 'Material'.
APPEND wa_fcat2 TO it_fcat2.
CLEAR wa_fcat2.
lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MAKTX'.
wa_fcat2-seltext_l = 'Material Description'.
APPEND wa_fcat2 TO it_fcat2.
CLEAR wa_fcat2.
wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_EVENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_events .
wa_event-form = 'TOP'.
wa_event-name = 'TOP_OF_PAGE'.
APPEND wa_event TO it_event.
CLEAR wa_event.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-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_fcat
i_tabname = 'MARA'
it_events = it_event
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_mara
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout
it_fieldcat = it_fcat2
i_tabname = 'MAKT'
it_events = it_event
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_makt
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_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
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form TOP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top .
WRITE:/ 'Blocked ALV Report - 2 Blocks' COLOR 3.
ENDFORM.
Output is as follows.
Selection Screen
Required Output
1 comment:
You seem to have taken a great effort in writing such a blog. I appreciate that and we have a similar site where we train you on all the SAP course. click here to learn SAP ABAP
Post a Comment