Author |
Message
|
caoyuxing |
Posted: Tue Feb 15, 2011 10:06 pm Post subject: ABOUT ESQL "MOVE" |
|
|
Newbie
Joined: 15 Feb 2011 Posts: 4
|
HI,guys
I have used "MOVE" as documents guide.here is the sample code.
Code: |
WHILE LASTMOVE(sourceCursor) DO
SET targetCursor.ItemNumber = sourceCursor.item;
SET targetCursor.Description = sourceCursor.name;
SET targetCursor.Price = sourceCursor.prc;
SET targetCursor.quantity = 1;
CREATE NEXTSIBLING OF targetCursor AS targetCursor REPEAT;
MOVE sourceCursor NEXTSIBLING REPEAT TYPE NAME;
END WHILE; |
But it will build a blank "targetCursor". Because it has already created "targetCursor" even "WHILE" is false.
Now I delete the blank targetCursor using "DELETE FILED".
Can you tell me a more smooth way to do it ,without "DELETE" will be better!thanks! |
|
Back to top |
|
 |
Esa |
Posted: Wed Feb 16, 2011 12:40 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
It has always been difficult to find any mention of 'DO' statement in the documentation, but I recall having done this several times:
Code: |
DO
-- do something
WHILE LASTMOVE(cursor)
|
|
|
Back to top |
|
 |
Esa |
Posted: Wed Feb 16, 2011 12:54 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Sorry,
That is the way you do it in java. IN ESQL you do it with a LOOP which you LEAVE when the condition (LASTMOVE) is no longer true. |
|
Back to top |
|
 |
fatherjack |
Posted: Wed Feb 16, 2011 12:58 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
Rather than CREATE NEXTSIBLING you can CREATE LASTCHILD of taregtSource's parent before you SET the targetSource elements. _________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
Esa |
Posted: Wed Feb 16, 2011 1:09 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
fatherjack wrote: |
Rather than CREATE NEXTSIBLING you can CREATE LASTCHILD of taregtSource's parent before you SET the targetSource elements. |
Yes, but he has obviously done it before entering the WHILE loop.
So, do it this way:
Code: |
LOOP
Set the fieds
Move SourceCursor
if LASTMOVE is false, LEAVE
MOVE targetCursor NEXTSIBLING
END LOOP |
|
|
Back to top |
|
 |
fatherjack |
Posted: Wed Feb 16, 2011 1:20 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
Esa wrote: |
Yes, but he has obviously done it before entering the WHILE loop. |
So delete that line of code.
Esa wrote: |
So, do it this way |
There is more than one way to skin a cat. _________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
Esa |
Posted: Wed Feb 16, 2011 1:31 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
fatherjack wrote: |
So delete that line of code.
|
Think again.
fatherjack wrote: |
There is more than one way to skin a cat. |
True. Sorry that I cut it straight. I must have suddenly got bored of encouraging people to examine the manuals. In the future I will try to be more alert and follow the customs of this forum  |
|
Back to top |
|
 |
mgk |
Posted: Wed Feb 16, 2011 1:45 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
FYI, the ESQL equivalent of DO ... WHILE is the REPEAT ... UNTIL statement:
Code: |
REPEAT [statements] UNTIL [condition] END REPEAT |
Kind Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
Esa |
Posted: Wed Feb 16, 2011 2:17 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Thanks, mgk
I thought there was a way. I should have examined the manuals more carefully myself
Anyhow, LOOP gives you more control and I think it fits this case better. |
|
Back to top |
|
 |
caoyuxing |
Posted: Wed Feb 16, 2011 11:13 pm Post subject: |
|
|
Newbie
Joined: 15 Feb 2011 Posts: 4
|
mgk wrote: |
FYI, the ESQL equivalent of DO ... WHILE is the REPEAT ... UNTIL statement:
Code: |
REPEAT [statements] UNTIL [condition] END REPEAT |
Kind Regards, |
I have tried this way,and we will face the same problem |
|
Back to top |
|
 |
caoyuxing |
Posted: Wed Feb 16, 2011 11:16 pm Post subject: |
|
|
Newbie
Joined: 15 Feb 2011 Posts: 4
|
Esa wrote: |
Thanks, mgk
I thought there was a way. I should have examined the manuals more carefully myself
Anyhow, LOOP gives you more control and I think it fits this case better. |
thanks for your reply!But I have not fully understood fatherjack... |
|
Back to top |
|
 |
fatherjack |
Posted: Thu Feb 17, 2011 1:15 am Post subject: Re: ABOUT ESQL "MOVE" |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
I meant something like this
Code: |
WHILE LASTMOVE(sourceCursor) DO
CREATE LASTCHILD OF targetParent AS targetCursor NAME 'Fred';
SET targetCursor.ItemNumber = sourceCursor.item;
SET targetCursor.Description = sourceCursor.name;
SET targetCursor.Price = sourceCursor.prc;
SET targetCursor.quantity = 1;
MOVE sourceCursor NEXTSIBLING REPEAT TYPE NAME;
END WHILE; |
I've not run this so syntax may not be perfect. _________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
|