cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Factory calendar / working days handling in ABAP for KU

manuel_seeger
Explorer
1,488

Dear community,

I am writing an implementation of the Update Attributes of Campaign Header BAdI in SAP Marketing Cloud.

I want to add a number of working days to the end date of the campaign. Obviously I have access to the ABAP date type and classes like cl_abap_timestamp_util, however all these only let me add calendar days to a date.

Is there something in ABAP for Marketing Cloud BAdIs that I can use to access a factory calendar? Is there a build in way to add working days to a date, not calendar days? We can configure the factory calendar in Marketing Cloud, but I am looking for a way to access it in a BAdI implementation.

Best regards,

Manuel

Accepted Solutions (1)

Accepted Solutions (1)

former_member226
Employee
Employee

Hi,

As Kunal said you cannot directly access the factory or holiday calendar directly. BUT you can very well make use of standard CDS views to write a selct query based on your need. Few of the CDS views to check could be:

I_PublHolidayCalHolidayDate

I_PublicHolidayDatePerYear

I_PublHolidayCalHolidaysPerYr

I_FactoryCalWorkingDaysPerYr

These views can give you information about if a particular day is a public holiday or not. You need to call them using simple select statement, for example:

select PublicHolidayDate from I_PublHolidayCalHolidayDate into @data(lv_date) where PublicHolidayCalendar = '09'.
endselect.
manuel_seeger
Explorer

Hi Saurabh,

Thanks, that would be the solution to access calendar data from ABAP. We we can write our own calculation logic based on that.

As it looks however a custom BO is likely less work for us (in CH) since cantonal holidays are not delivered with the solution, and entering them manually for 26 cantons in SAP GUI would be too cumbersome.

Answers (1)

Answers (1)

KunalBansal
SAP Champion
SAP Champion

Hello manuel_seeger,

As per knowledge, the feature you're looking for is not possible in SMC.

Please Submit Improvement Request so that your idea could be evaluated by product management.

Refer to KBA 2812948 - How to create Improvement Request for SAP Marketing Cloud

I hope this is helpful. Thank you.

Best Regards,

Kunal Bansal, SAP Marketing Consultant

manuel_seeger
Explorer

Hello Kunal,

Yes, I figured as much. I have already submitted it in https://influence.sap.com/sap/ino/#/idea/253943

As a workaround I build the following library to at least determine if a date is on the weekend, so that we can correct for it. I am sure others will find this helpful.

YY1_CALENDAR=>GET_WEEKDAY_FROM_DATE

" Compute the weekday (1-7) for the given date (gregorian calendar)
"
" This is an implementation of the following formular, but corrected for 
" Monday = first day of the week instead of Sunday
" https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Disparate_variation
"
" weekday:
" Mon	    1
" Tue       2
" Wed       3
" Thu       4
" Fri	    5
" Sat       6
" Sun       7


data d type i.
data y type i.
data m type i.
data mp1 type f value '2.6'.
data mp2 type f value '0.2'.


m = input_date+4(2).
d = input_date+6(2).
y = input_date+0(4).


" Convert the start of the year to Julian calendar ( March 01)
if m < 3.
    y = y - 1.
endif.


" Convert month to Julian (March = 1, Feb = 12)
m = ( ( m + 9 ) mod 12 + 1 ).


weekday = ( ( d + floor( mp1 * m - mp2 ) + y mod 100 + floor( y mod 100 / 4 ) + floor( y / 400 ) - 2 * floor( y / 100 ) - 1 ) mod 7 + 7 ) mod 7 + 1.
KunalBansal
SAP Champion
SAP Champion
0 Likes

Hello manuel_seeger,

Thank you for sharing the workaround, looks good.

Please mark the thread answered. thank you.

best regards,

Kunal

Sandra_Rossi
Active Contributor
0 Likes
Manuel Seeger

ABAP kernel already has an implicit conversion of date to integer which gives the number of days since January 1st of 0001 AD (which includes the specificity of both Julian and Gregorian calendars). So the ABAP algorithm to get the week day is much simplified.

Code to obtain 0 = Saturday, 1 = Sunday, 2 = Monday ... 6 = Friday:

DATA: input_date TYPE d,
      weekday    TYPE i.

weekday = input_date MOD 7.
Code to obtain 1 for Monday ... 7 for Sunday:
weekday = ( ( input_date + 5 ) MOD 7 ) + 1.
manuel_seeger
Explorer
0 Likes

sandra.rossi

Very interesting, I did not know that! Begs the question why there are all these function modules around to calculate weekdays!

The statement does seem to confuse the Marketing Cloud web editor however. I am getting the expected computation, but also an error on the line where I do a datevar mod 7. Still good to know.

Sandra_Rossi
Active Contributor
0 Likes

Manuel Seeger Maybe "datevar" is not a variable of type D, or it doesn't contain a valid value.

Another example:

DATA(weekday) = sy-datum MOD 7.<br>

If running today (Wednesday for me), it returns 4, which corresponds to Wednesday as explained in my previous comment.

manuel_seeger
Explorer

Hi Sandra,

Thanks, it's fine and it works. During runtime I am getting the expected result. Just sometime the web based editor gives me something like "can't lookup index 0 in table" error on the line where I do a date mod 7. It's the editor though, not the code.