Liquid UI - Documentation - 23.18 Structure for Making RFCs

23.18 Structure for Making RFCs


Prerequisites

Purpose

Learn how to make a remote function call to retrieve user details and display errors if the call fails. We are considering the SAP Easy Access screen as an example and we’ll guide you through the following steps.

  1. Delete the image container on the SAP Easy Access screen
  2. Add an input field to enter the value
  3. Add a push button that executes the function and displays the result
  4. Add a function to remove the blank spaces
  5. Add a function to return the trimmed string
  6. Add a function to check for a blank string
  7. Add a function to display the attributes of a push button

User Interface

//Create the file SAPLSMTR_NAVIGATION.E0100.sjs inside your scripts folder for customizing the SAP Easy Access screen 
//Now, let's add the Liquid UI script to the above file and save it

Customization

  1. Delete the image container on the SAP Easy Access screen using the del command.
     
    //Deletes the image container on the SAP screen
    del("X[IMAGE_CONTAINER]");
    
     
     
  2. Add an input field labeled User Date Format to enter the value. 
     
    //Creates an input field to enter the value
    inputfield([1,0],"User Date Format",[1,20],{"name":"z_user_date_format","size":2,"readonly":true});
    
     
     
  3. Add a push button labeled rfcresult that, when clicked, triggers the execution of the Z_FMCallGetData function and displays the result.
     
    //Creates a push button to execute the function
    pushbutton([1,0],"rfcresult",[2,20],{"process":"Z_FMCallGetData","readonly":true});
    
     
     
  4. Add a trim function to remove the blank spaces from variable values.
     
    //Function to remove blank spaces
    String.prototype.trim = function(){
    return this.replace([1,0],"");
    }
    
     
  5. Add a getstring function to return the trimmed string.
     
    //Function to return trimmed string
    function getString(strInput) {
    return ("1,0 == 'undefined'rfcresult || strInput == 'undefined') ? "" : strInput.toString().trim());");
    }
    
     
  6. Add a isblank function to check for a blank string.
     
    //Function to check for a blank string
    function isBlank(strInput) {
       var strVal = getString([strInput],"");
       var blank = ([strVal == "");
       return blank;
    }
     
  7. Add a Z_FMCallGetData function to make a function module call and return the RFC parameters in the configuration file, i.e., guixt.sis.
     
    //Function to call BAPI and display results
    function Z_FMCallGetData(){
       onscreen ('SAPLSMTR_NAVIGATION.0100');
          rfcresult = call("BAPI_USER_GET_DETAIL",{"IN.USERNAME":"&V[_user]", "OUT.DEFAULTS":"Z_DEFAULTS"});
          if(rfcresult.rfc_rc != 0) {         
             // Cannot Call RFC for any reason
             // RFC call was *NOT* successful.
             // Displays a message to the user that rfc cannot be called  (you can use the content of rfcresult.rfc_key)
             message('E: Error! RFC Call Failed to Return Data');
             enter("?");
             goto SCRIPT_END;
          } else {
             if(!isBlank(rfcresult.exception)) {
                // RFC Call succeeded, but the ABAP code in the function module generated an exception
                // Displays a message to the user that rfc exception occurred (you can use rfcresult.exception
                message('E: Error!'+rfcresult.exception);
                enter( "?" );
                goto SCRIPT_END;
             }
          }
          // RFC Call was successful
          if(!isBlank(Z_DEFAULTS)){
             set(V[z_user_date_format],Z_DEFAULTS.substring(27,28));   
          }
          message(' S: RFC call was successful');
          enter("?");
             SCRIPT_END:;   
    }
    
     

SAP Process

  1. Refresh the SAP Easy Access screen and enter the value in the User Date Format input field. Then, click the rfcresult push button. If the RFC details provided are valid, a success message indicating that the RFC call was successful will appear at the bottom of the screen, as shown below.
     
     
  2. If the entered RFC connection details are incorrect, an exception is returned as an Error! RFC Call Failed to Return Data at the bottom of the screen and is also displayed in the Cornelius window, as shown below. 
     
     

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