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

ABAP code

Former Member
0 Likes
1,101

Hi Gurus,

My 'IF' condition should execute in first saturday after 10th of every month. So can any one tell me the code for the below logic to put in 'IF':

"First saturday after 10th of every month"

Thanks & Regards,

Balaji.S

12 REPLIES 12
Read only

Former Member
0 Likes
1,065

Huh?

Read only

Former Member
0 Likes
1,065

Hi,

Use this code:

IF sy-datum+6(2) GE 10.

Write your code here.

ENDIF.

Should work.

Read only

0 Likes
1,065

>

> Hi,

> Use this code:

>

> IF sy-datum+6(2) GE 10.

>

> Write your code here.

>

> ENDIF.

>

> Should work.

And what happens if we get to the second saturday of the month?

Read only

0 Likes
1,065

DATA: v_week TYPE P.

IF sy-datum+6(2) BETWEEN 10 AND 17. "first week after 10th

*--To find out day of the week

CALL FUNCTION 'DAY_IN_WEEK'

EXPORTING

DATUM = sy-datum

IMPORTING

WOTNR = v_week.

IF v_week = 6. "day 6 of the week is Saturday

Write your code here. (whatever needs to be executed on the Saturday after 10th)

ENDIF.

ENDIF.

Edited by: abapfreak on Oct 4, 2010 3:12 PM

Edited by: abapfreak on Oct 4, 2010 3:15 PM

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,065

Well do you want to schedule your program/txn execution for 10th of every month ???

Read only

0 Likes
1,065

>

> Well do you want to schedule your program/txn execution for 10th of every month ???

I think only his IF...ENDIF should run on the first saturday after the 10th of a month.

Read only

0 Likes
1,065

you are right .. but my point was whether on first saturday after the 10th of a month the report should be executed or not ? If this is the question then this can be achieved easily via job scheduling .

Else, why such a condition is needed ??

Read only

0 Likes
1,065

Hi,

Here is a solution if ur report run every day,

First u create a table , lets say itab1 , in se11 withe 3 column 'year' , 'Month' and 'flag.

Then in the report,

data : l_year(4),

l_mont(2),

l-day(2).

data : ls_itab1 like itab.

DATA: ld_day TYPE c.

l-year = sy-datum(4).

l-month.................

.................

Select single flag from itab1 into ls_itab1 where year = l-year and month = l-month.

if sy-subrc eq 0 and ls_itab1-flag is initial.

if l-day ge 10 .

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

date = sy-datum

IMPORTING

weekday = ld_day.

if ld_day. eq 'SATURDAY'.


ur code here

update itab1 set flag = 'X' where month es lmonth...................'

endif.

endif.

endif.

Hope this helps.

Read only

Former Member
0 Likes
1,065

Hi Gurus,

IF (first saturday after the 10th of a month)

..

..

..

..

..

ENDIF

Here in order to put in 'IF', i need the code for that logic.

Regards,

Balaji.S

Read only

Former Member
0 Likes
1,065

Hi,

Use FM "/OSP/GETDATE_WEEKDAY".

Pass IV_DAY_OF_WEEK as 6 i.e. 6th day of week which is SATURDAY
Pass IV_START_DATE as 11.current month.currenty year for oct. it would be 11.10.2010
time default is ok...

with this you would get the date of "First saturday after 10th of every month"

Try following values in SE37

IV_DAY_OF_WEEK  = 6
IV_START_DATE = 11.10.2010
Time ... let it be default time

Return value is : 16.10.2010 => which is a saturday

2nd Example

IV_DAY_OF_WEEK  = 6
IV_START_DATE = 11.11.2010
Time ... let it be default time

Return value is : 13.11.2010 => which is a saturday

CALL FUNCTION '/OSP/GETDATE_WEEKDAY'
 EXPORTING
   IV_DAY_OF_WEEK            = 6
   IV_START_DATE             = lv_date
   IV_TIME                   = '235959'
 IMPORTING
   EV_DATE_DAY_OF_WEEK       = lv_final
 EXCEPTIONS
   INVALID_DAY               = 1
   OTHERS                    = 2
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

if lv_final = sy-datum. " Today is the 1st saturday after 10th of that month
then..... do this...
else.
do this...
endif.

lv_final will have the date of 1st saturday after 10th of that month.

Thanks,

Best regards,

Prashant

Read only

Former Member
0 Likes
1,065

I have written the program... In my program for particular condition alone should execute 'first saturday after 10th of every month'.

No Jos shoul be scheduled.

Read only

Former Member
0 Likes
1,065

Moderator message - Please do not ask or answer basic date questions - thread locked and all points unassigned Rob