Test268 Section 3

From MidrangeWiki
Revision as of 03:59, 9 April 2006 by Copritch (talk | contribs) (DOWxx)
Jump to: navigation, search

<< Previous Section | Home | Next Section >>

Section 3 - Core RPG (15%)

Recognize appropriate use of RPG creation commands (e.g., CRTxxxPGM, CRTxxxMOD, CRTPGM, CRTBNDxxx)

  • CRTxxxPGM
    • Used for compiling a RPG OPM program .
  • CRTxxxMOD
    • Used for compiling a RPG ILE 4 module. It will create a non exectutable *module object.
  • CRTPGM
    • Used for linking one or more modules to create a program. It will create a executale *pgm object.
  • CRTBNDxxx
    • Used for comiling a RPG ILE 4 program. When the source is compiled, it will create a module in QTEMP and then create a program from it and finally deletes the module.

Define basic arrays (e.g., compile time, pre-run time, run time) using D specs

Compile Time

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++
DARC              S              3A   DIM(12) PERRCD(5) CTDATA

// Must be at the end of the code
**CTDATA ARC
48K16343J64044HComments can be placed here
12648A47349K346Comments can be placed here
50B125         Comments can be placed here

Pre-Run Time

Figure 68 shows the definition specifications required for two prerun-time arrays, a compile-time array, and a run-time array. Figure 68. Definition Specifications for Different Types of Arrays

HKeywords+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
H DATFMT(*USA) TIMFMT(*HMS)
D*ame+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++
 * Run-time array.  ARI has 10 elements of type date. They are
 * initialized to September 15, 1994.  This is in month, day,
 * year format using a slash as a separator as defined on the
 * control specification.
DARI              S               D   DIM(10) INZ(D'09/15/1994')
 *
 * Compile-time arrays in alternating format.  Both arrays have
 * eight elements (three elements per record).  ARC is a character
 * array of length 15, and ARD is a time array with a predefined
 * length of 8.
DARC              S             15    DIM(8) PERRCD(3)
D                                     CTDATA
DARD              S               T   DIM(8) ALT(ARC)
 *
 * Prerun-time array.  ARE, which is to be read from file DISKIN,
 * has 250 character elements (12 elements per record).  Each
 * element is five positions long.  The size of each record
 * is 60 (5*12). The elements are arranged in ascending sequence.
DARE              S              5A   DIM(250) PERRCD(12) ASCEND
D                                     FROMFILE(DISKIN)
 *
 * Prerun-time array specified as a combined file.  ARH is written
 * back to the same file from which it is read when the program
 * ends normally with LR on.  ARH has 250  character elements
 * (12 elements per record).  Each elements is five positions long.
 * The elements are arranged in ascending sequence.
DARH              S              5A   DIM(250) PERRCD(12) ASCEND
D                                     FROMFILE(DISKOUT)
D                                     TOFILE(DISKOUT)

// Must be at the end of the code
**CTDATA ARC
Toronto        12:15:00Winnipeg       13:23:00Calgary        15:44:00
Sydney         17:24:30Edmonton       21:33:00Saskatoon      08:40:00
Regina         12:33:00Vancouver      13:20:00

Run Time

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++
DARC              S              3A   DIM(12)

Use basic array handling (e.g., *IN, LOOKUP, SORTA, MOVE and MOVEA, indexing)

The LOOKUP operation can be used to search arrays.

Example:

FARRFILE IT F 5 DISK

*

DDPTNOS S 5S 0 DIM(50) FROMFILE(ARRFILE) D* C* The LOOKUP operation is processed and, if an element of DPTNOS equal C* to the search argument (DPTNUM) is found, indicator 20 is set on. C DPTNUM LOOKUP DPTNOS 20


SORTA :You can sort arrays using the “SORTA (Sort an Array)”.The array is sorted into sequence (ascending or descending), depending on the sequence specified for the array on the definition specification.

Code and use figurative constants (e.g., *LOVAL, *HIVAL, *ALL, *BLANKS, *ZEROS, *ON, *OFF)

  • *ALL
  • *BLANKS -- Fills an alpha field with ' '
  • *HIVAL -- Fills a field with the highest possible value the field can hold
  • *LOVAL -- Fills a field with the lowest possible value the field can hold
  • *OFF -- Generally used for indicators to either turn them off or check to see if they are off
  • *ON -- Generally used for indicators to either turn them on or check to see if they are on
  • *ZEROS -- Fills a numeric field with 0

Code and use job date and system date

Job Date

D CurDate         S               D   DATFMT(*ISO) INZ(*JOB)

System Date

D CurDate         S               D   DATFMT(*ISO) INZ(*SYS)

Code and use structured operation codes (e.g., DO, DOUxx, DOWxx, IF/ELSE/ELSEIF, SELECT/WHEN, CASxx/EXSR)

DO

DOUxx

/Free
 DOU %EOF(filename);
    // Logic
    READ filename;
 ENDDO;
/End-Free

DOWxx

/Free
 READ filename;
 DOW NOT %EOF(filename);
  // logic
  READ filename;
ENDDO;

IF/ELSE/ELSEIF

if mycondition;
  // the code
else;
  // other condition
endif;
if mycondition;
  // the code
elseif new condition;
  // new code
endif;

SELECT/WHEN

       select;                                                                                     
                                                                                                   
         when %trim(MonthName) = 'January' or                                                      
              %trim(MonthName) = 'JANUARY';                                                        
           return 1;                                                                               
                                                                                                   
         when %trim(MonthName) = 'February' or                                                     
              %trim(MonthName) = 'FEBRUARY';                                                       
           return 2;                                                                               
                                                                                                   
         when %trim(MonthName) = 'March' or                                                        
              %trim(MonthName) = 'MARCH';                                                          
           return 3;                                                                               
                                                                                                   
         when %trim(MonthName) = 'April' or                                                        
              %trim(MonthName) = 'APRIL';                                                          
           return 4;                                                                               
                                                                                                   
         when %trim(MonthName) = 'May' or                                                          
              %trim(MonthName) = 'MAY';                                                            
           return 5;                                                                               
                                                                                                   
         when %trim(MonthName) = 'June' or                                                         
              %trim(MonthName) = 'JUNE';                                                           
           return 6;                                                                               
                                                                                                   
         when %trim(MonthName) = 'July' or                                                         
              %trim(MonthName) = 'JULY';                                                           
           return 7;                                                                               
                                                                                                   
         when %trim(MonthName) = 'August' or                                                       
              %trim(MonthName) = 'AUGUST';                                                         
           return 8;                                                                               
                                                                                                   
         when %trim(MonthName) = 'September' or                                                    
              %trim(MonthName) = 'SEPTEMBER';                                                      
           return 9;                                                                               
                                                                                                   
         when %trim(MonthName) = 'October' or                                                      
              %trim(MonthName) = 'OCTOBER';                                                        
           return 10;                                                                              
                                                                                                   
         when %trim(MonthName) = 'November' or                                                     
              %trim(MonthName) = 'NOVEMBER';                                                       
           return 11;                                                                              
                                                                                                   
         when %trim(MonthName) = 'December' or                                                     
              %trim(MonthName) = 'DECEMBER';                                                       
           return 12;                                                                              
                                                                                                   
         other;                                                                                    
           return -1;                                                                              
                                                                                                   
       endsl;

CASxx/EXSR

Code and use structured operation codes with expressions (+, -, * ,/, **, <, >, =, (), and, or, not)

  • Addition
result = field1 + field2;
result += field3; // The expression is added to the target
  • Subtraction
result = field1 - field2;
result -= field3; // The expression is subtracted from the target
  • Multiplication
result = field1 * field2;
result *= field3; // The target is multiplied by the expression
  • Division
result = field1 / field2;
result /= field3; // The target is divided by the expression 
  • Exponentiation
result = field1 ** field2;
result **= field3; // The target is assigned the target raised to the power of the expression
  • Less Than
if field1 < field2;
  // my code here
endif;
  • Greater Than
if field1 > field2;
  // my code here
endif;
  • Equal
if field1 = field2;
  // my code here
endif;
  • Parenthesis
result = (field1 + field2) * field3;
  • And
if field1 > field2 and field3 > field4;
  // my code here
endif;
  • Or
if field1 > field2 or field3 > field4;
  // my code here
endif;
  • not
if field1 > field2 and not field3 > field4;
  // my code here
endif;

Code and use date data types and arithmetic operations, including date operations in expressions

Code and use SDS

See Program Status Data Structure

Code and use *INZSR

'*INZSR' is automatically run before any other mainline code.

begsr *inzsr;
  // code for the *inzsr here
endsr  //*inzsr;
NOTE
  • *INZSR can be defined only for MAIN subprocedure
  • RESET operation cant be used in *INZSR
  • If program returns with *INLR=*OFF, *INZSR will not be executed on next program invocation.
  • If program returns with *INLR=*OFF but *INZSR wasn't completed normaly, it will be executed on next program invocation.
  • If *INZSR is coded inside bounded module
    • it will be called only if MAIN subprocedure is called first.
    • if other subprocedure is called first only initalization of global storage occures.

Code and use RPG IV built-in functions

See Built In Functions

Use the H-spec keywords

See H-Spec Keywords

Use RPG IV OpCodes (e.g., Arithmetic, Date, Message, Array, Declarative, File, Branching, Indicator setting, String handling, Structured programming, compare, initialization, subroutine, data area)

Use the D-spec keywords

See D-Spec Keywords


<< Previous Section | Home | Next Section >>