Liquid UI - Documentation - 9.05 Get current date using BAPI in SAP

9.05 Get current date using BAPI in SAP


Prerequisites


Purpose

To get the current date in the user-specified date format. Here, the date format is retrieved using a function module call to BAPI_USER_GET_DETAIL or from SU03 transaction. We will walk you through the following steps.

  1. Delete unnecessary screen elements
  2. Create an input field to display the current date
  3. Add a pushbutton to call the function that displays the current date
  4. Create a function to capture the date from the object, and transform it to the target format
  5. Create a function to change the date from 6 digits or 8 digits to the correct format


User Interface


Create this file inside your script folder for customizing SAP Easy Access screen SAPLSMTR_NAVIGATION.E0100.sjs
//Now, let's start adding the following script content to the above file.


Customization
  1. Open SAP Easy Access screen and delete the image container on it, as shown below:
     
    // Deletes an image container on SAP Easy Access screen 
    del("X[IMAGE_CONTAINER]");
    

     
  2. Add an input field to display the current date.
     
    // Creates an input field with the label Date to display the date. 
    inputfield( [1,1], "Date", [1,10],{"name":"z_currentformattedDate", "size":10});
    
     
  3. Add a pushbutton to call the function, when clicked.
     
    // Creates a pushbutton with the label as Get current date to call a function, when clicked. 
    pushbutton([4,8], "Get current date","?",{"process":getCurrentDate});
     
  4. Now, add the following Liquid UI script to this file, and save the file.
     
    // Capture the date from object and transform it to targeting format
    function getCurrentDate(){
    var today = new Date();
    if(today.getMonth()<9){ //getMonth returns month value from 0~11, add "0" before actual month value if is JAN~SEP(1~9)
    curDateStr = today.getFullYear() + "0" + (today.getMonth()+1) + today.getDate();
    } else{ //No need to add "0" if actual month value is OCT~DEC (10~12)
    curDateStr = today.getFullYear() + (today.getMonth()+1) + today.getDate();
    }

    onscreen 'SAPLSMTR_NAVIGATION.0100'
    z_currentformattedDate = formatDate(curDateStr,"2"); //For format "mm/dd/yyyy", date format in function is 2
    enter('?');
    }

    // Change date from 6 digit or 8 digit to correct format:
    function formatDate(date,dformat){
    var date1 = "";
    month = date.substring(4,6);
    year = date.substring(0,4);
    date = date.substring(6,8);
    switch (dformat){
    case '1':
    date1 = date + "." + month + "." + year;
    break;
    case '2':
    date1 = month + "/" + date + "/" + year;
    break;
    case '3':
    date1 = month + "-" + date + "-" + year;
    break;
    case '4':
    date1 = year + "." + month + "." + date;
    break;
    case '5':
    date1 = year + "/" + month + "/" + date;
    break;
    case '6':
    date1 = year + "-" + month + "-" + date;
    break;
    }
    return (date1);
    }


SAP Process
  1. Now, refresh the SAP screen, and click the Get current date pushbutton. Then, you will get today’s date displayed on the input field, as shown in the image below.
     
     

Can't find the answers you're looking for?