Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Gokryzex
Contributor
Contributor

variabilize encoding in LOAD

Hello team! I need to load several files in an S3 bucket, my files are not always in the same format (delimiter and encoding in particular). I therefore defined the following function:

SUB load_table_from_s3(file_path, output_table_name, columns, encoding, delimiter)   
    $(output_table_name):
    LOAD
        $(columns)
    FROM [lib://S3-my_bucket (qlik-sense_qsadmin)/$(file_path)]
    (txt, $(encoding) , embedded labels, delimiter is '$(delimiter)', msq, no quotes);
END SUB;

CALL load_table_from_s3('file_1.csv', 'table_1', '*', 'utf8', ';')
CALL load_table_from_s3('file_2.csv', 'table_2', '*', 'codepage is 1252', '|')

I think there's an error with the encoding variable that isn't working. Could someone help me? Is it a good approach to work like this? Thanks in advance

Labels (1)
1 Reply
marcus_sommer

In general is such an approach be working but defining and calling the parameter respectively the variables could be tricky. This regards especially to the quoting - with single-quotes or double-quotes and/or wrapped in each other and/or without them - and depending of the context of the call you may need another syntax.

In the first step it could be helpful to comment the load-statement and using TRACE for each parameter/variable to see their content and format and then also combining them. Normally all necessary defining/calls should be directly possible but if some are too restive you could apply some extra steps in the sub and applying there the necessary quoting, like:

let vParameter1 = replace(Parameter1, chr(39), '');