rpg iv l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
RPG IV PowerPoint Presentation
Download Presentation
RPG IV

Loading in 2 Seconds...

play fullscreen
1 / 41

RPG IV - PowerPoint PPT Presentation


  • 271 Views
  • Uploaded on

RPG IV. Advanced Data Definition and Manipulation- Chapter 11. Objectives. Perform date arithmetic Define data that facilitate data manipulation, error trapping, debugging and program maintenance Use RPG IV built-in functions(BIF’s) to manipulate data. Data Types and Time.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'RPG IV' - kert


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
rpg iv

RPG IV

Advanced Data Definition and Manipulation- Chapter 11

objectives
Objectives
  • Perform date arithmetic
  • Define data that facilitate data manipulation, error trapping, debugging and program maintenance
  • Use RPG IV built-in functions(BIF’s) to manipulate data
data types and time
Data Types and Time
  • Three data types exist for dealing with time:
    • Date(D) -10 byte display yyyy-mm-dd
    • Time(T)- 8 byte display hh.mm.ss
    • Timestamp(Z) - 26 byte default display yyyy-mm-dd-hh.mm.ss.mmmmmm
  • Date supports 8 different formats
  • Time supports 5 different formats
  • Different separators are supported
date and time operations
Date and Time Operations
  • ADDDUR, SUBDUR and EXTRCT
  • Duration codes:
    • *YEARS (or *Y)
    • *MONTHS (or *M)
    • *DAYS (or *D)
    • *HOURS (or*H)
    • *MINUTES (or *MN)
    • *SECONDS (or *S)
    • *MSECONDS (or *MS)
adddur add duration
ADDDUR(Add Duration)
  • Add a duration coded in Factor 2 to the date specified in Factor 1
  • Storing the answer in the date, time or timestamp field specified as the Result field
  • Factor 2 must contain an integer field or literal
subdur subtract duration
SUBDUR(Subtract Duration)
  • Has two uses:
    • Subtract a date/time duration from a date/time value (similar to ADDDUR)
    • Calculate the duration between two date/time values
subtract a date time duration
Subtract a Date/Time Duration
  • Subtract a duration coded in Factor 2 to the date specified in Factor 1
  • Storing the answer in the date, time or timestamp field specified as the Result field
  • Factor 2 must contain an integer field or literal
calculate a duration between two date time values
Calculate a Duration Between Two Date/Time Values
  • Factor 1 and Factor 2 must contain data items of compatible types
  • Place an integer receiveing field followed by a duration code in the Result field
extrct extract date time timestamp
EXTRCT(Extract Date/Time/Timestamp)
  • Extract a portion of a data/time or timestamp and store in the Result field
  • Factor 2 date/time data item must be coupled with a duration code to signal which portion of the data/time unit is to be extracted
pointer data types
Pointer Data Types
  • Two kinds of pointer data types: basing pointers and procedure pointers
  • Used to access storage that is allocated dynamically throughout the program
  • Pointers store address of memory locations rather than data values
  • Procedure pointers must include the keyword PROCPTR
like field definition
LIKE (Field Definition)
  • The keyword LIKE allows you to define a field based on the attributes of another field
  • The entered number signals the extent of the increase or decrease in field length
data structures
Data Structures
  • Subdivide fields into subfields
  • Restructure records with different field layouts
  • Change field data types
  • Add a second dimension to arrays
data structures cont
Data Structures cont.
  • DS coded in 24-25 on D spec signals the beginning of a data structure
  • Enter name of data structure in 7-21
  • Follows same rules as field
  • Use absolute notation or length notation for subfields
overlay
OVERLAY
  • OVERLAY keyword indicates that a subfield overlays the storage of another subfield
  • If the data time within parentheses is an array, OVERLAY applies to each element of the array
externally described data structures
Externally Described Data Structures
  • Externally described data structures are useful when you want to standardize a data structure
  • Code an E in position 22
  • Name the external file using the EXTNAME keyword
multiple occurrence data structures
Multiple-Occurrence Data Structures
  • Repeated data structures
  • Keyword OCCURS
  • Number determines how many times the structure is repeated in storage
occur set get occurrence of a data structure
OCCUR (Set/Get Occurrence of a Data Structure)
  • OCCUR operation is used to establish which occurrence of the data structure is used next within the program
  • Factor 1 specifies which occurrence should be made current
  • Factor 2 contains the name of the DS
initialization and reinitialization of variables
Initialization and Reinitialization of Variables
  • INZ keyword will initialize to default value of data type
  • *INZSR is a subroutine that will be invoked automatically after the program completes its other start up tasks
  • CLEAR and RESET will allow you to reinitialize variables
file information data structures
File-Information Data Structures
  • A special data structure that can be defined for each file used by your program
  • This data structure contains subfields that provide info to your program about the file and I/O operations
  • The required entries in the F spec are; keyword INFDS and a parameter with the name of the data structure defined in the D Spec
program status data structures
Program-Status Data Structures
  • A data structure that can provide you with information about the program itself and about exceptions/errors that occur during program execution
  • An S in position 23 of a data structure definition line identifies a program-status data structure
error handling
Error Handling
  • Without explicit error handling within your program, any runtime error will cause the system to suspend the program
  • One technique to code the (E) error-handling extender with those operations that permit such an entry
  • Then perform an error routine if the %ERROR bif is on
slide22
*PSSR
  • Another error handling technique is to use a special subroutine called *PSSR
  • This subroutine will automatically receive control when a program error occurs
  • To send control to this subroutine for file errors, you must explicitly designate *PSSR as the error handler for the file
field inspection
Field Inspection
  • %SIZE(Get Size in Bytes)
  • %LEN(Get or Set Length)
  • %DECPOS(Get Number of Dec Positions)
  • %ELEM(Get Number of Elements)
  • TESTN(Test Numeric)
  • TEST(Test Date/Time/Timestamp)
  • SCAN(Scan String)
  • %SCAN(Scan for Characters)
  • CHECK(Check Characters)
  • CHECKR(Check Reverse)
slide24
%SIZE
  • Returns number of bytes or length of string
  • Used to determine size of field, literal, named constant, data structure, subfield, array or table
  • One required parameter to represnet data whose size you want to know
  • Second parameter *ALL- size of entire table, array or data structure
slide25
%LEN
  • Returns number of digits or characters in an expression
  • Especially useful with character expressions
  • For numeric expressions %LEN returns the precision of the expression
decpos
%DECPOS
  • Returns the number of decimal positions in a numeric variable or expression
  • Sometimes used with the %LEN function
slide27
%ELEM
  • Returns the number of elements in an array or a table or the number of occurrences in a multiple-occurrence data structure
  • Can be used in calculations or when defining other fields
testn
TESTN
  • Determine whether a character field contains all numeric characters, leading blanks followed by all numeric characters, or all blanks
  • Used to validate fields before performing calculations
slide29
TEST
  • Checks validity of date, time or timestamp fields
  • Checks character and numeric fields for valid date/time data
slide30
SCAN
  • Look for a characer or string of character within a character field
  • Case sensitive - recognizes upper and lower case
  • Blanks are not ignored
slide31
%SCAN
  • Nearly identical to SCAN
  • Performs the scan within an expression
check
CHECK
  • Similar to SCAN
  • Checks for discrepancies between individual characters of compare field and base string and signals absence of a base character from set of compare characters and stores it’s location in the result field
  • Checks left to right
checkr
CHECKR
  • Works exactly like CHECK
  • Checks the base string from right to left
field character manipulation
Field Character Manipulation
  • + (Concatenate Character Strings)
  • %TRIM, %TRIML, and %TRIMR (Trim Blanks)
  • %SUBST(Get Substring)
  • %DEC(Convert to Packed Decimal Format)
  • XLATE (Translate)
concatenate character strings
Concatenate Character Strings
  • Using the + operator with EVAL is a convenient way to concatenate two (or more) strings to form a new string
trim blanks
Trim Blanks
  • Remove leading and/or trailing blanks from their argument
  • %TRIML – removes leading blanks
  • %TRIMR – removes trailing blanks
  • %TRIM – removes both leading and trailing blanks
subst
%SUBST
  • Extracts a portion of a character string
  • Argument parameters in order: string from which extraction is to occur, position within that string where substring is to start and optional length of substring, parameters separated by a colon
slide38
%DEC
  • Converts the result of the expression to a packed-decimal format
  • %DECH (Convert to Packed Decimal Format with Half Adjust)
  • %INT (Convert to Integer Format)
  • %UNS(Convert to Unsigned Format)
  • %INTH and %UNSH are half adjust built in functions
xlate
XLATE
  • Translate or convert characters within a string to other characters
points to remember
Points to Remember
  • Fields can be defined relative to other field definitions using the keyword LIKE
  • You can define data structures that represent complex definitions of a given area of memory
points to remember cont
Points to Remember cont.
  • Data structures or subfields of data structures can be initialized easily as part of the data structure definition
  • Two special data structures of predefined subfields exist in RPG to provide information about the status of files used by the program or about the processing of the program itself