Liquid UI - Documentation - 12.11 Update multiple item fields based on the screen size

12.11 Update multiple item fields based on the screen size


Prerequisites


Purpose

To dynamically update multiple SAP item fields based on a resized screen display. The number of rows varies based on the screen size. And, the script should be updated based on the visible SAP rows before clicking on new items to populate the next set.

User Interface

//Create the file SAPLSMTR_NAVIGATION.E0100.sjs inside your script folder for customizing the SAP Easy Access screen.
//Now, let's start adding the Liquid UI script to the above file and save it.

Customization

  1. Logon to SAP, and delete the image container and unnecessary elements using the del command on the SAP Easy Access screen.
     
    // Deletes an image container on the SAP Easy Access screen/
    del("X[IMAGE_CONTAINER]");
    del('X[IMAGE_CONTAINER]'); // Delete ActiveX 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]');
     
  2. Create five input fields with labels as Document Date, Posting Date, Movement TypePlant, Storage Location, and Cost Center to enter the values, as shown below.
     
    inputfield([1,1], "Document Date", [1,20], {"name":"z_mb1a_docdate", "size":10, "date":true, "required":true});    // 12.12.2006
    inputfield([2,1], "Posting Date", [2,20], {"name":"z_mb1a_postdate", "size":10, "date":true, "required":true}); // 12.12.2006
    inputfield([3,1], "Movement Type", [3,20], {"name":"z_mb1a_mvmttype", "size":3, "required":true}); // 201
    inputfield([4,1], "Plant", [4,20], {"name":"z_mb1a_plant", "size":4, "required":true}); // 1000
    inputfield([5,1], "Storage Location", [5,20], {"name":"z_mb1a_sloc", "size":4, "required":true}); // 0001
    inputfield([6,1], "Cost Center", [6,20], {"name":"z_mb1a_costctr", "size":10, "required":true}); // 1000
     
  3. Add a toolbar push button with the label @0Z@Update-MB1A to execute the process mb1a_update on click, as shown in the image below.
     
    pushbutton([TOOLBAR],"@0Z@Update-MB1A", "?", {"process":mb1a_update});
     
  4. Add 10 rows with the comment "Item Material Quantity" along with input fields, as shown below.
     
    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);
    }

     
  5. Add the following Liquid UI script to this file and save it.
     
    // 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[i]]');
    set('V[z_temp_qty]','&V[z_mb1a_quantity_&V[i]]');
    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');
    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:;
    }

SAP Process

  1. Now, refresh the SAP Easy Access screen, and enter the values for the input fields created as follows.
     
  2. Click on the Update-MB1A toolbar push button to dynamically update the SAP multiple item fields on the MB1A transaction.
 
 

Can't find the answers you're looking for?