THIS PAGE HAS MOVED Add n number of working days to date (using SAP personal work schedule)
Latest info can be found at www.SAPDev.co.uk
Add n number of working days to date (using SAP personal work schedule) information can now be found at the new URL www.sapdev.co.uk/tips/date/date_workschedule.htm. Feel free to continue to view your SAP related data at the current site (www.sapdevelopment.co.uk) but please aware that slight modifications may have been made to improve this information over on www.sapdev.co.uk as well as new and related content being added!


Open all | Close all


Add n number of working days to date (using SAP personal work schedule)


The following ABAP code adds n number of WORKING days to a particular date using the employees work
schedule (tcode pt63) to calculate working day.

Simply add the below ABAP 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