Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
GHasan
Contributor III
Contributor III

QV Load Script

Hi, 

I have a text file that looks like: 

Value Desc1
1 = 'A'
2 = 'B'
3 = 'C'
4 = 'D'
;
Value Desc2
1 = 'Good'
2 = 'Bad'
3 = 'Average'
;
Value Desc3
A0 = 'Green'
B1 = 'Blue'
C2 = 'Red'

I want to load this file into QV and do some scripting in load script so the final output looks like this:

DescType Value ValueDesc
Desc1 1 'A'
Desc1 2 'B'
Desc1 3 'C'
Desc1 4 'D'
Desc2 1 'Good'
Desc2 2 'Bad'
Desc2 3 'Average'
Desc3 A0 'Green'
Desc3 B1 'Blue'
Desc3 C2 'Red'

Does anyone know how I can do that or maybe point towards a documentation? Thanks in advance.




Labels (2)
2 Replies
GHasan
Contributor III
Contributor III
Author

Hi Niclenix, 

Thank you for your reply. I think I should have mentioned that there are at least 20/30 mini tables within  ';' with different values and value descriptions. So the separating the temp tables will be very time consuming. Is there a way to achieve this with a loop statement? Like asking the load script to read this as one column and then whenever it finds the "value" it can  put "Desc1" in one column and "Value" in another column and "Value Desc" in 3rd column and then search through the rows and then when reaches the word "value" again then the put 'Desc2" under the last line of "Desc1" and then the "Value" and "Value Desc" in consecutive columns?

Please let me know if it does not make sense or if that is not the right way to move forward. I truly appreciate your help on this. Thanks 

GHasan
Contributor III
Contributor III
Author

I have a found a solution that works. Here is the script:

//Name the text file as 'Sample'
 
Temp:
LOAD
          @1 As Data
From [C:\Desktop\Sample.txt]
(txt, codepage is 28591, no labels, delimiter is '^', msq)
;
 
LET currentDescType = '';
LET currentDesc = '';
 
FOR i = 0 TO FieldValueCount('Data')
    LET line = Peek('Data', $(i), 'Temp');
 
    IF WildMatch(line, 'Value Desc*') THEN
        currentDescType = SubField(line, ' ', 2);
 
    ELSEIF WildMatch(line, '* = *')
        LET value = PurgeChar(SubField(line, '=', 1), ' ');
        LET valueDesc = PurgeChar(SubField(line, '=', 2), ' ');
 
        
        OutputTable:
        LOAD
            '$(currentDescType)' AS DescType,
            '$(value)' AS Value,
            '$(valueDesc)' AS ValueDesc
        AUTOGENERATE 1;
    ENDIF
NEXT;
 
Drop Table Temp;


The output looks like this:
GHasan_0-1686928323336.png

Thanks,