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

Date sustraction in selection-screen

Former Member
0 Likes
1,757

hi all,

i have two date fields BLDAT and BLDAT1 in selection-screen and i need if user do not give the input date in second field then it will take one month before date automatically in BLDAT1-LOW and BLDAT1-HIGH. can anyone tell me that how wud i do?

regards saurabh.

Edited by: saurabh srivastava on Dec 17, 2008 5:54 AM

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,698

Hello Saurabh,

You can try the method SUBTRACT_MONTHS_FROM_DATE of the Class CL_HRPAD_DATE_COMPUTATIONS.



AT SELECTION-SCREEN OUTPUT.

DATA:
  l_v_month TYPE i VALUE '1',
  l_v_date1 TYPE datum,
  l_v_date2 TYPE datum.

IF BLDAT1-LOW IS INITIAL. 

IF BLDAT-LOW IS NOT INITIAL.
      TRY.
          CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = BLDAT-LOW
              months     = l_v_month
            RECEIVING
              date       = l_v_date1.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.
ENDIF.

IF BLDAT-HIGH IS NOT INITIAL.
      TRY.
          CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = BLDAT-HIGH
              months     = l_v_month
            RECEIVING
              date       = l_v_date2.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.
ENDIF.

ENDIF.

    IF l_v_date1 IS NOT INITIAL OR
       l_v_date2 IS NOT INITIAL.
      bldat1-sign = 'I'.
      bldat1-option = 'BT'.
      bldat1-low = l_v_date1.
      bldat1-high = l_v_date2.
      APPEND bldat1.
    ENDIF.

Hope this is clear.

BR,

Suhas

Edited by: Suhas Saha on Dec 17, 2008 6:11 AM

Edited by: Suhas Saha on Dec 17, 2008 6:13 AM

Hello Saurabh,

You can try the method SUBTRACT_MONTHS_FROM_DATE of the Class CL_HRPAD_DATE_COMPUTATIONS.



AT SELECTION-SCREEN OUTPUT.

DATA:
  l_v_month TYPE i VALUE '1',
  l_v_date1 TYPE datum,
  l_v_date2 TYPE datum.

IF BLDAT1-LOW IS INITIAL. 

IF BLDAT-LOW IS NOT INITIAL.
      TRY.
          CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = BLDAT-LOW
              months     = l_v_month
            RECEIVING
              date       = l_v_date1.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.
ENDIF.

IF BLDAT-HIGH IS NOT INITIAL.
      TRY.
          CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = BLDAT-HIGH
              months     = l_v_month
            RECEIVING
              date       = l_v_date2.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.
ENDIF.

ENDIF.

    IF l_v_date1 IS NOT INITIAL OR
       l_v_date2 IS NOT INITIAL.
      bldat1-sign = 'I'.
      bldat1-option = 'BT'.
      bldat1-low = l_v_date1.
      bldat1-high = l_v_date2.
      APPEND bldat1.
    ENDIF.

Hope this is clear.

BR,

Suhas

Edited by: Suhas Saha on Dec 17, 2008 6:11 AM

Edited by: Suhas Saha on Dec 17, 2008 6:13 AM

12 REPLIES 12
Read only

Former Member
0 Likes
1,698

at selection-screen output.

call below f.m

it erdat ne ' '.

CCM_GO_BACK_MONTHS

EXPORTING

CURRDATE = erdat

BACKMONTHS = '001'

imPORTING

NEWDATE = erdat1.

endif.

Read only

GauthamV
Active Contributor
0 Likes
1,698

use this logic.


tables : bkpf.
select-options : bldat1 for bkpf-bldat.

if bldat1-low is initial.

data: d1 like sy-datum,
        d2 like sy-datum.
  d2 = sy-datum.
  d2+6(2) = '01'.
  d2 = d2 - 1. "prev mnth last date
  d1 = d2.
  d1+6(2) = '01'. "prev mnth start date
bldat1-low = d1.
bldat1-high = d2.
append bldat1.
clear bldat1.

write: bldat1-low,bldat1-high.

Read only

Former Member
0 Likes
1,698

hi gautam, jayshre, shan,

thanx for reply, actually i don want to subtract the date from sy-datum, i want to subtract the date from BLDAT-LOW and BLDAT-HIGH.

suppose i have : BLDAT-LOW = '20080501'.

BLDAT-HIGH = '20080531'

then i need in BLDAT1-LOW = '20080401'

BLDAT1-HIGH = '20080430'. it must be follow for every month like FEB and all ending with 30, 31, 28, 29..days. please tell me.

regards saurabh.

Read only

GauthamV
Active Contributor
0 Likes
1,698

If i am not wrong this is your requirement.


tables : bkpf.
select-options : bldat1 for bkpf-bldat.

data: d1 like sy-datum,
        d2 like sy-datum.


if bldat1-low is not initial.

  d2 = bldat1-low.
  d2+6(2) = '01'.
  d2 = d2 - 1. "prev mnth last date
  d1 = d2.
  d1+6(2) = '01'. "prev mnth start date
bldat1-low = d1.
bldat1-high = d2.
append bldat1.
endif.

write: bldat1-low,bldat1-high.

Read only

Former Member
0 Likes
1,698

hi,

can use this code .

DATA: DATE(10),

DATE1(10).

as per your requirement date-low is 01.04.2008 and high id 30.04.2008 right

you want to get last month values into DATE1.

so use this function module to get last date of previous month.

'JVA_LAST_DATE_OF_MONTH'. this function module input is just pass the value od date like this date-low(6), the result is 200804 so what my function module will do it will retrive last month(what ever comes comes from date field). here you will get DATE1-HIGH value like 31.03.2008(Example), for DATE1-LOW value you can caluculate directly from DATE field.

its start from 01.03(04-01).2008.

Regards,

Arjun.

Read only

Former Member
0 Likes
1,698

hi gautam,

thanks! its a gud answer as well as gud logic. now issue has been resolved.

regards saurabh.

Read only

Former Member
0 Likes
1,698

Hi,

Use this FM :

CALL FUNCTION 'CCM_GO_BACK_MONTHS'

EXPORTING

CURRDATE = SY-DATUM

BACKMONTHS = '1'

IMPORTING

NEWDATE = lv_date.

Hope this will help u.

Thanks,

Jayshree.

Read only

Former Member
0 Likes
1,698

hi,

i am unable to understand your requirement like you aresaying second field is not filled by user it as to take one month back date means from current month to one month back or what?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,699

Hello Saurabh,

You can try the method SUBTRACT_MONTHS_FROM_DATE of the Class CL_HRPAD_DATE_COMPUTATIONS.



AT SELECTION-SCREEN OUTPUT.

DATA:
  l_v_month TYPE i VALUE '1',
  l_v_date1 TYPE datum,
  l_v_date2 TYPE datum.

IF BLDAT1-LOW IS INITIAL. 

IF BLDAT-LOW IS NOT INITIAL.
      TRY.
          CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = BLDAT-LOW
              months     = l_v_month
            RECEIVING
              date       = l_v_date1.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.
ENDIF.

IF BLDAT-HIGH IS NOT INITIAL.
      TRY.
          CALL METHOD CL_HRPAD_DATE_COMPUTATIONS=>SUBTRACT_MONTHS_FROM_DATE
            EXPORTING
              start_date = BLDAT-HIGH
              months     = l_v_month
            RECEIVING
              date       = l_v_date2.
        CATCH cx_hrpa_violated_postcondition .
      ENDTRY.
ENDIF.

ENDIF.

    IF l_v_date1 IS NOT INITIAL OR
       l_v_date2 IS NOT INITIAL.
      bldat1-sign = 'I'.
      bldat1-option = 'BT'.
      bldat1-low = l_v_date1.
      bldat1-high = l_v_date2.
      APPEND bldat1.
    ENDIF.

Hope this is clear.

BR,

Suhas

Edited by: Suhas Saha on Dec 17, 2008 6:11 AM

Edited by: Suhas Saha on Dec 17, 2008 6:13 AM

Read only

Former Member
0 Likes
1,698

hi suhas and ilesh,

thanx for reply, suggession given by you are working only for months ending with '31'. if i put the date in BLDAT-LOW = '20080201' and BLDAT-HIGH = '20080229' then its returning the value BLDAT1-LOW = '20080101' and BLDAT1-HIGH = '20080129' which is wrong it must be BLDAT1-HIGH = '20080131' .

same problem for months ending with '30'. please suggest me accordingly.

regards saurabh.

Read only

GauthamV
Active Contributor
0 Likes
1,698

hi,

Did you check my prevoius reply ?

It works the same as you mentioned.

give BLDAT-LOW = '20080201' and BLDAT-HIGH = '20080229'

and you will get BLDAT-LOW = '20080101' and BLDAT-HIGH = '20080131' .

Read only

Former Member
0 Likes
1,698

Hi saurabh srivastava,

Check out below Code...

Run the program..

Fill the value for S_BLDAT-LOW and HIGH.

and then execute with keeping S_BUDAT blank...

and check out result.

SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-001.

TABLES : BKPF.

SELECT-OPTIONS : S_BLDAT FOR BKPF-BLDAT NO-EXTENSION,
                 S_BUDAT FOR BKPF-BUDAT NO-EXTENSION. "

SELECTION-SCREEN END OF BLOCK A.

AT SELECTION-SCREEN.

  DATA : DATE1 TYPE SY-DATUM,
        DATE2 TYPE SY-DATUM.

  LOOP AT SCREEN.
    IF S_BUDAT[] IS INITIAL.
      CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
        EXPORTING
          DATE      = S_BLDAT-LOW
          DAYS      = 00
          MONTHS    = 01
          SIGNUM    = '-'
          YEARS     = 00
        IMPORTING
          CALC_DATE = DATE1.

      CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
        EXPORTING
          DATE      = S_BLDAT-HIGH
          DAYS      = 00
          MONTHS    = 01
          SIGNUM    = '-'
          YEARS     = 00
        IMPORTING
          CALC_DATE = DATE2.

      S_BUDAT-LOW = DATE1.
      S_BUDAT-HIGH = DATE2.
      APPEND S_BUDAT.
      CLEAR S_BUDAT.

    ENDIF.
  ENDLOOP.

Still modify the code as per your exact req... this will be the logic for ur req...

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7