Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

Cycle FOR/WHILE/LOOP ETC.

Hi to everyone...

I have this problem about loops:

there is a long string that i have to divide in different parts but i'd like to use a cycle instead of rewriting many times the same code, changing the values in the SUBTRING FUNCTION!

this is my code:

SET Y= 9

FOR A=1 TO 10

TABLE_1:

SELECT SUBSTR(XXX, Y, 15) AS COLUMN_A

FROM TAB

LET Y=Y+15

NEXT

I'm glad of receive suggestions!!!

i'm really new

thanks to everyone!!

1 Solution

Accepted Solutions
Not applicable

Re: Cycle FOR/WHILE/LOOP ETC.

I could reach the aim

but with MID and LOAD it doesnt work!!

this is the perfect result i got:

SET Y=9;

FOR A=1 TO 10

SELECT

SUBTR(TAB.F1, $(Y), 15)

FROM TAB

/*WHERE XXX*/;

LET Y=$(Y)+15;

NEXT

7 Replies
Vegar
Valued Contributor II

Re: Cycle FOR/WHILE/LOOP ETC.

You missed some semicolons and use the wrong function(?)

SET Y= 9;

FOR A=1 TO 10

     TABLE_1:

     LOAD

          mid(F1, $(Y), 15) AS COLUMN_A

     RESIDENT

          TAB;

     LET Y= $(Y) + 15;

NEXT

Please ekskuse my Norglish and Swenglish typos.

Re: Cycle FOR/WHILE/LOOP ETC.

Is the dividing the strings only depends upon the size? because you specified 15?

any delimiters between the parts?

diegofcaivano
Contributor

Re: Cycle FOR/WHILE/LOOP ETC.

Hi.

I'm not sure what you are trying to accomplish, but you must place the variables inside $() to be evaluated.

SET Y=9;

FOR A=1 TO 10

     LOAD

          MID(X_FIELD, $(Y), 15) AS COLUMN_$(A)

     FROM X.QVD (qvd);

     LET Y=$(Y)+15;

NEXT

Hope it helps.

Not applicable

Re: Cycle FOR/WHILE/LOOP ETC.

because every 15 characters there are a field i want:

ex:

123456789pizza_______maccheroni_____mafia__________berlusconi_____ etc...

i would like

column_1        column_2           column _3            column_4              column_5

pizza              maccheroni         mafia                   berlusconi             ...........

Vegar
Valued Contributor II

Re: Cycle FOR/WHILE/LOOP ETC.

Take a look at this qvw file using Join.

TAB:

LOAD * INLINE [

    F1

    12345678pizza__________maccheroni_____mafia__________berlusca_______ etc..

];

SET Y= 9;

FOR A=1 TO 5

join LOAD

F1,

MID(F1, $(Y), 15) AS COLUMN_$(A)

RESIDENT TAB;

LET Y= $(Y) + 15;

NEXT

drop field F1;

Message was edited by: Vegar Arntsen, Lie Added the actual script I used in qvw.

Please ekskuse my Norglish and Swenglish typos.
Not applicable

Re: Cycle FOR/WHILE/LOOP ETC.

1)i feel stupid

2)your file is really good. but in my case the string that u call "F1" is in the database (in the table TAB):

THIS SHOULD BE: MID(TAB.F1, $(Y), 15))

so i'm not able to traslate ur code in relation to my aims.

thanks!!

Not applicable

Re: Cycle FOR/WHILE/LOOP ETC.

I could reach the aim

but with MID and LOAD it doesnt work!!

this is the perfect result i got:

SET Y=9;

FOR A=1 TO 10

SELECT

SUBTR(TAB.F1, $(Y), 15)

FROM TAB

/*WHERE XXX*/;

LET Y=$(Y)+15;

NEXT

Community Browser