1 / 41

RPG IV

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.

kert
Download Presentation

RPG IV

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RPG IV Advanced Data Definition and Manipulation- Chapter 11

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

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

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

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

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

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

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

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

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

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

  12. Data Structures • Subdivide fields into subfields • Restructure records with different field layouts • Change field data types • Add a second dimension to arrays

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

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

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

  16. Multiple-Occurrence Data Structures • Repeated data structures • Keyword OCCURS • Number determines how many times the structure is repeated in storage

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

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

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

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

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

  22. *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

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

  24. %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

  25. %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

  26. %DECPOS • Returns the number of decimal positions in a numeric variable or expression • Sometimes used with the %LEN function

  27. %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

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

  29. TEST • Checks validity of date, time or timestamp fields • Checks character and numeric fields for valid date/time data

  30. SCAN • Look for a characer or string of character within a character field • Case sensitive - recognizes upper and lower case • Blanks are not ignored

  31. %SCAN • Nearly identical to SCAN • Performs the scan within an expression

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

  33. CHECKR • Works exactly like CHECK • Checks the base string from right to left

  34. Field Character Manipulation • + (Concatenate Character Strings) • %TRIM, %TRIML, and %TRIMR (Trim Blanks) • %SUBST(Get Substring) • %DEC(Convert to Packed Decimal Format) • XLATE (Translate)

  35. Concatenate Character Strings • Using the + operator with EVAL is a convenient way to concatenate two (or more) strings to form a new string

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

  37. %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

  38. %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

  39. XLATE • Translate or convert characters within a string to other characters

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

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

More Related