Tracking the leave requests of an Employee with the status from Workflow

By Vijay Kumar Mukunthan, TCS

This program shows the detail leave list of the employee with the status of the workflow whether the leave got approved or rejected and other details like name, start date and end date of leave etc with traffic signaling light.

*&---------------------------------------------------------------------*
*& Report  ZWF_TRACKING
*&
*& This program is developed by Vijay Kumar

*  Published at SAPTechnical.COM
*&---------------------------------------------------------------------*
*& This program is used to track the whether the employee applied for leave
*& is approver or rejected and to check the status of the leave type
*& 0001 means Casual Leave
*& 0002 means Earned Leave
*&---------------------------------------------------------------------

REPORT  ZWF_TRACKING.
TABLES : SSCRFIELDS.
TYPE-POOLS: SLIS,ABAP.
TABLES : PTREQ_ATTABSDATA,PTREQ_HEADER,PTREQ_ITEMS.

DATA : BEGIN OF GT_OUTTAB OCCURS 0,
        EXCEPTION   
TYPE LVC_EXLED,
        REQUEST_ID   
TYPE TIM_REQ_ID,
        PERNR 
LIKE P0001-PERNR,
        ENAME 
TYPE EMNAM,
        BEGDA 
LIKE PTREQ_ATTABSDATA-BEGDA,
        ENDDA 
LIKE PTREQ_ATTABSDATA-ENDDA,
        SUBTY 
LIKE PTREQ_ATTABSDATA-SUBTY,
        SUBTYTEXT 
TYPE SBTTX,
        STATUS 
LIKE PTREQ_HEADER-STATUS,
        NOTICE_TEXT 
TYPE PTREQ_NOTICE-NOTICE_TEXT,
        DESCR 
LIKE  T572B-DESCR,
        MOD_USER 
LIKE PTREQ_HEADER-MOD_USER,
        CUSTOMER01 
LIKE PTREQ_ATTABSDATA-CUSTOMER01,
        CUSTOMER02 
LIKE PTREQ_ATTABSDATA-CUSTOMER02,
        CUSTOMER03 
LIKE PTREQ_ATTABSDATA-CUSTOMER03,
        CUSTOMER05 
LIKE PTREQ_ATTABSDATA-CUSTOMER05,
        UMSKD    
TYPE UMSKD,
        
END OF GT_OUTTAB .

DATA:
  GD_REPID         
TYPE SYREPID,
  GD_OKCODE        
TYPE UI_FUNC,
  GT_FCAT          
TYPE LVC_T_FCAT,
  GS_LAYOUT        
TYPE LVC_S_LAYO,
  GS_VARIANT       
TYPE DISVARIANT,
  GO_DOCKING       
TYPE REF TO CL_GUI_DOCKING_CONTAINER,
  GO_GRID          
TYPE REF TO CL_GUI_ALV_GRID.


DATA: FIELDCATALOG TYPE LVC_T_FCAT WITH HEADER LINE.

DATA:
 PERNR1         
TYPE PA0001-PERNR,
 LEA_TY1        
TYPE PA0001-SUBTY,
 BEGDA1         
TYPE PA0001-BEGDA,
 ENDDA1         
TYPE PA0001-ENDDA.

DATA : ENAME TYPE EMNAM,
       SUBTYTEXT 
TYPE SBTTX.

SELECTION-
SCREEN BEGIN OF BLOCK 01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS PERNR FOR PERNR1. SELECT-OPTIONS LEA_TY FOR LEA_TY1.
PARAMETERS : P_STATUS LIKE PTREQ_HEADER-STATUS.
SELECT-OPTIONS BEGDA FOR BEGDA1.
SELECT-OPTIONS ENDDA FOR ENDDA1.
SELECTION-
SCREEN END OF BLOCK 01.

START
-OF-SELECTION.
IF P_STATUS IS INITIAL.
  P_STATUS = 
'%' .
ENDIF.
 
SELECT A~REQUEST_ID A~STATUS A~MOD_USER
        
C~PERNR C~SUBTY C~BEGDA C~ENDDA C~CUSTOMER01
        
C~CUSTOMER02 C~CUSTOMER03 C~CUSTOMER05 C~UMSKD
        E~DESCR
   
INTO CORRESPONDING FIELDS OF TABLE GT_OUTTAB
    
FROM
   PTREQ_HEADER     
AS A INNER JOIN
   PTREQ_ITEMS      
AS B ON A~ITEM_LIST_ID = B~ITEM_LIST_ID INNER JOIN
   PTREQ_ATTABSDATA 
AS C ON B~ITEM_INS = C~ITEM_ID INNER JOIN
   T572B 
AS E ON C~UMSKD = E~DESCD
   
WHERE C~PERNR IN PERNR AND
         
C~SUBTY IN LEA_TY AND
         
C~BEGDA IN BEGDA AND
         
C~ENDDA IN ENDDA AND
         A~STATUS 
LIKE P_STATUS .

LOOP AT GT_OUTTAB.
CALL FUNCTION 'HR_TMW_GET_EMPLOYEE_NAME'
  
EXPORTING
    PERSON_NO          = GT_OUTTAB-PERNR
 
IMPORTING
   EDIT_NAME          =  ENAME

          .
GT_OUTTAB-ENAME = ENAME .

  
CALL FUNCTION 'HR_GET_SUBTYPE_TEXT'
    
EXPORTING
      INFTY                     = 
'2001'
      SUBTY                     = GT_OUTTAB-SUBTY
   
IMPORTING
     STEXT                     = SUBTYTEXT
   
EXCEPTIONS
     INFTY_NOT_FOUND           = 
1
     SUBTY_NOT_FOUND           = 
2
     INFTY_NOT_SUPPORTED       = 
3
     
OTHERS                    = 4
            .
  GT_OUTTAB-SUBTYTEXT = SUBTYTEXT.
  
SELECT NOTICE_TEXT FROM PTREQ_NOTICE INTO GT_OUTTAB-NOTICE_TEXT
  
WHERE REQUEST_ID = GT_OUTTAB-REQUEST_ID AND  VERSION_NO = '1'.
  
ENDSELECT.

  
SELECT DESCR FROM T572B INTO GT_OUTTAB-DESCR
    
WHERE DESCD = GT_OUTTAB-UMSKD AND SPRSL = 'E'.
    
ENDSELECT.
  
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  
ENDIF.
  
MODIFY GT_OUTTAB.
  
ENDLOOP.

  
LOOP AT GT_OUTTAB.
IF ( GT_OUTTAB-STATUS = 'POSTED' OR GT_OUTTAB-MOD_USER = 'ABABDEV' OR GT_OUTTAB-MOD_USER = 'WF-BATCH').
  
DELETE  GT_OUTTAB WHERE MOD_USER = 'ABAPDEV' OR MOD_USER = 'WF-BATCH'.
  
ENDIF.
  
ENDLOOP.

  
PERFORM INIT_CONTROLS.
  
PERFORM CHECK_CONDITION.

* Display data
  
CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    
EXPORTING
      IS_LAYOUT       = GS_LAYOUT
      IS_VARIANT      = GS_VARIANT
      I_SAVE          = 
'A'
    
CHANGING
      IT_OUTTAB       = GT_OUTTAB[]
      IT_FIELDCATALOG = FIELDCATALOG[]
    
EXCEPTIONS
      
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.
*    MESSAGE ID mid TYPE mtype NUMBER num.
  
ENDIF.
  
CALL SCREEN '0100'.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------
MODULE STATUS_0100 OUTPUT.
  
SET PF-STATUS 'STATUS_0100'.
  
SET TITLEBAR 'TITLE'.
  
CASE SY-UCOMM.
    
WHEN 'BACK' OR
         
'EXIT'  OR
         
'CANCEL'.
      
SET SCREEN 0.
      
LEAVE SCREEN.
    
WHEN OTHERS.
      
CALL METHOD GO_GRID->REFRESH_TABLE_DISPLAY
        
EXCEPTIONS
          FINISHED       = 
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.
  
ENDCASE.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------
MODULE USER_COMMAND_0100 INPUT.

  
CASE SY-UCOMM.
    
WHEN 'BACK' OR
         
'EXIT'  OR
         
'CANCEL'.
      
SET SCREEN 0.
      
LEAVE SCREEN.
    
WHEN OTHERS.
      
CALL METHOD GO_GRID->REFRESH_TABLE_DISPLAY
        
EXCEPTIONS
          FINISHED = 
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.
  
ENDCASE.
  
CLEAR: GD_OKCODE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------
FORM INIT_CONTROLS .

* Create ALV grid
  
CREATE OBJECT GO_GRID
    
EXPORTING
      I_PARENT = GO_DOCKING
    
EXCEPTIONS
      
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.

  
PERFORM BUILD_FIELDCATALOG.
  
PERFORM SET_LAYOUT_AND_VARIANT.

ENDFORM.                    " INIT_CONTROLS

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------
FORM BUILD_FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'PERNR'.
  FIELDCATALOG-COLTEXT  = 
'PERSONAL NO'.
  FIELDCATALOG-OUTPUTLEN  = 
8.
  FIELDCATALOG-EMPHASIZE  = 
'X'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'ENAME'.
  FIELDCATALOG-COLTEXT  = 
'EMPLOYEE_NAME'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'BEGDA'.
  FIELDCATALOG-COLTEXT  = 
'START_DATE'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'ENDDA'.
  FIELDCATALOG-COLTEXT  = 
'END_DATE'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'SUBTY'.
  FIELDCATALOG-COLTEXT  = 
'LEAVE_CODE'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'SUBTYTEXT'.
  FIELDCATALOG-COLTEXT  = 
'LEAVE_TEXT'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'STATUS'.
  FIELDCATALOG-COLTEXT  = 
'STATUS'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'MOD_USER'.
  FIELDCATALOG-COLTEXT  = 
'APPROVER'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

 FIELDCATALOG-FIELDNAME  = 
'NOTICE_TEXT'.
  FIELDCATALOG-COLTEXT  = 
'NOTE FOR APPROVER'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

 FIELDCATALOG-FIELDNAME  = 
'DESCR'.
  FIELDCATALOG-COLTEXT  = 
'REASON'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

 FIELDCATALOG-FIELDNAME  = 
'CUSTOMER01'.
  FIELDCATALOG-COLTEXT  = 
'ADDRESS'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

 FIELDCATALOG-FIELDNAME  = 
'CUSTOMER02'.
  FIELDCATALOG-COLTEXT  = 
'CONTACT_NO'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

 FIELDCATALOG-FIELDNAME  = 
'CUSTOMER03'.
  FIELDCATALOG-COLTEXT  = 
'STREET & CITY'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME  = 
'CUSTOMER05'.
  FIELDCATALOG-COLTEXT  = 
'STATE'.
  FIELDCATALOG-COL_OPT = 
'x'.
  
APPEND FIELDCATALOG TO FIELDCATALOG.
  
CLEAR  FIELDCATALOG.

ENDFORM.                    " BUILD_FIELDCATALOG_KNB1

*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------
FORM SET_LAYOUT_AND_VARIANT .

  
CLEAR: GS_LAYOUT,
         GS_VARIANT.

  GS_LAYOUT-CWIDTH_OPT = ABAP_TRUE.
  GS_LAYOUT-ZEBRA      = ABAP_TRUE.
  GS_LAYOUT-EXCP_FNAME = 
'EXCEPTION'.  " define column for LED
  GS_LAYOUT-EXCP_LED   = ABAP_TRUE.

  GS_VARIANT-
REPORT = SYST-REPID.
  GS_VARIANT-HANDLE = 
'GRID'.

ENDFORM.                    " SET_LAYOUT_AND_VARIANT

*&---------------------------------------------------------------------*
*&      Form  CHECK_CONDITION
*&---------------------------------------------------------------------
FORM CHECK_CONDITION .
* define local data
  
DATA: LS_OUTTAB  LIKE GT_OUTTAB.

  
LOOP AT GT_OUTTAB INTO LS_OUTTAB.
    
IF ( LS_OUTTAB-STATUS = 'APPROVED' OR  LS_OUTTAB-STATUS = 'POSTED').
      LS_OUTTAB-EXCEPTION = 
'3'.  " GREEN LED/traffic light
    
ELSEIF  ( LS_OUTTAB-STATUS = 'REJECTED' OR LS_OUTTAB-STATUS = 'ERROR' OR LS_OUTTAB-STATUS = 'DELETED').
      LS_OUTTAB-EXCEPTION = 
'1'.  " RED LED / traffic light
    
ELSEIF  ( LS_OUTTAB-STATUS = 'SENT' OR LS_OUTTAB-STATUS = 'WITHDRAWN').
      LS_OUTTAB-EXCEPTION = 
'2'.  " yellow LED / traffic light
    
ENDIF.
    
MODIFY GT_OUTTAB FROM LS_OUTTAB INDEX SYST-TABIX.
  
ENDLOOP.

ENDFORM.                    " CHECK_CONDITION  

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image