Selection Screen :- On the Selection Screen bellow you will have to enter the date between you want to display the changes and personal numbers or you can leave it blank for display changes of all Employees.
Output :- Bellow is the Screen Shot of the First Screen it will show up all the infotypes which have changed with the Employee's Personal Number and Name
After Click on any Change Category it will show up the details of that infotype as shown bellow.
Code :-Just Copy Past Bellow Code Save, Active and ready to display changes
REPORT zfsl_hremdch NO STANDARD PAGE HEADING.
TABLES: pa0000.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001 .
SELECT-OPTIONS: soaedat FOR pa0000-aedtm OBLIGATORY NO-EXTENSION,
sopernr FOR pa0000-pernr.
SELECTION-SCREEN END OF BLOCK main.
************************************************************************
* Types Defined *
************************************************************************
TYPES: BEGIN OF ty_tables, " Type for All HR Master Table Name and Description
tabname LIKE dd02l-tabname,
ddtext LIKE dd02t-ddtext,
END OF ty_tables.
TYPES: BEGIN OF ty_mas. " Type for HR Master Data Change
INCLUDE: STRUCTURE pakey,
TYPE ty_tables.
TYPES: ename LIKE pa0001-ename,
aedtm LIKE pa0000-aedtm,
uname LIKE pa0000-uname,
END OF ty_mas.
TYPES: BEGIN OF ty_pa0001, " Type for Ename and Plans
pernr LIKE pa0001-pernr,
ename LIKE pa0001-ename,
END OF ty_pa0001.
************************************************************************
* Declaration of Variables *
************************************************************************
DATA: it_tables TYPE STANDARD TABLE OF ty_tables WITH HEADER LINE,
wa_tables TYPE ty_tables,
it_mas TYPE STANDARD TABLE OF ty_mas WITH HEADER LINE,
wa1_mas TYPE ty_mas,
wa2_mas TYPE ty_mas,
it_pa0001 TYPE SORTED TABLE OF ty_pa0001 WITH HEADER LINE WITH UNIQUE KEY pernr,
wa_pa0001 TYPE ty_pa0001,
str_date TYPE string,
str_len TYPE i,
date_low TYPE c LENGTH 10,
date_high TYPE c LENGTH 10,
flag TYPE c LENGTH 1.
************************************************************************
* FIELD-SYMBOLS *
************************************************************************
FIELD-SYMBOLS: <wa_mas_c> TYPE ty_mas.
************************************************************************
* Declaration of RANGES *
************************************************************************
DATA: rg_pernr LIKE RANGE OF pa0000-pernr WITH HEADER LINE.
************************************************************************
* START-OF-SELECTION *
************************************************************************
START-OF-SELECTION.
* Format Date to Display on the Screen Top of Page
CLEAR: date_low, date_high.
WRITE: soaedat-low TO date_low, soaedat-high TO date_high.
IF soaedat-high <> '00000000' .
CONCATENATE 'Date: From' date_low 'to' date_high INTO str_date SEPARATED BY space.
ELSE.
CONCATENATE 'Date:' date_low INTO str_date SEPARATED BY space.
ENDIF.
* Select All the Table Name and Description Start from PA
SELECT dd02l~tabname dd02t~ddtext
INTO CORRESPONDING FIELDS OF TABLE it_tables
FROM dd02l LEFT OUTER JOIN dd02t ON ( dd02l~tabname = dd02t~tabname AND dd02t~ddlanguage = 'E' )
WHERE dd02l~tabname LIKE 'PB%'.
* Now Delete all other Tables name Because we Need name from PA0000 to PA9999 we are dealing with all Infotypes 0000 to 9999
LOOP AT it_tables INTO wa_tables.
IF wa_tables-tabname+2(4) CO '0123456789' AND STRLEN( wa_tables-tabname ) = 6 .
ELSE.
DELETE it_tables INDEX sy-tabix.
ENDIF.
ENDLOOP.
SORT it_tables BY tabname.
** Get all the Changed Data and Append it to Internal Table and also Append pernrs to a Range for further USE
rg_pernr-sign = 'I'. rg_pernr-option = 'EQ'.
LOOP AT it_tables INTO wa_tables.
SELECT pernr subty objps sprps endda begda seqnr aedtm uname
APPENDING CORRESPONDING FIELDS OF TABLE it_mas
FROM (wa_tables-tabname)
WHERE aedtm IN soaedat
AND pernr IN sopernr.
IF sy-subrc = 0.
LOOP AT it_mas ASSIGNING <wa_mas_c> WHERE tabname IS INITIAL.
<wa_mas_c>-tabname = wa_tables-tabname.
<wa_mas_c>-ddtext = wa_tables-ddtext.
rg_pernr-low = <wa_mas_c>-pernr.
APPEND rg_pernr.
ENDLOOP.
ENDIF.
ENDLOOP.
* Delete all duplicate pernrs because we Need Distinct For this First Sort by low
SORT rg_pernr BY low.
DELETE ADJACENT DUPLICATES FROM rg_pernr COMPARING low.
IF rg_pernr[] IS NOT INITIAL.
* Select Ename and Plans from PA0001 for all pernr in Range
SELECT mandt pernr subty objps sprps endda begda seqnr ename " We need only Pernr and Ename but because me using FOR ALL ENTRIES IN so talking all Key Fields
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE it_pa0001
FOR ALL ENTRIES IN rg_pernr
WHERE pernr = rg_pernr-low
AND endda = '99991231'.
* Now Place Names against every pernr
LOOP AT it_mas ASSIGNING <wa_mas_c> .
READ TABLE it_pa0001 WITH TABLE KEY pernr = <wa_mas_c>-pernr.
IF sy-subrc = 0.
<wa_mas_c>-ename = it_pa0001-ename.
ENDIF.
ENDLOOP.
ENDIF.
IF it_mas[] IS INITIAL.
MESSAGE: 'No Change History Found' TYPE 'I'.
ENDIF.
SORT: it_mas BY pernr tabname aedtm begda.
* Now Write the Master Internal Table on the Screen in the Specific Format
LOOP AT it_mas INTO wa1_mas.
* Uncomment this code if want to see Table Description between ( )
** Here we only need the infotype name not Prefix Before Table Description So Get only Text in “ ( ) “
* SEARCH wa1_mas-ddtext FOR '('.
* IF sy-subrc EQ 0.
* str_len = 60 - sy-fdpos.
* wa1_mas-ddtext = wa1_mas-ddtext+sy-fdpos(str_len).
* ELSE.
* CLEAR: wa1_mas-ddtext.
* ENDIF.
wa2_mas = wa1_mas.
AT NEW pernr.
WRITE: 1(140) sy-uline,
/1 '|',
2(12) wa2_mas-pernr CENTERED HOTSPOT ON,
14(1) '|',
15(30) wa2_mas-ename HOTSPOT ON,
45(1) '|',
46(60) wa2_mas-ddtext HOTSPOT ON,
106(1) '|',
107(20) wa2_mas-uname CENTERED HOTSPOT ON,
127(1) '|',
128(12) wa2_mas-aedtm CENTERED HOTSPOT ON.
HIDE : wa2_mas.
WRITE: 140(1) '|',
/1(140) sy-uline.
flag = 'X'.
ENDAT.
IF flag EQ 'X'.
flag = ''.
ELSE.
WRITE: /1 '|',
45(1) '|',
46(60) wa2_mas-ddtext HOTSPOT ON,
106(1) '|',
107(20) wa2_mas-uname CENTERED HOTSPOT ON,
127(1) '|',
128(12) wa2_mas-aedtm CENTERED HOTSPOT ON,
140(1) '|'.
HIDE : wa2_mas.
WRITE: /1 '|',
45(96) sy-uline.
ENDIF.
AT END OF pernr.
WRITE: 1(140) sy-uline.
ENDAT.
ENDLOOP.
************************************************************************
* AT LINE-SELECTION *
************************************************************************
AT LINE-SELECTION.
DATA: it_ref TYPE REF TO data.
DATA: lvc_title TYPE lvc_title.
* Creation of Dynamic Internal Table
CREATE DATA it_ref TYPE STANDARD TABLE OF (wa2_mas-tabname).
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
ASSIGN it_ref->* TO <itab>.
* Selection of Changed Data
SELECT * FROM (wa2_mas-tabname)
INTO CORRESPONDING FIELDS OF TABLE <itab>
WHERE pernr = wa2_mas-pernr
AND aedtm <= wa2_mas-aedtm.
IF sy-subrc = 0.
* Show ALV for select records
PERFORM show_alv.
ENDIF.
************************************************************************
* AT SELECTION-SCREEN OUTPUT *
************************************************************************
AT SELECTION-SCREEN OUTPUT.
IF soaedat[] IS INITIAL.
soaedat-high = sy-datum.
APPEND soaedat TO soaedat.
ENDIF.
************************************************************************
* INITIALIZATION *
************************************************************************
INITIALIZATION.
************************************************************************
* TOP-OF-PAGE *
************************************************************************
TOP-OF-PAGE.
WRITE: 1(140) sy-uline,
/1 '|',
2(139) 'HR: Master Data Change' CENTERED COLOR 1,
140(1) '|' ,
/1 '|',
2(139) str_date CENTERED COLOR 1,
140(1) '|' .
WRITE: /1(140) sy-uline,
/1 '|',
2(12) 'Personal No.' CENTERED COLOR 1,
14(1) '|',
15(30) 'Name of Employee' CENTERED COLOR 1,
45(1) '|',
46(60) 'Changed Category' CENTERED COLOR 1,
106(1) '|',
107(20) 'Changed By' CENTERED COLOR 1,
127(1) '|',
128(12) 'Changed On' CENTERED COLOR 1,
140(1) '|',
/1(140) sy-uline.
************************************************************************
* FORMs *
************************************************************************
*&---------------------------------------------------------------------*
*& Form show_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM show_alv.
TYPE-POOLS: slis.
DATA: wa_layout TYPE slis_layout_alv.
DATA: it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.
CONCATENATE wa2_mas-tabname+2(4) '=>' wa2_mas-ddtext INTO lvc_title SEPARATED BY space.
* For Sorting
CLEAR wa_sort.
wa_sort-fieldname = 'AEDTM'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
* for Layout
wa_layout-zebra = 'X'.
wa_layout-colwidth_optimize = 'X'.
* Display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_structure_name = wa2_mas-tabname
i_grid_title = lvc_title
is_layout = wa_layout
it_sort = it_sort
i_default = 'X'
i_save = 'X'
TABLES
t_outtab = <itab>
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. "show_alv
0 comments:
Post a Comment