Author Topic: Dynamic Readonly Status Handling  (Read 2602 times)

Leo Chu

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 16
    • View Profile
Dynamic Readonly Status Handling
« on: January 27, 2016, 01:56:03 PM »
Liquid UI: Dynamic Readonly Status Handling

Purpose:
The example is to change readonly status for created elements between Create/Change/Display transactions.
Those transactions will load same script according to the same screen number and screen name.
In order to create multiple commands for different readonly status of elements, this can save amount of scripts in large screen modification efficiently.

Below example uses IW31 - Create Maintenance Order/IW32 - Change Maintenance Order/IW33 - Display Maintenance Order as example.
The script merges some fields from "Location" tab to "HeaderData" tab so user don't need to go to extra tab to enter data.
It demonstrates how created inputfields can change its readonly status dynamically according to correspond conditions.


Step 1: Create user interface for the initial screen of IW32 - Change and IW33 - Display
//User Interface
onUIEvents["Enter"] = {"fcode":"?", "process":iw32iw33Execute};      //Execute when user hits enter on screen

Note: No need to create the functionality for IW31 is because it doesn't require pre-fetch data when create


Step 2: Create the function to fetch data from initial screen
//Function to execute and fetch data from "Location" tab
function iw32iw33Execute(){
   onscreen "SAPLCOIH.0101"
      enter();
      onmessage               //Error handling
         if(_message.substring(0,2) == "E:"){
            message(_message);
            enter("?");
            goto FUNC_END;
         }
         else
            enter();
            
   onscreen "SAPLCOIH.0101"      //Error Handling
      if(_message.substring(0,2) == "E:"){
         message(_message);
         enter("?");
         goto FUNC_END;
      }
      else
         enter();

   onscreen "SAPLCOIH.3000"
      set("V[iw3x_status]", "&F[Sys.Status]");
      enter("=ILOA");         //Go to "Location" tab
      
   onscreen "SAPLCOIH.3000"
      set("V[iw3x_maint_plant]", "&F[MaintPlant]");
      set("V[iw3x_location]", "&F[Location]");
      set("V[iw3x_room]", "&F[Room]");
      set("V[iw3x_plant_section]", "&F[Plant section]");
      set("V[iw3x_work_center]", "&F[Work center]");
      enter("=IHKZ");         //Go to "HeaderData" tab
      
FUNC_END:;      
}


Step 3: Create condition to change status flag in detail screen
//If transaction is IW31 or IW32 but system status doesn't contain "CLSD"
if(_transaction == "IW31" || (_transaction == "IW32" && iw3x_status.indexOf("CLSD")<0)){
   iw3x_readonly_flag = false;
}
//If transaction is IW33 or system status contains "CLSD"
else if(_transaction == "IW33" || iw3x_status.indexOf("CLSD")>-1){
   iw3x_readonly_flag = true;
}

Note: Variable "iw3x_readonly_flag" will be use to change readonly status


Step 4: Create user interface in detail screen
del("P[Location]");               //Remove "Location" tab on screen

if(_page.exists("HeaderData")){
   box("G[First operation]+[6,0]", "G[First operation]+[10,80]", "Location");
   inputfield("G[Location]+[1,1]", "MntPlant", "G[Location]+[1,12]",
      {"name":"iw3x_maint_plant", "size":4, "readonly":iw3x_readonly_flag});
   inputfield("G[Location]+[2,1]", "Location", "G[Location]+[2,12]",
      {"name":"iw3x_location", "size":10, "readonly":iw3x_readonly_flag});
   inputfield("G[Location]+[3,1]", "Room", "G[Location]+[3,12]",
      {"name":"iw3x_room", "size":8, "readonly":iw3x_readonly_flag});
   inputfield("G[Location]+[1,41]", "Plant section", "G[Location]+[1,57]",
      {"name":"iw3x_plant_section", "size":3, "readonly":iw3x_readonly_flag});
   inputfield("G[Location]+[2,41]", "Work center", "G[Location]+[2,57]",
      {"name":"iw3x_work_center", "size":8, "readonly":iw3x_readonly_flag});
}

Note: Use variable "iw3x_readonly_flag" as the value of readonly option for each create element command


Step 5: Conditionalize save function will only be trigger when readonly status is false
if(!iw3x_readonly_flag){
   onUIEvents["/11"] = {"fcode":"?", "process":iw3xSave};      //Execute when user hits save on screen
}

Note: Process "iw3xSave" should be designed to copy created variables to SAP fields in "Location" tab and save


See attachments for code samples
« Last Edit: June 20, 2017, 01:47:05 PM by Leo Chu »