Thursday, October 18, 2012

Use of break logic


One reason for changing the name of the column variable is to use a selected column in an expression that has no name. For example:

begin-select
count(name) &cust_cnt (,1)
   if &cust_cnt < 100
      print 'Less than 100 customers'
   end-if
   position (+1)
from customers
group by city, state
end-select

Use break logic in a report to:

Add white space to reports.

Avoid printing redundant data.

Perform conditional processing on variables that change.

Print subtotals.

LET is the assignment command in SQR, for building complex expressions.


PRINT ON-BREAK performs special processing when a value changes, such as the
state column in a listing of customer addresses.
_ ON-BREAK SKIPLINES inserts space between groups of records.
_ ON-BREAK LEVEL arranges breaks hierarchically.
_ PRINT=CHANGE/TOP-PAGE prints a column after a page break or after a change
in the column's value.
_ NEXT-LISTING keeps a group of lines on the same page.
_ The SQR reserved variable $current-date holds the current date and time.
SQR provides numeric, string, and date variables. Numeric variables are preceded
with a pound sign (#) and start out as 0. String variables are preceded with a
dollar sign ($) and start out as null. There is no need to initialize either variable
type.
_ LET is the SQR assignment command. It allows you to build expressions.
_ The BEFORE and AFTER arguments set break procedures.
_ The SET and LEVEL qualifiers, in conjunction with BEFORE and AFTER, determine
the order of events.
_ The SAVE qualifier saves the value of a previous group to a variable.


à encode '<009>' into $sep ! Separator character is TAB

The ENCODE command stores the ASCII code for the tab character in the
variable $sep. The code (9) is enclosed in angle brackets to indicate that it is a
non-display character. SQR treats it as a character code and set the variable
accordingly. ENCODE is a useful way to place nonalpha and nonnumeric
characters into variables.

The NEW-PAGE command is used in this example in an unusual way. It really
causes a new line and carriage return at the end of each record, with the line
number reset to 1. The page is not ejected because of the FORMFEED=NO
argument in the DECLARE-LAYOUT command. Remember, this report is
meant to be exported, not printed.

No comments: