Author Topic: Update Resizeable SAP Multiple Item Fields Dynamically  (Read 6979 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 96
    • View Profile
Update Resizeable SAP Multiple Item Fields Dynamically
« on: February 25, 2016, 06:33:44 PM »
Purpose:
To update SAP multiple Item fields dynamically based on re-sized screen display. The number of rows would vary based on the screen size and the script should update based on displayed SAP rows and then click on new items to populate the next set.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// Purpose: Function is called to remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// Purpose: Function is called to validate if the variable holds blank or null value
function isBlank(jvar){
   if(typeof jvar == 'string') {
      jvar = jvar.trim();
   }
   return(jvar == 'undefined' || jvar == null || jvar == "" || jvar == void 0);
}

// Purpose: Function is called to update SAP multiple Item Fields Dynamically based on re-sized screen display
function mb1a_update(){
   var z_mb1a_relrow = 1;
   var z_mb1a_absrow = 1;
   var z_mb1a_material_total_counter = 0;
   
   if(isBlank(z_mb1a_docdate)){
      return('E: Enter Document Date');
   }
   if(isBlank(z_mb1a_postdate)){
      return('E: Enter Posting Date');
   }
   if(isBlank(z_mb1a_mvmttype)){
      return('E: Enter Movement Type');
   }
   if(isBlank(z_mb1a_plant)){
      return('E: Enter Plant');
   }
   if(isBlank(z_mb1a_sloc)){
      return('E: Enter Storage Location');
   }
   if(isBlank(z_mb1a_costctr)){
      return('E: Enter Cost Center');
   }
   
   // Below logic to check and validate Material and Quantity fields
   for(var i=1;i<z_endrow;i++){
      set('V[z_temp_mat]','&V[z_mb1a_material_&V]');
      set('V[z_temp_qty]','&V[z_mb1a_quantity_&V]');
      z_temp_mat = z_temp_mat.trim();
      z_temp_qty = z_temp_qty.trim();
      
      // Make Material required if Quantity is entered
      if((isBlank(z_temp_mat)) && (!isBlank(z_temp_qty))){
         return("E: Please enter Material for Item: "+i);
      }
      
      // Make Quantity required if Material is entered
      if((!isBlank(z_temp_mat)) && (isBlank(z_temp_qty))){
         return("E: Please enter Quantity for Item: "+i);
      }
      
      // Increment the counter if material and quantity are not all filled
      if((!isBlank(z_temp_mat)) && (!isBlank(z_temp_qty))){
         z_mb1a_material_total_counter++;
         continue;
      }
   }
   
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      enter('/nMB1A');
   
   onscreen 'SAPMM07M.0400'
      set('F[Document Date]','&V[z_mb1a_docdate]');
      set('F[Posting Date]','&V[z_mb1a_postdate]');
      set('F[Movement Type]','&V[z_mb1a_mvmttype]');
      set('F[Plant]','&V[z_mb1a_plant]');
      set('F[Storage Location]','&V[z_mb1a_sloc]');
      enter();
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;
      
   onscreen 'SAPMM07M.0421'   
      set('F[Cost Center]','&V[z_mb1a_costctr]');
      enter();
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;
         
   NEW_ITEM:;         
   onscreen 'SAPMM07M.0421'   
      NEXT_MATERIAL:;
      set('V[z_temp_mat]','&V[z_mb1a_material_&V[z_mb1a_absrow]]');
      set('V[z_temp_qty]','&V[z_mb1a_quantity_&V[z_mb1a_absrow]]');
      
      if(!isBlank(z_temp_mat)){
         if(z_mb1a_relrow == 1){
            set('F[MSEG-MATNR]','&V[z_temp_mat]');      // First material field
            set('F[MSEG-ERFMG]','&V[z_temp_qty]');      // First quantity field
         } else{
            set('V[z_mb1a_cur_item_onscreen]','&F[MSEG-MATNR.&V[z_mb1a_relrow]]');
            if(!isBlank(z_mb1a_cur_item_onscreen)){
               set('F[MSEG-MATNR.&V[z_mb1a_relrow]]','&V[z_temp_mat]');   // Subsequent material fields - F[MSEG-MATNR.1]
               set('F[MSEG-ERFMG.&V[z_mb1a_relrow]]','&V[z_temp_qty]');   // Subsequent quantity fields - F[MSEG-ERFMG.1]
            } else{
               goto ENTER_ON_SCREEN;
            }
         }
         z_mb1a_relrow++;
         z_mb1a_absrow++;
         goto NEXT_MATERIAL;
      } else{
         ENTER_ON_SCREEN:;
         if(z_mb1a_relrow < 3){
            set('V[z_mb1a_last_item_onscreen]',"&F[MSEG-ZEILE]");
         } else{
            set('V[z_mb1a_last_item_onscreen]',"&F[MSEG-ZEILE."+(z_mb1a_relrow-1)+"]");
         }
      }
      enter();
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;

   NEXT_ITEM:;      
   onscreen 'SAPMM07M.0410'
      REPEAT_ENTER:;
      enter();
      onmessage
      if(_message.substring(0,2) == 'E:'){
         message(_message);
         enter('/n');
         goto SCRIPT_END;
      } else if(_message.substring(0,2) == 'W:'){
         goto REPEAT_ENTER;
      } else{
         goto NEXT_ITEM;
      }
      
   onscreen 'SAPMM07M.0421'
      if(_message.substring(0,2) == "E:"){
         message(_message);
         enter('/n');
         goto SCRIPT_END;
      }
      z_mb1a_last_item_onscreen = parseInt(z_mb1a_last_item_onscreen).toString();
      if(z_mb1a_last_item_onscreen == z_mb1a_material_total_counter){
         enter('?');         // Post or Save, but just doing refresh in this example
      } else{
         z_mb1a_relrow = 1;
         enter("/19");      // Click "New Item"
         goto NEW_ITEM;
      }
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;
         
   SCRIPT_END:;
}


// User Interface
del('X[IMAGE_CONTAINER]');      // Delete AxtiveX Container on SAP Easy Access screen
del('P[User menu]');
del('P[SAP menu]');
del('P[SAP Business Workplace]');
del('P[Display role menu]');
del('P[Add to Favorites]');
del('P[Delete Favorites]');
del('P[Change Favorites]');
del('P[Move Favorites down]');
del('P[Move Favorites up]');
del('P[Create role]');
del('P[Assign users]');
del('P[Documentation]');

inputfield([1,1], "Document Date", [1,20], {"name":"z_mb1a_docdate", "size":10, "date":true, "required":true});   
inputfield([2,1], "Posting Date", [2,20], {"name":"z_mb1a_postdate", "size":10, "date":true, "required":true});   
inputfield([3,1], "Movement Type", [3,20], {"name":"z_mb1a_mvmttype", "size":3, "required":true});            
inputfield([4,1], "Plant", [4,20], {"name":"z_mb1a_plant", "size":4, "required":true});                     
inputfield([5,1], "Storage Location", [5,20], {"name":"z_mb1a_sloc", "size":4, "required":true});            
inputfield([6,1], "Cost Center", [6,20], {"name":"z_mb1a_costctr", "size":10, "required":true});            

z_endrow = 10;
comment([8,01], "Item   Material          Quantity");      
for(item_counter=1; item_counter<z_endrow; item_counter++){         // Display 10 rows on UI
   inputfield([item_counter+8,01], {"name":"z_mb1a_item_&V[item_counter]", "size":4, "readonly":"true", "alignright":"true", "nolabel":"true"});
   inputfield([item_counter+8,06], {"name":"z_mb1a_material_&V[item_counter]", "size":18, "nolabel":"true"});      // 1157
   inputfield([item_counter+8,25], {"name":"z_mb1a_quantity_&V[item_counter]", "size":10, "nolabel":"true"});
   
   set("V[z_mb1a_item_&V[item_counter]]", item_counter);
}

pushbutton([TOOLBAR], "@0Z@Update - MB1A", '?', {"process":mb1a_update});   // Function call to update


See attachments for code samples!