180 likes | 303 Views
BR-CONTEXT 301. ContextContext.wb Library Functions. Context Context.wb - Library Functions. Data Driven Programming. Enhance Existing programs. Quickly Develop new Programs. Powerful Set of Library Functions. EMPLOYEE.WB. Data Driven Programming. Context Manager Database
E N D
BR-CONTEXT 301 Context\Context.wb Library Functions
Context\Context.wb - Library Functions • Data Driven Programming. • Enhance Existing programs. • Quickly Develop new Programs. • Powerful Set of Library Functions. • EMPLOYEE.WB
Data Driven Programming • Context Manager Database • Application Information • Table Information • Field Information • USE SQL fields as variables. • Self Documented Programs. • READ #EMPLOYER_HANDLE,using EMPLOYER_FORMALL$:MAT EMPLOYER_DATA$,MAT EMPLOYER_DATA • PRINT EMPLOYER_DATA$(EMPLOYER_NAME)
Enhance Existing Programs • Replace Hard Coded Lines: • OPEN Statements. • Form Statements. • Individual variables. • Sometimes it’s ok to use Both. • Not all Programs need to be enhanced. • Use Libraries as Much as Possible.
Develop New Programs • Use Library Functions: • Easily Open Tables. • Automatically Generate Form Statements. • Automatically Generate Variables. • Hard Coded variables replaced: • EMPLOYER_DATA$(EMPLOYER_NAME). • Dynamic Field Processing: • Use Libraries to Validate. • Field Names (SSN, NAME, _DATE). • Store Additional Information in Context.
Library Functions • Context\Context.wb: • A Program to import file layouts into Context. • A Group of Powerful Library Functions. • Documented in BR-ODBC.CHM • Functions: • Open Tables & Index Files. • Create Form Statements & Variables. • Process CSV or TAB Delimited Files.
EMPLOYEE.WB • Simple Report on ADS Sample Data. • Demonstrates library functions. • Creates a simple MS-Excel Spreadsheet. • Uses the Context Manager Database • Written entirely in Business-Rules! • To Run: • CD ADS • RUN EMPLOYEE
Employee – 100 FNOPEN_TABLE • FNOPEN_TABLE(APPLICATION$,FILENAME$,MAT TABLE_HANDLES) • This function will open a table defined within the context manager, along with all of it's related index files. The file handles will be passed to an array. • Parameters: • Application$ - Application Code . • FILENAME$ - Table or File Code . • MAT TABLE_HANDLES - Array of File Handles assigned to each of the available index files. • Returns: • Table handle assigned to "Key1" or the "Primary Index". • Example: • 00100LET EMPLOYEE_RESULT=FNOPEN_TABLE("PAYROLL","EMPLOYEE",MAT EMPLOYEE_HANDLES)
Employee – 200 FNSTATUS_FILE • FNSTATUS_FILE(MAT NAME_FILE$,MAT KFNAME_FILE$,MAT USE_FILE$) • This function will return 3 arrays. Containing information about the files that are currently open. • Parameters: • MAT NAME_FILE$ - An array containing the files that are currently open. • MAT KFNAME_FILE$ - An array containing the Key Names for the open files. • MAT USE_FILE$ - Contains a Shorthand List of both Name & KFNAME. • Returns: The highest file that is currently open. • Example: • LET FNSTATUS_FILE(MAT NAME_FILE$,MAT KFNAME_FILE$,MAT USE_FILE$) • LET EMPLOYEE_HANDLE=SRCH(MAT USE_FILE$,"NAME="&EMPLOYEE_DRIVE$&"EMPLOYEE,KFNAME="&EMPLOYEE_DRIVE$&"EMPLOYEE.KEY")
Employee – 310 FNCONTEXT • FNCONTEXT(APPLICATION$,FILENAME$,ALIAS$,MAT DATA$,MAT DATA,MAT FIELDSC$,MAT FIELDSN$,&FORM_C$,&FORM_N$,&FORM_ALL$) • This function will assign values to the required fields that will be used to perform IO and define the "SQL Names" for the fields within a particular table. • Parameters: • APPLICATION$ - Context Application Code • FILENAME$ - File or TABLE to use • ALIAS$ - Specific Record Layout to Use • MAT DATA$ - Array contains Character variables in IO statements. • MAT DATA -Array contains Numeric variables in IO statements. • MAT FIELDSC$ -Array populated by the function, Character "SQL Field Names". • MAT FIELDSN$ - Array populated by the function, Numeric "SQL Field Names". • FORM_C$ -String variable “cform$” statement read Character variables. • FORM_N$ -String variable “cform$” statement read Numeric variables. • FORM_ALL$ -String variable “cform$” statement read both data types.
Employee – 310 FNCONTEXT • Example: • 00300 DIM EMPLOYEE_DATA$(1)*80,EMPLOYEE_DATA(1),EMPLOYEE_FIELDSC$(1)*20,EMPLOYEE_FIELDSN$(1)*20,EMPLOYEE_FORMC$*512,EMPLOYEE_FORMN$*512,EMPLOYEE_FORM_ALL$*51200310 LET FNCONTEXT(APPLICATION$:="PAYROLL",FILENAME$:="EMPLOYEE",ALIAS$:="EMPLOYEE",MAT EMPLOYEE_DATA$,MAT EMPLOYEE_DATA,MAT EMPLOYEE_FIELDSC$,MAT EMPLOYEE_FIELDSN$,EMPLOYEE_FORMC$,EMPLOYEE_FORMN$,EMPLOYEE_FORM_ALL$) • In the above example, the Data & Form variables for EMPLOYEE from the PAYROLL application will be populated. (Note, no file is opened, but the arrays are re-dimensioned to match the appropriate information for EMPLOYEE.
Employee – 420 FNPACK_FORM$ • FNPACK_FORM$*1024(F$*2048;PACK_TYPE) • This function is automatically used by FNCONTEXT, but may be useful to pack other form statements. • Parameters: • PACKED_FORM$- Form Statement to Process • PACK_TYPE - Logical Value (0 Returns Unpacked,1 Returns variable as CFORM$) • Returns: • The form statement with duplicates converted to a compressed format ("3*C"). Based on PACK_TYPE, it will also return the CFORM$ or compiled value. • Example: • 00400 DIM PACKED_FORM$*25600410 LET PACKED_FORM$="FORM POS 1,C 8,C 1,C 1,N 6,PD 6.2,POS 50,C 80"00420 PRINT PACKED_FORM$00430 PRINT FNPACK_FORM$(PACKED_FORM$,PACK=0) • In the above example, the program will disply the form statement before & after the function. The packed form statement will look like this: • FORM POS 1,C 8,2*C 1,N 6,PD 6.2,POS 50,C 80
Employee – 500 FNINDEX_HANDLE • FNINDEX_HANDLE(INDEX_KEY$*80; ACCESS_RIGHT$, &RECORD_PRIOR) • This function is used to identify the file handle for existing index file. It is also capable of opening the data file if it is missing. • Parameters: • INDEX_KEY$ - The "Shorthand" for the index file we want to open. • ACCESS_RIGHT$ - INPUT,OUTPUT,OUTIN • RECORD_PRIOR - Record pointer (-1 File was closed, 0 No record, >0 Record # assigned). • Returns: The file handle for the requested index handle. • Example: • 00100 LET EMPLOYEE_RESULT=FNOPEN_TABLE("PAYROLL","EMPLOYEE",MAT EMPLOYEE_HANDLES)00500 LET EMPLOYEE_INDEX_HANDLE=FNINDEX_HANDLE("NAME=F:EMPLOYEE,KFNAME=F:EMPLOYEE.KEY") • The above example will find the file that has already been opened by FNOPEN_TABLE, and will assign EMPLOYEE_INDEX_HANDLE to the appropriate file handle. (In this example, there was only one index, so it was a bit redundant, but the example still works).
Employee – 600 FNGET_VAR$ • FNGET_VAR$*128(UNQ$, MAT FIELDSC$, MAT FIELDSN$) • This function actually creates a "PROC FILE" to be executed by the calling program. Once you execute the proc, local variables will be created for use within your application. These variables are assigned automatically based on the "SQL Names" defined in the context database. • Parameters: • UNQ$ - Unique "Prefix" name to be used when creating the BR variables. • MAT FIELDSC$ - An Array Containing "Character" or String Variable Names. • MAT FIELDSN$ - An Array Containing "Numeric" Variable Names. • Returns:Name of a "temporary Proc" that will be executed. • Example: • EXECUTE "PROC="&FNGET_VAR$(PREFIX$:="EMPLOYEE",MAT EMPLOYEE_FIELDSC$,MAT EMPLOYEE_FIELDSN$) • The above example will execute the procedure created by FNGET_VAR$. That procedure will assign variable such as the following. • EMPLOYEE_EMP_NAME • EMPLOYEE_EMP_ADDRESS • EMPLOYEE_EMP_ZIP • In order to use the "Name Field" within the application you would use the "DATA$" array as in the following example. • PRINT "Name=";employee_DATA$(EMPLOYEE_EMP_NAME)
Employee – 1000-1090 • OPEN#1: "NAME="&ENV$("TEMP")&"\EMPLOYEE.XLS,REPLACE,RECL=32000",DISPLAY,OUTPUT • PRINT#1: "<html>" • Simple Print statements. • Using HTML, create a table. • .XLS file name tricks MS-EXCEL.
Employee 1100 • MAIN_READ • READ#EMPLOYEE_HANDLE,USING EMPLOYEE_FORM_ALL$,RELEASE: MAT EMPLOYEE_DATA$,MAT EMPLOYEE_DATA EOF FINIS • Read Employee Data into 2 Arrays. • Use “Hard Coded Names” to reference fields. • Lookup available fields in: • MAT EMPLOYEE_FIELDSC$ • MAT EMPLOYEE_FIELDSN$
Employee 1110-1900 • Loop Through Records. (Filter by CO_NUM) • 1110 IF TRIM$(EMPLOYEE_DATA$(EMPLOYEE_CO_NUM))<>"1" THEN !: • GOTO READ_NEXT • Output HTML to Create EXCEL Spreadsheet • 01200PRINT#1: "<tr>" • 01210PRINT#1: "<td align=right>";EMPLOYEE_DATA$(EMPLOYEE_EMP_NUM);"</td>" • 01220PRINT#1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_NAME);"</td>" • 01230PRINT#1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_ADDRESS);"</td>" • 01240PRINT#1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_CITY);"</td>" • 01250PRINT#1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_ST);"</td>" • 01260PRINT#1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_ZIP);"</td>" • 01270PRINT#1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_SEX);"</td>“ • 01280PRINT#1: '<td align="right" STYLE="vnd.ms-excel.numberformat:$#,##0.00_)[semicolon][Red]($#,##0.00)">';SALARY;'</td>' • 01290PRINT#1: "</tr>" • 01900READ_NEXT:GOTO MAIN_READ
Employee – 510Launch Excel • 05100EXECUTE "sys -c -m start %TEMP%\Employee.xls" • Start command will launch EXCEL or equivalent application.