7 Replies Latest reply: Oct 30, 2012 12:52 PM by Riccardo Pettenuzzo

# 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 really new

thanks to everyone!!

• ###### 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:

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

RESIDENT

TAB;

LET Y= \$(Y) + 15;

NEXT

• ###### 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?

• ###### 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             ...........

• ###### Re: Cycle FOR/WHILE/LOOP ETC.

Take a look at this qvw file using Join.

TAB:

F1

12345678pizza__________maccheroni_____mafia__________berlusca_______ etc..

];

SET Y= 9;

FOR A=1 TO 5

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.

• ###### 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!!

• ###### 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

• ###### 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

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

FROM X.QVD (qvd);

LET Y=\$(Y)+15;

NEXT

Hope it helps.