Back Issues

Flexible Thinking in FOCUS

The power of FOCUS and WebFOCUS lies in the subtleties of the FOCUS language itself. As all languages do, it allows users to mix, reorganize, reorder, and adjust elements to describe conditions, isolate problems, and find solutions. And as most sophisticated languages that offer alternatives for expressing essentially the same thought, FOCUS generally provides many language options for solving a particular problem. Their differences, however, may be subtle or extreme.

Let’s consider, for example, problems faced in reporting such as taking data, turning it into usable business information, and presenting it in an appropriate fashion. For most FOCUS users, reporting immediately triggers thoughts of TABLE, TABLEF, MATCH, and MORE. In fact, there are a number of other FOCUS environments that you may find equally useful in the reporting arena, areas such as Dialogue Manager, MODIFY, and MAINTAIN. These environments can greatly extend the types of reporting application problems that you can address, so let’s consider a simple TABLE request and then review ways that we might wish to extend its reach into other areas.

TABLE

The TABLE environment, including TABLE, TABLEF, MATCH, and MORE, provides ideal solutions for processing sets of data with common characteristics, usually defined through FOCUS Master File Descriptions.

This input dataset may include structures built with JOIN, linking multiple segments or files of similar or diverse types. It may comprise a number of files concatenated together based on common characteristics. Regardless of the underlying structures, the TABLE environment processes every record with exactly the same set of directions.

These directions can include DEFINE and COMPUTE statements, the various verbs and verb objects available (SUM, PRINT, COUNT, LIST, WRITE, ADD), selection criteria provided through IF and WHERE clauses, and extensive sorting and formatting options generated with BY and ON clauses. For instance:

DEFINE FILE CAR
PROFIT/D12.2=RETAIL_COST ­ DEALER_COST;
END
TABLE FILE CAR
SUM PROFIT AS ‘COUNTRY,PROFIT’
BY COUNTRY 
SUM PROFIT AS  ‘CAR, PROFIT’
BY COUNTRY
BY CAR
WHERE COUNTRY CONTAINS ‘ AN’
ON TABLE HOLD AS CARRPT1 FORMAT ALPHA

END

When run, this request applies the above instructions to each record retrieved and selected for the report. The resulting HOLD file contains a set of records with common characteristics defined in a Master File Description.

The key to TABLE, TABLEF, MATCH, and MORE is this: If you can assemble the data that you need to work with into a set, and you wish to create a set of data as an output, the TABLE environment is an excellent choice.

But what if you wish to process this same set of records but place the output into different files with different structures based upon the data contents of each record? How would you generate different output records for this data depending upon certain values in the data that you are reading?

MODIFY/MAINTAIN

For cases where you intend to create different records based upon the data values in each record, MODIFY or MAINTAIN may be just the reporting tool that you need.

As in the TABLE environment, you can concatenate files together with a USE or COMBINE statement – up to 63 files in FOCUS 7.3 – and you can JOIN files together for the purposes of LOOKUP operations. While you do not have the DEFINE expression engine available, even if there are DEFINE statements in the Master File Description, you can use COMPUTE to perform many of the same types of data modifications.

CMS FILEDEF ENGLAND DISK ENGLAND DATA A (RECFM F LRECL 132 DISP MOD
CMS FILEDEF FRANCE  DISK FRANCE  DATA A (RECFM F LRECL 132 DISP MOD
CMS FILEDEF OTHERS  DISK OTHERS  DATA A (RECFM F LRECL 132 DISP MOD
-RUN 
 
MODIFY FILE CAR

CASE COUNTRY
 NEXT COUNTRY
  ON NEXT COMPUTE RPT/A5=SUBSTR(10,COUNTRY,1,5,5,RPT);
  ON NEXT GOTO CAR
  ON NONEXT GOTO EXIT
ENDCASE

CASE CAR
COMPUTE RPT/A5=RPT;
NEXT CAR
  ON NEXT GOTO MODEL
  ON NONEXT GOTO COUNTRY
ENDCASE

CASE MODEL
COMPUTE RPT/A5=RPT;
NEXT MODEL
  ON NEXT GOTO BODYTYPE
  ON NONEXT GOTO CAR
ENDCASE

CASE BODYTYPE
 COMPUTE RPT/A5=RPT;
 NEXT BODYTYPE
  ON NEXT COMPUTE
         RC/D12.2=D.RETAIL_COST;
         DC/D12.2=D.DEALER_COST;
  ON NEXT COMPUTE PROFIT/D12.2= RC-DC;
  ON NEXT IF RPT EQ 'ENGLA' THEN GOTO ENGLAND
          ELSE IF RPT EQ 'FRANC' THEN GOTO FRANCE
          ELSE GOTO OTHERS;
  ON NONEXT GOTO MODEL
ENDCASE

CASE ENGLAND
 COMPUTE RPT/A5=RPT;
         PROFIT=PROFIT;
 TYPE ON ENGLAND
  "ENGLAND"
  " CAR <T.CAR  MODEL <T.MODEL "
  " PROFIT <T.PROFIT RETAIL COST <D.RETAIL_COST "
  " RETAIL COST <D.RETAIL_COST DEALER_COST <D.DEALER_COST "
  "****************************************************************"
  GOTO BODYTYPE
ENDCASE

CASE FRANCE
 COMPUTE RPT/A5=RPT;
          PROFIT=PROFIT;
 TYPE ON FRANCE
  "    FRANCE:CAR <T.CAR  MODEL <T.MODEL "
  "    DCOST - <D.DEALER_COST  RCOST - <D.RETAIL_COST "
  "    PROFIT <T.PROFIT "
  "---------------------------------------------------------------"
  GOTO BODYTYPE
ENDCASE

CASE OTHERS
  COMPUTE RPT/A5=RPT;
                      PROFIT=PROFIT;
  TYPE ON OTHERS
  "         OTHER - <T.COUNTRY "
  "         MODEL IS <T.MODEL PROFIT IS <T.PROFIT "
  "================================================================"
  GOTO BODYTYPE
  ENDCASE
  CASE DONE
ENDCASE

DATA

END

Here we used MODIFY to generate different record formats based upon the data values and placed the output into different files.

Within the MAINTAIN environment you have the set-processing capabilities of TABLE plus the single-record processing capabilities of MODIFY.

Dialogue Manager

Dialogue Manager also provides report-generating capabilities, albeit without the performance or subtleties of TABLE. Dialogue Manager provides a language for creating linear procedures in which you define variables, read data from files, compute new values for existing variables or fields, or compute new fields, and write data out to files. You declare whatever you intend to manipulate in Dialogue Manager in an &variable and can then use these variables to create temporary internal fields or new output fields.

Since you cannot logically combine or join files in Dialogue Manager, you must read any required files as you need them, however, with ­READ NOCLOSE you may open and read any number of files, placing record data in &variables as you go.

Dialogue Manager -READ statements are particularly effective for files with internal file structures that you cannot read sequentially, such as FOCUS or SQL. Usually you can use or build subroutines to retrieve such data. Subroutines are supported within FOCUS Dialogue Manager, provided they meet standard FOCUS subroutine requirements.

As a file is read, the index variables technique allows you to easily create and maintain variables holding data that you require from each record. The -SET command allows you to manipulate the data, turning it into whatever you wish to output. You may loop using -REPEAT statements to process the data repetitively in an efficient manner.

Having created whatever data you wish to output, you can -WRITE it to a file you define in a FILEDEF or ALLOCATE statement.

Since the report formatting options within Dialogue Manager are very limited, if you require special layouts you may wish to post-process your files with TABLE requests to take advantage of Style Sheets or other TABLE formatting constructs.

Summary

As you can see, FOCUS offers many options for addressing reporting requirements ranging from the simple to the complex. The strengths of the native TABLE language for basic set-based reporting are extended through MODIFY/MAINTAIN syntax to accommodate special handling based on field-value tests during processing. When you need to alter processing dynamically, based on tests following variable substitution, you can address these evolutionary situations in Dialogue Manager. Then, coming full circle, you may employ sophisticated TABLE formatting syntax to produce elaborate layouts with your Dialogue Manager output.

You have all the tools; the key is using them effectively.

Back Next