Code SQL built-in and scalar functions as keywords for the database access calls DB-DECLARE, DB-OBTAIN, and DB-PROCESS.
DB-DECLARE cursorname [correlname1.]copylibname-REC ... function1[(](expression)[,expression[,Y][)]] ... function2[(](expression)[,expression[,Y][)]] . . . ... functionN[(](expression)[,expression[,Y][)]] ... WHERE ...
DB-OBTAIN REC [correlname1.]copylibname-REC ... function1[(](expression)[,expression[,Y][)]] ... function2[(](expression)[,expression[,Y][)]] . . . ... functionN[(](expression)[,expression[,Y][)]] ... WHERE ...
DB-PROCESS REC [correlname1.]copylibname-REC ... [DB-PROCESS-ID name] ... function1[(](expression)[,expression[,Y][)]] ... function2[(](expression)[,expression[,Y][)]] . . . ... functionN[(](expression)[,expression[,Y][)]] ... WHERE ...
DB-OBTAIN .. REC PARTDESC-REC .. WHERE .. MAX (PD_LONG_DESC) = 3
DB-DECLARE D2MAST-CURSOR D2TAB-REC ... MIN((PM_UNIT_BASE_PRICE),WS-PM-UNIT-BASE-PRICE,Y) ... COUNT((DISTINCT PM_COLOR),WS-PM-COLOR,Y) ... WHERE PM_PART_NO = :WS-PART-NO
DB-OBTAIN REC D2TAB-REC ... MAX((PM_UNIT_BASE_PRICE),WS-MAX-PRICE,Y) ... MIN((PM_UNIT_BASE_PRICE * PM_UNITS),WS-MIN-RESULT,Y) ... WHERE PM_PART_SHORT_DESC = 'WIDGET'
Generated code:
EXEC SQL SELECT MAX(PM_UNIT_BASE_PRICE) MIN(PM_UNIT_BASE_PRICE * PM_UNITS) into :WS-MAX-PRICE, :WS-MAX-PRICE-IND :WS-MIN-RESULT :WS-MIN-RESULT-IND FROM AUTHID.D2MASTER WHERE PM_PART_SHORT_DESC = 'WIDGET' END-EXEC.
DB-OBTAIN REC D2TAB-REC ... SUM(PM_UNITS) ... AVG((PM_UNITS),WS-AVG-UNITS,Y) ... WHERE PM_PART_NO = '23432'
Generated code:
EXEC SQL select SUM(PM_UNITS) AVG(PM_UNITS) INTO :D2TAB-REC.PM-UNITS :IND-D2TAB-REC.IND-PM-UNITS, :WS-AVG-UNITS :WS-AVG-UNITS-IND FROM AUTHID.D2MASTER WHERE PM_PART_NO = '23432' END-EXEC.
DB-OBTAIN REC D2MASTER-REC ... MAX((PM-UNITS),WS-MAX-PM-UNITS) ... COUNT((*),WS-PM-COUNT-FLD) ... AVG((PM-UNIT-BASE-PRICE),WS-AVG-PRICE) ... WHERE PM-PART-SHORT-DESC='WIDGET' ... AND PM-COLOR='RED'
Generated code:
EXEC SQL select MAX(PM-UNITS) MIN(PM-UNIT-BASE-PRICE) COUNT(*) AVG(PM-UNIT-BASE-PRICE) INTO WS-MAX-PM-UNITS WS-MAX-PM-UNITS-IND, WS-PM-COUNT-FLD, WS-AVG-PRICE WS-AVG-PRICE-IND FROM AUTHID.D2MASTER WHERE PM-PART-SHORT-DESC='WIDGET' AND PM-COLOR='RED' END-EXEC.
DB-OBTAIN REC D2INVEN-REC ... IN_PART_NO ... DATE(IN_DATE_LAST_UPDTE) ... TIME((IN_TIME_LAST_UPDTE),WS-TIME-RETURN,Y) ... CHAR((IN_DATE_LAST_ORDER,ISO),WS-CHAR-RETURN) ... IN_QTY_ONHAND ... WHERE IN_PART_NO = '23432'
Generated code:
EXEC SQL SELECT IN_PART_NO DATE(IN_DATE_LAST_UPDTE) TIME(IN_TIME_LAST_UPDTE) CHAR(IN_DATE_LAST_ORDER,ISO) IN_QTY_ONHAND INTO :D2INVEN-REC.IN-PART-NO, :D2INVEN-REC.IN-DATE-LAST-UPDTE :IND-D2INVEN-REC.IN-DATE-LAST-UPDTE, :WS-TIME-RETURN :WS-TIME-RETURN-IND, :WS-CHAR-RETURN :WS-CHAR-RETURN-IND, :D2INVEN-REC.IN-QTY-ONHAND :IND-D2INVEN-REC.IN-QTY-ONHAND FROM AUTHID.D2INVTRY WHERE IN_PART_NO = '23432' END-EXEC.