How do I repeat this set of code?

I know you will cringe at my code stucture by its part-time and I'm trying..
The following works well, but I need it to repeat at the end and go back to the top for another item input, unless F4 is pressed.
Can someone help show me how I might accomplish this.
Note the statements at the top and bottom of the code.
Might be a simple as blocking with a repeat but I don't know how to do that.
'preceiate any and all help.
------------------------------------------------------------------------------------------------
define var sdate as date.
define var edate as date.
define var holddate as date.
define var starttot as int.
define var runtot as int.
define var item as char format "x(15)".
define var additional as int.
define var startrun as int.
define var incrament as int.
define var inhand as int.
define var wink as int.
wink = 0.

define temp-table hold
FIELD a_date like sod_due_date
FIELD a_starttot like starttot LABEL "On Hand"
FIELD a_runtot like runtot LABEL "Qty Req"
FIELD a_startrun like startrun LABEL "Net Amt"
FIELD a_factor as int LABEL "Factor(+-)".

/* WANT TO COME BACK TO HERE FROM BELOW */
/* UNLESS THE USER PRESS F4 */

starttot = 0.
item = "".
update item label "What Item (or leave blank to exit and print)"
with frame witem.

for each in_mstr where in_part = item no-lock:
starttot = starttot + in_qty_oh.

display
in_site
int(in_qty_oh)
with down frame mike no-labels no-box.
end.
pause 0.

display
"" starttot LABEL "STARTING QTY"
"--------------------------------------------------------------------"
with frame witem side-labels no-box.

for each sod_det where sod_part = item
and sod_due_date >= today break by sod_part by sod_due_date:
if first-of (sod_part) then
sdate = sod_due_date.
end.

for each sod_det where sod_part = item
and sod_due_date >= today break by sod_part by sod_due_date:
if last-of (sod_part) then
edate = sod_due_date.
end.

incrament = (edate + 1) - (sdate).
holddate = sdate - 1.

repeat:
create hold.
a_date = holddate + 1.
a_starttot = 0.
a_runtot = 0.
a_startrun = 0.
a_factor = 0.
holddate = holddate + 1.

if holddate = edate then
for each sod_det where sod_part = "48-12340" and sod_due_date >= today
break by sod_due_date:
runtot = runtot + sod_qty_ord.

if last-of(sod_due_date) then

do :
find hold where a_date = sod_due_date.
assign a_starttot = starttot
a_runtot = runtot
a_startrun = starttot - runtot.
display hold.
update hold.a_factor
runtot = 0.
starttot = int(a_startrun) + a_factor.
end.
end.
if a_date = edate then
/* WANT TO GIVE OPTION TO GO BACK TO TOP OR EXIT AT THIS POINT */.
end.

------------------------------------------------------------------------------------------------
 
To loop just use a named block eg:

Code:
/* ... */
MAIN-LOOP:
repeat on END-KEY undo, leave:
	/* WANT TO COME BACK TO HERE FROM BELOW */
	/* UNLESS THE USER PRESS F4 */
 
	assign
		starttot = 0
		item = "".
	update item label "What Item (or leave blank to exit and print)"
	with frame witem.
 
/* ... */
		if a_date = edate then
			next MAIN-LOOP.
	end. /* repeat */
end. /* MAIN-LOOP */

Some things that might want to consider:

You should define variables as no-undo unless (unlikley) you want them undone when a transaction is rolled back. Updates to none-undo variables are written into the database bi log files and affect performance.

Code:
define var sdate as date [b]no-undo[/b].
define temp-table hold [b]no-undo[/b]
	field ...


Whenever referencing database fields always proceed field name with table name eg sod_part.sod_due_date not sod_due_date this will make the code much easier to read and avoids compile problems when a field is in more than one table.

When assigning multiple variables/fields use an assign statement, it results in more efficient code. eg:

Code:
assign
	a_date = holddate + 1
	a_starttot = 0
	a_runtot = 0
	a_startrun = 0
	a_factor = 0.
 
Top