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

About Date validation

Former Member
0 Likes
1,387

Hi guys we are using a particular zprogram to do mass update from excel sheets.unfortunately the dates are picking out of range like 32,33 etc.so how to check any date validation has been maintained or not in that zprogram? thanks in advance guys.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,318

Do you mean that the date value coming into the program is 32,33? Someone needs to correct their spreadsheet. But serious, put the data into a char8 field. If the fields contains only 0-9 and the first two characters are 19 or 20, the 5th and 6th are in 01-12, and the 7th and 8th are between 01 and 31, you've probably got a date value.

8 REPLIES 8
Read only

Former Member
0 Likes
1,319

Do you mean that the date value coming into the program is 32,33? Someone needs to correct their spreadsheet. But serious, put the data into a char8 field. If the fields contains only 0-9 and the first two characters are 19 or 20, the 5th and 6th are in 01-12, and the 7th and 8th are between 01 and 31, you've probably got a date value.

Read only

0 Likes
1,318

is there any check available so that even if the spread sheet is wrong,error can be displayed while uploading?

Read only

0 Likes
1,318

yes i mean it is updating as 32.10.2010 in the way

Read only

0 Likes
1,318

This function module checks whether the date is valid - DATE_CHECK_PLAUSIBILITY

Brenda

Read only

0 Likes
1,318

Hi Teja,

If you could upload your spreadsheet to generic internal table (or date to char10 field) and then you can probably validate the incoming date... The key here would be the predefined date format in your excel spreadsheet... Based on that format, you can then convert the external date to internal date format and you should be able to validate the date once it is converted to internal date format

Read only

0 Likes
1,318

You can also use:

CALL FUNCTION 'RP_CHECK_DATE'
      EXPORTING
        date         = l_date
      EXCEPTIONS
        date_invalid = 1
        OTHERS       = 2.

Read only

former_member182010
Active Participant
0 Likes
1,318

Hello TEJA161,

Put the date in internal format (i.e., YYYYMMDD). You can use function module NUMBER_OF_DAYS_PER_MONTH_GET to determine the number of days in the month for a given year. Then check if date is between the 1st and the last day of a particular month.

Kind Regards,

Rae Ellen Woytowiez

Read only

Clemenss
Active Contributor
0 Likes
1,318

Hi Teja,

recently I found an extremely simple way to validate a date:

data: 
  lv_date_test type sy-datum.
lv_date_test = <your test date in internal format>.
subtract  1 from lv_date_test.
add  1 to lv_date_test.
if lv_date_test NE <your test date in internal format>.
  write: / <your test date in internal format>, 'is no valid date in this galaxy'.
endif.

But from the few information you give, it seems to come in external format. Then you should use FM RS_CONV_EXT_2_INT :


  DATA:
    ls_tabfield TYPE tabfield,
    lv_date     type sy-datum.
  ls_tabfield-tabname = 'SYST'.
  ls_tabfield-fieldname   = 'DATUM'.

CALL FUNCTION 'RS_CONV_EX_2_IN'
    EXPORTING
      input_external                     = <your test date in external format>
      table_field                        = ls_tabfield
*   CURRENCY                           = CURRENCY
    IMPORTING
      output_internal                    = lv_date
    EXCEPTIONS
      input_not_numerical                = 1
      too_many_decimals                  = 2
      more_than_one_sign                 = 3
      ill_thousand_separator_dist        = 4
      too_many_digits                    = 5
      sign_for_unsigned                  = 6
      too_large                          = 7
      too_small                          = 8
      invalid_date_format                = 9
      invalid_date                       = 10
      invalid_time_format                = 11
      invalid_time                       = 12
      invalid_hex_digit                  = 13
      unexpected_error                   = 14
      invalid_fieldname                  = 15
      field_and_descr_incompatible       = 16
      input_too_long                     = 17
      no_decimals                        = 18
      invalid_float                      = 19
      conversion_exit_error              = 20
      OTHERS                             = 21
            .
  IF sy-subrc NE 0.
    write: / <your test date in external format>, 'is no valid date in this galaxy'.
  ENDIF.

Regards,

Clemens