ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

External procedure & testing program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • External procedure & testing program

    In the end this will be a procedure that takes in two parms:
    • order number decimal 7,0
    • order line number decimal 3,0 (I will call counter)


    chain to the order detail file find the order/counter
    then write some information from this table into another
    table. If an error occurs then set on the procedure
    error indicator and end.

    The start of the code (enough to compile)
    OEHPRT
    PHP Code:
    ~

         
    h nomain expropts(*resdecpos)
          *=============================================================
          * 
    Program OEHPRT
          
    Purpose - return error flag after writting OEHPRINT records
          
    *           using pro#  &  counter.

          
    Written March 21st 2007
          
    Author  Jamie Flanary

          
    Program Description
          
    *   This program will return error flag after writting
          
    *   OEHPRINT records using pro#  &  counter.

          
    *   The OEHPRT_CP copy member should be used by programs that
          
    *   call this procedure to obtain the procedure prototype fields.
          *
          *    
    InPronumber             Dec  7  0   Input
          
    *    InCounter               Dec  3  0   Input
          
    *    Outerror                Char 1      Input/OutPut
          
    *
          * 
    Indicator Usage
          
    *   None
          
    *=============================================================

            
          * 
    This copy book is in my source file just for testing
          
    I would recommend creating a seperate source file for 
          * 
    your procedures and copy booksMaybe QPRCSRC  


          
    /COPY SOURCE,OEHPRT_CP


          
    ****************************************************************
          * 
    Standalone Field Definitions                                 *
          ****************************************************************

          * 
    Program message parameters

         d errorind        s               n

          
    Beginning of procedure

         P OEHPRT          B                   EXPORT

          
    Procedure interface

         
    d OEHPRT          PI              n
         d  InProNumber                   7  0 VALUE
         d  InCounter                     3  0 VALUE

          
    /free

               
    //--------------------------------------------------------
               // MAIN PROGRAM
               //--------------------------------------------------------

                    
    exsr  Hskpg;

                    return 
    errorind;

               
    //--------------------------------------------
               // Hskpg - one time run subroutine
               //--------------------------------------------
                    
    begsr Hskpg;



                    
    endsr;

               
    //--------------------------------------------

          
    /end-free

          
    Endding of procedure
         P OEHPRT          E 
    Now the copy book..
    (makes it easier for other program to call - Ill show you later)

    OEHPRT_CP
    PHP Code:
    ~

          * 
    OEHPRT_CP Copy Member for procedure to write record to OEHPRINT

         D oehprt          PR              n
         D  InProNumber                   7  0 VALUE
         D  InCounter                     3  0 VALUE 

    Create the module

    PHP Code:
    CRTRPGMOD MODULE(JAMIELIB/OEHPRTSRCFILE(JAMIELIB/SOURCE
    How do I know if this is working


    Write a test program and call it.
    Compile it like this: (Then debug)
    PHP Code:
    CRTRPGMOD MODULE(JAMIELIB/OEHPRTTSTSRCFILE(JAMIELIB/SOURCE

    Then:
    crtpgm jamielib/oehprttst module(oehprttst oehprt
    OEHPRTTST
    PHP Code:
    ~
          * 
    Program message parameters

         d OutCounter      s              7  0
         d OutProNumber    s              3  0
         d WriteError      s               n

          
    /COPY SOURCE,OEHPRT_CP

          
    /free

               
    //--------------------------------------------------------
               // MAIN PROGRAM
               //--------------------------------------------------------

               // Test the procedure if error then dont continue with code


                    
    if OEHPRT(OutProNumber OuTCounter) = *Off;
                     
    // . . . . . . do more processing
                    
    else;
                     
    writeerror = *on;
                    endif;

                    *
    inlr = *on;

          /
    end-free 
    I know .. Now your asking STILL How do I know this worked....
    well lets change program OEHPRT to test this.

    PHP Code:
    ~

         
    h nomain expropts(*resdecpos)
          *=============================================================
          * 
    Program OEHPRT
          
    Purpose - return error flag after writting OEHPRINT records
          
    *           using pro#  &  counter.

          
    Written March 21st 2007
          
    Author  Jamie Flanary

          
    Program Description
          
    *   This program will return error flag after writting
          
    *   OEHPRINT records using pro#  &  counter.

          
    *   The OEHPRT_CP copy member should be used by programs that
          
    *   call this procedure to obtain the procedure prototype fields.
          *
          *    
    InPronumber             Dec  7  0   Input
          
    *    InCounter               Dec  3  0   Input
          
    *    Outerror                Char 1      Input/OutPut
          
    *
          * 
    Indicator Usage
          
    *   None
          
    *=============================================================

            
          * 
    This copy book is in my source file just for testing
          
    I would recommend creating a seperate source file for 
          * 
    your procedures and copy booksMaybe QPRCSRC  


          
    /COPY SOURCE,OEHPRT_CP


          
    ****************************************************************
          * 
    Standalone Field Definitions                                 *
          ****************************************************************

          * 
    Program message parameters

         d errorind        s               n

          
    Beginning of procedure

         P OEHPRT          B                   EXPORT

          
    Procedure interface

         
    d OEHPRT          PI              n
         d  InProNumber                   7  0 VALUE
         d  InCounter                     3  0 VALUE

          
    /free

               
    //--------------------------------------------------------
               // MAIN PROGRAM
               //--------------------------------------------------------

                    
    exsr  Hskpg;
                    
    errorind = *on;
                    return 
    errorind;

               
    //--------------------------------------------
               // Hskpg - one time run subroutine
               //--------------------------------------------
                    
    begsr Hskpg;



                    
    endsr;

               
    //--------------------------------------------

          
    /end-free

          
    Endding of procedure
         P OEHPRT          E 
    Now place in debug and you will see that the indicator in the calling program
    will be set *on
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com
Working...
X