context\context.wb library functions. data driven programming. enhance existing programs. quickly...

18
Context\Context.wb Library Functions

Upload: delphia-caldwell

Post on 25-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

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

Context\Context.wbLibrary Functions

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

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

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

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)

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

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.

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

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.

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

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.

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

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

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

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)

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

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

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

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.

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

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.

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

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

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

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).

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

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)

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

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.

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

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$

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

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: "<tr>" ◦ 01210 PRINT #1: "<td align=right>";EMPLOYEE_DATA$

(EMPLOYEE_EMP_NUM);"</td>" ◦ 01220 PRINT #1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_NAME);"</td>" ◦ 01230 PRINT #1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_ADDRESS);"</td>" ◦ 01240 PRINT #1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_CITY);"</td>" ◦ 01250 PRINT #1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_ST);"</td>" ◦ 01260 PRINT #1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_EMP_ZIP);"</td>" ◦ 01270 PRINT #1: "<td>";EMPLOYEE_DATA$(EMPLOYEE_SEX);"</td>“◦ 01280 PRINT #1: '<td align="right" STYLE="vnd.ms-excel.numberformat:

$#,##0.00_)[semicolon][Red]($#,##0.00)">';SALARY;'</td>' ◦ 01290 PRINT #1: "</tr>" ◦ 01900 READ_NEXT: GOTO MAIN_READ

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

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