Liquid UI - Documentation - 23.14 Update Text Content with Editor

23.14 Update Text Content with Editor


Prerequisites

Purpose

In this article, you will learn how to copy text content to the SAP text editor screen to manage specific SAP long text controls that are incompatible with the copytext command. To demonstrate this process, we are considering the Change Standard Order: Overview screen as an example and we’ll guide you through the following steps:

  1. Navigate to the Change Standard Order: Overview screen
  2. Add a group box to collate related screen elements
  3. Add a textbox where the user can enter the text
  4. Add a push button to save the text and execute the process
  5. Add a function to trim blank spaces in a string
  6. Add a function to check if the string value is blank
  7. Add a function to split the string value
  8. Add a function to check the long text is blank
  9. Add a function to update the text in the SAP text editor

User Interface

//Create the file SAPMV45A: E4001.sjs inside your scripts folder for customizing the Change Standard Order: Overview screen 
//Now, let's add the Liquid UI script to the above file and save it

Customization

  1. Navigate to the Change Sales Order: Initial Screen enter 5235 in the Order input field and click Enter, then you will be navigated to the Change Standard Order: Overview screen, as shown below.
     
     
  2. Add a group box labeled Term of Delivery to collate related screen elements.
     
    //Creates a group box to collate related screen elements
    box([0,87], [5,125], "Term of Delivery");
    
     
     
  3. Add a textbox inside the group box where the user can enter the text, as shown below:
     
    //Creates a textbox to enter the text
    textbox([1,89], [5,119], {"name":"z_va01_term_of_delivery_text"});
    
     
     
  4. Add a push button labeled save icon to execute va01SaveText process on click.
     
    //Creates a pushbutton to execute va01SaveText 
    pushbutton([4,122], "@2L\\QSave Text@", "?", {"process":va01SaveText, "size":[1,2], "using":{"l_seq":6}});
     
     

    //Now, let's start adding the below Liquid UI script to the esession.sjs file and save it.

  5. Add a function to trim the string values.
     
    //Function to trim string 
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
    } 
    
     
  6. Add the isBlank function to check the string value entered in the input field is blank.
     
    //Function to check if the string blank
    function isBlank(jvar) {
        println(jvar);
        if (jvar=="undefined" || jvar== void 0 || jvar.toString().trim()=="" || jvar==null) {
           return true;
        } else {
           return false;
        }
    }
    
     
  7. Add the splitText function to split a string into an array of values
     
    //Function to split a string    
    function splitText(longText, charSize){
       charSize = parseInt(charSize);
       var textArray = longText.split('\n');
       var resultArray = [], matchedArray = [];
       var new_line_content = "", remained_line_content = "", cur_line = "";
       
       for(var iCount=0; iCount<textArray.length; iCount++){
          new_line_content = textArray[iCount].replace(/\t+/g," ").trim();      //Text editor doesn't support Tab content
          
          do{
             remained_line_content = "";
             if(new_line_content.length > charSize){
                cur_line = new_line_content.substring(0,charSize);
                matchedArray = cur_line.match(/((\S*\s+\S*)+\s)|(\S*)/g);
                remained_line_content = new_line_content.substring(matchedArray[0].length, new_line_content.length)
                new_line_content = matchedArray[0];
             }
             resultArray.push(new_line_content);
             new_line_content = remained_line_content;
          } while(new_line_content.length > 0)
       }
                      
       return resultArray;
    }
    
     
  8. Add the isTextBoxBlank function to check the blank long text specified in the textbox.
     
    //Function to check if longtext is blank
    function isTextBoxBlank(longText) {
       var bTextExist = true;
       var arrText = longText.split('\n');
       for(var iCount=0; iCount<arrText.length; iCount++) {
          if(!isBlank(arrText[iCount].trim())) {
             bTextExist = false;
             break;
          }
       }
       return bTextExist;
    }
    
     

    //Now, let's add the below Liquid UI script to the SAPMV45A:E4001.sjs file and save it

  9. Add the va01SaveText function to copy the text entered in the textbox and paste the text into an SAP text editor.
     
    //Function to copy text content to SAP text editor screen
    function va01SaveText(param){
        var z_va0x_find_text_counter = param.l_seq;                //Copy passed sequence parameter 
    
        onscreen "SAPMV45A.4001"
            if(isBlank(z_va01_term_of_delivery_text.trim())){    //Skip copy text if textbox is blank
                goto SKIP_COPY_TEXT;
            }
            var start_line=1;                                    //Set initial values
            var blank_line=0; 
            enter('/Menu=3,2,11');                                //Go to Header Data-> Text tab
            onmessage                                            //Error handling
                if(_message.substring(0,2) == "E:"){
                    message(_message);
                    enter('?');
                    goto FUNC_END;
                }
                else
                    enter();
            
        onscreen 'SAPMV45A.4002'
            enter('=TP_FIRST');                         //Go to first option in the list
            
    RECHECK_FIND_TEXT:;
        onscreen 'SAPMV45A.4002'
            if(z_va0x_find_text_counter > 0){           //According to sequence value
                z_va0x_find_text_counter--;
                enter('=TP_NEXT');                       //Go to next text in the list
                goto RECHECK_FIND_TEXT;
            }
            else{
                enter('=TP_DETAIL');                            //Go to text editor
            }
            
        onscreen 'SAPLSTXX.2102'
            enter('/Menu=3,3');                              //Change editor
            
        onscreen 'SAPLSTXX.1100'
            enter("/Menu=1,7");                          //Cancel existing content
            
        onscreen 'SAPLSPO1.0100'
            enter("=YES");                                 //Select "yes" in the popup
            
        onscreen 'SAPLSTXX.1100'
            setcursor('cell[TABLE,3,'+(start_line+2)+']');
            var tmp_next_line = "";
            enter();
        
    NEXT_LINE:;
        onscreen 'SAPLSTXX.1100'
            //Copy each line from textbox to a temp string
            copytext({"fromtext":"z_va01_term_of_delivery_text", "tostring":"tmp_line", "line":start_line});
            
            //Remove "indent" in the string if it's not empty
            if(!isBlank(tmp_line)){
                tmp_line = tmp_line.replace(/\t+/g," ").trim();    
            }else{
                tmp_line = "";
            }
            
            //Merge the temp next line with current line
            if(!isBlank(tmp_next_line)){
                tmp_line = tmp_next_line + " " + tmp_line;
            }
            
            if(!isBlank(tmp_line)){
                if(tmp_line.length > 72){        //If length of current line exceed 72 characters
                    tmp_chk_text = tmp_line.substring(0,72);
                    tmp_last_space = tmp_chk_text.lastIndexOf(" ");
                    tmp_next_line = tmp_line.substring(tmp_last_space, tmp_line.length);
                    tmp_line = tmp_line.substring(0,tmp_last_space);
                } else {
                    tmp_next_line = "";
                    tmp_line = tmp_line.trim();
                }
                set('cell[TABLE,3,'+(start_line+2)+']',tmp_line);
                blank_line = 0;
                start_line++;
                setcursor('cell[TABLE,3,'+(start_line+2)+']');
                enter();
                goto NEXT_LINE;
            } else {
                if(blank_line < 2){   //If count of continue blank line is less than 2 
                    set('cell[TABLE,3,'+(start_line+2)+']',"");
                    blank_line++;
                    start_line++;
                    setcursor('cell[TABLE,3,'+(start_line+2)+']');
                    enter();
                    goto NEXT_LINE;
                }
            }
            enter('/11');                                        //Save after change
            
        onscreen "SAPMV45A.4001"
    SKIP_COPY_TEXT:;
            enter("?");
            
    FUNC_END:;
    }
    
     

SAP Process

  1. Refresh the SAP screen, enter the long text in the textbox, and click the save button. Subsequently, an SAP GUI security window will appear, requesting authorization. Mark the checkbox and click Allow, as shown below:
     
     
  2. You will observe that the long text entered is displayed in the SAP text editor screen.
     
     

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