SQL
With DB-DECLARE
DB-DECLARE cursorname correlname1.copylibname-REC ... [DISTINCT] ... [column1 [... columnN]]|[NONE] . ... correlnameN.copylibname-REC ... [column1 [... columnN]]|[NONE] . ... [WHERE correlname.column1 op [:]value|correlname.column2 ... [AND|OR correlname.column3 op [:]value|correlname.column4 . ... AND|OR correlname.columnN operator [:]value|correlnameN]] ... [ORDER ... column1 [ASC|DESC] [...columnN [ASC]]]
With DB-OBTAIN
DB-OBTAIN REC correlname1.copylibname-REC ... [DISTINCT] ... [column1 [... columnN]]|[NONE] . ... REC correlnameN.copylibname-REC ... [column1 [... columnN]]|[NONE] ... [WHERE correlname.column1 op [:]value|correlname.column2 ... [AND|OR correlname.column3 op [:]value|correlname.column4 . ... AND|OR correlname.columnN op [:]val|correlname.columnN]]
With DB-PROCESS
DB-PROCESS REC correlname1.copylibname-REC ... [DB-PROCESS-ID name] ... [DISTINCT] ... [column1 [... columnN]]|[NONE] . ... REC correlnameN.copylibname-REC ... [column1 [... columnN]]|[NONE] ... [WHERE correlname.column1 op [:]value|correlname.column2 ... [AND|OR correlname.column3 op [:]value|correlname.column4 . ... AND|OR correlname.columnN op [:]val|correlname.columnN]] ... [DB-LOOP-MAX=number] ... [ORDER ... column1 [ASC|DESC] [...columnN [ASC|DESC]]] Controlled logic block
DB-OBTAIN REC A.D2TAB-REC ... PM_PART_NO PM_UNITS PM_COLOR ... REC B.D2INVEN-REC ... IN_PART_NO IN_QTY_ONHAND ... IN_DATE_LAST_ORDER ... WHERE A.PM_PART_NO = B.IN_PART_NO ... AND A.PM_COLOR = 'RED' ... AND B.IN_COLOR = 'RED'
Declare the cursor D2JOIN-CUR and include columns from tables D2MASTER and D2INVTRY. Use a WHERE clause to select rows where:
DB-DECLARE D2JOIN-CUR A.D2TAB-REC ... DISTINCT ... PM_PART_NO PM_COLOR ... B.D2INVEN-REC ... IN_PART_NO IN_QTY_ONHAND ... WHERE A.PM_PART_NO = B.IN_PART_NO ... AND B.IN_QTY_ONHAND > 100 ... ORDER A.PM_PART_NO B.IN_QTY_ONHAND DESC
Process the cursor D2MAST-ID. The cursor set includes columns from tables D2MASTER and D2INVTRY. Use a WHERE clause to include rows in the cursor set where:
DB-PROCESS REC A.D2TAB-REC ... DB-PROCESS-ID D2MAST-ID ... DISTINCT ... PM_PART_NO PM_COLOR ... REC B.D2INVEN-REC ... IN_PART_NO IN_COLOR ... WHERE A.PM_PART_NO = B.IN_PART_NO ... AND A.PM_PART_SHORT_DESC = ... :WS-PART-SHORT-DESC ... AND B.IN_QTY_ONHAND > 100 ... DB-LOOP-MAX=999 ... ORDER A.PM_PART_NO ASC ... A.PM_COLOR ASC
DB-PROCESS REC A.D2INVEN-REC ... DB-PROCESS-ID D2MAST-ID ... IN_PART_NO ....IN_QTY_ONHAND ... IN_DATE_LAST_ORDER ... REC B.D2INVEN-REC ... IN_PART_NO (:WS-PART-NO) ... IN_QTY_ONHAND (:WS-QTY-ONHAND) ... WHERE A.IN_DATA_LAST_ORDER = B.IN_DATE_LAST_ORDER ... AND A.IN_QTY_ONHAND > 100