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

get weekday number having date

Former Member
0 Likes
1,316

Hi SAPpers I have a code

DATA: dayattr TYPE casdayattr OCCURS 0 WITH HEADER LINE.
DATA: hcal LIKE scal-hcalid, fcal LIKE scal-fcalid.

fcal = 'CZ'.
hcal = 'CS'.

CALL FUNCTION 'DAY_ATTRIBUTES_GET'
  EXPORTING
    factory_calendar = fcal
    holiday_calendar = hcal
    date_from        = '20071025'
    language         = sy-langu
  TABLES
    day_attributes   = dayattr.

WRITE: / dayattr-weekday.

I need to get weekday-number, but no matter which date I give to the function (date_from) it returns '1'. 20071025 is thursday, so I assume that dayattr-weekday should be '4' (or '5' if sunday is the first day). What am I doing wrong? Greetings

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,009

hi Piotr,

try to fill the date_to parameters of the FM as well.

ec

Hi SAPpers I have a code

DATA: dayattr TYPE casdayattr OCCURS 0 WITH HEADER LINE.
DATA: hcal LIKE scal-hcalid, fcal LIKE scal-fcalid.

fcal = 'CZ'.
hcal = 'CS'.

CALL FUNCTION 'DAY_ATTRIBUTES_GET'
  EXPORTING
    factory_calendar = fcal
    holiday_calendar = hcal
    date_from        = '20071025'
    language         = sy-langu
  TABLES
    day_attributes   = dayattr.

WRITE: / dayattr-weekday.

I need to get weekday-number, but no matter which date I give to the function (date_from) it returns '1'. 20071025 is thursday, so I assume that dayattr-weekday should be '4' (or '5' if sunday is the first day). What am I doing wrong? Greetings

6 REPLIES 6
Read only

Former Member
0 Likes
1,009

Hi,

Try this DATE_TO_DAY.

Reward if this helps,

Satish

Read only

Former Member
0 Likes
1,009

Piotr,

The FM raises an exception if you dont give a "<b>date_to</b>". Instead try this.

DATA: dayattr TYPE casdayattr OCCURS 0 WITH HEADER LINE.
DATA: hcal LIKE scal-hcalid, fcal LIKE scal-fcalid.
 
fcal = 'CZ'.
hcal = 'CS'.
 
CALL FUNCTION 'DAY_ATTRIBUTES_GET'
  EXPORTING
    factory_calendar = fcal
    holiday_calendar = hcal
    date_from        = '20071025'
    date_to            ='20071025' 
    language         = sy-langu
  TABLES
    day_attributes   = dayattr.

if sy-subrc = 0.
loop at dayattr.
WRITE: / dayattr-weekday.
endloop.
endif.

Regards

Aneesh.

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,010

hi Piotr,

try to fill the date_to parameters of the FM as well.

ec

Read only

Former Member
0 Likes
1,009

hi,

try like this....


LOOP AT dayattr WHERE date EQ '20071025'.
  WRITE: / dayattr-weekday.
ENDLOOP.


Read only

naimesh_patel
Active Contributor
0 Likes
1,009

It is required to pass the EXPORTING parameter DATE_TO even if there isn't any range of dates.

CALL FUNCTION 'DAY_ATTRIBUTES_GET'
  EXPORTING
    factory_calendar = fcal
    holiday_calendar = hcal
    date_from        = '20071025'
    date_to           = '20071025'  " <<<
    language         = sy-langu
  TABLES
    day_attributes   = dayattr.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
1,009

Hi Piotr,

I am not sure based on what requirement you are using it but i just tested the FM 'DAY_ATTRIBUTES_GET' in SE37 to get proper output i.e to get the day num' for the same i did some small changes as follows:

<b>1.</b> <b>date_from</b> - here don't pass SAP format date instead give as <b>mm/dd/yyyy</b> format. Inorder to convert the SAP date format to mm/dd/yyyy use CONVERSION_EXIT_PDATE_OUTPUT FM i.e.

CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT'

EXPORTING

input = <b>lv_date</b> " say this has your date 20071025

IMPORTING

output = <b>lv_cdate</b>. " This wud have 10/25/2007

<b>2. Also pass date_to value in the FM</b> with same date value

CALL FUNCTION 'DAY_ATTRIBUTES_GET'

EXPORTING

factory_calendar = 'CZ'

holiday_calendar = 'CS'

date_from = <b>lv_cdate</b>

<b>date_to = lv_cdate</b>

language = sy-langu

TABLES

day_attributes = dayattr.

WRITE: / dayattr-weekday. " I had value as 4 here

If this answers your query inform me.

Regards,

Bharathy.