Author Topic: Reading List Screen Data: Extracting Material No & Generating List of Checkboxes  (Read 4125 times)

Ashfaq Ahmed

  • Administrator
  • Newbie
  • *****
  • Posts: 32
    • View Profile
Purpose: Reading List Screen Data: Extracting Material Numbers and Generating a Checkbox List of Materials

This article explains how to generate a list of materials from the List screen, which facilitates the display of material details as needed.

Prequisties:
Liquid UI WS

Please follow the below steps:

Step-1 : Open the Script file "SAPLSTMTR_NAVIGATION.E0100.sjs" or Create it if it is not present in the WS Directory as configured in the "guixt.sjs" file.

Step-2 : Add the below Code Snippet and Save it.

//Deleting the Screen Controls
//Liquid UI Code:
del("X[IMAGE_CONTAINER]");
del([/color][/b]"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[Delete Favorites");
del("P[Delete Favorites");
del("P[Change Favorites");
del("P[Move Favorites down");
del("P[Move Favorites up");
del("P[Create role");

//Function to set the screen layout.
function fn_navigate(param){
    set("V[z_screen]","");
    set("V[z_layout]","");
}

//Design Screen.
if(z_screen==undefined || z_screen==""){
    pushbutton([3,1], "@12@Generate Material List",{ "process":z_readfromlist});
    inputfield([1,1],"Max Entries",[1,12],{"name":"z_max","size":"11"});
}

//Function to read the list screen data
function z_readfromlist(){   
    title("Generating Material List....")
    z_material_array  = []; 
    lfvrow = 1;
    onscreen 'SAPLSMTR_NAVIGATION.0100'
        enter("/NSE16");
    onscreen 'SAPLSETB.0230'
        set('F[table Name]', 'MARA');
        enter();
   
    onscreen '/1BCDWB/DBMARA.1000'
        set("F[MAX_SEL]","&V[z_max]");
        enter("/8");
   
    onscreen 'SAPLSETB.0120'
        SCROLL_NEXT:;
        enter("/scrolltoline=&V[lfvrow]");
    onscreen 'SAPLSETB.0120'
        enter("/hscrollto=0");
    if(z_max=="1"){
        goto START;
    }
    if(lfvrow >= _listlastvisiblerow){
        goto END;
    }
    START:;
    lfvrow = _listfirstvisiblerow;
    llvrow = _listlastvisiblerow;
    z_row = 5;

    LOOP:; 
    set("V[z_matval]","&#["+z_row+",20]");   
    z_material_array.push(z_matval);
    lfvrow = lfvrow+1;   
   
    if(lfvrow <= _listlastvisiblerow){   
        z_row = z_row+1;
        goto LOOP;
    }
    if(z_max==1){
        goto END;
    }
    else{
        goto SCROLL_NEXT;
    }   
    END:;

    for(var col = 0; col < z_material_array.length; col++) {
         var objReeb = <"#["+row+","+col+"]">;
        if (objReeb && objReeb.isValid) {
            var trimmedName = objReeb.name.toString().trim();
            if (trimmedName === '5' || trimmedName === '') {
                retString += value + ' ';
                value = "";
            } else if (trimmedName !== lastReebName) {
                value = trimmedName;
                lastReebName = value;
            }
        }
    }

    set("V[z_layout]","1");
    enter("/3");
    onscreen 'SAPLSETB.0120'
        enter("/3");
    onscreen '/1BCDWB/DBMARA.1000'
        enter("/3");
    onscreen 'SAPLSETB.0230'
        enter("/3");
    onscreen 'SAPLSMTR_NAVIGATION.0100'
        enter("?");
    set("V[z_screen]","home");
}
 
//Function to checks the material(s) selection and navigate to MM02
function checkSelection() {
    selected = [];
    for (k=0; k<z_material_array.length;k++) {
        var chkName = "chk"+ (k+1);
        if (eval(chkName) == 'X') {
            selected.push(z_material_array[k]);
        }
    }
    if (selected.length > 1) {
        return("Execute one Material at a Time ");
    }
    if (selected.length == 0) {
        return("No Materials Selected");
    }
    enter("/nmm03")
    onscreen 'SAPLMGMM.0060'
    set("F[Material]",selected[0]);
    enter();
    onscreen 'SAPLMGMM.0070'
        set("cell[Table,0,1]","X");
        set("cell[Table,0,2]","X");
        set("cell[Table,0,3]","X");
        set("cell[Table,0,4]","X");
        set("cell[Table,0,5]","X");
        set("cell[Table,0,6]","X");
        set("cell[Table,0,7]","X");
        set("cell[Table,0,8]","X");
        set("cell[Table,0,9]","X");
        set("cell[Table,0,10]","X");
        set("cell[Table,0,11]","X");
        enter("/6");
    onscreen 'SAPLMGMM.0080'
        enter();
    onscreen 'SAPLMGMM.0080'
        enter();
    onscreen 'SAPMSDYP.0010'
        enter();
}

//Design Screen.
if(z_layout=="1"){
    box([1,0], [z_material_array.length+5,25], "Material List");
    pushbutton([z_material_array.length+3,2], "@16@Display Material",{"process":checkSelection,"size":[2,21]});
    pushbutton([TOOLBAR], "@H9@Home","?",{"process":fn_navigate , "using":{"l_screen":""}});
    for(l=0,m=3;l<z_material_array.length;l++,m++)
    checkbox([m,2], z_material_array[l],{name: "chk"+(l+1)});
}


Refer to the Attachment for clarity....
« Last Edit: May 17, 2024, 10:01:01 AM by Ashfaq Ahmed »