Liquid UI - Documentation - 18.08 Copy file content to textbox

18.08 Copy file content to textbox


Prerequisites


Purpose:

This article guides you through the process of copying file content to a textbox using copytext() and readfile(), which enables users to open a file, read its contents, and seamlessly copy them into the desired field on the SAP screen.

To demonstrate this, we are considering the SAP Easy Access screen. Please proceed with the following actions.

  1. Delete the image container on the SAP Easy Access screen.
  2. Add a toolbar push button to initiate the process.
  3. Add a textbox to display the text copied from the file.
  4. Add a function to copy the text from the file.

 

User Interface

//Create this file inside your script folder for customizing the SAP Easy Access screen: SAPLSMTR_NAVIGATION.E0100.sjs

//Now, let's add the Liquid UI script to the above file and save it.

  

Customization

  1. Delete the image container on the SAP Easy Access screen using del().
     
    // Deletes the image container
    del("X[IMAGE_CONTAINER]");
    
     
      
  2. Add a toolbar push button labeled Copy from File to initiate the copy operations on click.
      
    //Creates a toolbar push button to execute the z_readfile process.
    pushbutton([TOOLBAR],'Copy from File','?',{'process':z_readfile});
     
      
  3. Create a textbox with the technical name z_textbox to display the copied text from the txt file.
      
    //Creates a textbox with z_textbox as its technical name.
    textbox([2,1], [8,117], {"name":"z_textbox", "textfont":"Arial", "textheight":"12", "textweight":"5"});
      
  4. Add a function to copy the text from a file.
      
    // Function to copy the text from file
    function z_readfile()
    {
    // filename specifies the file in use
    // command opens specified file
    //NEXT_LINE_READ:
         openfile('filenames.txt'); 
    // read file data into variable
    function isBlank(jvar) {
       if(jvar==void 0 || jvar=="" || jvar==null) {
          return true;
        }
       else {
          return false;
        }
    }
         readfile('filenames.txt',{"z_content":true}); 
         if(isBlank(z_content)){   // condition to exit loop
             println("<<<<<<<<<<<<<>>>>>>>>>>>>>");
             goto END; 
          } 
         copytext({"fromstring":"z_content","totext":"z_textbox", "appendline":true}); //copy data from variable to textbox
         //goto NEXT_LINE_READ;
    END:
         closefile('filenames.txt');  //close opened file
    }
    
     

SAP Process

  1. Refresh the SAP screen, and click on the toolbar push button Copy from File. This action copies the content from the filenames.txt file to the created textbox, as shown below.
     
     
     
    Note: The file to be read should be in your scripts folder, and the filename is case-sensitive.

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