ALV Grid Display With Checkbox To Process Selected Records at Runtime
ALV Grid Display With Checkbox To Process Selected Records at Runtime
ALV Grid Display With Checkbox To Process Selected Records at Runtime
hfgjkljullo
Ghfigji[pk][\g\
Hghjg
Ghdjgh
Rhgiwjg
: Tarun Gambhir
*&
*&
timely completions.
*&---------------------------------------------------------------------*
*& Display records in first screen in ALV Grid Display with checkboxes
*& appended with each record and perform an user action to display the
*& selected records into another ALV Gird
*& or user can use their own code as per their requirements
*&---------------------------------------------------------------------*
REPORT zpm_wo NO STANDARD PAGE HEADING MESSAGE-ID zmsg_wo.
*&---------------------------------------------------------------------*
*
TYPE POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS : slis. " used for ALV output
*&---------------------------------------------------------------------*
*
TYPE DECLARATION
*&---------------------------------------------------------------------*
TYPES :
* for table aufk (work order details)
BEGIN OF t_aufk,
aufnr TYPE aufk-aufnr, " order number
CONTANTS DECLARATION
*&---------------------------------------------------------------------*
CONSTANTS : c_check(1) VALUE 'X',
c_langu(1) VALUE 'E',
RANGES DECLARATION
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
RANGES : r_auart FOR aufk-auart. "for order type
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_var TYPE disvariant-variant. " variant parameter
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*
VARIABLE DECLARATIONS
*&---------------------------------------------------------------------*
DATA : v_rep_id TYPE sy-repid, " report id
v_istat TYPE tj02t-istat, " order status
v_cdate TYPE sy-datum,
v_line_count TYPE i,
*&---------------------------------------------------------------------*
* TYPE OF T_AUFK
* internal table to select records for damaged order types
DATA : it_aufk TYPE STANDARD TABLE OF t_aufk,
* work area for damaged order types
wa_aufk TYPE t_aufk.
* TYPE OF T_JEST
* internal table to select object number based upon user status
DATA : it_jest TYPE STANDARD TABLE OF t_jest,
* work area to select object number based upon user status
wa_jest TYPE t_jest.
* TYPE OF T_AFKO
* internal table to select the basic finish date corresopnding to work order
DATA : it_afko TYPE STANDARD TABLE OF t_afko,
* work area to select the basic finish date corresopnding to work order
wa_afko TYPE t_afko.
* TYPE OF T_QMEL
* internal table to select the notification number corresopnding to object number
DATA : it_qmel TYPE STANDARD TABLE OF t_qmel,
* work area to select the notification number corresopnding to object number
wa_qmel TYPE t_qmel.
* TYPE OF T_FINAL
* final internal table to select final records to be displayed
DATA : it_final TYPE STANDARD TABLE OF t_final,
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field TYPE slis_fieldcat_alv. "work area for field catalog
* SORTING INFO
DATA : it_sort TYPE slis_t_sortinfo_alv, "internal table for sorting field
wa_sort TYPE slis_sortinfo_alv. "work area for sorting field
* FOR LAYOUT OF ALV GRID
DATA : wa_layout TYPE slis_layout_alv. "work area for layout design
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field1 TYPE slis_t_fieldcat_alv, "internal table for field catalog
wa_field1 TYPE slis_fieldcat_alv. "work area for field catalog
* SORTING INFO
DATA : it_sort1 TYPE slis_t_sortinfo_alv, "internal table for sorting field
wa_sort1 TYPE slis_sortinfo_alv. "work area for sorting field
* FOR LAYOUT OF ALV GRID
DATA : wa_layout1 TYPE slis_layout_alv. "work area for layout design
*&---------------------------------------------------------------------*
*
INITIALIZATION
*&---------------------------------------------------------------------*
*
IN THE PROGRAM
*&---------------------------------------------------------------------*
INITIALIZATION.
v_rep_id = sy-repid.
r_auart-sign = 'I'.
r_auart-option = 'BT'.
r_auart-low = 'PM01'.
" report id
" for inclusive
" for between operator
" order type(low value)
r_auart-high = 'PM02'.
APPEND r_auart.
v_cdate = sy-datum - 7.
AT SELECTION-SCREEN OUTPUT
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
CLEAR p_var. "clear variant value
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
PERFORM f4_variant_help USING p_var.
*&---------------------------------------------------------------------*
*
AT-SELECTION SCREEN
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
IF p_var EQ ' '.
PERFORM get_default_variant USING p_var.
*&---------------------------------------------------------------------*
*
VARIANTS
*&---------------------------------------------------------------------*
ELSE.
PERFORM check_variant_existence USING p_var.
ENDIF.
*&---------------------------------------------------------------------*
*
START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
REFRESH it_jest.
REFRESH it_aufk.
REFRESH it_afko.
REFRESH it_qmel.
REFRESH it_final.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
SELECT SINGLE
istat
FROM tj02t
INTO (v_istat)
WHERE
txt04 EQ c_ustat AND
spras EQ c_langu.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
SELECT
objnr
FROM jest
INTO TABLE it_jest
WHERE
stat EQ v_istat.
IF sy-subrc <> 0.
MESSAGE e003.
ELSE.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
SELECT
aufnr
ktext
objnr
FROM aufk
INTO TABLE it_aufk
FOR ALL ENTRIES IN it_jest
WHERE
objnr EQ it_jest-objnr AND
auart IN r_auart.
IF sy-subrc <> 0.
MESSAGE e002.
ELSE.
*&---------------------------------------------------------------------*
*
select into it_afko table: order number and basic finish date
v_cdate variable
*&---------------------------------------------------------------------*
SELECT
aufnr
gltrp
FROM afko
INTO TABLE it_afko
FOR ALL ENTRIES IN it_aufk
WHERE
aufnr EQ it_aufk-aufnr AND
gltrp LE v_cdate.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
SELECT
aufnr
qmnum
FROM qmel
INTO TABLE it_qmel
FOR ALL ENTRIES IN it_aufk
WHERE
aufnr EQ it_aufk-aufnr.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*
TABLE
*&---------------------------------------------------------------------*
* read internal table it_jest into work area wa_jest
LOOP AT it_jest INTO wa_jest.
* read it_aufk based on object number from wa_jest
READ TABLE it_aufk INTO wa_aufk WITH KEY objnr = wa_jest-objnr.
* if records found
IF sy-subrc EQ 0.
* read it_afko for order number and description based on order number
READ TABLE it_afko INTO wa_afko WITH KEY aufnr = wa_aufk-aufnr.
* if records found
IF sy-subrc EQ 0.
wa_final-aufnr = wa_afko-aufnr. "move order number to it_final
wa_final-ktext = wa_aufk-ktext. "move description to it_final
ELSE.
* if no record found then move to next loop pass
CONTINUE.
ENDIF.
ELSE.
* if no record found then move to next loop pass
CONTINUE.
ENDIF.
* read it_qmel for description based on the order number selected above
READ TABLE it_qmel INTO wa_qmel WITH KEY aufnr = wa_final-aufnr.
* if records found
IF sy-subrc EQ 0.
wa_final-qmnum = wa_qmel-qmnum. "move notification number to it_final
ENDIF.
* finally append the records into the final internal table
APPEND wa_final TO it_final. "append wa_final into it_final
CLEAR wa_final. "clear work area
CLEAR wa_aufk. "clear work area
CLEAR wa_qmel. "clear work area
ENDLOOP.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
DESCRIBE TABLE it_final
LINES v_line_count.
IF ( v_line_count EQ 0 ).
MESSAGE i002. "error message
EXIT.
ENDIF.
*&---------------------------------------------------------------------*
*
END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM field_catalog.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM sort_field.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM set_layout.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM alv_display.
*&---------------------------------------------------------------------*
*&
SUBROUTINE DEFINITIONS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FIELD_CATALOG
*&---------------------------------------------------------------------*
*
SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog .
wa_field-fieldname = 'FLAG'. " name of field from internal table
wa_field-tabname = 'IT_FINAL'. " internal table name
wa_field-outputlen = 2.
*&---------------------------------------------------------------------*
*&
Form SORT_FIELD
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM sort_field .
wa_sort-spos = 1.
*&---------------------------------------------------------------------*
*&
Form SET_LAYOUT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM set_layout .
wa_layout-zebra = c_check.
ENDFORM.
" SET_LAYOUT
*&---------------------------------------------------------------------*
*&
Form ALV_DISPLAY
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
*
I_INTERFACE_CHECK
I_BYPASSING_BUFFER
I_BUFFER_ACTIVE
=''
=''
=''
i_callback_program
= v_rep_id
i_callback_pf_status_set
= 'PF'
i_callback_user_command
I_CALLBACK_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
" report id
=''
=''
=''
=
=''
=
=
= wa_layout
it_fieldcat
= it_field
IT_EXCLUDING
IT_SPECIAL_GROUPS
it_sort
= it_sort
IT_FILTER
IS_SEL_HIDE
I_DEFAULT
i_save
= 'A'
is_variant
= wa_variant
IT_EVENTS
IT_EVENT_EXIT
IS_PRINT
IS_REPREP_ID
I_SCREEN_START_COLUMN
I_SCREEN_START_LINE
I_SCREEN_END_COLUMN
I_SCREEN_END_LINE
=0
I_HTML_HEIGHT_TOP
=0
I_HTML_HEIGHT_END
IT_ALV_GRAPHICS
IT_HYPERLINK
IT_ADD_FIELDCAT
IT_EXCEPT_QINFO
IR_SALV_FULLSCREEN_ADAPTER
=
= 'X'
" variant name
=
=
=
=
=0
=0
=0
=0
=
=
* IMPORTING
*
E_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER
TABLES
t_outtab
= it_final
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.
" ALV_DISPLAY
*&---------------------------------------------------------------------*
*&
Form pf
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
-->RT_EXTAB
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZTG_STAT'.
ENDFORM.
"pf
*&---------------------------------------------------------------------*
*&
Form USER_COMMAND
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
*
*
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.
* assign the function code to variable v_okcode
lv_okcode = sy-ucomm.
* handle the code execution based on the function code encountered
CASE lv_okcode.
* when the function code is EXECUTE then process the selected records
WHEN 'EXECUTE'.
* refresh it_process when user processes selected records
REFRESH it_process.
* to reflect the data changed into internal table
DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data.
ENDIF.
*----------------------------------------------------------------------*
* sort the internal table by flag descending so that the selected
* records are appended at the beginning of internal table
*----------------------------------------------------------------------*
SORT it_final BY flag DESCENDING.
*----------------------------------------------------------------------*
* move the selected records from final internal table into another
* internal table so that they can be processed
*----------------------------------------------------------------------*
LOOP AT it_final INTO wa_final WHERE flag = 'X'.
wa_process-aufnr = wa_final-aufnr.
wa_process-ktext = wa_final-ktext.
wa_process-qmnum = wa_final-qmnum.
APPEND wa_process TO it_process.
ENDLOOP.
"USER_COMMAND
*&---------------------------------------------------------------------*
*&
Form F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
<--P_P_VAR text
*----------------------------------------------------------------------*
FORM f4_variant_help USING p_p_var.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant
* I_TABNAME_HEADER
* I_TABNAME_ITEM
=
=
* IT_DEFAULT_FIELDCAT
i_save
= 'A'
i_display_via_grid
= 'X'
IMPORTING
* E_EXIT
es_variant
EXCEPTIONS
not_found
=1
program_error
=2
OTHERS
= 3.
IF sy-subrc = 0.
* PASS THE SELECTED VARIANT TO THE SELECTION SCREEN FIELD
p_p_var = wa_i_variant-variant.
ELSEIF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
" F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*&
Form GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM get_default_variant USING l_p_var.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save
= 'A'
CHANGING
cs_variant
EXCEPTIONS
wrong_input = 1
not_found
=2
program_error = 3
OTHERS
= 4.
" GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*&
Form CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM check_variant_existence USING l_p_var.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
wa_variant-variant = l_p_var.
*&---------------------------------------------------------------------*
*
THE PARAMETER
*&---------------------------------------------------------------------*
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save
= 'A'
CHANGING
cs_variant
EXCEPTIONS
wrong_input = 1
not_found
=2
program_error = 3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE e001.
ENDIF.
ENDFORM.
" CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
*&
Form USER_ACTION
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM user_action.
*
it_process
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM field_catalog1.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM sort_field1.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM set_layout1.
*&---------------------------------------------------------------------*
*
*&---------------------------------------------------------------------*
PERFORM alv_display1.
ENDFORM.
" F4_FILE_REQUEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog1 .
REFRESH it_field1.
CLEAR wa_field1.
wa_field1-fieldname = 'AUFNR'.
wa_field1-fieldname = 'KTEXT'.
wa_field1-fieldname = 'QMNUM'.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM sort_field1.
wa_sort1-spos = 1.
wa_sort1-fieldname = 'AUFNR'.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM set_layout1 .
wa_layout1-zebra = c_check.
ENDFORM.
" SET_LAYOUT1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM alv_display1.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
*
I_INTERFACE_CHECK
I_BYPASSING_BUFFER
I_BUFFER_ACTIVE
=''
=''
=''
i_callback_program
= v_rep_id
i_callback_pf_status_set
i_callback_user_command
I_CALLBACK_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
" report id
=''
=''
=''
=''
=''
=
=''
=
=
= wa_layout1
it_fieldcat
= it_field1
IT_EXCLUDING
IT_SPECIAL_GROUPS
it_sort
= it_sort1
IT_FILTER
IS_SEL_HIDE
I_DEFAULT
i_save
=''
is_variant
IT_EVENTS
IT_EVENT_EXIT
IS_PRINT
IS_REPREP_ID
I_SCREEN_START_COLUMN
I_SCREEN_START_LINE
I_SCREEN_END_COLUMN
I_SCREEN_END_LINE
=0
I_HTML_HEIGHT_TOP
=0
I_HTML_HEIGHT_END
IT_ALV_GRAPHICS
IT_HYPERLINK
IT_ADD_FIELDCAT
IT_EXCEPT_QINFO
IR_SALV_FULLSCREEN_ADAPTER
=
= 'X'
=
=
=
=
=0
=0
=0
=0
=
=
* IMPORTING
*
E_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER
TABLES
t_outtab
= it_process
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.
" ALV_DISPLAY1
If no records selected and user click EXECUTE button, error message 'NO RECORDS SELECTED' displayed
Else If records selected and EXECUTE button is pressed, the seleected records to be displayed in another ALV
Grid.