Intrduction To ALVAbap List viewer
CODE SNIPPET FOR
ALV
By Debesh
ALV LIST Display
ALV GRID Display
ALV using OOP
Abap List viewer
1. ALV List & Grid Display (Page 1-12)
2. ALV using OOPs (Page 13-26)
ALV List & Grid Display
*&---------------------------------------------------------------------*
*& Report ZTEST_ALV_LIST_DISPLAY
*&---------------------------------------------------------------------*
*& DEVELOPER : DEBESH
*& DATE
: 29TH JANUARY
*&---------------------------------------------------------------------*
*& EXAMPLE ON ALV LIST DISPLAY
*&---------------------------------------------------------------------*
REPORT ztest_alv_list_display.
********** DATA DECLARATION *********
TYPE-POOLS: slis.
TABLES : ekko.
DATA : BEGIN OF lt_ekpo OCCURS 0,
By Debesh
Page 1
Abap List viewer
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
bukrs LIKE ekpo-bukrs,
werks LIKE ekpo-werks,
lgort LIKE ekpo-lgort,
bednr LIKE ekpo-bednr,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
netwr LIKE ekpo-netwr,
brtwr LIKE ekpo-brtwr,
ntgew LIKE ekpo-ntgew,
END OF lt_ekpo.
DATA : lt_catlog TYPE slis_t_fieldcat_alv.
DATA : lv_repid TYPE sy-repid VALUE sy-repid.
DATA : lt_events TYPE slis_t_event.
********** SELECTION SCREEN **********
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS : s_ebeln FOR ekko-ebeln NO INTERVALS NO-EXTENSION.
PARAMETERS
: r_rad1 TYPE c RADIOBUTTON GROUP rg1 ,
r_rad2 TYPE c RADIOBUTTON GROUP rg1 .
SELECTION-SCREEN END OF BLOCK b1.
********** ROUTINES DECLARATION **********
By Debesh
Page 2
Abap List viewer
PERFORM sub_collect_data.
CHECK lt_ekpo[] IS NOT INITIAL.
PERFORM sub_create_catlog.
CHECK lt_catlog IS NOT INITIAL.
PERFORM sub_get_events.
PERFORM sub_display_list.
********* LOGIC *********
*&---------------------------------------------------------------------*
*&
Form SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*
COLLECT DATA FOR DISPLAY
*----------------------------------------------------------------------*
FORM sub_collect_data .
SELECT ebelp
matnr
bukrs
werks
lgort
bednr
menge
netpr
netwr
brtwr
By Debesh
Page 3
Abap List viewer
ntgew FROM ekpo
INTO TABLE lt_ekpo
WHERE ebeln IN s_ebeln.
ENDFORM.
" SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_CATLOG
*&---------------------------------------------------------------------*
*
BUILD FIELD CATALOG
*----------------------------------------------------------------------*
FORM sub_create_catlog .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name
= lv_repid
i_internal_tabname
= 'LT_EKPO'
* I_STRUCTURE_NAME
* I_CLIENT_NEVER_DISPLAY
i_inclname
= 'X'
= lv_repid
* I_BYPASSING_BUFFER
* I_BUFFER_ACTIVE
=
=
CHANGING
ct_fieldcat
= lt_catlog
EXCEPTIONS
inconsistent_interface
By Debesh
=1
Page 4
Abap List viewer
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.
**********************How to create catalog manually ???
* fieldcatalog-fieldname = 'EBELN'.
* fieldcatalog-seltext_m = 'Purchase Order'.
* fieldcatalog-col_pos
= 0.
* fieldcatalog-outputlen = 10.
* fieldcatalog-emphasize = 'X'.
* fieldcatalog-key
= 'X'.
* append fieldcatalog to fieldcatalog.
* clear fieldcatalog.
ENDFORM.
" SUB_CREATE_CATLOG
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_LIST
*&---------------------------------------------------------------------*
*
DISPLAY LIST
*----------------------------------------------------------------------*
By Debesh
Page 5
Abap List viewer
FORM sub_display_list .
IF NOT r_rad1 IS INITIAL.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK
=''
* I_BYPASSING_BUFFER
* I_BUFFER_ACTIVE
=''
i_callback_program
= lv_repid
* I_CALLBACK_PF_STATUS_SET
=''
* I_CALLBACK_USER_COMMAND
* I_STRUCTURE_NAME
* IS_LAYOUT
it_fieldcat
=
= lt_catlog
* IT_EXCLUDING
* IT_SPECIAL_GROUPS
* IT_SORT
* IT_FILTER
* IS_SEL_HIDE
* I_DEFAULT
= 'X'
* I_SAVE
=''
* IS_VARIANT
it_events
=
= lt_events[]
* IT_EVENT_EXIT
* IS_PRINT
* IS_REPREP_ID
By Debesh
=''
=
=
=
Page 6
Abap List viewer
* I_SCREEN_START_COLUMN
=0
* I_SCREEN_START_LINE
=0
* I_SCREEN_END_COLUMN
=0
* I_SCREEN_END_LINE
=0
* IR_SALV_LIST_ADAPTER
* IT_EXCEPT_QINFO
* I_SUPPRESS_EMPTY_DATA
= ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER
* ES_EXIT_CAUSED_BY_USER
TABLES
t_outtab
= lt_ekpo
EXCEPTIONS
program_error
OTHERS
=1
=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.
ELSEIF NOT r_rad2 IS INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
*
I_INTERFACE_CHECK
I_BYPASSING_BUFFER
By Debesh
=''
=''
Page 7
Abap List viewer
*
I_BUFFER_ACTIVE
=''
i_callback_program
= lv_repid
I_CALLBACK_PF_STATUS_SET
I_CALLBACK_USER_COMMAND
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
it_fieldcat
=
=
=
= lt_catlog
IT_SPECIAL_GROUPS
IT_SORT
IT_FILTER
IS_SEL_HIDE
I_DEFAULT
= 'X'
I_SAVE
IS_VARIANT
IT_EVENT_EXIT
IS_PRINT
IS_REPREP_ID
By Debesh
=''
=''
IT_EXCLUDING
=''
it_events
=''
=
=
=''
=
= lt_events
=
=
=
Page 8
Abap List viewer
*
I_SCREEN_START_COLUMN
=0
I_SCREEN_START_LINE
I_SCREEN_END_COLUMN
I_SCREEN_END_LINE
I_HTML_HEIGHT_TOP
=0
I_HTML_HEIGHT_END
=0
IT_ALV_GRAPHICS
IT_HYPERLINK
IT_ADD_FIELDCAT
IT_EXCEPT_QINFO
IR_SALV_FULLSCREEN_ADAPTER
=0
=0
=0
=
=
* IMPORTING
*
E_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER
TABLES
t_outtab
= lt_ekpo
EXCEPTIONS
program_error
OTHERS
=1
=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.
By Debesh
Page 9
Abap List viewer
ENDIF.
ENDFORM.
" SUB_DISPLAY_LIST
*&---------------------------------------------------------------------*
*&
Form sub_get_events
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM sub_get_events .
DATA : ls_events LIKE LINE OF lt_events.
DATA : lv_index TYPE sy-tabix.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type
=0
IMPORTING
et_events
= lt_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.
ELSE.
READ TABLE lt_events INTO ls_events WITH KEY name = 'TOP_OF_PAGE'.
IF sy-subrc IS INITIAL.
By Debesh
Page 10
Abap List viewer
lv_index = sy-tabix.
ls_events-name = 'TOP_OF_PAGE'.
ls_events-form = 'TOP-OF-PAGE'.
MODIFY lt_events INDEX lv_index FROM ls_events TRANSPORTING form.
ENDIF.
ENDIF.
ENDFORM.
" sub_get_events
*&---------------------------------------------------------------------*
*&
Form top-of-page
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM top-of-page.
DATA : lt_comment TYPE slis_t_listheader,
wa_comment TYPE slis_listheader,
lv_header(100) TYPE c,
lv_lines TYPE n.
DESCRIBE TABLE lt_ekpo LINES lv_lines.
wa_comment-typ = 'H'.
wa_comment-key = ''.
CONCATENATE text-001 s_ebeln-low '=' lv_lines INTO lv_header SEPARATED
BY space.
wa_comment-info = lv_header.
By Debesh
Page 11
Abap List viewer
APPEND wa_comment TO lt_comment.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary
= lt_comment
I_LOGO
I_END_OF_LIST_GRID
I_ALV_FORM
.
ENDFORM.
"top-of-page
OUTPUT
1. List Display
2. Grid Display
By Debesh
Page 12
Abap List viewer
ALV Display using OOP concept
*&---------------------------------------------------------------------*
*& Report ZTEST_ALV_OOP
*&---------------------------------------------------------------------*
*& DEVELOPER : DEBESH
*& DATE
: 30TH JANUARY
*&---------------------------------------------------------------------*
*& EXAMPLE ON ALV USING OOPS
* Create a container - Create Grid inside container - Get catalog * Collect data - Set o/p table inside grid
*&---------------------------------------------------------------------*
REPORT ZTEST_ALV_OOP.
********** DATA DECLARATION *********
type-pools: slis.
tables : ekko.
types : begin of ty_ekpo ,
ebelp like ekpo-ebelp,
matnr like ekpo-matnr,
By Debesh
Page 13
Abap List viewer
bukrs like ekpo-bukrs,
werks like ekpo-werks,
lgort like ekpo-lgort,
bednr like ekpo-bednr,
menge like ekpo-menge,
netpr like ekpo-netpr,
netwr like ekpo-netwr,
brtwr like ekpo-brtwr,
ntgew like ekpo-ntgew,
end of ty_ekpo.
data : begin of lt_ekpo_tmp occurs 0, " For REUSE_ALV_FIELDCATALOG_MERGE
ebelp like ekpo-ebelp,
" as it does not support TYPE
matnr like ekpo-matnr,
bukrs like ekpo-bukrs,
werks like ekpo-werks,
lgort like ekpo-lgort,
bednr like ekpo-bednr,
menge like ekpo-menge,
netpr like ekpo-netpr,
netwr like ekpo-netwr,
brtwr like ekpo-brtwr,
ntgew like ekpo-ntgew,
end of lt_ekpo_tmp.
data : lt_ekpo type standard table of ty_ekpo.
data : lt_catlog type lvc_t_fcat , " For LVC_FIELDCATALOG_MERGE
By Debesh
Page 14
Abap List viewer
ls_catlog type lvc_s_fcat.
data : lt_catlog_temp type slis_t_fieldcat_alv, "For REUSE_FIELDCATALOG
ls_catlog_temp type slis_fieldcat_alv. "_MERGE
data : lv_repid type sy-repid value sy-repid.
data : lt_events type slis_t_event.
data : lo_cont1 type ref to cl_gui_docking_container, " DOCKET
lo_cont type ref to cl_gui_custom_container, " CUSTOM
lo_grid type ref to cl_gui_alv_grid.
********** SELECTION SCREEN **********
selection-screen begin of block b1 with frame.
select-options : s_ebeln for ekko-ebeln no intervals no-extension.
selection-screen end of block b1.
********** ROUTINES DECLARATION **********
start-of-selection.
call screen 9000.
*&---------------------------------------------------------------------*
*&
Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*
PBO routine
*----------------------------------------------------------------------*
module status_9000 output.
set pf-status 'ZSTAT'.
set titlebar 'ALV USING OOP'.
By Debesh
Page 15
Abap List viewer
perform sub_create_container.
perform sub_create_grid.
perform sub_collect_data.
perform sub_create_catlog.
perform sub_set_grid.
endmodule.
" STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
*
Docket/Custom container can be used
*----------------------------------------------------------------------*
form sub_create_container .
******************** For DOCKET container
create object lo_cont1
exporting
*
parent
repid
dynnr
side
extension
style
lifetime
= lifetime_default
caption
metric
=0
ratio
By Debesh
= dock_at_left
= 50
=
= '95'
Page 16
Abap List viewer
*
no_autodef_progid_dynnr
name
exceptions
cntl_error
=1
cntl_system_error
=2
create_error
=3
lifetime_error
=4
lifetime_dynpro_dynpro_link = 5
others
=6
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*************************For Custom container
* CREATE OBJECT lo_cont
* EXPORTING
** parent
*
container_name
** style
** lifetime
= 'LO_CONT'
=
= lifetime_default
** repid
** dynnr
** no_autodef_progid_dynnr
* EXCEPTIONS
By Debesh
Page 17
Abap List viewer
*
cntl_error
=1
cntl_system_error
create_error
=3
lifetime_error
=4
lifetime_dynpro_dynpro_link = 5
OTHERS
=2
=6
* 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.
" SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_GRID
*&---------------------------------------------------------------------*
*
Create a grid object
*----------------------------------------------------------------------*
form sub_create_grid .
create object lo_grid
exporting
* i_shellstyle
=0
* i_lifetime
By Debesh
Page 18
Abap List viewer
i_parent
= lo_cont1
* i_appl_events
= space
* i_parentdbg
* i_applogparent =
* i_graphicsparent =
* i_name
* i_fcat_complete = space
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others
=5
.
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.
" SUB_CREATE_GRID
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_CATLOG
*&---------------------------------------------------------------------*
*
Use REUSE_ALV_FIELDCATALOG_MERGE when an internal table or local
structure is used for data collecting table.
By Debesh
Page 19
Abap List viewer
*
Use LVC_FIELDCATALOG_MERGE when global structure is used
*----------------------------------------------------------------------*
form sub_create_catlog .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name
= lv_repid
i_internal_tabname
= 'LT_EKPO_TMP'
I_STRUCTURE_NAME
I_CLIENT_NEVER_DISPLAY
i_inclname
=
= 'X'
= lv_repid
I_BYPASSING_BUFFER
I_BUFFER_ACTIVE
=
=
changing
ct_fieldcat
= lt_catlog_temp
exceptions
inconsistent_interface
program_error
others
=1
=2
=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.
By Debesh
Page 20
Abap List viewer
loop at lt_catlog_temp into ls_catlog_temp.
move-corresponding ls_catlog_temp to ls_catlog.
append ls_catlog to lt_catlog.
clear ls_catlog.
endloop.
*****************LVC_FIELDCATALOG_MERGE is used only for DDIC structures
* CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
* EXPORTING
** I_BUFFER_ACTIVE
** I_STRUCTURE_NAME
** I_CLIENT_NEVER_DISPLAY
** I_BYPASSING_BUFFER
= 'X'
=
* i_internal_tabname
= 'LT_EKPO'
* CHANGING
*
ct_fieldcat
= lt_catlog
* EXCEPTIONS
* inconsistent_interface
* program_error
* OTHERS
*
=1
=2
=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.
By Debesh
Page 21
Abap List viewer
endform.
" SUB_CREATE_CATLOG
*&---------------------------------------------------------------------*
*&
Form SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form sub_collect_data .
select ebelp
matnr
bukrs
werks
lgort
bednr
menge
netpr
netwr
brtwr
ntgew from ekpo
into table lt_ekpo
where ebeln in s_ebeln.
if sy-subrc is initial.
lt_ekpo_tmp[] = lt_ekpo.
endif.
By Debesh
Page 22
Abap List viewer
endform.
" SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*&
Form SUB_SET_GRID
*&---------------------------------------------------------------------*
*
GRID display using SET_TABLE_FOR_FIRST_DISPLAY
*----------------------------------------------------------------------*
form sub_set_grid .
call method lo_grid->set_table_for_first_display
* EXPORTING
* i_buffer_active
* i_bypassing_buffer
* i_consistency_check
* i_structure_name
* is_variant
* i_save
=
=
* i_default
= 'X'
* is_layout
* is_print
* it_special_groups
* it_toolbar_excluding
* it_hyperlink
=
=
* it_alv_graphics
* it_except_qinfo
* ir_salv_adapter
By Debesh
Page 23
Abap List viewer
changing
it_outtab
= lt_ekpo
it_fieldcatalog
= lt_catlog
* it_sort
* it_filter
exceptions
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
others
=4
.
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.
" SUB_SET_GRID
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*
User Interaction
*----------------------------------------------------------------------*
module user_command_9000 input.
data lv_ucomm type sy-ucomm.
lv_ucomm = sy-ucomm.
By Debesh
Page 24
Abap List viewer
case lv_ucomm.
when 'EXIT'.
perform sub_free_objects.
leave program.
when 'BACK'.
perform sub_free_objects.
set screen '0'.
leave screen.
endcase.
endmodule.
" USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*&
Form SUB_FREE_OBJECTS
*&---------------------------------------------------------------------*
*
Free grid and container respectively
*----------------------------------------------------------------------*
form sub_free_objects .
call method lo_grid->free
exceptions
cntl_error
=1
cntl_system_error = 2
others
= 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
By Debesh
Page 25
Abap List viewer
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
call method lo_cont1->free
exceptions
cntl_error
=1
cntl_system_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.
endform.
" SUB_FREE_OBJECTS
Output
By Debesh
Page 26