Liquid UI - WS Reference Library

Validate date format and display message


Prerequisites


Purpose

To check the validity of user entered date format by retrieving date format from SU03 transaction and comparing with user entered value.


User Interface

Log into SAP and on the SAP Easy Access Screen you will see the Liquid UI field. Enter the date and click on ‘Validate Date’.



Liquid UI Script

//SAPLSMTR_NAVIGATION.E0100.sjs


del('X[IMAGE_CONTAINER]');        // Delete ActiveX Container on SAP Easy Access screen

// Purpose: Function is called to remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// Purpose: Function is called to validate if the variable holds blank or null value
function isBlank(jvar){
    if(typeof jvar == 'string') {
        jvar = jvar.trim();
    }
    return(jvar == 'undefined' || jvar == null || jvar == "" || jvar == void 0);
}

// Purpose: Function is called to validate the date
function isValidDate(date,dformat){
    switch(parseInt(dformat)){
    case 1:
        var matches = /^(\d{2})[-\.](\d{2})[-\.](\d{4})$/.exec(date);
        if (matches == null)
            return false;
        else
            return true;
        break;
    case 2:
        var matches = /^(\d{2})[-\/](\d{2})[-\/](\d{4})$/.exec(date);
        if (matches == null)
            return false;
        else
            return true;
        break;
    case 3:
        var matches = /^(\d{2})-(\d{2})-(\d{4})$/.exec(date);
        if (matches == null)
            return false;
        else
            return true;
        break;   
    case 4:
        var matches = /^(\d{4})[-\.](\d{2})[-\.](\d{2})$/.exec(date);
        if (matches == null)
            return false;
        else
            return true;
        break;
    case 5:
        var matches = /^(\d{4})[-\/](\d{2})[-\/](\d{2})$/.exec(date);
        if (matches == null)
            return false;
        else
            return true;
        break;
    case 6:
        var matches = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
        if (matches == null)
            return false;
        else
            return true;
        break;
    }                              
}

// Retrieve Date Format and check the validity of user entered Date
function checkDateFormat(){
    if(isBlank(z_date)){
        return('E: Enter Date');
    }
    
    onscreen 'SAPLSMTR_NAVIGATION.0100'
        enter('/nSU3');
    
    onscreen 'SAPLSUU5.0100'
        enter('=DEFA');
        
    onscreen 'SAPLSUU5.0100'
        set('V[USERDATEFORMAT]','&F[USDEFAULTS-DATFM]');    // Date Format
        USERDATEFORMAT = parseInt(USERDATEFORMAT.trim());
        switch(USERDATEFORMAT) {
            case 1: {set('V[USERDATEFORMATMSG]','DD.MM.YYYY');} break;
            case 2: {set('V[USERDATEFORMATMSG]','MM/DD/YYYY');} break;
            case 3:    {set('V[USERDATEFORMATMSG]','MM-DD-YYYY');} break;
            case 4: {set('V[USERDATEFORMATMSG]','YYYY.MM.DD');} break;
            case 5: {set('V[USERDATEFORMATMSG]','YYYY/MM/DD');} break;
            case 6: {set('V[USERDATEFORMATMSG]','YYYY-MM-DD');} break;
            default: {set('V[USERDATEFORMATMSG]','*INVALID*');} break;
        }        
        enter('/N');
    
    onscreen 'SAPLSMTR_NAVIGATION.0100'
        validDate = isValidDate(z_date,USERDATEFORMAT);
        if(!validDate){
            message("E: Enter Date in " + USERDATEFORMATMSG +" Format");
        } else{
            message    ("S: Valid Date");
        }
        enter('?');
        
    FUNC_END:;
}

// User Interface
inputfield([1,1], "Date", [1,10], {"name":"z_date", "size":10});
pushbutton([1,23], "Validate Date", '?', {"process":checkDateFormat, "size":[1,15]});

 


Was this information helpful? Send Feedback