FM to validate a date

Hi!
I have a text field which may store a date or some text.
I need to validate if the contents of field is a valid date or not.
Is there a function module for the same?
Also what are the commonly used FM for date validations or conversions?
Thanks a lot.
Regards,
(Points will be awarded for help)

HI,
======================================================================
Description : This program has two macros and a sample code which is showing how to use that,.
Macro 1. > Val_date                                   
Macro 2. > Valdate                                    
It return SY-Subrc value if it 0 then the entered date
is valid else either the date is invalid or the specified format is invalid                           
PROGRAM ZDATE_VALIDATE .
Validation of Date
DEFINE VAL_DATE.
  CLEAR: %_DATE1,
         %_DATE2.
  %_DATE1(4)   = &1. "Year
  %_DATE1+4(2) = &2. "Month
  %_DATE1+6(2) = &3. "Date
  %_DATE2 = %_DATE1 - 1.
  %_DATE2 = %_DATE2 + 1.
  IF %_DATE1 <> %_DATE2.
    SY-SUBRC = 1.
  ELSE.
    SY-SUBRC = 0.
  ENDIF.
END-OF-DEFINITION.
DEFINE VALDATE.
Passing Parameters: &1 - Date
                    &2 - Date Format
Date Format:
DDMMYYYY  MMDDYYYY  YYYYMMDD  YYYYDDMM
SY-SUBRC Return Value:
                    1 invalid date
                    0 Valid Date
                    2 Invalid Format
  DATA: %_DATE1 LIKE SY-DATUM  ,
        %_DATE2 LIKE SY-DATUM ,
        %_DATE3(8).
  case &2.
    when 'DDMMYYYY'.
      val_date &14(4) &12(2) &1+0(2).
    when 'MMDDYYYY'.
      val_date &14(4) &10(2) &1+2(2).
    when 'YYYYMMDD'.
      val_date &10(4) &14(2) &1+6(2).
    when 'MMYYYYDD'.
      val_date &12(4) &10(2) &1+6(2).
    when others.
      sy-subrc =  2.
  endcase.
END-OF-DEFINITION.
     SAMPLE USE of above MACRO              *
DATA: V_DATE(8).
V_DATE = '30022002'.
*=>
VALDATE V_DATE 'DDMMYYYY'.
*=>
IF SY-SUBRC = 0.
  WRITE:/ 'Valid Date'.
ELSEIF SY-SUBRC = 1.
  WRITE:/ 'Invalid Date'.
ELSEIF SY-SUBRC = 2.
  WRITE:/ 'Invalid Format'.
ENDIF.
*-- End of Program
Hope you use this .....
Thanks
Sudheer

Similar Messages

  • How to validate the dates in the table control ?

    How to validate the dates in the table control ?
    Can I write like this ?
    LOOP AT it_tab .
    CHAIN.
    FIELD : it_tab-strtdat,it_tab-enddat.
    module date_validation.
    ENDCHAIN.
    ENDLOOP.
    Module Date_validation.
    ranges : vdat type sy-datum.
    vdat-sign = 'I'.
    VDAT-LOW = it_tab-STRTDAT.
    VDAT-HIGH = it_tab-ENDDAT.
    VDAT-OPTION = 'BT'.
    APPEND VDAT.
    WHAT CODE I have to write here to validate ?
    and If I write like this How can we know which is the current row being add ?
    It loops total internal table ..?
    Bye,
    Muttu.

    Hi,
    I think there is no need to put chain endchain.
    To do validation you have to write module in PAI which does required validations.
    Thanks
    DARSHAN PATEL

  • How to validate a date in message mapping

    Hi experts,
                    how to validate a date in message mapping. For ex:  if date comes as 2008/02/31, then file it shold not get processed.how to achieve this in message mapping. Please help .
    Thanks&Regards,
    Reyaz Hussain

    Hi,
    There are few simple ways for date validation as follow,
    1.If you would like to handle it in XI only, then in message mapping you could verify about it with the help of generating smart exception.
    For e.g in mapping there is one Date conversion API i.e. somthing DateTransformation It converts the incoming date format to required format. Here give the date format i.e expected from Sender File.
    If in case the format miss-matched then it will create the exception.
    You could handle this exception with the use of [Alert notification|http://help.sap.com/saphelp_nw04/helpdata/en/2c/abb2e7ff6311d194c000a0c93033f7/frameset.htm] and could be even able to notify to sender system about it.
    2. The another solution is easy for SAP synchornous communication --If you are passing the file data to SAP, then you could use below function modules to verify date format in receiver RFC/BAPI or inbound IDOC program. If the sy-subrc is not 0 then don't process further.
    CONVERT_DATE_FORMAT
    ISU_DATE_FORMAT_CHECK
    Thanks
    Swarup

  • Function module to validate posting date

    Hi all,
    i am using function module amfi_period_get_and_check to validate posting date.
    if posting date is not open this module raises error message but when i am using it
    in my code its not showing error message but when i am executing the module
    it is showing the message for the same date
    please reply soon
    thnx

    at selection-screen on pos_dt.
    CALL FUNCTION 'AMFI_PERIOD_GET_AND_CHECK'
      EXPORTING
        i_bukrs                = com_code-low
      I_GJAHR                =
        i_koart                = 's'
      I_KONTO                = ' '
       I_MONAT                = '00'
       I_BUDAT                = pos_dt.
    IMPORTING
      E_MONAT                =
      E_GJAHR                =
    EXCEPTIONS
      ERROR_PERIOD           = 1
      ERROR_PERIOD_ACC       = 2
      OTHERS                 = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • To find the date type fields in the row and validate those date fields

    TYPES : BEGIN OF TY_MARA,
              MATNR TYPE MARA-MATNR,
              ERSDA TYPE MARA-ERSDA,
              ERNAM TYPE MARA-ERNAM,
              LAEDA TYPE MARA-LAEDA,
              MTART TYPE MARA-MTART,
            END OF TY_MARA.
    DATA : it_mara TYPE STANDARD TABLE OF ty_mara,
          it_mara1 TYPE STANDARD TABLE OF ty_mara,
           wa_mara TYPE ty_mara.
    loop at it_mara into wa_mara.
      describe field wa_mara-ersda type c_data.
    if c_data eq 'D'.
      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
        EXPORTING
          date                            = wa_mara-ersda
       EXCEPTIONS
         PLAUSIBILITY_CHECK_FAILED       = 1
         OTHERS                          = 2
      IF sy-subrc eq 0.
    wa_mara-ersda = '00000000'.
        append wa_mara to it_mara1.
        write :wa_mara-matnr,wa_mara-ersda.
        else.
            wa_mara-ersda = '00000000'.
        append wa_mara to it_mara1.
        write :wa_mara-matnr,wa_mara-ersda.
      ENDIF.
      endif.
      endloop.
    This issue regarding how to find the date type fields in the row and validate those date fields.If its not a valid date ,i have to assign initial value to that.
    I've tried that for single field using describe field.Please help me do that for all fields.

    Hi Sam,
     I believe we had discussed the same issue in the below thread. Can you please refer the below one?
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/d93e16ff-c123-4b36-b60b-60ccd34f6ca7/calculate-time-differences-in-infopath?forum=sharepointcustomizationprevious
    If it's not helping you please let us know
    Sekar - Our life is short, so help others to grow
    Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
    you see a reply being an answer to the question of the thread, click "Mark As Answer

  • How to validate the date in my class

    Hi
    In my project with jsp and struts I need to validate the date field.
    So in the action class I want to validate the date that is the date is in dd/mm/year format?
    can anybody please give some idea to do this?
    Thank you so much.

    Here is a method that validates day/month/year using the Calendar class.
         public boolean validateDate(int day, int month, int year) {
              try {
                   Calendar cal = Calendar.getInstance();
                   cal.clear();
                   cal.setLenient(false);
                   cal.set(year, month-1, day);
                   // need to call getTime() to make the calendar compute/validate the date
                   cal.getTime();
                   return true;
              catch (IllegalArgumentException e) {               
                   return false;
         }

  • How to validate when date format is diff Internally and externally

    Hello,
    How can I validate the Date format if Internal format and external format is different.
    Ex :
    *  SELECT SINGLE CRTSP
    **                FROM /SAPSLL/PR
    **                INTO L_CRTSP
    **                WHERE CRTSP IN S_CRTSP .
    CRTSP (YYYY/DD/MM HHMMSEC) Internal Format
    S_CRTSP (YYYY/DD/MM) External format - selection option
    I had done following to convert the internal format to external format.
    DATA : LV_DT TYPE STRING.
    DATA :  L_CRTSP TYPE /SAPSLL/CRTSP.
    SELECT SINGLE CRTSP
                    FROM /SAPSLL/PR
                    INTO L_CRTSP.
    MOVE : L_CRTSP TO LV_DT. "(YYYY/DD/MM HHMMSEC)
    L_LEN = STRLEN( LV_DT ).
    L_DATE = LV_DT+0(8).
    I have the date format that i need in L_DATE."  (YYYY/DD/MM)
    Now how should I validate?
    *  SELECT SINGLE CRTSP
    **                FROM /SAPSLL/PR
    **                INTO L_CRTSP
    **                WHERE CRTSP IN S_CRTSP .
    Please let me know how can I validate or how can I write the select query to validate this field.
    There should be some way using Wildcard or some function module...which I am not sure...
    Any suggestions will be appreciated!
    Regards,
    Kittu
    Edited by: Kittu on Jan 6, 2009 12:58 PM

    Hello,
    Thank you for youe response and I apprecaite the help so far.
    This logic work if it is Parameter...When I have select option it is not working as it is not taking the range values...
    SELECT GUID_PR "Primary Key as GUID in "RAW" Format
    CRTSP "PRODUCT CREATED ON
    CHTSP "PRODUCT CHANGED ON
    FROM /SAPSLL/PR
    INTO TABLE T_PR.
    DATA : T_PR1 TYPE TY_PR OCCURS 0 WITH HEADER LINE.
    DATA:  W_TEST    TYPE STRING,
           W_LV_LEN  TYPE I,
           W_LV_LEN1 TYPE I,
           W_LV_DATE(20)  TYPE C,
           W_LV_DATE1(20) TYPE C.
    DATA : W_V(8) TYPE C,
           S_CT(11) TYPE C.
    SORT T_PR BY CRTSP CHTSP.
    LOOP AT T_PR INTO WA_PR.
      W_TEST = WA_PR-CRTSP.
      W_LV_LEN = STRLEN( W_TEST ).
      W_LV_DATE = W_TEST+0(8).
    ** IF WE SELECT ONLY ONE DATE IN SELECT OPTION
    s_crtsp VALUE IS - IEQ20040101..bY REMOVING FIRST THRID DIGITS
    WE ARE GETTING THE S_CRTSP VALUE IS 20040101 AND THIS LOGIC IS WORKING FINE..
       MOVE S_CRTSP TO S_CT.
      W_LV_LEN1 = STRLEN( S_CT ).
      W_LV_DATE1 = S_CT+3(8).
    *  IF W_LV_DATE NE S_CRTSP
    IF W_LV_DATE NE W_LV_DATE1.
      W_FLG = 'X'.
        DELETE T_PR INDEX SY-TABIX.
      ENDIF.
      CLEAR W_FLG.
    ENDLOOP.
    Can we do anything for this...
    ANy suggestions would be apprecaited!
    Regards,
    Kittu

  • Validate the Date Time

    Does any java library class support to validate the date of the user input?

    Error index is concerned with the pattern not with the value.
    SimpleDateFormat test = new SimpleDateFormat("yyyy-MM-dd");
    ParsePosition p = new ParsePosition(0);
    p.setErrorIndex(-1);
    Date d=test.parse("2002-1130",p);  //does not match the pattern
    System.out.println(p.getErrorIndex()); // index other than -1 expected
    p.setErrorIndex(-1);  //  initialize
    d=test.parse("2002-11-31",p);// match the pattern but value invalid
    System.out.println(p.getErrorIndex()); //-1 expected

  • Validate the date

    I have to validate the date, using following rules. How I can validate.
    �     Valid date
    �     Not in the past
    �     Not more than 56 days in the future

    See DateFormat/SimpleDateFormat.parse()
    http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html#parse(java.lang.String)
    and Calendar.add()
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html#add(int,%20int)
    There are also before(), after(), and compareTo() methods in Calendar.
    Message was edited by:
    jbish

  • Validate long date in javascript & OnSubmit problem

    hi i need to validate long date format "E, dd MMM yyyy HH:mm:ss" or Thu, 18 Jul 2002 12:52:49 that is key in by the user. but i'm not sure how to do this. i have couples of input data and i'm passing an object to the javascript function validateform using OnSubmit. Which one is better, using OnSubmit or OnCick for this kind of parameter passing. Eg <form method="POST" action="insert.jsp" onSubmit="return validateForm(this)"> However i'm having a problem where when there is an invalid input from the user, it will notify the user but it will also send the form to the insert.jsp at the same time. Therefore the user can't correct the invalid data. The function return false for valid input and true for invalid. Please help!!! urgent.... thanks in advance

    Your problem is you have used
    <input type="submit" onClick="OnSubmit();">
    this won't work.
    Instead try
    <input type="button" value="someValue" onClick="OnSubmit();">
    This may help. All the best.

  • PL SQL Procedure to validate the data before inserting

    Hi All,
    I have a PLSQL procedure that validates the data and also inserts the data into the table. That procedure must be run to validate each row to be inserted. My doubt is how to reference that procedure within the interface of ODI.
    After reading some posts that mention the use of procedures, I think the best option is to call the procedure inside the knowledge module (inside a cursor that does a insert clause). Am I correct?
    As the KM's do a lot of verification and use temporary tables, I don't know what are the steps to be modified. Also, I would like to know if it's necessary to modified only the IKM or the LKM too.
    I'm using the IKM Oracle Incremental Update (PL SQL) and LKM Oracle to Oracle.
    Thanks.
    Luciene

    by validating data you mean looking up some table and see if it exists?
    If this is the case the you can implement this using a user function.
    If validation fails then you may put a -1 into the mapping.
    Then put a constraint on the target( say column is -1) and enable flow control.

  • When reading from the file validate the date  'DD/MM/YYYY'  format

    Hi,
    reading from the file ,validate the date format 'DD/MM/YYYY'.
    Thanks & regards
    venkata

    I suppose that you are writing a program in some programming language, probably PL/SQL. So, you can use TO_DATE function and handle the exception when it occurs.
    create or replace procedure tstdt
    as
      stdt varchar(10);
      dt date;
    begin
      stdt := '20/10/2006';
      dt := to_date(stdt);
       dbms_output.put_line('date is correct
    exception
    when others then
      dbms_output.put_line('Invalid Date');
    end;[],
    Miguel

  • Validate the data in the internal table with the date in selection screen

    Hi all,
    I want to validate the data in the internal table and get only the records with the input date in the selection screen.
    The date is in the select options and please let me know how to get the records only if it satisfies the input date in the selection screen.
    Regards,
    Shalem

    For Ex.
    SELECT-OPTIONS: S_DATE FOR VBAK-VDATU
    If you want to read one INTERNAL TABLE record
    READ TABLE it_tab(internal table name) WHERE vdatu(date field name in the internal table) = s_date
    If you want to move more then one
    LOOP AT it_tab WHERE vdatu = s_date.
    Take the field values in another table and append it. then end loop.
    you will get the records which only have the date in select option..
    If you want detail code give me internal table name and select option name i will write you the code.
    regards
    Yuvaram

  • Can SOA validate invoice data before the webservice sends a response?

    I'm working with another branch of the company, and they're having trouble getting SOA to validate invoice data before it goes into Oracle financials.  They claim that SOA can't validate the invoices according to our business rules, and can only validate the input data based on the schema defined in the webservice.  Even the validation from the schema is useless because it produces schema violation rules that I can't return to a user. 
    After the webservice lets go of the data, there's a multi-step scheduled process where the data is handed off from scheduled process to scheduled process, so SOA can't guarantee in any way to the client end that invoices will get into the database. and worse, the data could get "stuck" at any one of these stages far after a user has submitted it.
    Is any of this true?  Is there no programming language within SOA that can perform validation of the business rules, and insert the data into Oracle all on it's own?  I've little or no familiarity with Oracle, but it's kind of incredible to believe that this is how Oracle designed the major interface to interact with 3rd party applications.

    People insist on using HTTP because it is the easiest to get through forward proxies, reverse proxies, and firewalls.
    If you don't have to deal with those devices, then there are other protocol options.
    As far as the amount of data, that is what my customers want to upload...
    I suppose I could break it down into multiple requests, use compression etc.
    I could also have the server reset the connection on a fatal error like this. (one which occurs within the POST body)
    That would eliminate the keep-alive also since I do not want to waste another 10 minutes to resync the messages.
    Regards,
    Tim

  • Simple question: validate infocube data by comparing it with PSA data

    Hi all,
    I want to validate infocube data by comparing it with PSA data, for that i went through PSA via context menu. After that i generated export datasource. Then i am not able to find PSA Export datasource? where can i find that..
    Thanks
    raju

    Hi all,
    I´ve tryied to VALIDATE INFOCUBE DATA BY COMPARING IT WITH PSA DATA making the step by step contained in the HOW TO ...
    The problem is that I have the following error when i activate the transfer rules after aggregating the infoobjet 0TCTREQUID and don´t know how to resolve it:
    " IDoc segment /BIC/CICA7ZBW_RECEP_DI could not be assigned to IDoc ZSCA002
    Message no. RSAR240
    Diagnosis
    The transfer structure is assigned to IDoc ZSCA002 as an IDoc segment for the data transfer between source system and Business Information Warehouse.
    This assignment failed.
    System response
    IDoc segment /BIC/CICA7ZBW_RECEP_DI not known to IDoc V2&. Therefore, no data import can take place from the source system for this InfoSource."
    Any idea of what could have happend?
    Thanks in advance,
    Diego

  • Validate the data for SAP system

    How do you validate the data for SAP receiver system (RFC or IDOC adapter)?
    It is necessary to recognize does exists reference object or does field has the right value.
    Do you validate it in BPM or you handle  application/technical acnowlegment? Or Messaging monitoring is enough for your requirements.
    In case of ABAP Proxy will it enough to catch Fault Message in order to define what happens?

    Hi,
    there are two different kinds of validations:
    syntactical validation (length and data types of fields etc.) and semantical validations (correct customer in order, allowed number range etc.)
    From a theoretical point of view, only the first kind should be carried out in XI, all semantical validations should be part of the backend inbound processing. And indeed for IDocs and RFCs you will get according error messages in the backend. If you call proxies, you will need to code that yourself.
    In General i'd implement syntactical validations in XI, if more a necessary then XI already carries out (e.g. mandatory fields filled). For data validations i would rely on the backend, meaning for IDocs you should look into using ALEAUD IDoc, which will return any error messages during IDoc inbound processing. For RFCs you can have Exceptions defined which will translate to a negative application ACK.
    Regards
    Christine

Maybe you are looking for

  • Emails sent from alias are not appearing as alias address with recipients

    I have a personal domain name email alias. I have linked this to a free Outlook account. I have set up the outlook account on TB using my personal domain alias. However, when I send an email using the alias, it appears in the recipient's inbox as com

  • Special Character for in-line previous page reference:

    OS: Windows XP Pro SP2 Software: IDCS2 I'm working on a document and I need to make an inline reference to an item two pages back (not a "continued on/from"). This document is used in two different books, and the page numbers change in each book. Is

  • Autocorrel​ation function

    I have 25,000 data points in a Excel/txt file. I'd like Labview to read the data, calculate the autocorrelation function and save the autocorrelation results in another file. Here's the idea: http://www.protein-solutions.com/psi_books/light_s​catteri

  • Movement type post to COPA or not?

    Dear all, Can any one tell me how to control if a movement type posted to COPA or not? For example, movement type 201 (GI for cost center) only posted to cost center, movement type 901 (GI scrapping COPA) posting to COPA. Actually I want to set one m

  • Updated to 3.1 and CPU maxed out causing click and pops

    I upgraded to Mainstage 3.1 and now the CPU meter is maxed out when I change presets and also MainStage runs at 100 % causing clicks and breaks in the sound when using a vst plugin S-Gear by Scuffham.  Earlier versions work fin at 20% to 50% CPU.  I