Liquid UI - Documentation - 23.18 Structure for Making RFCs

23.18 Structure for Making RFCs


Prerequisites


Purpose

To learn how to make a remote function call to get the user details and capture the errors if the call was not successful. We will walk you through the following steps.

  1. Delete unnecessary elements on the SAP screen
  2. Add an input field to enter the function parameters
  3. Add a pushbutton to call BAPI and execute the process
  4. Add the trim function to remove the blank spaces
  5. Add a getstring function to return the trimmed string
  6. Add an isblank function to check for a blank string
  7. Add a function to display the attributes of a pushbutton


User Interface

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

  1. Open the SAP Easy Access screen and clear the unnecessary elements.
     
    //Deletes unnecessary screen elements on the SAP Easy Access screen 
    clearscreen();
    
     
  2. Add an input field with the title User Date Format to enter the parameters for the function.
     
    // Creates an input field at row 1 and column 0 position with size 2 on the screen with z_user_dateformat as its technical name.
    inputfield([1,0],"User Date Format",[1,20],{"name":"z_user_date_format","size":2,"readonly":true});
    
     
  3. Add a toolbar pushbutton rfcresult that calls the function BAPI, and executes a process, when clicked.
     
    //Creates a pushbutton with a label as rfcresult to call RFC.
    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 trim, to remove blank spaces from variable values.
    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 an isblank function to check for a blank string.
     
    //Function to check for a blank string.
    // Specifically used to determine if input exist in the edit field
    function isBlank(strInput) {
       var strVal = getString([strInput],"");
       var blank = ([strVal == "");
       return blank;
    }
     
  7. Create a function to make a function module call, and return the RFC parameters in the configuration file, i.e., guixt.sjs. Save the changes made on your script file.
     
    //The function to call BAPI and display results.
    // Specifically used to determine if input exists in the edit field
    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.
             // Display 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
                // Display 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:;   
    }
    

    Note: Save the changes in the script file and refresh the SAP screen to view the customizations.

     
  8. Click the rfcresult pushbutton to make an RFC call. If the entered RFC connection details are incorrect, return an exception as "Error! RFC Call Failed to Return Data," in the Cornelius window, as shown below.
     
     
  9. If the RFC details provided are valid, a success message appears as "RFC call was successful," on clicking  the rfcresult pushbutton.
     
     

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