Author Topic: Making Structured RFC Calls  (Read 65 times)

lakshmi.k

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 6
    • View Profile
Making Structured RFC Calls
« on: March 18, 2024, 10:13:32 PM »
Purpose:
Below example demonstrates structure to make function module calls, display message to the user if the call was successful and display an error message if the call was not successful.

Note:
To make the function module call, it is required to provide the rfc parameters in the configuration file i.e, guixt.sjs

Liquid UI Code:
----------------------------------------------------------------------------------------------------------------------
Script File Name: SAPLSMTR_NAVIGATION.E0100.sjs
----------------------------------------------------------------------------------------------------------------------
// User Interface
clearscreen();
inputfield([1,0],"Message",[1,10],{"name":"z_message","size":70,"readonly":true});
pushbutton([3,1],"Get Messsage","?",{"size":[2,20],"process":getMessage});

//Functions
//To remove blank spaces from variable values
String.prototype.trim = function() {
   return this.replace(/^\s+|\s+$/g,"");
}

//Function to return trimmed string
function getString(strInput) {
   return (typeof(strInput) == 'undefined' || strInput == 'undefined') ? "" : strInput.toString().trim();
}

//Function to check for blank string
function isBlank(strInput) {
   var strVal = getString(strInput);
   var blank = strVal == "";
   return blank;
}

//Function to call BAPI and display results
function getMessage(){
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      rfcresult = call('BAPI_USER_CHANGE',{'in.USERNAME':'&V[_user]','out.GENERATED_PASSWORD':'z_gen_pswd','table.RETURN':'z_return'});
      if(rfcresult.rfc_rc != 0) {         
         // Cannot Call RFC for any reason
         // RFC call was *NOT* successful.
         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 user, that rfc exception occured (you can use rfcresult.exception)
            message('E: Error! '+rfcresult.exception);
            enter("?");
            goto SCRIPT_END;
         }
      }

      // RFC call was successful
      if(!isBlank(z_return)){
         set('V[z_message]', z_return.toString().substring(24,244));   
      }
      message('S: RFC call was successful');
      enter('?');
    SCRIPT_END:;   
}