Skip to Content

Main

************************************************************************
* Object Name : REPORT  ZHCM_ASMNT3 *
* Author/Company Name : Krishnakant Joshi *
* Transport Request *
* Creation Date * 01/30/2013
************************************************************************
* Description: *  Report to display Employee Manager
************************************************************************
* Dependencies *
************************************************************************
* Modification History *
************************************************************************
* Date Programmer Client Ref No. Description Correction *
************************************************************************
REPORT  zhcm_asmnt3.
*&**********************************************************************
*&    INCLUDE
*&**********************************************************************
INCLUDE : zhcm_asmnt3_top,        “Global Types and Data
zhcm_asmnt3_screen,    
“Screen
zhcm_asmnt3_form.      
“Subroutines
*&**********************************************************************
*&    INITIALIZATION
*&**********************************************************************
INITIALIZATION.
v_repid = sy-repid.
*&**********************************************************************
*&    AT SELECTION-SCREEN.
*&**********************************************************************
AT SELECTION-SCREEN.
*&———————————————————————*
*& Validate the screen inputs manualy for Manager levels
PERFORM validation.
*&**********************************************************************
*&    AT SELECTION-SCREEN OUTPUT.
*&**********************************************************************
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = c_PNPS$MSL OR screen-name = c_PNPS$MCD.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
*&**********************************************************************
*&    START-OF-SELECTION
*&**********************************************************************
START-
OF-SELECTION.
*&———————————————————————*
*& Populate fieldcatalog table to create structure for dynamic table
PERFORM  build_fieldcatalog.
IF i_fieldcatalog IS NOT INITIAL.
*&———————————————————————*
*& Get dynamic table to define final table structure
PERFORM get_dyntable.
*&———————————————————————*
* Create dynamic work area and assign to FS
DATA :lr_line  TYPE REF TO data.
CREATE DATA lr_line LIKE LINE OF <x_final>.
ASSIGN lr_line->* TO <x_wfinal>.
*&———————————————————————*
* Get HRP1001
PERFORM get_hrp1001.
*&———————————————————————*
* Get PA0001
PERFORM get_pa0001.
ENDIF.
*&**********************************************************************
*&    GET PERNR
*&**********************************************************************
GET pernr.
APPEND INITIAL LINE TO <x_final> ASSIGNING <x_wfinal>.
*&———————————————————————*
*& Get Action details
PERFORM get_0000.
*&———————————————————————*
*& Get Organizational assignments
PERFORM get_0001.
*&**********************************************************************
*&    END-OF-SELECTION
*&**********************************************************************
ENDOF-SELECTION.
IF <x_final> IS NOT INITIAL.
PERFORM  set_layout.
PERFORM  display_alv_report.
ELSE.
MESSAGE text017 TYPE c_i.
ENDIF.

 
 

TOP

*&———————————————————————*
*&  Include           ZHCM_ASMNT3_TOP
*&———————————————————————*
TYPE-POOLS: slis.
TABLES: pernr.
INFOTYPES: 0000, 0001, 1001.
*&**********************************************************************
*&   TYPES
*&**********************************************************************
TYPES:
*&———————————————————————*
*&  HRP1001
BEGIN OF t_hrp1001,
otype             
TYPE otype,
objid             
TYPE hrobjid,
rsign             
TYPE rsign,
relat             
TYPE relat,
begda             
TYPE begdatum,
endda             
TYPE enddatum,
subty             
TYPE subtyp,
sclas            
TYPE sclas,
sobid            
TYPE sobid,
END OF t_hrp1001,
BEGIN OF t_pa0001,
pernr            
TYPE pernr-pernr,
objps            
TYPE objps,
endda            
TYPE begdatum,
begda            
TYPE enddatum,
ename            
TYPE emnam,
END OF t_pa0001.
*&**********************************************************************
*&   DATA
*&**********************************************************************
*&  ALV data
DATA: i_fieldcatalog      TYPE lvc_t_fcat,
w_fieldcatalog     
TYPE lvc_s_fcat,
i_fieldcat         
TYPE STANDARD TABLE OF slis_fieldcat_alv,
w_fieldcat         
TYPE slis_fieldcat_alv,
v_repid            
LIKE sy-repid,
v_gridtitle        
TYPE lvc_title,
w_layout           
TYPE slis_layout_alv,
v_colpos           
TYPE i VALUE  1.
*&———————————————————————*
*&  Variables
DATA :v_pernr             TYPE pernr-pernr,
v_mgrid            
TYPE hrobjid,
v_ename            
TYPE emnam.
*&———————————————————————*
*&  Internal tables
DATA :i_hrp1001           TYPE STANDARD TABLE OF t_hrp1001,
i_pa0001           
TYPE STANDARD TABLE OF t_pa0001.
*&**********************************************************************
*&   FIELD-SYMBOLS
*&**********************************************************************
FIELD-SYMBOLS:<x_final>   TYPE STANDARD TABLE,
<x_wfinal>,
<x_field>,
<x_hrp1001>
TYPE  t_hrp1001,
<x_pa0001>
TYPE  t_pa0001.
*&**********************************************************************
*&   CONSTANTS
*&**********************************************************************
CONSTANTS : c_e           TYPE c          VALUE ‘E’, “Constant For E
c_i          
TYPE c          VALUE ‘I’, “Constant For I
c_x          
TYPE c          VALUE ‘X’, “Constant For X
c_1          
TYPE c          VALUE ‘1’, “Constant For 1
c_01         
TYPE plog-plvar VALUE ’01’,
c_a          
TYPE c          VALUE ‘A’,
c_b          
TYPE c          VALUE ‘B’,
c_s          
TYPE plog-otype VALUE ‘S’,
c_o          
TYPE plog-otype VALUE ‘O’,
c_p          
TYPE plog-otype VALUE ‘P’,
c_a002       
TYPE plog-subty VALUE ‘A002’,
c_a001       
TYPE plog-subty VALUE ‘A001’,
c_a008       
TYPE plog-subty VALUE ‘A008’,
c_b012       
TYPE plog-subty VALUE ‘B012’,
c_002        
TYPE plog-subty VALUE ‘002’,
c_001        
TYPE plog-subty VALUE ‘001’,
c_008        
TYPE plog-subty VALUE ‘008’,
c_012        
TYPE plog-subty VALUE ‘012’,
c_1001       
TYPE plog-infty VALUE ‘1001’,
c_0123456789 
TYPE char10     VALUE ‘0123456789’,
c_pnps$msl   
TYPE char08     VALUE ‘PNPS$MSL’,
c_pnps$mcd   
TYPE char08     VALUE ‘PNPS$MCD’.

 
 

SCREEN

*&———————————————————————*
*&  Include           ZHCM_ASMNT3_SCREEN
*&———————————————————————*
************************************************************************
*& Selection screen
************************************************************************
SELECTION-
SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text011.
*& Parameter for the selection of manager level
PARAMETERS : p_level TYPE char02 DEFAULT 1 OBLIGATORY.
SELECTION-
SCREEN END OF BLOCK b1.

 
 

FORM

*&———————————————————————*
*&  Include           ZHCM_ASMNT3_FORM
*&———————————————————————*
*&———————————————————————*
*&      Form  VALIDATION
*&———————————————————————*
*       Validate manager level
*———————————————————————-*
FORM validation .
*———————————————————————-*
*& Check for manager level whether it is numeric or not,
IF p_level CA c_0123456789.
*———————————————————————-*
*&  Manager level must be greater than 0
IF p_level = 0.
MESSAGE text021 TYPE c_e.
ENDIF.
ELSE.
MESSAGE text021 TYPE c_e.
ENDIF.
ENDFORM.                    ” VALIDATION
*———————————————————————-*
* Form build_fieldcatalog *
*———————————————————————-*
* This form is used set field catalog
*———————————————————————-*
FORM build_fieldcatalog .
DATA: lv_field      TYPE lvc_fname,
lv_seltext   
TYPE lvc_txt,
lv_sy_index  
TYPE char02.
*———————————————————————-*
* Populate fieldcatalog table static fields
PERFORM set_fieldcatalog USINGtext000 text001“Employee #
text002 text003“Name
text004 text005“Cost Center
text006 text007“Org. Unit
*———————————————————————-*
* Populate fieldcatalog table for Manager level fields
DO p_level TIMES.
CLEAR: lv_field, lv_seltext.
lv_sy_index = sy-
index.
*———————————————————————-*
*& Populate PERNR column
CONCATENATE text013 lv_sy_index INTO lv_field.       “Field Name
CONCATENATE text008 lv_sy_index text000 INTO lv_seltext. “Text
PERFORM set_fieldcatalog USING :  lv_field lv_seltext.
*———————————————————————-*
*& Populate Manager Position column
CLEAR: lv_field, lv_seltext.
CONCATENATE text014 lv_sy_index INTO lv_field.       “Field Name
CONCATENATE text008 lv_sy_index text009 INTO lv_seltext. “Text
PERFORM set_fieldcatalog USING :  lv_field lv_seltext.
*———————————————————————-*
*& Populate Manager name column
CLEAR: lv_field, lv_seltext.
CONCATENATE text015 lv_sy_index INTO lv_field.       “Field Name
CONCATENATE text008 lv_sy_index text010 INTO lv_seltext. “Text
PERFORM set_fieldcatalog USING :  lv_field lv_seltext.
ENDDO.
ENDFORM.                    ” BUILD_FIELDCATALOG
*———————————————————————-*
* Form set_fieldcatalog *
*———————————————————————-*
* This form is used to set field catalog
*———————————————————————-*
FORM set_fieldcatalog  USING p_field   TYPE lvc_fname
p_seltext
TYPE lvc_txt.
*———————————————————————-*
*Populate fieldcatalog for Dynamic table
CLEAR  w_fieldcatalog.
w_fieldcatalog-fieldname   = p_field.    
“Field Name
w_fieldcatalog-seltext     = p_seltext.  
“Text
w_fieldcatalog-coltext     = p_seltext.
w_fieldcatalog-col_pos     = v_colpos.   
“Column position
APPEND w_fieldcatalog TO i_fieldcatalog.
*———————————————————————-*
*Populate ALV fieldcatalogs
CLEAR  w_fieldcat.
w_fieldcat-fieldname   = p_field.
w_fieldcat-seltext_m   = p_seltext.
w_fieldcat-col_pos     = v_colpos.
APPEND w_fieldcat TO i_fieldcat.
v_colpos = v_colpos +
1.
ENDFORM.                    ” set_fieldcatalog
*&———————————————————————*
*&      Form  GET_DYNTABLE
*&———————————————————————*
*       Get dynamic table for populated fieldcatalog table
*———————————————————————-*
FORM get_dyntable .
*———————————————————————-*
*& Create dynamic table
DATA: li_final TYPE REF TO data.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fieldcatalog
IMPORTING
ep_table        = li_final.
*———————————————————————-*
*& Assign retrived structure to a field symbol
ASSIGN li_final->* TO <x_final>.
CLEAR: i_fieldcatalog, w_fieldcatalog.
ENDFORM.                    ” GET_DYNTABLE
*&———————————————————————*
*&      Form  GET_HRP1001
*&———————————————————————*
*       Get Relations
*———————————————————————-*
FORM get_hrp1001 .
SELECT  otype objid rsign relat begda
endda subty sclas sobid
FROM hrp1001
INTO TABLE i_hrp1001
WHERE (    otype = c_o    OR
otype = c_s    )
AND   objid > 0
AND   plvar = c_01
AND ( rsign = c_a    OR
rsign = c_b    )
AND ( relat = c_001  OR
relat = c_002 
OR
relat = c_008 
OR
relat = c_012  )
AND   istat = c_1
AND   endda >= pn-begda
AND   begda <= pn-endda
AND   infty = c_1001
AND ( subty = c_a002 OR
subty = c_a001
OR
subty = c_a008
OR
subty = c_b012 )
AND ( sclas = c_o    OR
sclas = c_p   
OR
sclas = c_s    ).
IF sy-subrc = 0.
*———————————————————————-*
*& Sort table as per the keys in subsequent read statements
SORT i_hrp1001 BY otype objid rsign relat
subty sclas endda
DESCENDING
begda
DESCENDING.
ENDIF.
ENDFORM.                    ” GET_HRP1001
*&———————————————————————*
*&      Form  GET_PA0001
*&———————————————————————*
*       Get Org Data
*———————————————————————-*
FORM get_pa0001 .
SELECT pernr objps endda begda ename
INTO TABLE i_pa0001
FROM pa0001
WHERE  pernr > 0
AND endda >= pn-begda
AND begda <= pn-endda.
IF sy-subrc = 0.
*&———————————————————————*
*& Sort table to get latest recors up
SORT i_pa0001 BY pernr  endda DESCENDING
begda 
DESCENDING.
*&———————————————————————*
*& Delete duplicate entries
DELETE ADJACENT DUPLICATES FROM i_pa0001 COMPARING pernr.
ENDIF.
ENDFORM.                    ” GET_PA0001
*&———————————————————————*
*&      Form  GET_0000
*&———————————————————————*
*       Get action details
*———————————————————————-*
FORM get_0000 .
*&———————————————————————*
*& Get action data
rp-
providefromlast p0000 space pn-begda pn-endda.
IF pnp-sw-found = c_1.
UNASSIGN <x_field>.
ASSIGN COMPONENT  text000
OF STRUCTURE <x_wfinal> TO <x_field>.
IF <x_field> IS ASSIGNED.
<x_field> = p0000-pernr.
ENDIF.
ENDIF.
ENDFORM.                                                    ” GET_0000
*&———————————————————————*
*&      Form  GET_0001
*&———————————————————————*
*       Get organizatioal assignments
*———————————————————————-*
FORM get_0001 .
DATA: lv_ORGEH TYPE ORGEH.
rp-
providefromlast p0001 space pn-begda pn-endda.
IF pnp-sw-found = c_1.
*& Employee Name
UNASSIGN <x_field>.
ASSIGN COMPONENT text002
OF STRUCTURE <x_wfinal> TO <x_field>.
IF <x_field> IS ASSIGNED.
<x_field> = p0001-ename.
ENDIF.
*& Cost center
UNASSIGN <x_field>.
ASSIGN COMPONENT  text004
OF STRUCTURE <x_wfinal> TO <x_field>.
IF <x_field> IS ASSIGNED.
<x_field> = p0001-kostl.
ENDIF.
*& Org. unit
UNASSIGN <x_field>.
ASSIGN COMPONENT  text006
OF STRUCTURE <x_wfinal> TO <x_field>.
IF <x_field> IS ASSIGNED.
<x_field> = p0001-orgeh.
lv_ORGEH  = p0001-orgeh.
*&———————————————————————*
*& Get Manager data
PERFORM get_manager USING p_level CHANGING lv_ORGEH.
ENDIF.
ENDIF.
ENDFORM.                                                    ” GET_0001
*&———————————————————————*
*&      Form  GET_MANAGER
*&———————————————————————*
*       Get manager data
*———————————————————————-*
FORM get_manager USING    p_level TYPE char02
CHANGING p_orgeh TYPE orgeh.
DATA : lv_count         TYPE i,
lv_position_col 
TYPE char20,
lv_pernr_col    
TYPE char20,
lv_name_col     
TYPE char20,
lv_sy_index     
TYPE char02.
CLEAR: v_ename, v_mgrid, v_pernr.
lv_count = p_level.
*———————————————————————-*
*Get Manager
DOlv_count TIMES.
lv_sy_index = sy-
index.
*———————————————————————-*
*Get Manager Position
UNASSIGN <x_hrp1001>.
READ TABLE i_hrp1001 ASSIGNING <x_hrp1001>
WITH KEY  otype = c_o
objid = p_orgeh
rsign = c_b
relat = c_012
subty = c_b012
sclas = c_s
BINARY SEARCH.
IF <x_hrp1001> IS ASSIGNED.
v_mgrid = <x_hrp1001>-sobid.
“Manager Position
*———————————————————————-*
*Get position column name
CONCATENATE text014 lv_sy_index INTO lv_position_col.
UNASSIGN <x_field>.
ASSIGN COMPONENT  lv_position_col
OF STRUCTURE <x_wfinal> TO <x_field>.
*———————————————————————-*
*Set position column
IF <x_field> IS ASSIGNED.
<x_field> = v_mgrid.
ENDIF.
*———————————————————————-*
*Get Manager PERNR
UNASSIGN <x_hrp1001>.
READ TABLE i_hrp1001 ASSIGNING <x_hrp1001>
WITH KEY  otype = c_s
objid = v_mgrid
rsign = c_a
relat = c_008
subty = c_a008
sclas = c_p
BINARY SEARCH.
IF <x_hrp1001> IS ASSIGNED.
v_pernr = <x_hrp1001>-sobid.
*———————————————————————-*
*Get pernr column name
CONCATENATE text013 lv_sy_index INTO lv_pernr_col.
UNASSIGN <x_field>.
ASSIGN COMPONENT  lv_pernr_col
OF STRUCTURE <x_wfinal> TO <x_field>.
*———————————————————————-*
*Set pernr column
IF <x_field> IS ASSIGNED.
<x_field> = v_pernr.
ENDIF.
*———————————————————————-*
*Get Manager NAME
UNASSIGN <x_pa0001>.
READ TABLE i_pa0001 ASSIGNING <x_pa0001>
WITH KEY  pernr = v_pernr
BINARY SEARCH.
IF <x_hrp1001> IS ASSIGNED.
v_ename = <x_pa0001>-ename.
*———————————————————————-*
*Get pernr column name
CONCATENATE text015 lv_sy_index INTO lv_name_col.
UNASSIGN <x_field>.
ASSIGN COMPONENT  lv_name_col
OF STRUCTURE <x_wfinal> TO <x_field>.
*———————————————————————-*
*Set pernr column
IF <x_field> IS ASSIGNED.
<x_field> = v_ename.
ENDIF.
ENDIF.
ELSE.
*———————————————————————-*
*No manager position is assigned
EXIT.
ENDIF.
ENDIF.
*———————————————————————-*
*Go to next level of organization unit
IF lv_count <> sy-index.
UNASSIGN <x_hrp1001>.
READ TABLE i_hrp1001 ASSIGNING <x_hrp1001>
WITH KEY  otype = c_o
objid = p_orgeh
rsign = c_a
relat = c_002
subty = c_a002
sclas = c_o
BINARY SEARCH.
IF <x_hrp1001> IS ASSIGNED.
p_orgeh = <x_hrp1001>-sobid.
“Next level organization unit
ELSE.
EXIT.
ENDIF.
ENDIF.
ENDDO.
ENDFORM.                    ” GET_MANAGER
*———————————————————————-*
* Form set_layout *
*———————————————————————-*
* This form is used to set report layout
*———————————————————————-*
FORM set_layout.
w_layout-no_hotspot = c_x.
w_layout-zebra  = c_x.
w_layout-colwidth_optimize = c_x.
ENDFORM.                    “set_layout
*———————————————————————-*
* Form display_alv_report *
*———————————————————————-*
* This form is used to display report
*———————————————————————-*
FORM display_alv_report .
v_gridtitle =
text016.
* ALV GRID DISPLAY Function Modulecall———————————
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program     = v_repid
i_callback_top_of_page =
‘TOP_OF_PAGE’
it_fieldcat            = i_fieldcat
is_layout              = w_layout
i_grid_title           = v_gridtitle
TABLES
t_outtab               = <x_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.                    “display_alv_report
*———————————————————————-*
* top_of_page *
*———————————————————————-*
* This form is used to set top of page
*———————————————————————-*
FORM top_of_page.
DATA : li_header TYPE TABLE OF slis_listheader,
lw_header
TYPE slis_listheader,
lv_count
TYPE i,
lv_date
TYPE char10.
*&———————————————————————*
*& Manager level
lw_header-info = p_level.
lw_header-
key = text018.
lw_header-typ = c_s.
APPEND lw_header TO li_header.
CLEAR lw_header.
*&———————————————————————*
*& No. of records
DESCRIBE TABLE <x_final> LINES lv_count.
WRITE lv_count TO lw_header-info.
lw_header-
key = text019.
lw_header-typ = c_s.
APPEND lw_header TO li_header.
*&———————————————————————*
*& Rundate
CLEAR lw_header.
WRITE: sy-datum TO lv_date USING EDIT MASK ‘__/__/____’.
lw_header-info = lv_date.
lw_header-
key = text020.
lw_header-typ = c_s.
APPEND lw_header TO li_header.
CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
EXPORTING
it_list_commentary = li_header.
ENDFORM.                    “TOP_OF_PAGE

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply