Previous Topic: WHEN/DO Term DefinitionsNext Topic: Other Things You Can Do


Example 4: SET Statement

Question

I always use the same complicated calculation in my queries. Can I define it as a term?

Answer

You could create a term that includes several SET statements and calculations that everyone in your group could share whenever they want to print the results of calculations.

Your term definition looks like this:

=> CREATION PANEL --------------------------------------------------------------------------DQD10 DATAQUERY: EDITOR CURRENT TABLE: ________________________________ ------------------------------------------------------------------------------- NAME: sales-net______ TYPE: term__ STATUS: public_ DESCRIPTION: figure net income after taxes______________________________ ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+. .. ================================ T O P ===================================== .. SET NET = YTD-COMMISSION + YTD-WAGES .. SET SALARY (6.2) = NET - YTD-TAX .. .. .. .. .. .. .. =========================== B O T T O M ================================== ------------------------------------------------------------------------------- <PF1> HELP <PF2> RETURN <PF3> DISPLAY COLUMNS <PF4> DISPLAY KEYS <PF5> DISPLAY ALL <PF6> LIST TABLES <PF7> BACKWARD <PF8> FORWARD <PF9> TEMPLATE <PF10> VALIDATE <PF11> RIGHT/LEFT <PF12> PROCESS MODE

Note that the term status is PUBLIC so that other users can share it. All users can now use the calculations in any query that reads tables containing the column names used in the SET statements.

Examples

Here are two different queries that use the SALES-NET term:

 FIND ALL PERSONNEL ROWS
      WITH CITY = 'DALLAS'
 RELATED BY NUMBER TO PAYROLL ROWS
      WITH YTD-COMMISSION > 100
 SALES-NET
 PRINT FROM PERSONNEL NAME
                      ADDRESS
                      SALARY
 FIND ALL SALESMEN ROWS
      WITH CITY = 'DALLAS'
 RELATED BY SLMN-ID TO PAYROLL ROWS
      WITH YTD-COMMISSION > 100
     SALES-NET
 SET BONUS = NET * .10
 PRINT FROM SALESMEN NAME
                     SALARY
                     BONUS