REPORT z_alv_cdhdr_cdpos.
*---------------------------------------------------------------------
*This ALV report displays tables CDHDR and CDPOS *
*---------------------------------------------------------------------
TYPE-POOLS slis. " Global ALV types
*---------------------------------------------------------------------
* constants
*---------------------------------------------------------------------
CONSTANTS : c_x VALUE 'X',
c_eb9 TYPE syucomm VALUE '&EB9',
c_refresh TYPE syucomm VALUE '&REFRESH'.
*---------------------------------------------------------------------
* types
*---------------------------------------------------------------------
TYPES :BEGIN OF ty_s_cdhdr.
INCLUDE TYPE cdhdr.
TYPES :checkbox TYPE xfeld,
END OF ty_s_cdhdr,
BEGIN OF ty_s_cdpos.
INCLUDE TYPE cdpos.
TYPES : checkbox TYPE xfeld,
END OF ty_s_cdpos.
*---------------------------------------------------------------------
* internal tables
*---------------------------------------------------------------------
DATA : gs_cdhdr TYPE cdhdr, " Change document header
* Layout for ALV
gs_layout TYPE slis_layout_alv,
* Change document header
t_cdhdr TYPE TABLE OF ty_s_cdhdr.
*---------------------------------------------------------------------
* selection screen design
*---------------------------------------------------------------------
SELECT-OPTIONS : s_objcls FOR gs_cdhdr-objectclas OBLIGATORY,
s_objtid FOR gs_cdhdr-objectid,
s_chngnr FOR gs_cdhdr-changenr,
s_usrnam FOR gs_cdhdr-username DEFAULT sy-uname,
s_udate FOR gs_cdhdr-udate DEFAULT sy-datum,
s_time FOR gs_cdhdr-utime,
s_tcode FOR gs_cdhdr-tcode,
s_plncnr FOR gs_cdhdr-planchngnr,
s_chngno FOR gs_cdhdr-act_chngno,
s_wsplnd FOR gs_cdhdr-was_plannd,
s_chngid FOR gs_cdhdr-change_ind.
SELECTION-SCREEN SKIP.
PARAMETERS p_max TYPE numc3 OBLIGATORY DEFAULT '200'.
*---------------------------------------------------------------------
* start-of-selection .
*---------------------------------------------------------------------
START-OF-SELECTION.
PERFORM f_read_data.
*---------------------------------------------------------------------
* end-of-selection .
*---------------------------------------------------------------------
END-OF-SELECTION.
PERFORM f_display_cdhdr.
*---------------------------------------------------------------------
*Form f_read_data
*---------------------------------------------------------------------
FORM f_read_data.
*Read Change document header
SELECT * INTO TABLE t_cdhdr
UP TO p_max ROWS
FROM cdhdr
WHERE objectclas IN s_objcls
AND objectid IN s_objtid
AND changenr IN s_chngnr
AND username IN s_usrnam
AND udate IN s_udate
AND utime IN s_time
AND tcode IN s_tcode
AND planchngnr IN s_plncnr
AND act_chngno IN s_chngno
AND was_plannd IN s_wsplnd
AND change_ind IN s_chngid.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------
*
*Form f_display_cdhdr
*---------------------------------------------------------------------
FORM f_display_cdhdr.
DATA :ls_event_exit TYPE slis_event_exit,
lt_event_exit TYPE slis_t_event_exit.
gs_layout-zebra = c_x.
gs_layout-colwidth_optimize = c_x.
gs_layout-group_change_edit = c_x.
gs_layout-allow_switch_to_list = c_x.
gs_layout-box_fieldname = 'CHECKBOX'.
*Activate 'More' button
CLEAR ls_event_exit.
ls_event_exit-after = c_x.
ls_event_exit-ucomm = c_eb9. " More
APPEND ls_event_exit TO lt_event_exit.
*Activate refresh button
CLEAR ls_event_exit.
ls_event_exit-after = c_x.
ls_event_exit-ucomm = c_refresh. " Refresh
APPEND ls_event_exit TO lt_event_exit.
*Display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'PF_STATUS_SET'
i_structure_name = 'CDHDR'
is_layout = gs_layout
it_event_exit = lt_event_exit
i_save = 'A'
TABLES
t_outtab = t_cdhdr.
ENDFORM. " F_DISPLAY_CDHDR
*---------------------------------------------------------------------
*
*FORM USER_COMMAND *
*---------------------------------------------------------------------
FORM user_command USING u_ucomm TYPE syucomm
us_selfield TYPE slis_selfield. "#EC CALLED
*Macro definition
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = c_x.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DATA :
ls_cdhdr TYPE ty_s_cdhdr,
ls_sort TYPE slis_sortinfo_alv,
lt_sort TYPE slis_t_sortinfo_alv,
*Change document items
lt_cdpos TYPE TABLE OF ty_s_cdpos.
CASE u_ucomm.
WHEN '&IC1' OR c_eb9.
PERFORM check_marked USING us_selfield.
*Read Change document items
LOOP AT t_cdhdr INTO ls_cdhdr WHERE checkbox = c_x.
SELECT * APPENDING TABLE lt_cdpos
FROM cdpos
WHERE objectclas = ls_cdhdr-objectclas
AND objectid = ls_cdhdr-objectid
AND changenr = ls_cdhdr-changenr.
ENDLOOP.
m_sort 'CHANGENR'.
*Display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_structure_name = 'CDPOS'
is_layout = gs_layout
it_sort = lt_sort
i_save = 'A'
TABLES
t_outtab = lt_cdpos.
WHEN c_refresh.
PERFORM f_read_data.
us_selfield-refresh = c_x.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------
*Form CHECK_MARKED
*---------------------------------------------------------------------
*
*What has been marked in t_cdhdr
*---------------------------------------------------------------------
FORM check_marked USING us_selfield TYPE slis_selfield.
FIELD-SYMBOLS :
TYPE ty_s_cdhdr.
READ TABLE t_cdhdr TRANSPORTING NO FIELDS
WITH KEY checkbox = c_x.
IF NOT sy-subrc IS INITIAL AND
NOT us_selfield-tabindex IS INITIAL.
READ TABLE t_cdhdr INDEX us_selfield-tabindex ASSIGNING .
-checkbox = c_x.
ENDIF.
ENDFORM. " CHECK_MARKED
*---------------------------------------------------------------------
*
*FORM PF_STATUS_SET *
*---------------------------------------------------------------------
FORM pf_status_set USING ut_extab TYPE slis_t_extab. "#EC CALLED
*Display 'Refresh' button and 'More' button
DELETE ut_extab WHERE fcode = c_refresh
OR fcode = c_eb9.
SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING ut_extab.
ENDFORM. " PF_STATUS_SET
*---------------------------------------------------------------------*
* how to use the function module
*---------------------------------------------------------------------*
*--- how to use the function module CHANGEDOCUMENT_READ_HEADERS
REPORT zchange_headers .
DATA: BEGIN OF it_cdhdr OCCURS 0.
INCLUDE STRUCTURE cdhdr.
DATA: END OF it_cdhdr.
PARAMETERS: begdate LIKE cdhdr-udate ,
enddate LIKE cdhdr-udate ,
begtime LIKE cdhdr-utime ,
endtime LIKE cdhdr-utime .
INITIALIZATION .
begdate = sy-datum .
enddate = sy-datum .
begtime = '000001' .
endtime = '235959'.
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
date_of_change = begdate
objectclass = 'EINKBELEG' "Object Class T-Code: SCDO
time_of_change = begtime
username = sy-uname
date_until = enddate
time_until = endtime
TABLES
i_cdhdr = it_cdhdr
EXCEPTIONS
no_position_found = 1
wrong_access_to_archive = 2
time_zone_conversion_error = 3
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF sy-subrc = 0.
LOOP AT it_cdhdr.
WRITE:/ it_cdhdr-objectclas,
it_cdhdr-objectid,
it_cdhdr-changenr,
it_cdhdr-username,
it_cdhdr-udate,
it_cdhdr-utime,
it_cdhdr-tcode.
ENDLOOP.
ENDIF.ALSO READ:
- ALV Report With User Defined Buttons In It's Toolbar.
- ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC.
- Displaying Percentage In ALV List / Grid Display.
- Handling An ALV Grid With Check Box Using A Method.
..... Back To Index On ALV List/ Grid Display.
..... Back To MAIN INDEX.