B304 Support

Embed Size (px)

Citation preview

  • 7/27/2019 B304 Support

    1/22

    Module 4: The Support Environment forFastExport, MultiLoad, and TPump

    After completing this module, you will be able to:

    Explain the elements of the Support Environment.

    Use the Support Environment to invoke a utility.

    Process parameter input from a host file.

    Use system and user-defined variables.

    Write messages to an output file.

  • 7/27/2019 B304 Support

    2/22

    Support Environment

    Provides a common environment - language, functions, flexibility, etc. forutilities such as MultiLoad, FastExport, and TPump.

    Provides a fully-nested .RUN file facility.

    Interprets utility commands and provides error reporting.

    Supports a wide range of DDL and DML commands.

    Allows for conditional processing of commands.

    Supports system-defined and user-defined variables.

    Allows logic to be applied both before and after the utility executes.

    Provides recovery management from a Teradata or host failure.

  • 7/27/2019 B304 Support

    3/22

    Setting Up the Support Environment

    Utilities are invoked by the Support Environment after the preparatorystatements have been executed:

    .LOGTABLE

    .LOGON

    These may be followed by SQL statements to: Set the default database.

    Establish a CHECKPOINT in the Permanent Journal.

    CREATE and DROP Tables, etc.

    Set system variables.

    Retrieve control parameters from outside sources (database or flat file).

    Comments may be included with scripts.

    /*This job is used to ..*/

  • 7/27/2019 B304 Support

    4/22

    Invoking Utilities

    MultiLoad is invoked with: .BEGIN [IMPORT] MLOAD

    or.BEGIN DELETE MLOAD

    FastExport is invoked with: .BEGIN EXPORT

    TPump is invoked with: .BEGIN LOAD

    Upon initialization, the Support Environment reviews the Restart Log Table todetermine whether or not this is a restart.

    If it is, the Support Environment will not submit a previously successfulstatement a second time.

    .LOGTABLE CustLog_fxp ;

    .LOGON . . . . . . . . ;

    .BEGIN EXPORT;

    .EXPORT OUTFILE Cust_f i le;SELECT * FROM Customer;.END EXPORT;

    .LOGOFF ;

    Support Environment Commands

  • 7/27/2019 B304 Support

    5/22

    Support Environment Commands

    .DATEFORM Specify INTEGERDATE or ANSIDATE.

    .LOGTABLE Acquires or creates the Restart Log Table.

    .LOGON Connects multiple sessions to Teradata.

    .LOGOFF Terminates the utility operation.

    .ACCEPT Input parameters to Support Environment.

    .RUN Specifies an external script file.

    .IF THEN Identifies statements to be executed if certain conditions

    .ELSE are true (.IF) or (.ELSE) otherwise.

    .ENDIF Resumes the program after a .IF condition.

    .ROUTE Specifies output file other than SYSPRINT.

    .DISPLAY Writes messages to a specific destination.

    .SET Assigns a data type and value to a variable.

    .SYSTEM Submits an operating system command to the clientenvironment.

  • 7/27/2019 B304 Support

    6/22

    Initializing the Log Table

    The .LOGTABLE command is required.

    .LOGTABLE and .LOGON commands must be the first statements processed(either directly or via the .RUN command).

    .LOGTABLE creates a new table or acquires an existing Log Table.

    Privileges required for the Log Table:

    CREATE TABLE (to create a new table) INSERT UPDATE SELECT

    By default, the log table is created in your default database which requiresPERM space.

    The format of the Log Table is unique to each of the utilities (FastExport,MultiLoad, and TPump).

  • 7/27/2019 B304 Support

    7/22

    Initialization and Wrap Up Commands

    .LOGON [ tdp id/ ] username, [ password[ ,'acct id' ] ] ; Uti l i ty wi l l run anystartupst r ing

    definedfor the user.

    .LOGOFF [ retcode] ; Permits u ser tospecify return-code; otherwise,high watermark

    is returned.

    .RUN FILE f i leid Identif ies externalsource of

    contro l s tatements and opt ion al lyignoresextraneou s data - nest

    up to 16 levels of .RUN.

    [ IGNOREcharpos1charpos1 THRUTHRU charpos2charpos1 THRU charpos2

    ] ;

    When the Utility terminates, it returns to the HOST with a high watermark return code:

    00 Successful completion04 Warning08 User error12 Severe internal error

    16 No output message available

  • 7/27/2019 B304 Support

    8/22

    .ACCEPT Working with Variables

    The ACCEPT command can ...

    accept from a single data record from an external source, and use it to setone or more utility variables.

    accept from a system variable and use it to set a utility variable.

    .ACCEPTvar, . . [FROM] FILE f i leid[ IGNORE

    charpos1charpos1THRUTHRU charpos2charpos1THRU charpos2

    .ACCEPTvar [FROM]ENVIRONMENT VARIABLE env_var;ENV VAR

    ] ;

    Uti l ity v ar iables wi l l be replaced by their values before text is displayed.

    For display o r evaluat ion, var iable names m ust b e preceded w ith an ampersand (&).

    If the value is a character, the variable name mus t be enclos ed in sin gle quo tes.

  • 7/27/2019 B304 Support

    9/22

    Support Environment System Variables

    Variable Descr ipt ion Format Example&SYSDATE System Date YY/MM/DD 03/10/13

    &SYSDATE4 System Date YYYY/MM/DD 2003/10/13

    &SYSTIME System Time HH:MM:SS 16:11:33

    &SYSDAY Day of Week X(3) MON

    &SYSOS Host Op System X(5) UNIX or Win32

    &SYSUSER MVS/UNIX User Id tfact30

    &SYSRC Return Code 0

    Mult iLo ad Specif ic Variables

    &SYSDELCNT(n) Delete Count Ex., &SYSDELCNT1, &SYSDELCNT2, ...

    &SYSINSCNT(n) Insert Count Ex., &SYSINSCNT1, &SYSINSCNT2, ...

    &SYSUPDCNT(n) Update Count

    &SYSETCNT(n) Error Table Count&SYSUVCNT(n) Uniqueness Violation Count Note: n is 1 to 5

    .SET var [TO] expression; Permits a var iable to be set or reset to an expression or

    a pre-exist in g variable.

    Example: .SET dbase TO 'terafact30';.SET tname TO 'customer';

  • 7/27/2019 B304 Support

    10/22

    .DISPLAY and .ROUTE Commands

    Used to w ri te messages to sp eci f ied f i le id.

    Changes rout ing of defaul t output .

    ECHO permits routing to default and a

    second copy anywhere in scr ip t .

    .DISPLAY ' text'[TO] FILE f i leid;

    .ROUTE MESSAGES [TO] FILE f i leid

    [ WITH ] ECHO [ TO ] FILE f i leid

    [ WITH ] ECHO [ OFF ] ;Examples:

    .DISPLAY 'Run Date - &SYSDATE4' TO /dev/tty;

    Run Date - 2003/02/24

    .ACCEPT home FROM ENV VAR HOME;

    .DISPLAY 'The $HOME directory is &home' TO *;

    The $HOME directory is /home2/terafact30(* - the output is directed to standard output device.)

    .ROUTE MESSAGES TO FILE /tmp/mldrun1.out WITH ECHO TO FILE /dev/tty;

  • 7/27/2019 B304 Support

    11/22

    Example: Using Variables in a Script

    .LOGTABLE CustLog_fxp ;

    .LOGON . . . . . . . . ;

    .ACCEPT home FROM ENV VAR HOME;

    .SET dbase TO 'terafact30';

    .SET tname TO 'customer';

    .SET expname TO '&home/cust_file';

    .SYSTEM 'rm -f&expname';

    .DISPLAY 'Exporting data file &expname'TO FILE /dev/tty;

    .BEGIN EXPORT;

    .EXPORT OUTFILE &expname;

    SELECT * FROM &dbase..&tname;.END EXPORT;

    .LOGOFF ;

    Data file saved in UNIX:/home2/terafact30/cust_file

    Output to terminal screen:Exporting data file /home2/terafact30/cust_file

    Portion of FastExport output:

    0011 SELECT * FROM &dbase..&tname;**** 12:23:10 UTY2402 Previous statement

    modified to:0012 SELECT * FROM terafact30.customer;

    Example:

    Output:

  • 7/27/2019 B304 Support

    12/22

    Working with Control Logic

    .IF cond i t ional expression THEN ;

    i f condi t ion is true,

    then execute these statement(s);

    .ELSE ;i f cond i t ion is false,

    then execute these statement(s);

    .ENDIF ;

    .IF is fol lowed b y a cond i t ional expression that

    in i t iates execut ion of sub sequent commands and

    statements.

    .ELSE is fol lowed by c ommand s and statements

    wh ich execute when the preceding IF comm and is

    false.

    .ENDIF delimi ts the grou p of comm ands and

    statements subject to p revious IF or ELSEcommands .

    Note:The Support Environment utilities (MultiLoad, FastExport, and TPump) support thenesting of .IF commands up to 100 levels.

  • 7/27/2019 B304 Support

    13/22

    Support Environment Example Input

    Create or Ac quir e Restart Lo g Table.

    Run comm ands in f i le logon.

    Check Day of Week. Write a mes sage

    and term inate Job if n ot 'FRI' (Case-

    specif ic) .

    Invok e ut i l i ty.

    .LOGON lst4300/KAC,amber96;

    /home/kac/logon

    .LOGTABLE CustLog_mld ;

    .RUN FILE /home/kac/logon ;

    .IF '&SYSDAY' NE 'FRI' THEN ;.DISPLAY 'This job runs on Friday'

    TO FILE /tmp/display_out ;.LOGOFF ;

    .ENDIF ;

    .BEGIN IMPORT MLOAD

    . . .

  • 7/27/2019 B304 Support

    14/22

    Support Environment Example Output

    MultiLoad Utility Output

    Logon / connection0001 .LOGTABLE Cust_Logtable ;

    0002 .RUN FILE /home/kac/logon;

    0003 .LOGON lst4300/KAC, ;

    15:18:30 FRI MAY 24, 2002

    UTY6211 A successful connect was made to the DBC.

    15:18:30 FRI MAY 24, 2002UTY6211 Logtable KAC.Cust_Logtable has been created.

    Processing Control Statements0004 .IF &SYSDAY NE FRI THEN ;

    15:18:30 FRI MAY 24, 2002

    UTY2402 Previous statement modified to:0005 .IF FRI NE FRI THEN;

    0006 .DISPLAY This job runs on Friday

    TO FILE /tmp/display_out;

    0007 .LOGOFF;

    0008 .ENDIF;

    0009 .BEGIN IMPORT MLOAD

  • 7/27/2019 B304 Support

    15/22

    Teradata SQL Support

    The Support Environment supports:

    Utility operations.

    DML and DDL functions for preparatory tasks in the same job-step,avoiding multiple utility invocations.

    TERADATA SQL statements beginning with the following keywords can beused:

    ALTER/MODIFY CHECKPOINTCREATE (CD,CT,CV, CM) DELETE (DEL)DROP INSERT (INS)RENAME UPDATE (UPD)

    REPLACE VIEW/MACRODATABASE GRANTREVOKE

    COLLECT STATISTICS GIVECOMMENT ONSET SESSION COLLATION RELEASE

    User-generated transactions (BT, ET) and SELECT are not supported.

  • 7/27/2019 B304 Support

    16/22

    Script Example Input

    .LOGTABLE restartlog2_mld;

    .LOGON lst4900/tfact05,password ;

    .ACCEPT num, name FROM FILE datain;

    .SET nbrin to 2 ;

    .IF &num = &nbrin THEN;

    UPDATE Control_Table SET Status = '&name' WHERE ID = &num ;.DISPLAY 'Update of record &nbrin successful'

    TO FILE /tmp/display2_out ;

    .ENDIF ;

    .LOGOFF ;

    Host File: datain 0 0 0 2 ' T e x t '

    The script is for setting up a MultiLoad operation. The data base table isnamed Control_Table. It has columns named Status and ID.

  • 7/27/2019 B304 Support

    17/22

  • 7/27/2019 B304 Support

    18/22

    Summary

    Support Environment:

    Common environment for utilities such as MultiLoad, FastExport, andTPump.

    Provides error reporting.

    Supports a wide range of DDL and DML commands for one-step jobs. Allows for conditional processing.

    Supports system- and user-defined variables.

    Provides recovery management from a Teradata or host failure.

  • 7/27/2019 B304 Support

    19/22

    Review Questions

    Match the item in the first column to its corresponding statement in the second column.

    _____ 1. LOGTABLE A. Connects sessions to Teradata

    _____ 2. .LOGON B. Uses a single data record to set one or more utility variables

    _____ 3. .ACCEPT C. System variable

    _____ 4. UPDATE D. Identifies the log to create or acquire

    _____ 5. &SYSDATE E. Teradata SQL statement permitted by Support Environment

  • 7/27/2019 B304 Support

    20/22

    Module 4: Review Question Answers

    Match the item in the first column to its corresponding statement in the second column.

    __D__ 1. LOGTABLE A. Connects sessions to Teradata

    __A__ 2. .LOGON B. Uses a single data record to set one or more utility variables

    __B__ 3. .ACCEPT C. System variable

    __E__ 4. UPDATE D. Identifies the log to create or acquire

    __C__ 5. &SYSDATE E. Teradata SQL statement permitted by Support Environment

  • 7/27/2019 B304 Support

    21/22

    Lab Exercises

    Lab Exercise 4-1 (Optional)

    PurposeIn this lab, you will set up the Support Environment, and take data from an input record (data4_1)and insert it to a row in your customer table.

    What you needAU.Customer and your Customer Table.

    Tasks1. Create a file or data set (data4_1) and enter the following data for INSERT into the Customer table:

    Customer_Number 10001Last_Name 'YourLastName'First_Name 'YourFirstName'Social_security 333445555

    Use the format:10001 'YourLastName' 'YourFirstName' 333445555 (items separated by spaces)

    2. Prepare a Support Environment script that defines the record to the Support Environment, using theACCEPT to read the record and use the SET command to dynamically modify the table name in yourINSERT statement. Use FastExport to execute this script.

    3. Test the result: SELECT * FROM Customer WHERE Customer_Number = 10001;

  • 7/27/2019 B304 Support

    22/22

    Lab Solutions for 4-1

    Lab Exercise 4-1

    cat lab322.fld

    .LOGTABLE Lab41_log_fxp;

    .LOGON u4455/tljc30,tljc30;

    .ACCEPT cnum, lname, fname, ssec FROM FILE data4_1;

    .SET filename TO 'Customer';INSERT INTO &filename

    VALUES (&cnum, '&lname', '&fname', &ssec) ;.LOGOFF;

    fastload < lab412.fxp