Author Topic: Structure for making RFC calls  (Read 6489 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
Structure for making RFC calls
« on: October 02, 2019, 05:59:46 PM »
Purpose:
Structure to make function module calls and capture any errors if the call was not successful or capture any exceptions and display to the user.

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       // SAP Easy Access
----------------------------------------------------------------------------------------------------------------------------------------------
// User Interface
clearscreen();
inputfield([1,0],"User Date Format",[1,20],{"name":"z_user_dateformat","size":2,"readonly":true});
pushbutton([3,1],"Get Date Format","?",{"size":[2,20],"process":Z_FMCallGetData});

// Related functions
// Function trim, 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
// Specifically used to determine if input exist in the edit field

function isBlank(strInput) {
   var strVal = getString(strInput);
   var blank = strVal == "";
   return blank;
}

// 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.
         // Display message to 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 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_DEFAULTS)){
         set('V[z_user_dateformat]', Z_DEFAULTS.substring(27,28));   
      }
      message('S: RFC call was successful');
      enter('?');
      
   SCRIPT_END:;   
}


See attachments for code samples!
« Last Edit: June 10, 2022, 01:18:14 PM by Benjamin Dasari »