Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORIF STATEMENT 3

Status
Not open for further replies.

rstitzel

MIS
Apr 24, 2002
286
0
0
US
I'm fairly new to RPG programming. I have a program that I've written in RPG Free. Below is a snippet of the code:

/FREE
READ RSALTR;
DOW NOT %EOF;
IF DELET <>'D';
IF ROUTE = ROUTENUM1;
OREQ ROUTE ROUTENUM2;
OREQ ROUTE ROUTENUM3;
CHAIN IDB RSBLCK;
RS1 = 0;
RS2 = 0;
RS3 = 0;
RS4 = 0;
RS5 = 0;
EXCEPT UPBLCK;
CHAIN IDB RSBLCK;

The problem I'm having is with the OREQ Statements. I know I've have the syntax incorrect. Could someone show me how I should modify the code above that If ROUTE = RouteNum1 or RouteNum2 or RouteNum3 then perform some calcs.

Hope that makes sense.

Thanks in advance for any and all help.
 
I believe the EOF needs the file parameter. haven't done much in the free formatting yet though. eg: %EOF(RSALTR);

_____________________________________________________________________
[sub]Where have all my friends gone to????[/sub]
onpnt2.gif

 
Try this instead, OREQ is not a valid RPG IV free form opcode.

Code:
/FREE                              
      READ RSALTR;                  
      DOW NOT %EOF;                 
      IF DELET <>'D';               
         IF ROUTE = ROUTENUM1 or Route = RouteNum2 or
              Route= RouteNum3;
           CHAIN IDB RSBLCK;          
           RS1 = 0;                   
           RS2 = 0;                   
           RS3 = 0;                   
           RS4 = 0;                   
           RS5 = 0;                   
           EXCEPT UPBLCK;             
           CHAIN IDB RSBLCK;

It's not necessary to say OREQ, just say 'or' as I've shown above, and it should work.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Thanx, and not a problem. What software are you using to edit your source code? (Websphere, Code/400, PDM, etc)?

RedMage1967
IBM Certifed - RPG IV Progammer
 
I use Code/400 to edit and PDM and I also use Lansa. I use CODE Designer to create my display files, physical files. Makes it so easy. Which is great because I was hired about a year ago to rewrite all the in house programs that are all written in RPG II. A great challenge :)

Thanks again for your help.

 
Check the help files in the Code/400 editor. They are usually a pretty good source of information. When in the editor, got to Help, RPG ILE, then either Operation Codes or Built in Functions. The reference and programming guide are also availble in html format from the help menu.

RedMage1967
IBM Certifed - RPG IV Progammer
 
onpnt

Specifing the file name with %EOF is optional. If no file name is specified, it defaults the most recent file that had an I/O operation. I always try to put the file name with the BIF %EoF.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Sounds like good practice to include the file name. How would that look like in free?
 
Like this, the change is in bold

Code:
/FREE                              
      READ RSALTR;                  
      DOW NOT %EOF[b](RsAltr)[/b];                 
      IF DELET <>'D';               
         IF ROUTE = ROUTENUM1 or Route = RouteNum2 or
              Route= RouteNum3;
           CHAIN IDB RSBLCK;          
           RS1 = 0;                   
           RS2 = 0;                   
           RS3 = 0;                   
           RS4 = 0;                   
           RS5 = 0;                   
           EXCEPT UPBLCK;             
           CHAIN IDB RSBLCK;

RedMage1967
IBM Certifed - RPG IV Progammer
 
Ignore previous post, got the edit TGML codes wrong, try this one intead, the change is in bold

Code:
/FREE                              
      READ RSALTR;                  
      DOW NOT %EOF[b](RsAltr)[/b];                 
      IF DELET <>'D';               
         IF ROUTE = ROUTENUM1 or Route = RouteNum2 or
              Route= RouteNum3;
           CHAIN IDB RSBLCK;          
           RS1 = 0;                   
           RS2 = 0;                   
           RS3 = 0;                   
           RS4 = 0;                   
           RS5 = 0;                   
           EXCEPT UPBLCK;             
           CHAIN IDB RSBLCK; 



[COLOR=red]RedMage[/color]1967
[COLOR=blue][b]IBM[/b][/color] Certifed - RPG IV Progammer
 
Give this a try...

/FREE
READ RSALTR;
DOW NOT %EOF(RSALTR);
IF DELET = 'D';
READ RSALTR;
ITER;
ENDIF;
IF ROUTE = ROUTENUM1 or
ROUTE = ROUTENUM2 or
ROUTE = ROUTENUM3;
CHAIN IDB RSBLCK;
CLEAR RS1;
CLEAR RS2;
CLEAR RS3;
CLEAR RS4;
CLEAR RS5;
EXCEPT UPBLCK;
ENDIF;
READ RSALTR;
ENDDO;


 
Thanks to both Bobtwigg and Redmage1967. I plan to make this a common practice. Thanks!
 
/Free is cool. I use it all the time now. I even convert complicated programs to /free to help simplify them a bit (the indenting helps). You can change from fixed to /free by using CODE.

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
iSeriesCodePoet

I like free form as well. All new development is being done in free form. The convert to free form cmd that comes with Code/400 works OK. It does some things that I personally don't like. Plus, if the opecode doesn't have a free-form equalivent (like MOVE), it leaves it as a fixed field 'C'. Also, it doesn't convert some other ops codes to BIF's, so I still spend time re-typing programs even after I've converted them. If you're interested, I found a work around to converting from Character to Numeric data type without using the MOVE opcode.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Most of the MOVE commands that I see the RPG II programmer used are usually just concatenating two fields. Taking a piece of one string and combining it with another. Is there a free-form command to concatenate? And yes I would be interested in your work-around.

Thanks again!
 
To concatenate two fields together, use the plus sign, like so:

Code:
Field = 'My' + ' ' + 'Program';

Field will be equal to &quot;My Program&quot;. Check out the EVALR, %TRIM, %TRIML and %TRIMR. Also check out %Scan and %Replace.

Move work around.

Define in you &quot;D&quot; specs, a data structure that has only one subfield in it. Define the subfield as a zoned data type with the correct size and decimal positions that you need. Then, strip out any non-numeric characters in the string you wish to convert ($, commas, periods, etc). Look below:

Code:
D Chardata      DS
D  Number              8S 2
D
D InChar              12    Inz('$12,000.20')
/Free

 ***Strip out the dollar sign, comma and period first, so 
InChar now equals &quot;1200020&quot;.  I use a subprocedure to do this.  

 CharData = InChar;
/End-Free

If your check the value of Number, it will equal 12000.02.


RedMage1967
IBM Certifed - RPG IV Progammer
 
Here's a better example of what I'm was trying to say with my previous post.

Code:
D ConvertDollar   PR             8S 2
D   InValue                     11    Value


/free

EvalR Current = ConvertDollar(%TrimR(%Subst(Mp2Fmt:8:11)));


/End-Free
P PrintStmts      E
//=========================================================/Eject
//=========================================================//  SUBPROCEDURE:  ConvertDollar
//       PURPOSE:  Convert character to dollar value
//
//  DATE          CHANGED BY          REASON
//
//=========================================================P ConvertDollar   B
//---------------------------------------------------------D ConvertDollar   PI             8S 2
D   CharValue                   11    Value
D
D NegativeAmt     S               N   Inz(*Off)
D CharDollar      Ds
D  DollarAmt                     8S 2
//---------------------------------------------------------/Free

 If %Scan('-':CharValue) > 0;
   NegativeAmt = *On;
   EvalR CharValue = %TrimR(%Replace('':CharValue:
                       %Scan('-':CharValue):1));
 Else;
   NegativeAmt = *Off;
 EndIf;
 DoW %Scan(',':CharValue) > 0;
   EvalR CharValue = %TrimR(%Replace('':CharValue:
                        %Scan(',':CharValue):1));
 EndDo;
 EvalR CharValue = %TrimR(%Replace('':CharValue:%Scan ('.':CharValue):1));
EvalR CharDollar = CharValue;
If NegativeAmt;
  DollarAmt = DollarAmt * -1;
EndIf;
Return DollarAmt;

/End-Free
//---------------------------------------------------------P ConvertDollar   E
//=========================================================

The above code snipet converts a character value that is retrieved from a converted spoolfile, so the value can be used in calcualtions.

RedMage1967
IBM Certifed - RPG IV Progammer
 
I am usually converting from numeric to character or vise versa or changing date formats. I have seen many examples, I just never remember them. Could you give a couple examples of that.

Actually, lets create a new thread for just this.

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top