PROFILE for Your Synonym: MFD_PROFILE Noreen Redden FOCUS Users of New England 2012 1 MFD_PROFILE The Basics 22 MFD_PROFILE Why? • Set the values of global variables defined in the Master File for use in Master and/or Access File Descriptions. • Create a lookup file for Master File DEFINE commands or DBA attributes. • Create a DBAFILE, which can be derived from an external data source and used to restrict access during execution of a request that references the Master File. • Issue FOCUS commands such as JOIN or FILTER FILE. 3 MFD_PROFILE What and When •FOCEXEC (.fex) file executed EACH TIME is opened for: • TABLE • TABLEF • GRAPH • MATCH FILE • CHECK, ?f, ?ff • Multiple MFD_PROFILES may be executed • JOIN or Cross-References • MORE • MATCH FILE 4 MFD_PROFILE Global Variables VARIABLE NAME=[&&]var, USAGE=Aln, [DEFAULT=defvalue,][QUOTED={OFF|ON},] $ • Master Attributes which may be parameterized include: POSITION OCCURS REMARKS DESCRIPTION TITLE HELPMESSAGE DBA USERID and VALUE • Access Attributes which may be parameterized include: CONNECTION TABLENAME DIRECTORY EXTENSION 5 MFD_PROFILE: Global Variables FILE=GRPPOL ,SUFFIX=SQLORA ,MFD_PROFILE=GRPPOL VARIABLE NAME=LTD, USAGE=A30, DEFAULT='LTD or ETD',$ SEGNAME=GRPPOL,SEGTYPE=S0 FIELD=GROUP_CODE,GCODE,A8,TITLE='Group Code',$ FIELD=GROUP_NAME,,A30,TITLE='Group Policy Holder',$ FIELD=CONTRACT_NO,CONTRACT,A8,TITLE='Contract Number',$ FIELD=LONG_TERM,LTD,A1,TITLE=&&LTD , $ FIELD=EFFECT_DATE,,YYMD,TITLE='Effective,Date' ,$ -IF &1 NE ‘GRPPOL’ GOTO NOVAR1; -SET &&LTD = IF &&TEAM_NAME EQ ‘GM’ THEN ‘Extended Term’ ELSE ‘Long Term’; - NOVAR1 6 MFD_PROFILE Create or Point to Files FILE=GRPPOL ,SUFFIX=SQLORA ,MFD_PROFILE=GRPPOL VARIABLE NAME=LTD, USAGE=A30, DEFAULT='LTD or ETD',$ SEGNAME=GRPPOL,SEGTYPE=S0 FIELD=GROUP_CODE,GCODE,A8,TITLE='Group Code',$ FIELD=GROUP_NAME,,A30,TITLE='Group Policy Holder',$ FIELD=CONTRACT_NO,CONTRACT,A8,TITLE='Contract Number',$ FIELD=LONG_TERM,LTD,A1,TITLE=&&LTD , $ FIELD=EFFECT_DATE,,YYMD,TITLE='Effective,Date' ,$ FILTER SELECTGRPS = IF DECODE GROUP_CODE(TEAMRESP ELSE 2) EQ 0 THEN 1 ELSE 0 ; -IF &1 NE ‘GRPPOL’ GOTO NOVAR1; -SET &&LTD = IF &&TEAM_NAME EQ ‘GM’ THEN ‘Extended Term’ ELSE ‘Long Term’; -NOVAR1 FILEDEF TEAMRESP DISK c:\userapp\teamresp.dat 7 MFD_PROFILE Security FILE=GRPPOL ,SUFFIX=SQLORA ,MFD_PROFILE=GRPPOL SEGNAME=GRPPOL,SEGTYPE=S0 VARIABLE NAME=&&LTD, USAGE=A30, DEFAULT='LTD or ETD',$ VARIABLE NAME=&&UID, USAGE=A8, DEFAULT=‘ ‘,$ VARIABLE NAME=&&DBAVAL,USAGE=A50, DEFAULT=GROUP_CODE EQ ‘X’ AND GROUP_CODE EQ ‘Y’;,$ FIELD=GROUP_CODE,GCODE,A8,TITLE='Group Code',$ FIELD=GROUP_NAME,,A30,TITLE='Group Policy Holder',$ FIELD=CONTRACT_NO,CONTRACT,A8,TITLE='Contract Number',$ FIELD=LONG_TERM,LTD,A1,TITLE=&&LTD , $ FIELD=EFFECT_DATE,,YYMD,TITLE='Effective,Date' ,$ FILTER SELECTGRPS = IF DECODE GROUP_CODE(TEAMRESP ELSE 2) EQ 0 THEN 1 ELSE 0 ; END DBA=DBA,$ USER=&&UID,ACCESS=R,RESTRICT=VALUE_WHERE, NAME=GRPPOL,VALUE=&&DBAVAL,$ 8 MFD_PROFILE: Security -IF &1 NE ‘GRPPOL’ GOTO NOVAR1; -SET &&LTD = IF &&TEAM_NAME EQ ‘GM’ THEN ‘Extended Term’ ELSE ‘Long Term’; -NOVAR1 TABLE FILE TEAMS PRINT GRP_RESP WHERE TEAM EQ &&TEAM_NAME ON TABLE SAVE AS TEAMRESP END -ALL -SET &&DBAVAL= SELECTGRPS; 9 MFD_PROFILE: Security FILE=GRPPOL ,SUFFIX=SQLORA ,MFD_PROFILE=GRPPOL VARIABLE NAME=&&LTD, USAGE=A30, DEFAULT='LTD or ETD',$ SEGNAME=GRPPOL,SEGTYPE=S0 FIELD=GROUP_CODE,GCODE,A8,TITLE='Group Code',$ FIELD=GROUP_NAME,,A30,TITLE='Group Policy Holder',$ FIELD=CONTRACT_NO,CONTRACT,A8,TITLE='Contract Number',$ FIELD=LONG_TERM,LTD,A1,TITLE=&&LTD , $ FIELD=EFFECT_DATE,,YYMD,TITLE='Effective,Date' ,$ FILTER SELECTGRPS = IF DECODE GROUP_CODE(TEAMRESP ELSE 2) EQ 0 THEN 1 ELSE 0 ; END DBA=DBA,DBAFILE=MYFILE,$ 10 MFD_PROFILE: Security DEFINE FILE SYSCOLUM LINENO WITH TBNAME = LINENO + 1; LINED/A80 = IF LINENO EQ 1 THEN 'FILE=MYFILE,SUFFIX=FIX' ELSE IF LINENO EQ 2 THEN ' SEGNAME=ONE,SEGTYPE=S0' ELSE IF LINENO EQ 3 THEN ' FIELDNAME=ONE,,A1,A1,$' ELSE IF LINENO EQ 4 THEN 'END' ELSE IF LINENO EQ 5 THEN 'DBA=DBA,$' ELSE IF LINENO EQ 6 THEN 'USER='' '',ACCESS=R, RESTRICT=VALUE,NAME=SYSTEM, ' | ' VALUE= RECORDLIMIT EQ 5,$' ELSE IF LINENO EQ 7 THEN ' RESTRICT=VALUE,VALUE=' | 'SELECTGRPS,$' ELSE IF LINENO EQ 8 THEN 'USER=NORM,ACCESS=R,' | 'RESTRICT=VALUE,NAME=SYSTEM,' | 'VALUE=SELECTGRPS,$' ELSE ' '; END TABLE FILE SYSCOLUM PRINT LINED ON TABLE SAVE AS MYFILE WHERE LINENO LE 8 END 11 Prerequisites MFD_PROFILE FILE=GRPPOL ,SUFFIX=SQLORA ,MFD_PROFILE=GRPPOL SEGNAME=GRPPOL,SEGTYPE=S0 … FIELD=EFFECT_DATE,,YYMD,TITLE='Effective,Date' ,$ FILTER SELECTGRPS = IF DECODE GROUP_CODE(TEAMRESP ELSE 2) EQ 0 THEN 1 ELSE 0 ; -NOVAR1 TABLE FILE TEAMS PRINT GRP_RESP WHERE TEAM EQ &&TEAM_NAME ON TABLE SAVE AS TEAMRESP END FILTER FILE GRPPOL DAYS/I5 = DATEDIFF(EFFECT_DATE,'&YYMD','D‘); NAME=CURRENT WHERE DAYS LE 5 END SET FILTER = CURRENT IN GRPPOL ON 12 MFD_PROFILE GG Application 13 13 Application Requirements • Validate all user access to the files. • Only Managers have access to orders > 1 week old. • Corporate users have access to GGORDERS and GGPRODs for all stores/regions. • Store users have access to GGORDERS only for their store. • Regional personnel have access to GGORDERS for all stores within the Region. 14 Application Synonyms 15 15 GGORDER FILENAME=GGORDER, SUFFIX=FOC,MFD_PROFILE=GGPROF,$ SEGNAME=ORDER01, SEGTYPE=S1,$ FIELD=ORDER_NUMBER, ALIAS=ORDNO1, FORMAT=I6, TITLE='Order,Number', DESC='Order Identification Number',$ FIELD=ORDER_DATE, ALIAS=DATE, FORMAT=MDY, TITLE='Order,Date', DESC='Date order was placed',$ FIELD=STORE_CODE, ALIAS=STCD, FORMAT=A5, TITLE='Store,Code', DESC='Store Identification Code (for order)',$ FIELD=PRODUCT_CODE, ALIAS=PCD, FORMAT=A4, TITLE='Product,Code', DESC='Product Identification Code (for order)',$ FIELD=QUANTITY, ALIAS=ORDUNITS, FORMAT=I8, TITLE='Ordered,Units', DESC='Quantity Ordered',$ SEGNAME=ORDER02, SEGTYPE=KU, PARENT=ORDER01, CRFILE=GGPRODS, CRKEY=PCD, CRSEG=PRODS01 ,$ FILTER CURRENT = DATEDIF(ORDER_DATE,'&YYMD','D') LE 5;,$ END DBA=DBA,DBAFILE=GGPROFP,$ 16 GGPRODS FILENAME=GGPRODS, SUFFIX=FOC,MFD_PROFILE=GGPROFP,$ SEGNAME=PRODS01, SEGTYPE=S1 FIELD=PRODUCT_ID, ALIAS=PCD, FORMAT=A4, INDEX=I, TITLE='Product,Code', $ FIELD=PRODUCT_DESCRIPTION, ALIAS=PRODUCT, FORMAT=A16, TITLE='Product', $ FIELD=VENDOR_CODE, ALIAS=VCD, FORMAT=A4, INDEX=I, TITLE='Vendor ID', $ FIELD=VENDOR_NAME, ALIAS=VENDOR, FORMAT=A23, TITLE='Vendor Name', $ FIELD=PACKAGE_TYPE, ALIAS=PACK, FORMAT=A7, TITLE='Package‘,$ FIELD=SIZE, ALIAS=SZ, FORMAT=I2, TITLE='Size', $ FIELD=UNIT_PRICE, ALIAS=UNITPR, FORMAT=D7.2, TITLE='Unit,Price', $ END DBA=DBA,DBAFILE=GGPROFP,$ 17 GGREGION FILENAME=GGREGION, SEGNAME=SALES01, SEGTYPE=DKU,CRFILE=GGSALES, CRINCLUDE=ALL ,$ FOLDER=GGREGION,$ FIELD=REGION, ALIAS=E05, FORMAT=A11, INDEX=I, TITLE='Region', DESC='Region code',$ FIELD=STCD, ALIAS=E08, FORMAT=A05, INDEX=I, TITLE='Store ID', DESC='Store identification code (for sale)',$ 18 Human Resources File FILENAME=HR, SUFFIX=ORASQL,$ SEGNAME=HR1, SEGTYPE=S0 FIELD=EID, ALIAS=employeeid, FORMAT=A09, A09,$ FIELD=JOBCODE,jobcode,A8,A8,$ FIELD=DIVISION, ALIAS=division, FORMAT=A23, A23, DESC=CORP or Region name,$ FIELD=STORENUMBER, ALIAS=storeno, FORMAT=A5, A5,$ END DBA=pO02_can,$ USER=pOc02_an,ACCESS=R,$ 19 GGPROFP.fex -DYNAM ALLOC F HR DA PMSNMR.HR.FOCUS SHR REU -RUN SET MSG=OFF SET DBACSENSITIV = ON SET COLLATION=SRV_CI -RUN TABLE FILE HR PRINT * WHERE EID EQ '&&LOGON_ID' ON TABLE SAVE AS HR1 FORMAT ALPHA END -RUN -SET &LNES = &LINES; -RDIT -SET &FOUNDIT = IF &LNES EQ 0 THEN 'N' ELSE 'Y'; 20 GGPROFP.fex(cont) -SET &JOBCODE = '________'; -IF &FOUNDIT EQ 'N' GOTO WRITIT; -READ HR1 &EID.9. &JOBCODE.A8. &DIVISION.A23. &STNMBR.A5. -* could use –READFILE (RELEASE 7.7) -* Only build for current user, -SET &USER = 'USR' | &MDYY | EDIT(&JOBCODE, '$$$9'); -* rules based on last 2 digits of JOBCODE -SET &JOBL = EDIT(&JOBCODE,'$$$$$$99'); -RUN -PASS &USER 21 GGPROF.fex (cont) FILEDEF OUTFI DISK TEMP/GGPROFP.mas -RUN -WRITIT -* CREATES THE DBAFILE GGPROFP.MAS -WRITE OUTFI FILE=GGPROFP,SUFFIX=FIX -WRITE OUTFI SEGNAME=ONE,SEGTYPE=S0 -WRITE OUTFI FIELDNAME= ONE,,A1,A1,$ -WRITE OUTFI END -WRITE OUTFI DBA=DBA,$ -*ET &ECHO=ALL; -SET &RST = 'ACCESS = R,'; -WRITE OUTFI USER = &USER , &RST -IF &FOUNDIT EQ 'N' GOTO NOG; 22 GGPROF.fex (cont) -* CORP MANAGERS HAVE NO RESTRICTIONS -IF &DIVISION EQ 'CORP' AND &JOBL GE '09' GOTO END1; -* CORP NON-MANAGERS ARE RESTRICTED ONLY ON CURRENT -IF &DIVISION EQ 'CORP' GOTO NOST; -* ALL OTHERS ARE RESTRICTED ON STORE CODES -SET &RST2= 'RESTRICT=VALUE_WHERE,NAME=SYSTEM,'; -WRITE OUTFI &RST2 -WRITE OUTFI VALUE=STORE_CODE IN FILE STRS; ,$ -* NON-MANAGERS RESTRICTED TO CURRENT INFORMATION -NOST -SET &RST2= 'RESTRICT=VALUE_WHERE,NAME=SYSTEM,'; -IF &JOBL GE '09' GOTO END1; -WRITE OUTFI &RST2| VALUE=CURRENT;,$ -GOTO END1; 23 GGPROF.fex (cont) -NOG -SET &RST2= 'RESTRICT=VALUE_WHERE,NAME=SYSTEM,'; -WRITE OUTFI &RST2 -WRITE OUTFI VALUE=STORE_CODE EQ 'A' -WRITE OUTFI VALUE= AND STORE_CODE EQ 'B';,$ -END1 -WRITE OUTFI ,$ -CLOSE OUTFI 24 GGPROF.fex (cont) -* DBAFILE WRITTEN, BUT STORE_CODES SHOULD BE IN FILE -IF &DIVISION EQ 'CORP' GOTO NOM; TABLE FILE GGREGION PRINT STCD -IF &JOBL GE '06' GOTO REGT; WHERE STCD EQ '&STNMBR' ; -GOTO FINTEST -REGT WHERE REGION EQ '&DIVISION' ; -FINTEST ON TABLE SAVE AS STRS END -RUN 25 Output: Regional User USER = USR05032012X , ACCESS = R, RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=STORE_CODE IN FILE STRS; ,$ RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=CURRENT;,$ Store Order Ordered Code Date Units ,$ ----R1019 R1020 R1250 ----04/30/12 05/01/12 04/28/12 04/29/12 04/30/12 05/01/12 04/28/12 04/29/12 04/30/12 05/01/12 ------5230 5203 6660 6644 1762 2031 6540 7372 1864 2423 26 Output: Regional Manager USER = USR05032012X , ACCESS = R, RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=STORE_CODE IN FILE STRS; ,$ Store Order ,$ Code ----R1019 R1020 R1250 Date ----04/02/12 04/03/12 04/04/12 . . . 04/08/12 04/02/12 04/15/12 . . . 04/19/12 04/02/12 04/15/12 . . . Ordered Units ------6285 8259 6907 5006 2326 4994 5305 1558 4536 27 Output: Store User USER = USR05032012X , ACCESS = R, RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=STORE_CODE IN FILE STRS; ,$ RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=CURRENT;,$ ,$ PAGE 1 Store Code ----R1019 Order Date ----04/30/12 05/01/12 Ordered Units ------5230 5203 28 Output: Corporate Manager USER = USR05032012X , ACCESS = R, RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=CURRENT;,$ ,$ Store Order Code ----R1019 R1020 R1040 R1041 Date ----04/30/12 05/01/12 04/28/12 04/29/12 04/30/12 05/01/12 04/30/12 05/01/12 04/28/12 04/29/12 04/30/12 Ordered Units ------5230 5203 6660 6644 1762 2031 5104 5090 6409 7439 2465 29 Output: Invalid User USER = USR050320120 , ACCESS = R, RESTRICT=VALUE_WHERE,NAME=SYSTEM, VALUE=STORE_CODE EQ 'A',$ VALUE= AND STORE_CODE EQ 'B';,$ ,$ (FOC047) THE USER DOES NOT HAVE SUFFICIENT ACCESS RIGHTS TO THE FILE: GGORDER 30 31