SQL
DB-DECLARE cursorname [correlname1.]copylibname-REC . . ... UNION [ALL] DB-OBTAIN REC copylibname-REC . . ... [ORDER ... column1 [ASC|DESC] [...columnN [ASC|DESC]]]
DB-PROCESS REC [correlname1.]copylibname-REC . . ... UNION [ALL] DB-OBTAIN REC copylibname-REC . . ... [ORDER ... column1 [ASC|DESC] [...columnN [ASC|DESC]]]
See the applicable database call for parameter descriptions.
Unite DB-DECLARE with one DB-OBTAIN; eliminate duplicate rows; sort the combined table in ascending order by PM_PART_NO, then in descending order by PM_UNIT_BASE_PRICE and PM_UNITS. Note that the column literals STMT1 and STMT2 identify which call retrieves each row.
DB-DECLARE D2MAST-CURSOR D2TAB-REC ... DISTINCT ... PM_PART_NO PM_UNIT_BASE_PRICE PM_UNITS 'STMT1' ... WHERE PM_PART_SHORT_DESC = :WS-PART-SHORT-DESC ... AND PM_UNIT_BASE_PRICE BETWEEN 50 AND 150 ... UNION DB-OBTAIN REC D2TAB-REC ... PM_PART_NO PM_UNIT_BASE_PRICE PM_UNITS 'STMT2' ... WHERE PM_PART_SHORT_DESC = :WS-PART-SHORT-DESC ... AND PM_UNIT_BASE_PRICE > 300 ... AND PM_UNITS > 1000 ... ORDER 1,2 DESC, 3 DESC
Unite DB-PROCESS with one DB-OBTAIN call. Sort the combined table in ascending order by PM_PART_NO, then in descending order by PM_UNIT_BASE_PRICE and PM_UNITS.
DB-PROCESS REC D2TAB-REC ... DB-PROCESS-ID D2UNION-ID ... DISTINCT ... PM_PART_NO PM_UNIT_BASE_PRICE PM_UNITS ... WHERE PM_PART_SHORT_DESC = :WS-PART-SHORT-DESC ... AND PM_UNIT_BASE_PRICE > 50 ... AND PM_UNIT_BASE_PRICE < 150 ... DB-LOOP-MAX=500 ... UNION DB-OBTAIN REC D2TAB-REC ... PM_PART_NO PM_UNIT_BASE_PRICE PM_UNITS ... WHERE PM_PART_SHORT_DESC = :WS-PART-SHORT-DESC ... AND PM_UNIT_BASE_PRICE > 300 ... AND PM_UNITS > 1000 ... ORDER 1,2
Because return-fields are not specified for JOB_NAME and PROC_NAME, the host variables of those same names are used. In the case of the literal P, no host variable exists so a return-field must be specified. Specify return-fields only in the DB-DECLARE or DB-PROCESS statements.
DB-PROCESS ... REC A.HTJCLD-REC ... DB-PROCESS-ID SHARED-ID ... JOB_NAME ... PROC_NAME ... REC B.HTJOBR-REC ... 'P' (WS-HOLD-ACTION) ... WHERE B.RESOURCE = :WS-RESOURCE AND ... B.JOB_NAME = :WS-JOB-NAME ... UNION ALL DB-OBTAIN REC A.HTJCLD-REC ... DISTINCT JOB_NAME ... PROC_NAME ... REC B.HTJSTEP-REC ... 'A' ... WHERE B.JOB_NAME = :WS-JOB-NAME ... ORDER 01 03 02
Retrieve different columns from two tables. Unite DB-PROCESS with one DB-OBTAIN call and sort the combined table in ascending order by UNIT_CODE, STD_MAT_INV_ACCT, and PART_NUMBER.
In the DB-PROCESS call, select five columns from table 1. However, in the DB-OBTAIN statement, select only two columns from table 2. To maintain the same number of columns for each select, enter literals as place holder values that correspond in data type to table 1. To use different columns in the DB-PROCESS call (or in a DB-DECLARE call), be sure that each corresponding column from the DB-PROCESS call (or DB-DECLARE call) and each DB-OBTAIN call match in data type.
DB-PROCESS REC MANAGE01-REC ... UNIT_CODE STD_MAT_INV_ACCT ... PART_NUMBER (WS-PART-NUMBER) ... UNIT_OF_MEASURE (WS-UNIT-OF-MEASURE) ... FREIGHT_CODE (WS-FREIGHT-CODE) ... WHERE NOT DATA_TYPE = `F' ... UNION DB-OBTAIN REC-MANAGE02-REC ... UNIT_CODE STD_MAT_INV_ACCT ... 999999 (WS-PART-NUMBER) ... `uc' (WS-UNIT-OF-MEASURE) ... `' (WS-FREIGHT-CODE) ... WHERE DATA_TYPE = `F' ... ORDER 1 2 3