× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Where's the RPG code in the IFS example? WAS: Having problems accessing IFS from RPGIV
  • From: Buck Calabro <buck.calabro@xxxxxxxxxxxxxxxxx>
  • Date: Thu, 13 Jan 2000 17:05:25 -0500

Booth,

One man's RPG is not the same as another's.  Take this for example:

     FTRACEL1 UP  E           K        DISK  
     ITOLLTAPE                                              
     I              TOLLTAPE                        TAPE  L1
     C  NL1                DELETTOLLTAPE 
This is a complete, useful program but there are more than a few people who
would not "get" this at a glance.  

How about having to look at code like this all day:
     C****************************************************************
     C* -AGAIN - READ THE PREVIOUS OR NEXT MASTER RECORD             *
     C****************************************************************
     CSR         AGAIN     BEGSR                                      
     C   08N61 16          READ ACIHST                   61           
     C   09N61 16          READPACIHST                   61           
     C   08N61 17          READ ACIHST08                 61           
     C   09N61 17          READPACIHST08                 61           
     C   08N61 18          READ ACIHST11                 61           
     C   09N61 18          READPACIHST11                 61           
     C   08N61 19          READ ACIHST10                 61           
     C   09N61 18          READPACIHST10                 61           
     C   61                SETOF                     60               
     C  N60                EXSR CLEAR                                 

Or this beauty:
     C           CLRYY     IFEQ REPYY                      
     C           CLRMM     COMP REPMM                    11
     C   11      CLRMM     COMP FROMM                    12
     C   11 12   CLRDD     SUB  REPDD     HOLD             
     C   11 12   HOLD      COMP 3                      1313
     C   11 12 13          ADD  1         LTFIVE           
     C                     END                             

The "c-like" example is pretty cryptic too, but don't blame RPG IV - the
above examples of RPG III fit into that category as well.  Consider how it
would look with a few comments and "wrapping" the nasty code in a procedure.
Notice that the mainline code here is exactly one line long.  In a "normal"
RPG IV program, I'd hide all these D specs in a /COPY member; they're
included here so you can see a compilable code snippet.

 * dftactgrp(*no) actgrp(qile) dbgview(*source) bnddir(qc2le)
                                                             
D OpenFile        pr                                         
D  FilePath                    255    const                  
D  Error                              like(ErrorCode)        
                                                             
 * File open                                                 
Dopen             pr            10i 0 extproc('open')        
D                                 *   value                  
D                               10i 0 value                  
D                               10u 0 value options(*nopass) 
D                               10u 0 value options(*nopass) 
                                                             
 * Report errors                                             
 *   #include <errno.h>                                      
 *                                                           
 *   int * __errno(void);                                    
 *                                                           
 *                                                           
D errnoF          PR              *   Extproc('__errno')     

 ******************************************************************
D ErrorCode       S             10I 0 inz                          

C                   Callp     OpenFile('/QOpenSys/x.txt':ErrorCode)
C                   Seton                                        LR
                                                                   
 ******************************************************************
P OpenFile        B                                                
D OpenFile        pi                                               
D  FilePath                    255    const                        
D  Error                              like(ErrorCode)              
                                                                   
D FileHandle      s             10i 0                              
D oflag           s             10u 0 inz(0)                       
D o_rdonly        s             10i 0 inz(1)                       
D o_textdata      s             10i 0 inz(16777216)                
D FileWork        s                   like(FilePath)               
D errnoP          S               *                                
D errno           S                   BASED(errnoP) like(ErrorCode)
                                                                   
 * Because you can't set %addr against a CONST field,              
 * make a copy of the CONST field and use THAT address...           
C                   eval      FileWork=FilePath                     
                                                                    
 * Open file in text mode, read only                                
C                   eval      oflag=o_rdonly + o_textdata           
C                   Eval      FileHandle=open(%addr(FileWork):oflag)
                                                                    
 * Call the "what error occurred" function                          
C                   EVAL      errnoP = errnoF                       
                                                                    
 * Tell the calling function what error (if any) occurred           
C                   Eval      Error=errno                           
                                                                    
P OpenFile        E                                                 

Here, all the "grunt work" is done inside the OpenFile procedure.  The
mainline code has no idea whether you are opening a standard DB2 external
file, an IFS file or a socket.  Rather than coding the procedure as a
"function" (which returns a value like "open" does), I wrote OpenFile to
return it's error code as a parameter - just like old-style RPG.  It's
really a matter of preference more than anything else.

By the way, you can't call these "c" functions from RPG III as far as I
know.  You can only do this in an ILE language.

Buck Calabro
Aptis; Albany, NY

> -----Original Message-----
> From: boothm@earth.goddard.edu 
> Sent: Thursday, January 13, 2000 12:39 PM
> To:   RPG400-L@midrange.com
> Subject:      Re: Having problems accessing IFS from RPGIV
> 
> I know, I know, we gotta keep up, we can't be old-fashioned, we gotta get 
> with the program...  but gee whizzzzz... 
> 
> where's there any RPG at all in this mystifying piece of RPGized-C++ code?
> 
>  I'd bet that there are not 5 out of 100 qualified RPG programmers that 
> can even begin to understand what is happening here.
> 
> If someone asked me to do the same function in real RPG code I would be 
> absolutely stuck. 
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.