ABAP ALV Programming
ABAP ALV Programming
ABAP ALV Programming
*&---------------------------------------------------------------------*
*& Report ZTEST_ALV_LIST_DISPLAY
*&---------------------------------------------------------------------*
*& DEVELOPER : DEBESH
*& DATE
: 29TH JANUARY
*&---------------------------------------------------------------------*
*& EXAMPLE ON ALV LIST DISPLAY
*&---------------------------------------------------------------------*
REPORT ztest_alv_list_display.
Page 1
By Debesh
Page 2
Form SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM sub_collect_data .
SELECT ebelp
matnr
bukrs
werks
lgort
bednr
menge
netpr
netwr
brtwr
By Debesh
Page 3
" SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_CATLOG
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM sub_create_catlog .
= 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
=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'.
ENDFORM.
" SUB_CREATE_CATLOG
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_LIST
*&---------------------------------------------------------------------*
*
DISPLAY LIST
*----------------------------------------------------------------------*
By Debesh
Page 5
=''
* 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
=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
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
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
" 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
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
= 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
*&---------------------------------------------------------------------*
*& 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.
Page 13
By Debesh
Page 14
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
PBO routine
*----------------------------------------------------------------------*
module status_9000 output.
set pf-status 'ZSTAT'.
set titlebar 'ALV USING OOP'.
By Debesh
Page 15
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
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
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
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
*
* ENDIF.
endform.
" SUB_CREATE_CONTAINER
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_GRID
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form sub_create_grid .
create object lo_grid
exporting
* i_shellstyle
=0
* i_lifetime
By Debesh
Page 18
= 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
*&---------------------------------------------------------------------*
*
By Debesh
Page 19
*----------------------------------------------------------------------*
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
** 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
*
* ENDIF.
By Debesh
Page 21
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
" SUB_COLLECT_DATA
*&---------------------------------------------------------------------*
*&
Form SUB_SET_GRID
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
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
= 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
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
User Interaction
*----------------------------------------------------------------------*
module user_command_9000 input.
data lv_ucomm type sy-ucomm.
lv_ucomm = sy-ucomm.
By Debesh
Page 24
endmodule.
*&---------------------------------------------------------------------*
*&
Form SUB_FREE_OBJECTS
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
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
=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