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 user details and capture errors if the call is not successful. We are considering the SAP Easy Access screen as an example and l 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 function parameters
  3. Add a push button 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 Z_FMCallGetData 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 Easy Access screen
    del("X[IMAGE_CONTAINER]");
    
     
     
  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 push button rfcresult that calls the function BAPI, and executes a process, when clicked.
     
    //Creates a push button 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.
     
    //Adds a trim function, 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.
     
    //Adds a 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.
     
    //Adds a 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.
     
    //Adds a 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.
             // 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:;   
    }
    
     

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

     

SAP Process

  1. Refresh the SAP Easy Access screen and click the rfcresult push button. If the RFC details provided are valid, a success message will appear as the RFC call was successful at the bottom of the screen, as shown below.
     
     
  2. If the entered RFC connection details are incorrect, it will return an exception as an Error! RFC Call Failed to Return Data on the bottom of the screen and in the Cornelius window, as shown below.
     
     

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