2 Replies Latest reply: May 22, 2018 9:55 AM by Felip Drechsler RSS

    Load and Write in a variable from text file

    sagar jagga

      Hi All,

       

      I want to load a variable in a table from a .txt file and then after want to change the value of the variable and again want to store the new value of the variable in the text file.

        • Re: Load and Write in a variable from text file
          Petter Skjolden

          Do you wish to do this in a load script?

          • Re: Load and Write in a variable from text file
            Felip Drechsler

            Use the following script to take a specific variable, change it and write it to the file.

             

            Data:
            Load * Inline
            [
            Name,Value
            A,1
            B,2
            C,3
            D,4
            ];
            
            
            Variables:
            LOAD [Variable Name], 
                 [Variable Value]
            FROM
            [C:\Users\sbt43959.SAU\Desktop\test.txt]
            (txt, codepage is 1252, embedded labels, delimiter is ',', msq);
            
            
            NoConcatenate
            _tmpVariables:
            Load
            *
            Resident Variables
            where [Variable Name]='A';
            
            
            let A.VariableName = peek('Variable Name',0,'_tmpVariables');
            let A.VariableValue = peek('Variable Value',0,'_tmpVariables');
            
            
            drop table _tmpVariables;
            
            
            // Changing the variable content
            NoConcatenate
            _tmpData:
            Load
            Name, Value
            Resident Data
            where Name = '$(A.VariableName)';
            
            
            // New value for variable A
            let A.VariableNewValue = peek('Value',0,'_tmpData');
            
            
            // Gets all the variables that weren't used
            NoConcatenate
            _tmpNewVariableFile:
            LOAD
            *
            Resident Variables
            where [Variable Name] <> '$(A.VariableName)';
            
            
            
            
            Concatenate(_tmpNewVariableFile)
            Load
            '$(A.VariableName)' as [Variable Name],
            '$(A.VariableNewValue)' as [Variable Value]
            AutoGenerate(1);
            
            
            store _tmpNewVariableFile into New_test.txt (txt);
            

             

            It will get the variable A, check the A field from the data table and overwrite the variable A value with the value from the Data table.

             

            Just used to files (test.txt and New_test.txt) for demonstrating that it changes the file.