N
nikita
Guest
I am fairly new to progress. I am trying to figure out the working of a nested for-each loop. Suppose I have three tables Customer, Order and Orderline. I would like to use break by on these tables based on customer.customer-num and Order.ordernum to generate a final report. This is the code I have so far.
for each Customer no-lock,
each order where
order.custnum = customer.custnum no-lock,
each orderline where
orderline.ordernum = order.ordernum
break by customer.custnum
by order.ordernum:
if first-of(customer.custnum) then do:
put stream s1 unformatted
space(3) customer.custnum format ">>>>9" space(1)
customer.name format "x(30)" space(1)
customer.city format "x(12)" space(1)
customer.state format "x(20)" space(1)
customer.country format "x(20)" space(1)
/*order.ordernum format "zzzzzzzzz9" space(1)
order.orderDate format "99/99/99" space(1)
order.orderStatus format "x(20)" */ skip .
end.
put stream s1 unformatted
space(95) order.ordernum format "zzzzzzzzz9" space(1)
order.orderDate format "99/99/99" space(1)
order.orderstatus format "x(20)" space(1).
end.
if first-of(order.ordernum) then do:
put stream s1 unformatted
orderline.linenum format ">>9" space(1)
orderline.itemnum format "zzzzzzzzz9" space(1)
orderline.price format "->,>>>,>>9.99" space(1)
orderline.qty format "->>>>9" skip.
Continue reading...
for each Customer no-lock,
each order where
order.custnum = customer.custnum no-lock,
each orderline where
orderline.ordernum = order.ordernum
break by customer.custnum
by order.ordernum:
if first-of(customer.custnum) then do:
put stream s1 unformatted
space(3) customer.custnum format ">>>>9" space(1)
customer.name format "x(30)" space(1)
customer.city format "x(12)" space(1)
customer.state format "x(20)" space(1)
customer.country format "x(20)" space(1)
/*order.ordernum format "zzzzzzzzz9" space(1)
order.orderDate format "99/99/99" space(1)
order.orderStatus format "x(20)" */ skip .
end.
put stream s1 unformatted
space(95) order.ordernum format "zzzzzzzzz9" space(1)
order.orderDate format "99/99/99" space(1)
order.orderstatus format "x(20)" space(1).
end.
if first-of(order.ordernum) then do:
put stream s1 unformatted
orderline.linenum format ">>9" space(1)
orderline.itemnum format "zzzzzzzzz9" space(1)
orderline.price format "->,>>>,>>9.99" space(1)
orderline.qty format "->>>>9" skip.
Continue reading...