{"id":1364,"date":"2015-03-30T08:52:27","date_gmt":"2015-03-30T07:52:27","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1364"},"modified":"2015-03-30T09:14:33","modified_gmt":"2015-03-30T08:14:33","slug":"abap-add-working-days-to-a-date-using-factory-calendar","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1364","title":{"rendered":"ABAP &#8211; Add working days to a date using Factory Calendar"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"358\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=358\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" data-orig-size=\"44,50\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Picasa&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1365690880&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"SAP\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" class=\" size-full wp-image-358 alignleft\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" alt=\"SAP\" width=\"44\" height=\"50\" \/>This article contains a code snippet showing how to add given number of <em>WORKING <\/em>days to<em> a <\/em>given starting date. To get the correct factory calendar, you have to search in Plant data.<!--more--><\/p>\n<h2>Get factory calendar ID<\/h2>\n<pre lang=\"abap\">FORM get_calendar_id USING    iv_werks       TYPE werks_d\r\n                     CHANGING cv_calendar_id TYPE fabkl.\r\n\r\n  SELECT SINGLE fabkl \r\n    INTO cv_calendar_id \r\n    FROM t001w \r\n    WHERE werks = iv_werks.\r\nENDFORM.<\/pre>\n<h2>Add working days<\/h2>\n<p>Now we have the factory calendar ID which we use to<\/p>\n<ol>\n<li>Covert current date to factory calendar date<\/li>\n<li>Add given number of days (ignoring the non-working days)<\/li>\n<li>Convert new factory date to normal date<\/li>\n<\/ol>\n<pre lang=\"abap\">FORM add_working_days USING iv_num_days    TYPE i\r\n                            iv_calendar_id TYPE fabkl\r\n                      CHANGING cv_date     TYPE sy-datum.\r\n\r\nDATA: lv_factorydate     TYPE scal-facdate,\r\n      lv_new_factorydate TYPE sy-datum.\r\n\r\n* 1. Convert date to factory date. \r\n  CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'\r\n    EXPORTING\r\n      date                = cv_date \"Starting date\r\n      factory_calendar_id = iv_calendar_id \"Plant factory calendar id\r\n    IMPORTING\r\n      factorydate         = lv_factorydate. \"Factory calender date\r\n\r\n* 2. Add [N] number of days to factory date\r\n  ADD iv_num_days TO lv_factorydate.\r\n\r\n* 3. Convert factory date back to actual date\r\n  CALL FUNCTION 'FACTORYDATE_CONVERT_TO_DATE'\r\n    EXPORTING\r\n      factorydate         = lv_factorydate\r\n      factory_calendar_id = iv_calendar_id\r\n    IMPORTING\r\n      date                = lv_new_factorydate.\r\n* Assign the new factory date to normal date format\r\n  cv_date = lv_new_factorydate.\r\nENDFORM<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This article contains a code snippet showing how to add given number of WORKING days to a given starting date. To get the correct factory calendar, you have to search in Plant data.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"ABAP - Add working days to a date using Factory Calendar","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,9],"tags":[446,417,419,418,420],"class_list":["post-1364","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-date_convert_to_factorydate","tag-factory-calendar","tag-factorydate_convert_to_date","tag-t001w"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-m0","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1364"}],"version-history":[{"count":3,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1364\/revisions"}],"predecessor-version":[{"id":1367,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1364\/revisions\/1367"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}