Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

PA30 is the transaction used for HR master data maintenance.

Below are the steps to follow at transaction level to get the Work Schedule details of an employee:

     1. Enter any personnel number in the Personnel no. field.

         

    

     2.Enter the infotype ID for ‘Planned Working Time’ in the Infotype field as we are now looking for the Planned work shift timings.

         


     3.With these inputs in the initial screen, select the ‘Display’ button on the top left.

         


     4.This screen would show the Work Schedule Rule, work timing and other details.

         



     5.Click the ‘Work Schedule’ button on the top left (shown in above screen) and it will display the scheduled work plan for the current month.

         

ABAP programming:


The above steps determine the process to get Planned work time from transaction PA30.

Now, let us see how this can be achieved using ABAP programming.


A standard Function module ‘CATS_GET_TARGET_HOURS’ can be used for this.

This function module would provide us with the information below:

  1. Date
  2. Hours
  3. Shift Start Time
  4. Shift End Time


The essential inputs to this FM are:

  1. Personnel Number
  2. Start Date
  3. End Date

*Call the function module to get current day’s target hours


CALL FUNCTION 'CATS_GET_TARGET_HOURS'
EXPORTING
PERNR                    = P_V_PERNR
BEGDA                    = SY-DATUM
ENDDA                    = SY-DATUM                                  
TABLES
TARGET_HOURS             = IT_HRS_PER_DAY
EXCEPTIONS
PERNR_NOT_FOUND          =
1
TOO_MANY_DAYS            =
2
ERROR_IN_SAP_ENHANCEMENT =
3
OTHERS                   = 4.
IF SY-SUBRC EQ 0.
  
READ TABLE IT_HRS_PER_DAY INTO WA_HRS_PER_DAY INDEX 1.
ENDIF.

Output :

     1. Date                 WA_HRS_PER_DAY-DATE

     2. Hours                    WA_HRS_PER_DAY-STDAZ

     3. Shift Start Time         WA_HRS_PER_DAY-SOBEG

     4. Shift End Time             WA_HRS_PER_DAY-SOEND

If the current day is a working day according to the Planned Work Schedule ( above figure in step 5), then the output from Function module would give us all the necessary information. If the current day (sy-datum) is a day OFF for the Employee, then the FM would not return us the information.


This code will retrieve the Start and End time of a shift in all cases.

* Get plant, Personnel subarea and End date

SELECT WERKS BTRTL ENDDA INTO TABLE IT_PA0001

FROM PA0001

WHERE PERNR = P_V_PERNR.

IF SY-SUBRC EQ 0.

* Get the latest work schedule

    SORT IT_PA0001 BY ENDDA DESCENDING.

    READ TABLE IT_PA0001 INTO WA_PA0001 INDEX 1.

    IF SY-SUBRC EQ 0.

* Get personnel subarea grouping for Work Schedules

        SELECT SINGLE MOSID INTO V_MOSID

        FROM T001P

        WHERE WERKS = WA_PA001-WERKS

        AND BTRTL   = WA_PA001-BTRTL.

        IF SY-SUBRC EQ 0.

* Get work schedule rule

            SELECT SINGLE SCHKZ INTO V_SCHKZ

            FROM PA0007

            WHERE PERNR = P_V_PERNR

            AND ENDDA = WA_PA001-ENDDA.

            IF SY-SUBRC EQ 0.

* Get the start and end time

               PERFORM GET_WORKSCHEDULE_RULE

  USING V_SCHKZ V_MOSID

   CHANGING V_START_TIME V_END_TIME.

            ENDIF.


         ENDIF.


       ENDIF.

ENDIF.

The logic in the highlighted subroutine PERFORM GET_WORKSCHEDULE_RULE :

* Get the Work Schedule Rule

SELECT * FROM T508A INTO TABLE LT_T508A
WHERE SCHKZ EQ V_SCHKZ
AND   MOSID EQ V_MOSID
ORDER BY ENDDA DESCENDING.
IF SY-SUBRC EQ 0.
  
READ TABLE LT_T508A INTO WA_T508A INDEX 1.


* Get the Daily Work Schedule Rule

      IF SY-SUBRC EQ 0.
     
SELECT SINGLE MOTPR
      ZMODN
      TPRG1
      TPRG2
      TPRG3
      TPRG4
      TPRG5
      TPRG6
      TPRG7
     
FROM T551A INTO (LV_MOTPR1, LV_ZMODN1,
      LV_TPRG1,
      LV_TPRG2, LV_TPRG3, LV_TPRG4,
      LV_TPRG5, LV_TPRG6, LV_TPRG7)
     
WHERE MOTPR EQ V_MOSID
     
AND   ZMODN EQ
WA_T508A-ZMODN.

      IF SY-SUBRC EQ 0.
 

* Check if the day is a week OFF for the given Employee

                 IF LV_TPRG1 <> 'OFF'.
           WA_TPROG = LV_TPRG1.
        
ENDIF.
        
IF LV_TPRG2 <> 'OFF'.
           WA_TPROG = LV_TPRG2.
        
ENDIF.
        
IF LV_TPRG3 <> 'OFF'.
           WA_TPROG = LV_TPRG3.
        
ENDIF.
        
IF LV_TPRG4 <> 'OFF'.
           WA_TPROG = LV_TPRG4.
        
ENDIF.
        
IF LV_TPRG5 <> 'OFF'.
           WA_TPROG = LV_TPRG5.
        ENDIF.
        
IF LV_TPRG6 <> 'OFF'.
           WA_TPROG = LV_TPRG6.
        
ENDIF.
        
IF LV_TPRG7 <> 'OFF'.
           WA_TPROG = LV_TPRG7.
        
ENDIF.

 

* Get the Planned Work Shift – Start time and End time
        
SELECT SINGLE SOBEG SOEND
        
FROM T550A INTO (LV_SOBEG, LV_SOEND)
        
WHERE MOTPR EQ  LV_MOTPR1
        
AND   TPROG EQ  WA_TPROG
        
AND   ENDDA EQ  WA_T508A-ENDDA.


        
IF SY-SUBRC EQ 0.
            P_V_START = LV_SOBEG.
            P_V_END   = LV_SOEND.
        
ELSE.
            P_V_START =
'000000'.
            P_V_END   =
'000000'.
        
ENDIF.

    
ELSE.
         P_V_START =
'000000'.
         P_V_END   =
'000000'.                                  


    ENDIF.


   ENDIF.

ENDIF.

Here we go! The variable P_V_START represents the Employee’s Planned Shift Start Time and P_V_END represents the Employee’s Planned Shift End Time.



1 Comment