Application Development and Automation 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: 
Read only

how to get week ?

Former Member
0 Likes
1,828

Hi,everybody,

now I have a question,Do you know how to get week number in a month.Is there a FM which can get the information in sap.

for example, In July 2006,there are include 27,28,29,30 weeks.

Best Regards

samuel

Hi,everybody,

now I have a question,Do you know how to get week number in a month.Is there a FM which can get the information in sap.

for example, In July 2006,there are include 27,28,29,30 weeks.

Best Regards

samuel

10 REPLIES 10
Read only

Former Member
0 Likes
1,590

Make use of the FM DATE_GET_WEEK

Reward the point and close the thread.

Read only

Former Member
0 Likes
1,590

Hi

Try DATE_GET_WEEK and NEXT_WEEK

Max

Read only

Former Member
0 Likes
1,590

i think there is not such type of fm..

but u can get no of week per month and now u can make logic for ur requirment...

The function module <b>DATE_GET_WEEK</b> gives the week no in that year in 2 digits. By using this function module twice , you can find out the Week in the month.(i.e use FM to calculate week no for month starting date, and use it second time to calculate the week no of the date,and then findout the difference).

Read only

Former Member
0 Likes
1,590

Hi,

See the functions in the group SCAL.

-Kiran

Read only

Former Member
0 Likes
1,590

Hi Liu,

U can use this FM : DATE_GET_WEEK

If it helps, please do reward.

Read only

Former Member
0 Likes
1,590

Hai

Check the following Code

Data : datum like prowf-ertag,

DATA: week LIKE scal-week.

CALL FUNCTION 'DATE_GET_WEEK'

EXPORTING

date = datum

IMPORTING

week = week

EXCEPTIONS

date_invalid = 1

OTHERS = 2.

write : week.

Thanks & regards

Sreeni

Read only

Former Member
0 Likes
1,590

Hi Liu,

Use FM GET_WEEK_INFO_BASED_ON_DATE

or FM HR_GBSSP_GET_WEEK_DATES

Copy the below code:-

DATA: lv_date TYPE datum,

lv_week_no TYPE p08_weekno,

lv_week1 TYPE char2 ,

lv_week2 TYPE char2 ,

lv_week3 TYPE char2 ,

lv_week4 TYPE char2 .

lv_date = '20060701'.

CALL FUNCTION 'HR_GBSSP_GET_WEEK_DATES'

EXPORTING

p_pdate = lv_date

IMPORTING

  • P_SUNDAY =

  • P_SATURDAY =

  • P_DAY_IN_WEEK =

p_week_no = lv_week_no.

lv_week1 = lv_week_no+4(2).

lv_week2 = lv_week1 + 1.

lv_week3 = lv_week2 + 1.

lv_week4 = lv_week3 + 1.

WRITE:/ 'Week 1 = ', lv_week1.

WRITE:/ 'Week 2 = ', lv_week2.

WRITE:/ 'Week 3 = ', lv_week3.

WRITE:/ 'Week 4 = ', lv_week4.

Regards,

Sameena

Read only

Former Member
0 Likes
1,590

Hi jxlmh,

1. 01-July-2006 To 31-July-2006

Output will be :

26

27

28

29

30

31

(26th week bcos 1st july - sunday also there)

2. Just copy paste this program,

and it will

DISPLAY THE WEEK NUMBERS

(from the DATE input)

3.

report abc.

type-pools : TSTR.

*----


  • DATA

*----


data : weeks type TSTR_GENSEGYEARTAB.

data : weekswa type line of TSTR_GENSEGYEARTAB.

data : TTSTR like TTSTR .

data : year type TSTR_YEARTAB.

data : yearwa type line of TSTR_YEARTAB.

data : GENSEGTAB TYPE TSTR_GENSEGTAB.

data : GENwa TYPE line of TSTR_GENSEGTAB.

data : tabix type i.

.

*----


  • SELECTION SCREEN

*----


select-options : mydate for sy-datum DEFAULT '20060701' TO '20060731'.

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

yearwa = mydate-low(4).

append yearwa to year.

CALL FUNCTION 'TSTR_PERIODS_WEEKS'

EXPORTING

IT_YEARTAB = year

IS_TTSTR = TTSTR

IMPORTING

ET_GENSEGTAB = weeks

EXCEPTIONS

ERROR = 1

OTHERS = 2

.

read table weeks into weekswa index 1.

GENSEGTAB = weekswa-GENSEGTAB.

loop at gensegtab into genwa.

tabix = sy-tabix.

if ( genwa-begin_date >= MYDATE-LOW and genwa-begin_date <= MYDATE-HIGH

)

or

( genwa-end_date >= MYDATE-LOW and genwa-end_date <= MYDATE-HIGH )

.

write 😕 sy-tabix.

endif.

endloop.

break-point.

regards,

amit m.

Read only

0 Likes
1,590

Hi,amit,

1. 01-July-2006 To 31-July-2006

Output will be :

26

27

28

29

30

31

but actually, the '31' does not belong to JULY, It belongs to August.Do you find the problem?

thanks your reply

Best Regards

Samuel Liu

Read only

0 Likes
1,590

Hi again,

1. 31st july belongs to august !

(i did not fully understand that)

2. 31st july, comes on monday,

and that week number is 31.

(for that matter, 1st-aug-2006 till 5th-aug-2006,

will also fall in 31st week

)

regards,

amit m.