Skip to Content
Author's profile photo Maksim Alyapyshev

How to create calendar day ABAP CDS view with working day flag

Hi, in this brief post I would like to create new customer ABAP CDS view with calendar days and column working day flag. This flag has value 1 if a day is a working day according to factory calendar and has value 0 in opposite case.

Recently Sergey Shablykin published a post about calculation of a difference in working days between two dates, and my current post is complementing it in some respects.

Introduction

  • With S/4HANA we have a standard CDS view I_CalendarDate based on SCAL_TT_DATE table, but there aren’t information about working days. However it could be important to have such flag, for example, when we need to count only working days or filtering something based on working dates only.
  • Information about working days in stored in SAP system in table TFACS. Besides a year we need to define factory calendar (TFACS-IDENT) to select data. So in logic we need to ‘crop’ information about working day from TFACS-MONXX columns.

Step-by-step

1.Create new ABAP CDS view Z_I_CALDAYWD based on table function:

2. Create ABAP class and implement logic in class method:

Notes:

  • We are using variable p_ident to select only needed factory calendar, e.i. ‘RU’ in Russia.
  • We are using column calendar day (scal_tt_date-calendarday), which is number of a day in month, to ‘crop’ work day flag from tfacs-monXX columns.
  • Base tables are not client dependent that’s why we don’t have mandt column and annotate ABAP CDS view respectively.

3. In result we have for factory calendar ‘RU’ and the beggining of 2018 calendar year:

 

Thank you for attention!

Assigned tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Dmitry Kuznetsov
      Dmitry Kuznetsov

      Hey, Maksim, you may want to look at the standard SAP-delivered view on top of table TFACS 😉 it's called P_FctryClndrDate2

      Author's profile photo Christian Winheller
      Christian Winheller

      Thank you so much Dmitry Kuznetsov 🙂

       

      Author's profile photo Former Member
      Former Member

      This is my version without the need of DB tables

       

          DECLARE F1DATE, F2DATE DATE;
          
          F1DATE := :P_YEAR     || '-01-01';
          F2DATE := :P_YEAR + 1 || '-01-01';  
          
          OTAB = SELECT GENERATED_PERIOD_START AS CALDAY,
                 CASE ADD_WORKDAYS( :P_IDENT, GENERATED_PERIOD_START, 0) 
                     WHEN GENERATED_PERIOD_START THEN 1 ELSE 0
                 END AS WDFLAG
                 FROM SERIES_GENERATE_DATE( 'INTERVAL 1 DAY', :F1DATE, :F2DATE);
               
          RETURN :OTAB;

       

      Author's profile photo Thorsten Watzke
      Thorsten Watzke

      Hi,

      that's exactly what I needed, thank you.... 🙂

      best Regards

      Thorsten

      Author's profile photo Dmitry Korostelev
      Dmitry Korostelev

      Hi, watch this CDS  VFCLM_BAM_DDL_DATE3

      Author's profile photo Marcelo Victor De Oliveira Faqueri Dos Anjos
      Marcelo Victor De Oliveira Faqueri Dos Anjos

      Hello,

      This is the CD you needed, and it is standard.
      Thank you very much

      Author's profile photo Christian Winheller
      Christian Winheller

       

      Thank you Dmitry Korostelev for sharing this!

      I like it having not too many columns.