qrpg.test

          * "F" (file) specs define files and other i/o devices
         F ARMstF1   IF   E       K     Disk    Rename(ARMST:RARMST)

          * "D" (data) specs are used to define variables
         D pCusNo          S              6p
         D pName           S             30a
         D pAddr1          S             30a

          * The "chain" command is used for random access of a keyed file
         C     pCusNo        chain     ARMstF1

          * If a record is found, move fields from the file into parameters
         C                   if        %found
         C                   eval      pName  = ARNm01
         C                   eval      pAddr1 = ARAd01
         C                   eval      pAddr2 = ARAd02
         C                   eval      pCity  = ARCy01
         C                   endif

          * RPG makes use of switches.  One switch "LR" originally stood for "last record"
          * LR flags the program and its dataspace as removable from memory

         C                   eval      *InLR = *On

          * "F" (file) specs define files and other i/o devices
         FARMstF1   IF   E        K     Disk    Rename(ARMST:RARMST)

          * "D" (data) specs are used to define variables and parameters
          * The "prototype" for the program is in a separate file
          * allowing other programs to call it
          /copy cust_pr
          * The "procedure interface" describes the *ENTRY parameters
         D getCustInf      PI
         D  pCusNo                        6p 0   const
         D  pName                        30a
         D  pAddr1                       30a
         D  pAddr2                       30a
         D  pCity                        25a
         D  pState                        2a
         D  pZip                         10a
          /free
            // The "chain" command is used for random access of a keyed file
            chain pCusNo ARMstF1;

            // If a record is found, move fields from the file into parameters
            if %found;
               pName  = ARNm01;
               pAddr1 = ARAd01;
               pAddr2 = ARAd02;
               pCity  = ARCy01;
               pState = ARSt01;
               pZip   = ARZp15;
            endif;

          // RPG makes use of switches.  One switch "LR" originally stood for "last record"
          // LR actually flags the program and its dataspace as removable from memory.
            *InLR = *On;
          /end-free

         H main(GetCustInf)
         D ARMSTF1       E DS
         P GetCustInf      B
         D GetCustInf      PI                  extpgm('CUS001')
         D  inCusNo                            like(arCNum) const
         D  outName                            like(arName)
         D  outAddr1                           like(arAdd1)
         D  outAddr2                           like(arAdd2)
         D  outCity                            like(arCity)
         D  outState                           like(arStte)
         D  outZip                             like(arZip)
          /free
           exec sql select arName, arAdd1, arAdd2, arCity, arStte, arZip
                    into  :outName, :outAddr1, :outAddr2, :outCity, :outState,
                          :outZip
                    from   ARMSTF1
                    where  arCNum = :inCusNo
                    fetch first 1 row only
                    with CS
                    use currently committed;
          /end-free
         P GetCustInf      E