Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Diego_780
Creator
Creator

SUB routine apparently not working to make prefixes on table dimensions (like qualify)

Hello qlik pros!

I need some help because i don´t understand how it works what i have.

Apparently, I have a Subroutine that takes the table name, makes a prefix and puts it to each dimension of that table and renames it (basically a qualify):

SUB PrefixFields(vTableName)
    LET vNumFields = NoOfFields('$(vTableName)');
    FOR i = 1 TO $(vNumFields)
        LET vField = FieldName($(i), '$(vTableName)');
        // Evitamos campos técnicos o ya renombrados
        IF Left('$(vField)', 2) <> '__' AND Index('$(vField)', '$(vTableName).') = 0 THEN
            LET vNewField = '$(vTableName)-' & '$(vField)';
            RENAME FIELD [$(vField)] TO [$(vNewField)];
            LET vField2 = FieldName($(i), '$(vTableName)');
        ENDIF
    NEXT i
END SUB

LET vURL = '"http://ws.visualnacert.com/vnwebservices/user/$(vUserid)/v3/persontypes"';

RestConnectorMasterTable:
SQL SELECT 
    "__KEY_root",
    (SELECT 
        "id",
        "value",
        "__FK_data"
     FROM "data" FK "__FK_data")
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION ( URL $(vURL));

[PersonTypes_data]:
LOAD    
    [id],
    [value]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_data]);
DROP TABLE RestConnectorMasterTable;

CALL PrefixFields('PersonTypes_data');

 

When i go to see the visor, i see it perfectly, for now, i have 3 tables and they do what its said to be programmed:

Diego_780_0-1761122217112.png

But when i try to store them into qvds with this script, it doesnt store with that prefix, and instead, stores the original names (id, desc):

For i = 0 to NoOfTables()-1
    LET vTabName = TableName(0);
    STORE [$(vTabName)] INTO [$(vRutaQVD_VISUAL)$(vTabName).qvd] (qvd);
    DROP TABLE [$(vTabName)];
Next i

 

How is that possible or what am I doing wrong exactly? If i see that the SUB and CALL apparently makes the job done.

Thanks in regards,

Diego.

Labels (4)
1 Reply
marcus_sommer

You may not look on the wanted qvd else on elder (temporary) ones because the store-routine used tablename(0) instead of tablename($(i)). Further if I remember correctly needs this kind of loop-iteration to be reversed if it contains a drop-logic - means something like:

for i = nooftables()-1 to 0 step -1

To check this kind of logic you could comment the store + drop and adding a trace-statement like:

trace $(i) - $(TabName);

Further I could imagine that you may get the above described results with the qualifying-statements, maybe like:

qualify *;
unqualify __*;

load ...;
store ...;

unqualify *;

Beside this I suggest to rethink the entire approach because this qualifying caused later a lot of efforts to remove it again or leading to complex and unsuitable data-models. A BI data-model should be de-normalized as much as possible. If a tracking/differentiating of the data is needed this information could be added as an extra source-field within the table.