Defining the contents of environment fields
When report generation begins, ReportWriter calls the routine RW_ENV_METHOD for each environment field to obtain the field’s contents. You can register your own version of this routine to provide whatever mechanism you think is necessary to define the contents of your environment fields. See Creating an environment field for additional information about environment fields.
RW_ENV_METHOD
subroutine RW_ENV_METHOD a_fld_name ,a ;Name of environment field to load (a15) a_type ,n ;Field type (d1) ; 1 Alpha. ; 2 Decimal. ; 3 Implied-decimal. a_dec_pl ,n ;Number of decimal places (if implied-decimal) (d2) a_class ,n ;One of the following values (d1) ; 0 Neither date nor time field. ; 1 - 6 Date field. ; 8 - 9 Time field. ; These values correspond to date and time storage ; formats in Appendix B. a_user_area ,a ;Associated user-text string (a40) a_fld_data ,a ;Field area to load (a99)
Discussion
The version of RW_ENV_METHOD that is supplied with your original ReportWriter distribution operates as follows:
- By default, RW_ENV_METHOD searches for an environment variable (or logical symbol) at the shell or operating-system level that has the same name as the defined environment field, and the field area is loaded with the contents of that variable, interpreted as alpha. If the variable is not defined, or if it contains data that is invalid for the field type, the field area is cleared.
- If the user text string for the field is set to “MSG,” the routine looks instead for a Synergy DBL SEND/RECV message with a message ID that matches the first six characters of the field name. The contents of the message are then loaded into the field area in the same way as an environment variable (as described above). If no such message is found, or if the data is invalid for the field type, the field area is cleared.
In the sample RW_ENV_METHOD subroutine below, two field names are recognized as coming from a firm master file. If the master file record has not yet been read, the file is opened and the records retrieved. The firm master record, along with the flag to indicate whether or not it has been previously read, are stored in a global data section so that they will be preserved between calls to RW_ENV_METHOD. Thus, the routine doesn’t have to reread the firm master file for each environment field.
The FIRMOFFC environment field will be loaded with a Y or N if it is declared alpha and a 1 or 0 if it is numeric.
If this routine does not recognize the environment field as coming from the firm master file, it looks for a logical symbol with the same name as the field and loads the data into the field according to its type. If the logical symbol is not defined, or if it contains invalid data for the specified type, the field is cleared.
subroutine rw_env_method ; ; Description: Supply values for environment fields. ; a_fldnam ,a ;Name of field to load a_type ,n ;Field type (1 = alpha, 2 = decimal, ; 3 = implied-decimal) a_dec ,n ;# of decimal places, if implied-decimal a_cls ,n ;Class (0 = normal, 1 = date, 9 = time) a_use ,a ;Associated user string a_field ,a ;Returned loaded field record chn ,d2 ;Firm master file channel srch ,d1 ;Search parameter global data section read_test, init record master_read ,d1 ;Has master file record been read yet? record master ;Firm management master file record firm_name ,a50 ;Firm name firm_office ,d1 ;Does firm use multiple offices? endglobal proc case a_fldnam of begincase 'FIRMNAME': begin if (.not. master_read) call read_master a_field = firm_name end 'FIRMOFFC': begin if (.not. master_read) call read_master case a_type of begincase ;1 - Alpha, assume Y/N begin if (firm_office) then a_field = 'Y' else a_field = 'N' end ;2 - Decimal, load as 1/0 %d(a_field) = firm_office ;3 - Implied-decimal, load as 1.0/0.0 %f(a_field, a_dec) = firm_office endcase end endcase else begin ;Unrecognized, look for logical clear buf xcall getlog (a_fldnam, buf) onerror (20) clear_it ;If bad data, clear the field case a_type of begincase ;1 - Alpha a_field = buf ;2 - Decimal %d(a_field) = buf ;3 - Implied-decimal %f(a_field, a_dec) = buf endcase offerror end return clear_it, ;Clear field, based on data type case a_type of begincase ;1 - Alpha clear a_field ;2 - Decimal clear %d(a_field) ;3 - Implied-decimal clear %f(a_field, a_dec) endcase return read_master, ;Read firm master file xcall u_open (chn, 'I:I', 'FIRMMSTR', srch) read (chn, master, 1) if (.not. srch) xcall u_close (chn) incr master_read ;Flag master file as read return endsubroutine