AZK RPG - Declarations - C4-1-107

  1. Ext Desc File for reading
    • Dcl-f Customers Disk(*Ext) Usage(*Input);
    • Dcl-f Customers Disk Usage(*Input);
    • Dcl-f Customers Disk;
    • Dcl-f Customers;
  2. Prog Desc Disk File for reading
    Dcl-f Customers Disk(145) Usage(*Input);
  3. Ext Desc Printer File
    • Dcl-f Custlist Printer(*Ext) Usage(*Output) Ovfind(*Endofpage);
    • Dcl-f Custlist Printer Usage(*Output) Ovfind(*Endofpage);
    • Dcl-f Custlist Printer Ovfind(*Endofpage);
  4. Prog Desc Printer File
    Dcl-f Custlist Printer(132) Usage(*Output) Ovfind(*Endofpage);
  5. Ext Desc Workstn (Display) File
    • Dcl-f Display Workstn Usage(*Input:*Output);
    • Dcl-f Display Workstn;
  6. File Usage in File Declaration
    • Usage(*Input)
    •    - read from file
    • Usage(*Output)
    •    - write to a file
    • Usage(*Input:*Output)
    •    - read and write
    • Usage(*Update)
    •    - change, bu not delete
    • Usage(*Delete)
    •    - delete record from file
    • Usage(*Update:*Delete)
    •    - change or delete
    • Usage(*Update:*Delete*Output)
    •    - change, delete or add
  7. Default usage in File Declaration
    • - omitting usage
    •    - Disk - Input
    •    - Printer - Output
    •    - Workstn - Input / Output

    • - omitting Device
    •    - Dcl-f Cudtomer;
    •       - Dick Usage(*Input) - assumed
  8. File keywords - C4-5-111
    • - Oflind
    • - Keyed
    • - Keyloc
    • - Rename
    • - Prefix
    • - Extdesc
    • - Extfile
    • - Extmbr
  9. Oflind
    • - Overflow Indicator
    • - used by printer file
    • - Oflind = *On when printed report reaches bottom of page
    • - after printing Headings, turn Oflind = *Off

    Dcl-f Custlist Printer Usage(*Output) Oflind(Endofpage);

    • If Endofpage;
    •    Write Header;
    •    Endofpage = *Off;
    • Endif;
  10. Keyed
    • - to process file by key
    • - Ext Desc File   

       Dcl-f Customers Keyed;

    - Pgm Desc File

    •    Dcl-f Customers Disk(145)
    •       Keyed(*Char:5) Keyloc(2);

    • - *Char - the only key type allowed for program-disc file
    • - key is 5 bytes long
  11. Keyloc
    • - for Pgm Desc File
    • - key begins in position 2 of record layout
    • - if missing - begins in 1st position
  12. Rename
    • - to rename record format
    •    - if record format is the same as file name
    •    - if 2 files have the same rec form names

    Dcl-f Customers Rename(Customers:Custrec);
  13. Prefix
    - to rename individual fields in an Ext Desc File

    • - add Prefix 'C2' to Custnames's fields
    •   
    • Dcl-f Customers Rename(Customers:Custrec)
    •    Prefix(C2);

    - to replace existing prefix (w 2 characters)

    • Dcl-f Customers Rename(Customers:Custrec)
    •    Prefix(C2:2);
  14. Extdesc
    • - to retrieve the record layout from specific library (not in *LIBL)
    • - overrides at compile time

    Dcl-f Customers Extdesc('DECLIB/CUSTOMERS);
  15. Extfile
    - to retrieve the record layout from specific library (not in *LIBL)

    - overrides at runtime

    Dcl-f Customers Extfile('PRDLIB/CUSTOMERS);

    - to override at compile and run-time

    • Dcl-f Customers Extdesc('PRDLIB/CUSTOMERS)
    •    Extfile('DECLIB/CUSTOMERS);

    - to override the same file at compile and run-time

    • Dcl-f Customers Extdesc('PRDLIB/CUSTOMERS)
    •    Extfile(*EXTDESC);
  16. Extmbr
    - overrides multimember file to a specific member

    • Dcl-f Customers Extdesc('PRDLIB/CUSTOMERS)
    •    Extmbr('DOMESTIC');
  17. Literal
    - fixed value

    • - Numeric Literals
    •    -456.23
    •    0.01478
    • - Character Literals
    •    'Anatoliy'
    •    '12-27-1963'
  18. Typed Literal
    • - Date
    •    - D'2008-03-15'
    • - Time
    •    - T'08.30.20'
    • - Timestamp
    •    - Z'2008-03-15-08.30.20.000000'
    • - Hexadecimal
    •    - X'F0F0F0'
  19. Named Constants
    - length and type attributes are implicit

    •         Dcl-c Taxrate .0765;
    •         Dcl-c Taxrate Const(.0765);
    •         Dcl-c Country 'Ukraine';
    •         Dcl-c Phoneedit '0(   )   -    ';
    •         Dcl-c Millenium D'2001-01-01';

    - always use a named constant instead of literals
  20. Figurative Constant
    • - *Blank / *Zero
    • - *On / *Off
    • - *Hival / *Loval
    • - *All - *All7;
    • - *Null - absence of any value
  21. Stand along variable - Char / Varchar / Ind
    • Dcl-s Name Char(20);   
    • Dcl-s Email Varchar(256);     256 - max
    • Dcl-s Indicator Ind;
  22. Stand along variable - Zoned
    - SQL equivalent NUMERIC

    • Dcl-s Daynumber Zoned(2:0);
    • Dcl-s Daynumber Zoned(2);
  23. Stand along variable - Packed
    - SQL equivalent DECIMAL

    Dcl-s Total Packed(8:2);
  24. Stand along variable - Int
    • - signed integer
    • - Int can be only:
    •    - 3  = 1 byte
    •    - 5  = 2 bytes    SMALLINT
    •    - 10 = 4 bytes    INT
    •    - 20 = 8 bytes    BIGINT
    •   
    • Dcl-s Counter Int(5);
  25. Stand along variable - Uns
    • - unsigned Integer
    • - Uns can be only:
    •    - 3  = 1 byte
    •    - 5  = 2 bytes    SMALLINT
    •    - 10 = 4 bytes    INT
    •    - 20 = 8 bytes    BIGINT

    Dcl-s Counter Uns(5);
  26. Stand along variable - Date / Time / Timestamp
    • Dcl-s Today Date;
    •  Dcl-s Now Time;
    •  Dcl-s Lastupdate Timestamp;
    •  Dcl-s Lastupdate Timestamp(0);
    •      - 0 - fractional seconds digit 0-12
  27. Initialization of Char(9) with all zeros
    • Dcl-s Check Char(9) Inz(X'000000000000000000');
    • Dcl-s Check Char(9) Inz(*Allx'00');
    • Dcl-s Check Char(9) Inz(*Loval);
  28. Initialization of Packed(7:2) with 999999.99
    • Dcl-s Highlimit Packed(7:2) Inz(999999.99);
    • Dcl-s Highlimit Packed(7:2) Inz(*Hival);
  29. Declare Current Date (System)
    • Dcl-s Today Date Inz(*Sys);
    • Dcl-s Today Date();
  30. Declare Job Date
    - "as of" of date that is assigned to a job when you run a program

    Dcl-s Job Date Inz(*Job);
  31. Declare User Profile
    Dcl-s Username Char(10) Inz(*User);
  32. Defining Data Structure
    • Dcl-ds Customer;
    •    Company       Zoned(2:0);
    •    Id            Zoned(5:0);
    •    Name          Char(35);
    •    Address       Char(35);
    •    Dcl-subf Read Char(5); - if name is the same as RPG operation        
    • End-ds

    - Numeric subfields are usually zoned
  33. Defining Indicators DS
    Ds predefined by IBM - Indicators DS

    • Dcl-ds Indicators;
    •    Exit    Ind Pos(3);
    •    Cancel  Ind Pos(12);
    •    Error   Ind Pos(50);
    •    Sflend  Ind Pos(40);
    • End-ds;
  34. Defining DS that must be initialized
    - initializes all subfields w initial values

    • Dcl-ds Phone;
    •    Areacode Zoned(3:0) Inz();
    •    Exchange Zoned(3:0) Inz(555);
    •    Localnbr Zoned(4:0) Inz;
    • End-ds;

    • Dcl-ds Phone Inz;
    •    Areacode Zoned(3:0);
    •    Exchange Zoned(3:0) Inz(555);
    •    Localnbr Zoned(4:0);
    • End-ds;
  35. Defining DS with Overlapping Subfields
    • Dcl-ds *N;
    •    Firstname   Char(5) Inz('Anatoliy');    
    •    Initial   Char(1) Overlay(Firstname);    = 'A'
    • End-ds;

    • Dcl-ds *N Inz;                      
    •    Phone Zoned(10);            = 2035503269
    •    Areacode Zoned(3:0) Overlay(Phone);    = 203 - Overlay 3 starting w 1st pos
    •    Exchange Zoned(3:0) Overlay(Phone:4);    = 550 - Overlay 3 starting w 4th pos
    •    Localnbr Zoned(4:0) Overlay(Phone:7);    = 3269 - Overlay 4 starting w 7th pos
    • End-ds;

    - can redefine subfields w different name and/or data types

    • Dcl-ds *N Inz;
    •    Basedate Date;
    •    Basechar Char(10) Overlay(Basedate);    - occupys the same location as Basedate
    •    End-ds;
  36. Defining Externally Described DS
    - DS has the same name as PF Customers

    Dcl-ds Customers Ext End-ds;

    - DS and PF have different names

    • Dcl-ds Custds Ext Extname('CUSTOMERS') End-ds;
    • Dcl-ds Custds Extname('CUSTOMERS') End-ds;
  37. Defining Externally Described DS with additional program describe subfields
    • Dcl-ds Custds Extname('CUSTOMERS');
    •    Lastdate Date;
    •    Rating   Char(1);
    • End-ds;
  38. Defining Externally Described DS with renaming subfields
    • Dcl-ds Custds Extname('CUSTOMERS');
    •    Address Extfld('CADDR');    // Address is a new name
    • End-ds;
  39. Defining Externally Described DS with initialization of subfields to the values of external file definition
    Dcl-ds Customers Ext Inz(*Extfld) End-ds;
  40. Defining Externally Described DS with overriding external default w its own Inz values
    • Dcl-ds Custds Extname('CUSTOMERS') Inz(*Extfld);
    •    Custno Extfld    Inz('999999999');      - Ext field w new value    
    •    Lastdate Date    Inz(*Sys);
    •    Rating   Char(1) Inz('5');
    • End-ds;
  41. Defining Qualified DS
    • - lets you to have multiple DS w identically named subfields
    • - can be program- or ext desc DS
    • - must be named DS

    • Dcl-ds Customer Qualified;
    •    Company       Zoned(2:0);    - Customer.Company
    •    Id            Zoned(5:0);    - Customer.ID
    •    Name          Char(35);        - Customer.Name
    •    Address       Char(35);        - Customer.Address
    • End-ds
    •             
    • Dcl-ds Vendor Qualified;
    •    Company       Zoned(2:0);    - Vendor.Company
    •    Id            Zoned(5:0);    - Vendor.ID
    •    Name          Char(35);        - Vendor.Name
    •    Address       Char(35);        - Vendor.Address
    • End-ds
  42. Defining Program Status Data Structure (PSDS)
    • DCL-DS pgm_stat PSDS;
    •    status *STATUS;
    •    routine *ROUTINE;
    •    library CHAR(10) POS(81);
    • END-DS;
  43. Defining File Information Data Structure (INFDS)
    • DCL-F myfile DISK(*EXT) INFDS(myfileInfo);
    • DCL-DS myfileInfo;
    •    status *STATUS;
    •    opcode *OPCODE;
    •    msgid CHAR(7) POS(46);
    • END-DS;
  44. Defining DS with a nested data structure subfield
    • DCL-DS employeeInfo QUALIFIED;
    •    id_no int(10);
    •    DCL-DS name;
    •       last VARCHAR(25);
    •       first VARCHAR(25);
    •       initial CHAR(1);
    •    END-DS;
    •    type VARCHAR(10);
    • END-DS;

    •  employeeInfo.id_no = 12345;
    •  employeeInfo.name.first = 'Robin';
    •  employeeInfo.name.last = 'Hood';
  45. Like
    • - defines stand along variable or DS subfield based on another data item
    • - copies only data attributes of the parent, not the value

    • Dcl-s Firstname Char(20);        = Char 20
    • Dcl-s Unitsale  Packed(9:2);        = Packed 9.2
    • Dcl-s Lastname  Like(Firstname);    = Char 20
    • Dcl-s Longname  Like(Firstname:+15);    = Char 35
    • Dcl-s Totalsale Like(Unitsale:+2)    = Packed 11.2
  46. Likeds
    • - defines DS like another DS
    • - copies only data attributes of the parent, not the value

    Dcl-ds Vendor Likeds(Customer);   - NO End-ds

    • - new Vendor DS is impicitly Qualified
    • - Vendor has the same subfields as Customer
    • - no additional fields are allowed (that's why NO End-ds)
    • - if Customer.Origdate is initialized to System Current Date, the Vendor.Origdate is not automatically initialized to System Current Date

    Dcl-ds Vendor Likeds(Customer) Inz(*Likeds);

    - now new Vendor DS copied w data attributes of the parent and values
  47. Likerec
    • - defines a DS to be like a PF defined in "Dcl-f"
    • - must refer to a rec format that exists in a file declared in the program

    • Dcl-f Customers Keyed;
    • Dcl-ds Before Likerec(Custsrec);    - NO End-ds (no additional subfields) 

    - allows to restrict a subfields in DS to keyfields only

    • Dcl-f Custdir Keyed;
    • Dcl-ds Custkeys Likerec(Custdrec:*Key);
Author
flashsmilenet
ID
340455
Card Set
AZK RPG - Declarations - C4-1-107
Description
AZK RPG - Declarations
Updated