Difference between revisions of "Free Form Calcs"

From MidrangeWiki
Jump to: navigation, search
m
(Example)
 
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:
 
Using free form calculations is quite easy.
 
Using free form calculations is quite easy.
  
* To start a section of free form calculations, simply put '/free' starting in column 7.
+
* To start a section of free form calculations, simply put '/free' starting in column 7 (not required after v7r1 TR 7).
 
* On the next line start your free form calculations.
 
* On the next line start your free form calculations.
 
* Each line must end with a semi-colon ";".
 
* Each line must end with a semi-colon ";".
 
* Calculations can span multiple lines.
 
* Calculations can span multiple lines.
* End the free form calculation area by putting '/end-free' starting in column 7 on the last line.
+
* End the free form calculation area by putting '/end-free' starting in column 7 on the last line (not required after v7r1 TR 7).
 +
 
 
=Limitations=
 
=Limitations=
 +
certain opcodes have not been implemented in free form RPG.  Many have been replaced with corresponding [[RPG Built In Functions | built in functions]].
 +
 +
These include ...
 +
* Move operations (it is debatable as to the wisdom of not supporting these operations)
 +
** MOVE
 +
** MOVEL
 +
** MOVEA
 +
** MHHZO
 +
** MHLZO
 +
** MLHZO
 +
** MLLZO
 +
* Arithmetic operations (use free form evaluations or corresponding built in function)
 +
** ADD
 +
** SUB
 +
** DIV
 +
** MULT
 +
** MVR
 +
** XFOOT (use [[%XFOOT]])
 +
* Comparison (use free form comparisons)
 +
** COMP
 +
** IFxx
 +
** WHENxx
 +
* Flow control
 +
** DO
 +
** GOTO
 +
* Parameters (use [[procedure interface]] definitions and [[prototyped calls]])
 +
** PARM
 +
** PLIST
 +
* Other
 +
** TESTB
 +
** TESTN
 +
** TESTZ
 +
** XLATE (use [[%XLATE]])
  
 
=Example=
 
=Example=
<pre>
+
<source lang="rpg">
C                  if        PCFRS = '*ALL'                 
+
C                  if        PCFRS = '*ALL'                 
C                  eval      #CFRSF = *BLANK               
+
C                  eval      #CFRSF = *BLANK               
C                  eval      #CFRSH = *BLANK               
+
C                  eval      #CFRSH = *BLANK               
C                  else                                     
+
C                  else                                     
C                  eval      #CFRSF = i_CF_Const(PCFRS)     
+
C                  eval      #CFRSF = i_CF_Const(PCFRS)     
C                  eval      #CFRSH = #CFRSF               
+
C                  eval      #CFRSH = #CFRSF               
C                  endif                                   
+
C                  endif                                   
 
                                                              
 
                                                              
/free                                                       
+
  /free                                                       
  if (pMOLS = '*ALL');                                       
+
  if (pMOLS = '*ALL');                                       
    eval #MOLSF = *blank;                                   
+
    eval #MOLSF = *blank;                                   
    eval #MOLSH = *blank;                                   
+
    eval #MOLSH = *blank;                                   
  else;                                                     
+
  else;                                                     
    eval #MOLSF = pMOLS;                                     
+
    eval #MOLSF = pMOLS;                                     
    eval #MOLSH = pMOLS;                                     
+
    eval #MOLSH = pMOLS;                                     
  endif;                                                     
+
  endif;                                                     
/end-free                                             
+
  /end-free                                             
 
      
 
      
C    C#RTNS        IFNE      '*EXITPGM'              
+
C    C#RTNS        IFNE      '*EXITPGM'
C    C#RTNS        ANDNE    '*RETURN'                                                                          
+
C    C#RTNS        ANDNE    '*RETURN'
</pre>
+
</source >

Latest revision as of 16:44, 31 May 2016

One of the major new features of RPG 4, introduced in V5R1, is free form calculation specifications.

Features

  • Removes the column restrictions on calculations.
  • Can be interspersed with standard, fixed form, calcs

Usage

Using free form calculations is quite easy.

  • To start a section of free form calculations, simply put '/free' starting in column 7 (not required after v7r1 TR 7).
  • On the next line start your free form calculations.
  • Each line must end with a semi-colon ";".
  • Calculations can span multiple lines.
  • End the free form calculation area by putting '/end-free' starting in column 7 on the last line (not required after v7r1 TR 7).

Limitations

certain opcodes have not been implemented in free form RPG. Many have been replaced with corresponding built in functions.

These include ...

  • Move operations (it is debatable as to the wisdom of not supporting these operations)
    • MOVE
    • MOVEL
    • MOVEA
    • MHHZO
    • MHLZO
    • MLHZO
    • MLLZO
  • Arithmetic operations (use free form evaluations or corresponding built in function)
    • ADD
    • SUB
    • DIV
    • MULT
    • MVR
    • XFOOT (use %XFOOT)
  • Comparison (use free form comparisons)
    • COMP
    • IFxx
    • WHENxx
  • Flow control
    • DO
    • GOTO
  • Parameters (use procedure interface definitions and prototyped calls)
    • PARM
    • PLIST
  • Other
    • TESTB
    • TESTN
    • TESTZ
    • XLATE (use %XLATE)

Example

<source lang="rpg">

C                   if        PCFRS = '*ALL'                
C                   eval      #CFRSF = *BLANK               
C                   eval      #CFRSH = *BLANK               
C                   else                                    
C                   eval      #CFRSF = i_CF_Const(PCFRS)    
C                   eval      #CFRSH = #CFRSF               
C                   endif                                   
                                                           
 /free                                                      
  if (pMOLS = '*ALL');                                      
    eval #MOLSF = *blank;                                   
    eval #MOLSH = *blank;                                   
  else;                                                     
    eval #MOLSF = pMOLS;                                    
    eval #MOLSH = pMOLS;                                    
  endif;                                                    
 /end-free                                             
    
C     C#RTNS        IFNE      '*EXITPGM'
C     C#RTNS        ANDNE     '*RETURN'

</source >