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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem with LOAD inside a FOR/NEXT clause

I'd like to load the same table several times, each time giving a different name to it's fields.

Say that I have a "NAME" field on the table. Then I want to load it once as NAME1 then NAME2 and so forth up to NAME10.

Looks easy but it does not work !

Attached sample is pretty straightforward to check the problem !

Any hints or suggestions ?

Thanks in advance !

1 Solution

Accepted Solutions
boorgura
Specialist
Specialist

I figured it out.

it was a problem with the resident table Map_Fields

This did the trick:

FOR NRO=1 TO 5
MAP_FIELDS$(NRO):
MAPPING LOAD * INLINE [
NAME_FROM,NAME_TO
SIGLUF_VSUFS,SIGLUF_VSUFS$(NRO)
NOMEUF_VSUFS,NOMEUF_VSUFS$(NRO)
];

VSUFS$(NRO):

LOAD
*
FROM TEST165P.CSV (OEM, TXT, DELIMITER IS ';', EMBEDDED LABELS, NO QUOTES);

RENAME FIELDS USING MAP_FIELDS$(NRO);

NEXT

View solution in original post

6 Replies
boorgura
Specialist
Specialist

Adriano,

not sure if you were looking for this:

FOR NRO = 1 TO 5

VSUFS$(NRO):
LOAD SIGLUF_VSUFS as SIGLUF_VSUFS$(NRO),
NOMEUF_VSUFS as NOMEUF_VSUFS$(NRO)
FROM [TEST165P.CSV] (ansi, txt, delimiter is ';', embedded labels, msq);

NEXT

Let me know if it works.

boorgura
Specialist
Specialist

Moreover,

if you want them in the same table:

you can use concatenate(VSUFS)

as opposed to storing into a new resident table.

Not applicable
Author

It could work. But I'm intrigued why my original MAP approach does not work.

As for concatenating, not a good idea.

This table above is for STATES or PROVINCES.

Say that I have a CLIENT table with three STATEs fields :

  • STATE where CLIENT was born
  • STATE where CLIENT did last order
  • STATE where CLIENT is living

So, we have three foreign keys pointing to the same table (STATEs). I prefered to clone this table. Thus the need to replicate it's load in three different tables...

boorgura
Specialist
Specialist

In the earlier scenario, you were trying to rename all fields to <fieldname> followed by 1

instead of <fieldname> followed by $(NRO)

I would assume that to be the reason.

Not applicable
Author

I posted wrong the ZIP file. Get it again and you'll see it fixed...

boorgura
Specialist
Specialist

I figured it out.

it was a problem with the resident table Map_Fields

This did the trick:

FOR NRO=1 TO 5
MAP_FIELDS$(NRO):
MAPPING LOAD * INLINE [
NAME_FROM,NAME_TO
SIGLUF_VSUFS,SIGLUF_VSUFS$(NRO)
NOMEUF_VSUFS,NOMEUF_VSUFS$(NRO)
];

VSUFS$(NRO):

LOAD
*
FROM TEST165P.CSV (OEM, TXT, DELIMITER IS ';', EMBEDDED LABELS, NO QUOTES);

RENAME FIELDS USING MAP_FIELDS$(NRO);

NEXT