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 logic needed

Former Member
0 Likes
1,359

select-options : mbadat for eban-badat.

I wish to restrict my user on selection screen.

As soon as user enters the date range it should validate that date range should not be greater than one month.

& i wish to restric multiple selection.

Plz guide.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,318

Hello-

data:v_date type sy-datum.

DATA:v_days LIKE p0347-scrdd.

select-options s_date for v_date.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

DATE1 = s_date-high

DATE2 = s_date-low

OUTPUT_FORMAT = '02'

IMPORTING

  • YEARS =

  • MONTHS =

DAYS = v_days

  • EXCEPTIONS

  • INVALID_DATES_SPECIFIED = 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 v_days GT 30.

message 'Date range more than 30 days' type 'I'.

endif.

Cheers,

~Srini....

11 REPLIES 11
Read only

Former Member
0 Likes
1,318

Use


PARAMETERS: mbadat for eban-badat.

To restrict for one value.

You'll need to edit the field for the 1 month restriction and provide an error message is your condition is not met.

Here's a simplified example.


START-OF-SELECTION.

  PERFORM screen_edits.
  CHECK scr_err IS INITIAL.

*&---------------------------------------------------------------------*
*&      Form  screen_edits
*&---------------------------------------------------------------------*
FORM screen_edits.
  CLEAR scr_err.
  

  IF Month_edit is bad.  " Code your own edit 
    scr_err = 'X'.
    MESSAGE s620.
  ENDIF.

ENDFORM.                    " screen_edits

Edited by: Paul Chapman on Apr 28, 2008 2:08 PM

Read only

Former Member
0 Likes
1,318

Hi Abhut,

Write below Code;

For restricting Multiple Selections Declare the Select Option as shown below:

SELECT-OPTIONS:
  mbadat for eban-badat NO-EXTENSION.

AT SELECTION-SCREEN.
DATA:
  date LIKE mbadat.

  date = mbadat-high - mbadat-low.
  IF date > 31.
    MESSAGE 'Date Range should be less than 1 Month' TYPE 'E'.
  ENDIF.

Regards,

Sunil

Read only

Former Member
0 Likes
1,319

Hello-

data:v_date type sy-datum.

DATA:v_days LIKE p0347-scrdd.

select-options s_date for v_date.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

DATE1 = s_date-high

DATE2 = s_date-low

OUTPUT_FORMAT = '02'

IMPORTING

  • YEARS =

  • MONTHS =

DAYS = v_days

  • EXCEPTIONS

  • INVALID_DATES_SPECIFIED = 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 v_days GT 30.

message 'Date range more than 30 days' type 'I'.

endif.

Cheers,

~Srini....

Read only

0 Likes
1,318

Data : v_days type PEA_SCRDD.

if mbadat is not INITIAL.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

DATE1 = mbadat-high

DATE2 = mbadat-low

OUTPUT_FORMAT = '02'

  • IMPORTING

  • YEARS =

  • MONTHS =

DAYS = v_days

  • EXCEPTIONS

  • INVALID_DATES_SPECIFIED = 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 v_days > 31.

MESSAGE 'Date Range should be less than 1 Month' TYPE 'E'.

ENDIF.

endif.

i hav defined this way but its giving dump for v_days.

Read only

0 Likes
1,318

declare it as :

DATA : v_days type PHK_SCRDD.

Read only

0 Likes
1,318

error says :

Function parameter "DAYS" is unknown.

What happened?

Error in ABAP application program.

The current ABAP program "ZSPURREQ" had to be terminated because one of the

statements could not be executed.

This is probably due to an error in the ABAP program.

Function module "HR_HK_DIFF_BT_2_DATES" was called

with the parameter "DAYS".

This parameter is not defined.

Read only

0 Likes
1,318

Hi Friend

try with this sample


REPORT ZEXAMPLE.

DATA: V_YEARS               LIKE P0347-SCRYY,

      V_MONTHS              LIKE P0347-SCRMM,

      V_DAYS                LIKE P0347-SCRDD.

PARAMETERS: P_SDATE LIKE SY-DATUM,

            P_EDATE LIKE SY-DATUM.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

     EXPORTING

          DATE1                   = P_EDATE

          DATE2                   = P_SDATE

          OUTPUT_FORMAT           = '05'

     IMPORTING

          YEARS                   = V_YEARS

          MONTHS                  = V_MONTHS

          DAYS                    = V_DAYS

     EXCEPTIONS

          INVALID_DATES_SPECIFIED = 1

          OTHERS                  = 2.

IF SY-SUBRC EQ 0.

WRITE:/ V_YEARS, 'YEARS,', V_MONTHS, 'MONTHS, AND', V_DAYS, 'DAYS HAVE PASSED'.

ELSE.

  WRITE:/ 'COULD NOT CALCULATE THE DIFFERENCE BETWEEN', P_SDATE, 'AND', P_EDATE.

ENDIF.

Rewards if useful

Read only

0 Likes
1,318

My date type is

select-options : mbadat for eban-badat NO-EXTENSION.

is it necessary to define sy-datum.

Read only

0 Likes
1,318

may be dear

when you change field type as sy-datum its not impact for your program contents.

Read only

Former Member
0 Likes
1,318

Use FM : HR_HK_DIFF_BT_2_DATES ..

with OUTPUT_FORMAT = 05

check the o/p ..

IF MONTHS = 1 and DAYS > 0

*error message

ENDIF.

USE FM : SELECT_OPTIONS_RESTRICT to restrict multiple

selection ...

Read only

Former Member
0 Likes
1,318

Hi,

Use the below code.

tables: eban.

select-options : mbadat for eban-badat no-extension.

data: v_days type i,

v_months type i,

v_years type i,

v_all_days type i.

if not mbadat-low is initial

and not mbadat-high is initial.

CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'

EXPORTING

BEG_DA = mbadat-low

END_DA = mbadat-high

IMPORTING

NO_DAY = v_days

NO_MONTH = v_months

NO_YEAR = v_years

NO_CAL_DAY = v_all_days.

if v_months gt 1.

message 'Invalid date range' type 'S'.

exit.

endif.

endif.

Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 28, 2008 2:52 PM