Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can we get week no from the date or check if the date is in even week of the month

former_member539645
Participant
0 Kudos
377

Hi All,

I have one requirement, where I have to add one restriction on Delivery date that the date should be in even week (i.e. 2nd & 4th Week of the month).

Is there any FM available in SAP where we can provide date as input & it will return week number of the month.

Thanks & Regards,

1 ACCEPTED SOLUTION

former_member539645
Participant
0 Kudos
263

I Used below logic in my code, if anyone has better & short solution for this, please let me know.

DATA: week1 TYPE fti_disp_2,
week11(2) TYPE c,
week2 TYPE fti_disp_2,
week22(2) TYPE c.

DATA: present_week TYPE i,
date TYPE sy-datum.

PARAMETERS: p_date TYPE sy-datum.


START-OF-SELECTION.

date = p_date.
date+6(2) = '01'. "First day of this month
date = date - 1. "last day of last month

CALL FUNCTION 'DISP_WEEK_GET'
EXPORTING
i_datum = date
IMPORTING
e_week = week1. " Last Month's last Week no

week11 = week1+4(2)."Get Only Week from YYYYWW

CALL FUNCTION 'DISP_WEEK_GET'
EXPORTING
i_datum = p_date
IMPORTING
e_week = week2."Current Week No

week22 = week2+4(2). "Get Only Week from YYYYWW

present_week = (week22 - week11) + 1.


WRITE present_week.
6 REPLIES 6

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos
263

Yes, there is a function module in SAP ABAP that allows you to provide a date as input and return the week number of the month. The name of the function module is WEEK_OF_MONTH.

0 Kudos
263

This FM is not available in the system

Sandra_Rossi
Active Contributor
0 Kudos
263

Which week day should a week start? i.e. if month starts on Wednesday, should that day be part of the "first week", or should the first week start on next Sunday or Monday, or other rule?

former_member539645
Participant
0 Kudos
263

Any start day is start of week

former_member539645
Participant
0 Kudos
264

I Used below logic in my code, if anyone has better & short solution for this, please let me know.

DATA: week1 TYPE fti_disp_2,
week11(2) TYPE c,
week2 TYPE fti_disp_2,
week22(2) TYPE c.

DATA: present_week TYPE i,
date TYPE sy-datum.

PARAMETERS: p_date TYPE sy-datum.


START-OF-SELECTION.

date = p_date.
date+6(2) = '01'. "First day of this month
date = date - 1. "last day of last month

CALL FUNCTION 'DISP_WEEK_GET'
EXPORTING
i_datum = date
IMPORTING
e_week = week1. " Last Month's last Week no

week11 = week1+4(2)."Get Only Week from YYYYWW

CALL FUNCTION 'DISP_WEEK_GET'
EXPORTING
i_datum = p_date
IMPORTING
e_week = week2."Current Week No

week22 = week2+4(2). "Get Only Week from YYYYWW

present_week = (week22 - week11) + 1.


WRITE present_week.

Sandra_Rossi
Active Contributor
0 Kudos
263

What do you consider to be the first day of 2nd week in December 2022 ?

What do you consider to be the first day of 4th week in December 2022 ?