Author Topic: #include - Preprocessor which makes function/file contents inline  (Read 6554 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
Purpose:
'#include' pre-processor is used to make the file contents load inline.
This is used for code readability if smaller functions have to be grouped into separate files and called inline.

SYNTAX::
// The 'filename.sjs' just has the script without any function header or closing brace
// No need to load the include files, however they need to be placed in the scripts root directory (Cannot be in subfolders)
#include 'filename.sjs'[Make sure there are no spaces after the closing quote]

NOTE::
 - Available from LUI Desktop Version 1.2.331 and LUI Server Version 3.5.575
 - Make sure there are no blank spaces after the include declaration or else include will not get executed

Liquid UI Code:
----------------------------------------------------------------------------------------------------------------------------------------------
Script File Name: SAPLSMTR_NAVIGATION.E0100.sjs       // Easy Access
----------------------------------------------------------------------------------------------------------------------------------------------
load("IW32_functions.sjs");

// User Interface
clearscreen();
inputfield( [1,1], "Order", [1,18],{ "name":"z_iw32_ordernum", "size":18, "required":true});
pushbutton([5,40],"Clear fields","?",{"process":clearData});
pushbutton([2,1],"Get Order Info [Syntax 1]","?",{"process":getOrderInfo_1});
comment([2,30],"This function does error handling, calls include function and returns to main function [Check Script Syntax]");
pushbutton([3,1],"Get Order Info [Syntax 2]","?",{"process":getOrderInfo_2});
comment([3,30],"The include function is being called entirely from the main function [Check Script Syntax]");
inputfield( [5,1], "Notification", [5,18],{ "name":"z_iw32_notifnum", "size":18});
inputfield( [6,1], "Func. Loc.", [6,18],{ "name":"z_iw32_funcloc", "size":18});
text([6,38], "&V[z_iw32_funclocdesc]");
inputfield( [7,1], "Sales Org.", [7,18],{ "name":"z_iw32_salesorg", "size":4});
inputfield( [8,1], "Distr. Channel", [8,18],{ "name":"z_iw32_distchannel", "size":2});
inputfield( [9,1], "Division", [9,18],{ "name":"z_iw32_division", "size":2});

----------------------------------------------------------------------------------------------------------------------------------------------
Script File Name: IW32_functions.sjs       // Functions file
----------------------------------------------------------------------------------------------------------------------------------------------
// Function prototype to trim blank characters from a string
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;
}

// Clear Data
function clearData(){
   set("V[z*]","");
}

// Get Order Information
function getOrderInfo_1(){
   if(isBlank(z_iw32_ordernum)){
      return("E: Enter Order number");
   }
   
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      enter("/nIW32");
      
   // Include Pre-processor makes the function inline   
   #include "INC_GET_ORDER_DATA_1.sjs"

        onscreen 'SAPLCOIH.3000'
      set("V[z_iw32_salesorg]","&F[Sales Org.]");
      set("V[z_iw32_distchannel]","&F[Distr. Channel]");
      set("V[z_iw32_division]","&F[Division]");
      enter("/n");
}

// Get Order Information
function getOrderInfo_2(){
#include "INC_GET_ORDER_DATA_2.sjs"
}

----------------------------------------------------------------------------------------------------------------------------------------------
// This function does error handling, calls include function and returns to main function
Script File Name: INC_GET_ORDER_DATA_1.sjs       // Include file with Syntax 1
----------------------------------------------------------------------------------------------------------------------------------------------
onscreen 'SAPLCOIH.0101'
   set('F[Order]','&V[z_iw32_ordernum]');   
   enter();
   onerror
      message(_message);
      enter("/n");
      goto SCRIPT_END;
      
onscreen 'SAPLCOIH.0101'
   if(_message.substring(0,2) == 'E:'){
      message(_message);
      enter("/n");
      goto SCRIPT_END;
   } else {
      enter("?");
   }         
      
onscreen 'SAPLCOIH.3000'
   set("V[z_iw32_notifnum]","&F[Notifctn]");
   set("V[z_iw32_funcloc]","&F[CAUFVD-TPLNR]");   //Func.Loc.
   set("V[z_iw32_funclocdesc]","&F[RIOT-PLTXT]");   //Func.Loc. Description
   enter("=ILOA");
   
SCRIPT_END:;   

----------------------------------------------------------------------------------------------------------------------------------------------
// The include function is being called entirely from the main function
Script File Name: INC_GET_ORDER_DATA_2.sjs       // Include file with Syntax 2
----------------------------------------------------------------------------------------------------------------------------------------------
if(isBlank(z_iw32_ordernum)){
   return("E: Enter Order number");
}

onscreen 'SAPLSMTR_NAVIGATION.0100'
   enter("/nIW32");
   
onscreen 'SAPLCOIH.0101'
   set('F[Order]','&V[z_iw32_ordernum]');   
   enter();
   onerror
      message(_message);
      enter("/n");
      goto SCRIPT_END;
      
onscreen 'SAPLCOIH.0101'
   if(_message.substring(0,2) == 'E:'){
      message(_message);
      enter("/n");
      goto SCRIPT_END;
   } else {
      enter("?");
   }         
      
onscreen 'SAPLCOIH.3000'
   set("V[z_iw32_notifnum]","&F[Notifctn]");
   set("V[z_iw32_funcloc]","&F[CAUFVD-TPLNR]");   //Func.Loc.
   set("V[z_iw32_funclocdesc]","&F[RIOT-PLTXT]");   //Func.Loc. Description
   enter("=ILOA");

onscreen 'SAPLCOIH.3000'
   set("V[z_iw32_salesorg]","&F[Sales Org.]");
   set("V[z_iw32_distchannel]","&F[Distr. Channel]");
   set("V[z_iw32_division]","&F[Division]");
   enter("/n");
   
SCRIPT_END:;   


See attachments for code samples!
« Last Edit: August 13, 2018, 04:34:00 PM by Benjamin Dasari »