Retrieve SAP personal work schedule

The following code demonstrates how to retrieve personnel work schedule, the example below uses the personnel work schedule to add n number of WORKING days to a particular date. Simply add the below FORM into you code and call it using the usual PERFORM command:

PERFORM add_working_days_workschedule USING ld_numdays CHANGING gd_date.


*&---------------------------------------------------------------------*
*&      Form  ADD_WORKING_DAYS_WORKSCHEDULE
*&---------------------------------------------------------------------*
*       Add n number of working days to date, using employees work
*       schedule to calculate working days
*----------------------------------------------------------------------*
*      <-- P_DAYS     Number of days to add
*      <-- P_PAYDATE  Starting date
*----------------------------------------------------------------------*
FORM add_working_days_workschedule USING p_days
                       CHANGING p_paydate TYPE sy-datum.
  DATA: ld_count  TYPE i,
        ld_memid(30) TYPE c.
* Copied from rptpsh10
  DATA: psp LIKE ptpsp      OCCURS 0 WITH HEADER LINE.
  DATA: BEGIN OF hd OCCURS 0,
        pernr LIKE pernr-pernr,
        name(40),
        inv_menge LIKE pakey-seqnr,      "ALV copies only 20 columns!
        moabw LIKE t001p-moabw,                               "
        mover LIKE t001p-mover,          "ALV copies only 20 columns!
        datum LIKE psp-datum,
        kurzt LIKE t246-kurzt,
        tprog LIKE psp-tprog,
        varia LIKE psp-varia,
         ttext LIKE t550s-ttext,
        vtart LIKE p2003-vtart,
         vtext LIKE t556t-vtext,
        motpr LIKE psp-motpr,
        sobeg(8),
        soend(8),
        stdaz LIKE ptev_rep_h-stdaz,
        ftkla LIKE psp-ftkla,
        tagty LIKE psp-tagty,
         tatxt LIKE t553t-langt,
        zmodn LIKE psp-zmodn,
         ptext LIKE t551s-ztext,
        mofid LIKE t508a-mofid,
         ftext LIKE thoct-ltext,
        menge LIKE ptev_rep_h-itanz,
        alvmarker TYPE rp_xfeld,
        END OF hd.
  ld_count = p_days.
  CONCATENATE sy-uname sy-uzeit INTO ld_memid.
* Z version of 'personal work schedule' report, created to export data
* to memory rather than display it on screen
  SUBMIT zrptpsh10_list_to_memory    WITH pnppernr EQ pernr-pernr
                     WITH pnpbegda EQ p2001-begda
                     WITH pnpendda EQ p2001-endda
                     WITH pnpbegps EQ p2001-begda
                     WITH pnpendps EQ p2001-endda
                     WITH pnptimed EQ ' '
                     WITH rdclust  EQ 'X'
                     WITH p_memid  EQ ld_memid
                     AND  RETURN.
* import datd from memoory
  IMPORT hd FROM MEMORY ID ld_memid.
* Check if days are working days
  WHILE ld_count GT 0.
    READ TABLE hd WITH KEY datum = p_paydate.
    IF hd-tprog NE 'FREE'.  "FREE equals non working day
      p_paydate = p_paydate + 1.
      ld_count = ld_count - 1.
    ELSE.
      p_paydate = p_paydate + 1.
    ENDIF.
  ENDWHILE.
ENDFORM.                    " ADD_WORKING_DAYS_WORKSCHEDULE

Related Articles

Payroll results (ABAP)
Display organisational structure
SAP HR infotypes
GET PERNR LAST and GET PAYROL
Retrieve multiple contracts for HR personnel and include in locical database selection/report
SAP HR Development help - ABAP code and information on various areas of HR development in SAP
ABAP code to retrieve Absence type text(AWART) from SAP table
ABAP to retrieve country grouping for personnel with SAP
Deleting an SAP HR Infotype
SAP HR Infotype selection
Creating a New SAP Infotype using transaction PM01 and PPCI
Retrieve comment texts from cluster table for SAP infotype 19
SAP Function module to call ABAP report from managers desktop(MDT)
SAP User Exits to Add functionality to the PBO and PAI of HR infotypes
Create SAP HR report category for logical database selection within ABAP report
SAP HR Selection Screen example
SAP HR Infotype Development Information, ABP and step by step instructions
Enhancing an Infotype - Add, change or modify fields of and SAP infotype
SAP Personal absence calander for SSP/SMP
ABAP Program to retrieve and display sickpay(SSP, SMP etc) with SAP
SAP Personal absence calendar (NCALE) using transaction PC00_M08_CLPC
Accessing NCALE data via the Results Log when running a payroll
Program to retrieve sickpay values
Processing the SAP HR Organisation unit
SAP HR Payroll results ( transaction code: PC_PAYRESULT)
Payroll results (ABAP)
Display Payroll results using SAP transaction PC_PAYRESULT