Kbase P23578: How to simulate a conditional DESCENDING order in a FOR EACH
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  18/04/2003 |
|
Status: Unverified
GOAL:
How to simulate a conditional DESCENDING order in a FOR EACH statement ?
FIX:
This sample will work against sports2000 database.
FOR EACH statement is stored in cust.i which is included in 2 internal procedures from cust.p.
To make the difference between ASC and DES order the include cust.i is called with or without ORDER preprocessor.
Use an include file for having a single place to maintain your code.
/* cust.p begin */
DEF VAR vlOrder AS LOGICAL.
FORM
vlOrder LABEL "Customer Name Order" FORMAT "Ascending/Descending"
WITH FRAME xx WIDTH 78 SIDE-LABELS.
REPEAT:
UPDATE vlOrder WITH FRAME xx.
IF NOT vlOrder THEN RUN cust_des.
ELSE RUN cust_asc.
END.
PROCEDURE cust_des :
/* set DESCENDING ORDER here */
{cust.i &ORDER="DESCENDING" }
END PROCEDURE.
PROCEDURE cust_asc :
/* no need for preprocessor since by default the order is ASCENDING, so ... */
{cust.i}
END PROCEDURE.
/* cust.p ends */
/* cust.i BEGINS */
FOR EACH customer NO-LOCK
,EACH order OF customer NO-LOCK
BREAK BY customer.NAME
{&ORDER} /* could be DESCENDING or nothing */ :
DISPLAY
customer.NAME WHEN FIRST-OF( customer.NAME )
order.ordernum
.
END.
/* cust.i ENDS */