Presentation is loading. Please wait.

Presentation is loading. Please wait.

Context\Context.wb Library Functions.  Data Driven Programming.  Enhance Existing programs.  Quickly Develop new Programs.  Powerful Set of Library.

Similar presentations


Presentation on theme: "Context\Context.wb Library Functions.  Data Driven Programming.  Enhance Existing programs.  Quickly Develop new Programs.  Powerful Set of Library."— Presentation transcript:

1 Context\Context.wb Library Functions

2  Data Driven Programming.  Enhance Existing programs.  Quickly Develop new Programs.  Powerful Set of Library Functions.  EMPLOYEE.WB

3  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)

4  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.

5  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.

6  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.

7  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

8  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:  00100 LET EMPLOYEE_RESULT=FNOPEN_TABLE("PAYROLL","EMPLOYEE",MAT EMPLOYEE_HANDLES)

9  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")

10  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.

11  Example: ◦ 00300 DIM EMPLOYEE_DATA$(1)*80,EMPLOYEE_DATA(1),EMPLOYEE_FIELDSC$(1)*20,EMPLOYEE_FI ELDSN$(1)*20,EMPLOYEE_FORMC$*512,EMPLOYEE_FORMN$*512,EMPLOYEE_FORM_AL L$*512 00310 LET FNCONTEXT(APPLICATION$:="PAYROLL",FILENAME$:="EMPLOYEE",ALIAS$:="EMPLOYE E",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.

12  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$*256 00410 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

13  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:EMPL OYEE.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).

14  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)

15  OPEN #1: "NAME="&ENV$("TEMP")&"\EMPLOYEE.XLS,REPLACE,RECL=32000",DISPLAY,OUTPUT  PRINT #1: " "  Simple Print statements.  Using HTML, create a table. .XLS file name tricks MS-EXCEL.

16  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$

17  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 ◦ 01200 PRINT #1: " " ◦ 01210 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_EMP_NUM);" " ◦ 01220 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_EMP_NAME);" " ◦ 01230 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_EMP_ADDRESS);" " ◦ 01240 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_EMP_CITY);" " ◦ 01250 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_EMP_ST);" " ◦ 01260 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_EMP_ZIP);" " ◦ 01270 PRINT #1: " ";EMPLOYEE_DATA$(EMPLOYEE_SEX);" “ ◦ 01280 PRINT #1: ' ';SALARY;' ' ◦ 01290 PRINT #1: " " ◦ 01900 READ_NEXT: GOTO MAIN_READ

18  05100 EXECUTE "sys -c -m start %TEMP%\Employee.xls"  Start command will launch EXCEL or equivalent application.


Download ppt "Context\Context.wb Library Functions.  Data Driven Programming.  Enhance Existing programs.  Quickly Develop new Programs.  Powerful Set of Library."

Similar presentations


Ads by Google