ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

My first function -- call RPG program and returns working date

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

  • My first function -- call RPG program and returns working date

    Really liking BCD!

    PHP Code:
    //------------------------------------------------------//
    // START:  GetNextWorkDate                              //
    //------------------------------------------------------//

    function GetNextWorkDate($Direction$Days$InDateMMDDYY )
    {

    /************** Step 1: set up parameter list description *****************************/
    /* Create an array that specifies the name of      */
    /* the input, the IO being performed, the variable */
    /* type, and the variable name.                    */
    /* Array example:*/

        
    $description = array(
         array(
          
    "Name"=>"direction",
          
    "IO"=>I5_IN,
          
    "Type"=>I5_TYPE_CHAR,
          
    "Length"=>"1"
         
    ),
         
         array(
          
    "Name"=>"days",
          
    "IO"=>I5_IN,
          
    "Type"=>I5_TYPE_PACKED,
          
    "Length"=>"5.0"
         
    ),
             array(
          
    "Name"=>"indatemmddyy",
          
    "IO"=>I5_IN,
          
    "Type"=>I5_TYPE_CHAR,
          
    "Length"=>"6"
         
    ),
             array(
          
    "Name"=>"outdatemmddyy",
          
    "IO"=>I5_INOUT,
          
    "Type"=>I5_TYPE_CHAR,
          
    "Length"=>"6"
         
    )
        );



    /************** Step 2: prepare the program for calling *****************************/
    /* Assign $lib and $pgm_nm the corresponding       */
    /* library and program name:                       */   
    $lib "LBIOBJ";
    $pgm_name "MSC09";

    $libl xl_get_parameter("libl");
    xl_set_libl($libl);

    $pgm i5_program_prepare("$lib/$pgm_name"$description);

    // Check if any errors occurred.
    if (!$pgm)
    {
        die(
    "i5_program_prepare"); 
    }


    /************** Step 3: assign the parameter values to send **********/
    /* Create an array with the input names and the    */
    /* corresponding values                            */
    /* Array example:                                  */
     
        
    $parameter = array(
         
    "direction"=>$Direction,
         
    "days"=>$Days,
         
    "indatemmddyy"=>$InDateMMDDYY,
         
    "outdatemmddyy"=>""
        
    );


    /************** Step 4: the parameters that will be returned from the program **/
    /* Create an array with the output parameters      */
    /* returned by the program.                        */
    /* Array example:                                  */

        
    $parmOut = array(
         
    "direction"=>"direction",
         
    "days"=>"days",
         
    "indatemmddyy"=>"indatemmddyy",
         
    "outdatemmddyy"=>"outdatemmddyy"
        
    );



    /************** Step 5: Call the program. *****************/
    $ret i5_program_call($pgm$parameter$parmOut);

    // to work with the compatibility wrapper for IBM i Toolkit for PHP, 
    // we need to extract the output variables
    if (function_exists('i5_output')) 
    {
        
    extract(i5_output());
    }


    // Check if any errors occurred.
    if (!$ret)
    {
        die(
    "i5_program_call");
        exit();
    }


    // return array
    $OutDateMMDDYY $outdatemmddyy;
    return 
    $OutDateMMDDYY;

    // Close the program handle (unload from memory).
    i5_program_close($pgm);

    }



    //------------------------------------------------------//
    // END:  Determine Work Date                            //
    //------------------------------------------------------// 

    call using this
    PHP Code:
    require('/esdi/websmart/v9.2/include/xl_functions001.php');

    global 
    $conn$outdatemdy;
    $conn =  xl_i5_connect( );
    xl_set_libl("TEST");

    $Direction 'F';
    $Days 10;
    $InDateMDY date("mdy");


    $outdatemdy GetNextWorkDate($Direction$Days$InDateMDY );

    echo 
    " Test Date Back: " $outdatemdy

    calls this old Nasty thing
    PHP Code:
                       
          
    *                                                                                             
          * 
    INPUT PARAMETERS                                                                            
          
    *   Description        Type  Size    How Used                                                 
          
    *   -----------        ----  ----    --------                                                 
          *   
    Direction          Char  1       B Find number of business                              
          
    *                                        days back from today.                                
          *                                    
    Find number of business                              
          
    *                                        days forward from today.                             
          *   
    Number of Days     Dec   5,0     Number of business days to                               
          
    *                                    be determined.                                           
          *   
    Start Date         Char  6       Date to begin search.                                    
          *   
    Date found         Char  6       Date found that satisfies                                
          
    *                                    search criteria.                                         
          *   
    Validty Checking   Char  5       Input     1=Y       Saturday date is okay                
          
    *                                              2=Y       Sunday date is okay                  
          
    *                                              3=Y       Holiday date is okay                 
          
    *                                              4                                              
          
    *                                              5                                              
                                                                                                        
          
    *                                                                                             
         
    d IncomeValid     s              5                                                             
         d PmDate          s              8  0                                                          
         d PmDesc          s             10                                                             
         d PmEMsg          s             70                                                             
         d PmLLDays        s              3  0                                                          
         d PmULDays        s              3  0                                                          
         d PmValid         s              5                                                             
         d WorkValid       s              5                                                             
          
    *                                                                                             
         
    D                 DS                                                                           
         D  MMDDYY                 1      6  0                                                          
         D  MMDD                   1      4  0                                                          
         D  YY                     5      6  0                                                          
          
    *                                                                                             
         
    D                 DS                                                                           
         D  DATX                   1      7  0                                                          
         D  DATX6                  2      7  0                                                          
         D  CX                     1      1  0                                                          
         D  YYX                    2      3  0                                                          
         D  MMDDX                  4      7  0                                                          
         D  MMX                    4      5  0                                                          
         D  DDX                    6      7  0                                                          
          
    *                                                                                             
         
    C                   EXSR      HSKPG                                                            
          
    *                                                                                             
          * 
    FORMAT PASSED DATE TO CYMD                                                                  
         C     YY            IFLT      80                                                               
         C                   Z
    -ADD     1             CX                                                 
         C                   
    ELSE                                                                       
         
    C                   CLEAR                   CX                                                 
         C                   
    ENDIF                                                                      
          *                                                                                             
         
    C                   Z-ADD     YY            YYX                                                
         C                   Z
    -ADD     MMDD          MMDDX                                              
                                                                                                        
         C                   
    IF        (MMX 04 OR MMX 06 OR                                         
         
    C                              MMX 09 OR MMX 11) AND                                       
         
    C                              DDX 31                                                        
         C                   
    EVAL       DDX 30                                                        
         C                   
    ENDIF                                                                      
         
    C                   IF        MMX 02 AND                                                     
         
    C                             (DDX 30 OR DDX 31)                                           
         
    C                   EVAL      DDX 28                                                         
         C                   
    IF        YYX 08 OR YYX 12 OR YYX 16                                 
         C                   
    EVAL      DDX 29                                                         
         C                   
    ENDIF                                                                      
         
    C                   ENDIF                                                                      
          *                                                                                             
          * 
    CONVERT PASSED DATE TO DAYS                                                                 
         C                   CLEAR                   
    ##DDD                                              
         
    C                   Z-ADD     DATX          ##CYMD                                             
         
    C                   CALL      'CVDT_YMD'                                                       
         
    C                   PARM                    ##CYMD                                             
         
    C                   PARM                    ##DDD                                              
          
    *                                                                                             
          * 
    TEST CHANGE AS VALID BUSINESS DAY                                                           
          
    CANNOT BE WEEKEND OR HOLIDAY                                                                
          
    *                                                                                             
         
    C     NUMDYS        IFNE      *ZEROS                                                           
         C     DIR           IFEQ      
    'B'                                                              
         
    C                   SUB       1             ##DDD                                              
         
    C                   ELSE                                                                       
         
    C                   ADD       1             ##DDD                                              
         
    C                   ENDIF                                                                      
         
    C                   ENDIF                                                                      
          *                                                                                             
         
    C                   Eval      *in89 = *On                                                      
          
    *                                                                                             
         
    C     *IN89         DOWEQ     *ON                                                              
         C     COUNT         ORLT      NUMDYS                                                           
         C                   CLEAR                   
    ##CYMD                                             
         
    C                   CALL      'CVDT_DAY'                                                       
         
    C                   PARM                    ##DDD                                              
         
    C                   PARM                    ##CYMD                                             
          
    *                                                                                             
         
    C                   Z-ADD     ##CYMD        DATX                                               
         
    C                   Z-ADD     DATX6         PmDate                                             
          
    *                                                                                             
          * 
    call date verification pgm.                                                                 
         
    c                   call      'MSC25'                                                          
         
    c                   parm                    PmDate                                             
         c                   parm      
    -999          PmLLDays                                           
         c                   parm      999           PmULDays                                           
         c                   parm      
    'TEST'        PmDesc                                             
         c                   parm      WorkValid     PmValid                                            
         c                   parm                    PmEMsg                                             
          
    *                                                                                             
         
    C                   Eval      *in89 = *Off                                                     
         c                   
    If        PmEmsg <> *blanks                                                
         C                   
    Eval      *in89 = *On                                                      
         c                   
    endif                                                                      
          * 
    INCREMENT DAYS FOUND COUNTER IF VALID DATE FOUND                                            
         C     
    *IN89         IFEQ      *OFF                                                             
         C                   ADD       1             COUNT                                              
         C                   
    ENDIF                                                                      
          *                                                                                             
         
    C     DIR           IFEQ      'B'                                                              
         
    C                   SUB       1             ##DDD                                              
         
    C                   ELSE                                                                       
         
    C                   ADD       1             ##DDD                                              
         
    C                   ENDIF                                                                      
          *                                                                                             
         
    C                   ENDDO                                                                      
          
    *                                                                                             
          * 
    FORMAT RETURNED DATE FIELD                                                                  
         C                   MOVE      MMDDX         MMDD                                               
         C                   MOVE      YYX           YY                                                 
         C                   MOVE      MMDDYY        MDYRUN                                             
          
    *                                                                                             
         
    C                   MOVE      *ON           *INLR                                              
          
    *                                                                                             
          *****************************************************                                         
          * 
    PROGRAM INITIALIZATION SUBROUTINE                                                           
          
    *****************************************************                                         
          *                                                                                             
         
    C     HSKPG         BEGSR                                                                      
          
    *                                                                                             
          * 
    DEFINE PARM LISTS                                                                           
         C     
    *ENTRY        PLIST                                                                      
         C                   PARM                    DIR               1                                
         C                   PARM                    NUMDYS            5 0                              
         C                   PARM                    MDY               6                                
         C                   PARM                    MDYRUN            6                                
         c                   parm                    IncomeValid                                        
          
    *                                                                                             
         
    c                   if        %parms >= 5                                                      
         c                   
    eval      WorkValid IncomeValid                                          
         c                   
    else                                                                       
         
    c                   eval      WorkValid = *blanks                                              
         c                   
    endif                                                                      
          *                                                                                             
         
    C                   CLEAR                   MDYRUN                                             
         C                   MOVE      MDY           MMDDYY                                             
          
    *                                                                                             
          * 
    DEFINE WORK FIELDS                                                                          
         C                   Z
    -ADD     *ZEROS        ##CYMD            7 0                              
         
    C                   Z-ADD     *ZEROS        ##DDD             7 0                              
         
    C     *LIKE         DEFINE    NUMDYS        COUNT                                              
          
    *                                                                                             
         
    C                   ENDSR 
    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

  • #2
    Re: My first function -- call RPG program and returns working date

    Convert date MMDDYY to Isodate

    PHP Code:
    // set program call parameter 
      
    $Direction 'F';
      
    $Days 1;
      
    $InDateMDY date("mdy");

      
    // RPG program requires MMDDYY *char date entered and returns the same 
      
    $outdatemdy GetNextWorkDate($Direction$Days$InDateMDY );
      
    // strtotime -- likes these formats:y-m-d, Y-m-d, m/d/y and m/d/Y, but not m-d-Y or m-d-y.
      // so I slammed some '/' in 
      
    $playdate substr($outdatemdy,0,2) . '/' substr($outdatemdy,2,2) . '/' substr($outdatemdy,4,2) ; 
      
    $isodate  date('Ymd'strtotime($playdate)); 
      
      
    // views as: ==> Start date: 100812 Play date: 10/08/12 ISODate: 20121008 
      
    echo( 'Start date: ' $outdatemdy ' Play date: ' $playdate ' ISODate: ' $isodate ' <br>'); 
    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

    Comment


    • #3
      Re: My first function -- call RPG program and returns working date

      V5R4 - my bane ....
      Greg Craill: "Life's hard - Get a helmet !!"

      Comment


      • #4
        Re: My first function -- call RPG program and returns working date

        I am a user of BCD's WebSmart php. I have a iSeries V5R4. I have several php Programs that call RPG programs that work fine but I have a
        problem with calling a CLP program?

        Here is the CLP Program:


        Code:
        PGM      PARM(&JOB &USER &NBR)                      
                                                                        
                    DCL        VAR(&JOB) TYPE(*CHAR) LEN(10)            
                    DCL        VAR(&USER) TYPE(*CHAR) LEN(10)           
                    DCL        VAR(&NBR) TYPE(*CHAR) LEN(6)             
                                                                        
                    RTVJOBA    JOB(&JOB) USER(&USER) NBR(&NBR)          
                    ENDPGM

        Here is the php generic function:


        Code:
        function generic()
        {    
            session_destroy();
            // Make all global variables available here
            foreach($GLOBALS as $arraykey=>$arrayvalue) 
            {
                if ($arraykey != "GLOBALS")
                {
                    global $$arraykey;
                }
            }
            $lib = "JMALIB";
            /********** Step 1: set up parameter list description ************/
            /* Create an array that specifies the name of      */
            /* the input, the IO being performed, the variable */
            /* type, and the variable name.                    */
            $description = array(
            array(
            "Name"=>"JOB",
            "IO"=>I5_INOUT,
            "Type"=>I5_TYPE_CHAR,
            "Length"=>"10"
            ) ,
            array(
            "Name"=>"USER",
            "IO"=>I5_INOUT,
            "Type"=>I5_TYPE_CHAR,
            "Length"=>"10"
            ) ,
            array(
            "Name"=>"NBR",
            "IO"=>I5_INOUT,
            "Type"=>I5_TYPE_CHAR,
            "Length"=>"6"
            )      
            );
            
            $name = $lib . DS . "RTVJOBACL"; 
            /********** Step 2: prepare the program for calling **************/
            $pgm = i5_program_prepare($name, $description);
            
            // Check if any errors occurred.
            if (!$pgm)
            {    
                echo "<br>";
                print_r(i5_errormsg());
                
                die("i5_program_prepare");
            }
            
            /********** Step 3: assign the parameter values to send **********/
            /* Create an array with the input names and the    */
            /* corresponding values.  You need to supply the   */
            /* actual parm values.                             */
            $in_parameters = array(
            "JOB"=>"$JOB" ,
            "USER"=>"$USER" ,
            "NBR"=>"$NBR"      
            );
            
            
            /********** Step 4: the parameters that will be returned *********/
            /* Create an array with the output parameters      */
            /* returned by the program.                        */
            $out_parameters = array(
            "JOB"=>"JOB" ,
            "USER"=>"USER" ,
            "NBR"=>"NBR"      
            );
            /********** Step 5: Call the program. ***************************/
            $ret = i5_program_call($pgm, $in_parameters, $out_parameters);    
            // Check if any errors occurred.
            if (!$ret) 
            {
                $prgmsg = "Call to RTVJOBACL was not successful";
                $color="red";
                $anonotp = "";
                wrtseg(ClsSeg);
                die("i5_program_call");
            }
            wrtseg(MainSeg);
        }
        The browser has a blank page with not errors. When I comment out the:


        Code:
            $ret = i5_program_call($pgm, $in_parameters, $out_parameters);    
            // Check if any errors occurred.
            if (!$ret) 
            {
                $prgmsg = "Call to RTVJOBACL was not successful";
                $color="red";
                $anonotp = "";
                wrtseg(ClsSeg);
                die("i5_program_call");
            }
        it write the segment to the browser page just fine. I took it you use BCD and might know what is wrong?

        James
        jmartin@jmartinassociates.net
        Last edited by jmartin; February 22, 2013, 11:53 AM.

        Comment


        • #5
          Re: My first function -- call RPG program and returns working date

          Do you have debugging turned on?

          Look to these tables on IFS --
          debug:
          /usr/local/zendsvr/share/toolkitapi/


          ZEND LOG:
          /usr/local/zendsvr/var/log/php.log

          I will be more than happy to help, but I have found that BCD support is second to none.
          Where is it failing?


          BCD Technical Support at (250) 655-1766 between 7:30 AM and 5:00 PM, US Pacific Time
          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

          Comment


          • #6
            Re: My first function -- call RPG program and returns working date

            this works for me:
            PHP Code:

            // Generation time code inserted here



            //    Program Name:  test.php 
            //    Program Title:  test
            //    Created by:   jamie
            //    Template name:  A Simple Page.tpl
            //    Purpose:        
            //    Program Modifications:

            require('/esdi/websmart/v9.2/include/xl_functions001.php');

            global 
            $conn$outdatemdy;
            $conn =  xl_i5_connect( );
            xl_set_libl("LSA");
              
              
            // set program call parameter 
              
            $Direction 'F';
              
            $Days 1;
              
            $InDateMDY date("mdy");

              
            // RPG program requires MMDDYY *char date entered and returns the same 
              
            $outdatemdy GetNextWorkDate($Direction$Days$InDateMDY );
              
            // strtotime -- likes these formats:y-m-d, Y-m-d, m/d/y and m/d/Y, but not m-d-Y or m-d-y.
              // so I slammed some '/' in 
              
            $playdate substr($outdatemdy,0,2) . '/' substr($outdatemdy,2,2) . '/' substr($outdatemdy,4,2) ; 
              
            $isodate  date('Ymd'strtotime($playdate)); 
              
              
            // views as: ==> Start date: 100812 Play date: 10/08/12 ISODate: 20121008 
              
            echo( 'InDate : '$InDateMDY ' Start date: ' $outdatemdy ' Play date: ' $playdate ' ISODate: ' $isodate ' <br>');
              
                
                
            // write the record
                
            Write2Debug('Test (PGM): InDate : '$InDateMDY ' Start date: ' $outdatemdy ' Play date: ' $playdate ' ISODate: ' $isodate ' <br>');
                
              
              
                
            /********** Step 1: set up parameter list description ************/
                /* Create an array that specifies the name of      */
                /* the input, the IO being performed, the variable */
                /* type, and the variable name.                    */
                
            $description = array(
                  array(
                  
            "Name"=>"injob",
                  
            "IO"=>I5_INOUT,
                  
            "Type"=>I5_TYPE_CHAR,
                  
            "Length"=>"10"
                 
            ) ,
                     array(
                  
            "Name"=>"inuser",
                  
            "IO"=>I5_INOUT,
                  
            "Type"=>I5_TYPE_CHAR,
                  
            "Length"=>"10"
                 
            ) ,
                     array(
                  
            "Name"=>"innumber",
                  
            "IO"=>I5_INOUT,
                  
            "Type"=>I5_TYPE_CHAR,
                  
            "Length"=>"06"
                 
            )     
                );


                
            /********** Step 2: prepare the program for calling **************/
                
            $pgm i5_program_prepare("JAMIELIB/RTVJOBACL"$description);

                
            // Check if any errors occurred.
                
            if (!$pgm)
                {
                 die(
            "i5_program_prepare");
                }

                
            /********** Step 3: assign the parameter values to send **********/
                /* Create an array with the input names and the    */
                /* corresponding values.  You need to supply the   */
                /* actual parm values.                             */
                
            $in_parameters = array(
              
            "injob"=>"" ,
              
            "inuser"=>"" ,
              
            "innumber"=>""     
                
            );


                
            /********** Step 4: the parameters that will be returned *********/
                /* Create an array with the output parameters      */
                /* returned by the program.                        */
                
            $out_parameters = array(
              
            "injob"=>"injob" ,
              
            "inuser"=>"inuser" ,
              
            "innumber"=>"innumber"     
              
            );


                
            /********** Step 5: Call the program. ***************************/
                
            $ret i5_program_call($pgm$in_parameters$out_parameters);

                
            // Check if any errors occurred.
                
            if (!$ret
                {
                 die(
            "i5_program_call");
                }




            // returned parms
              
            echo( 'job : '$Injob ' User: ' $inuser ' Number: ' $innumber ' ISODate: ' $isodate ' <br>');
              


                
            // Close the program handle (unload from memory).
                
            i5_program_close($pgm);
                
            i5_close($conn); 
            Click image for larger version

Name:	Noname.jpg
Views:	1
Size:	108.0 KB
ID:	126621
            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

            Comment


            • #7
              Re: My first function -- call RPG program and returns working date

              jamief
              One of my clients called with a problem. Had to break away and take care of it.
              Will look into this later.

              I really appreciate the help.

              Maybe we can keep in touch.

              Have a great week end.

              James
              jmartin@jmartinassociates.net

              Comment


              • #8
                Re: My first function -- call RPG program and returns working date

                jamief

                I see you are on WebSmart php V9.2. I am on Version V8.9.

                I tried your test program with no luck. I am looking into the logs to see what I can find out.

                James
                jmartin@jmartinassociates.net
                Last edited by jmartin; March 14, 2013, 05:31 PM.

                Comment


                • #9
                  Re: My first function -- call RPG program and returns working date

                  Jim,
                  It's not the version... I just upgraded about 30 days ago.
                  This runs under 8.9
                  Did you strip out all the non essential code in my example?
                  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

                  Comment


                  • #10
                    Re: My first function -- call RPG program and returns working date

                    jamief,

                    Yes but I found how to make it work. I changed the CLP program to a CLLE program and it works fine.

                    James
                    jmartin@jmartinassociates.net

                    Comment


                    • #11
                      Re: My first function -- call RPG program and returns working date

                      jamief,

                      On a side note, I am using WebSmartV8.9 (standalone) version. It cost a lot less and will still run
                      php on iSeries. I have installed Zend Server CE on my iSeries 270 which runs In the IFS. I also
                      installed Zend Server CE version 5.6.0 on my windows 7 Pro running PHP Version 5.4.0 and MySQL
                      version 5.6 planning to install DB2 Express C version 10.1

                      James
                      jmartin@jmartinassociates.net

                      Comment

                      Working...
                      X