ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Free Format RPG - Call program

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

  • Free Format RPG - Call program

    Hello,

    Can you call a program in free format RPG. I see a number of examples in free format RPG using called procedures(CALLP) but no actual calls with Parms. I looked at my RPG book and they end the free format and call the program with the parms using the C specs.

    Thanks,

    DAC

  • #2
    Re: Free Format RPG - Call program

    PHP Code:
         f@AD       cf   e             WORKSTN
          
    *
          * 
    Override for display
          
    *


          *
          * 
    Variable Definition
          
    *
         
    @scrn1          s              1    inz('Y')
         
    d CmdLength       s             15  5 inz(0)
         
    d CmdString       s            256    inz(*blanks)
         
    d dqlength        s              5  0
         d startstamp      s               z
         d TheData         s             80


           
    //
           //  external calls
           //

         
    d $command        pr                  extpgm('QCMDEXC')
         
    d   command                   5000    options(*varsize)
         
    d   Length                      15  5

         d $receiveDQ      pr                  extpgm
    ('QRCVDTAQ')
         
    d   dtaq                        10    const
         
    d   dtaqLib                     10    const
         
    d   maxlength                    5  0
         d   data                        80
         d   wait                         5  0 
    const

          /
    Free

            
    //--------------------------------------------------------
            // MAIN PROGRAM
            //--------------------------------------------------------
                 
    dow @scrn1 'Y';

                 
    s1time = %time();

                 
    write(ewindow1;

                 
    dqlength = %size(TheData);
                 
    $receiveDQ ('AUTODQ'  :
                             
    'QTEMP'   :
                             
    dqlength  :
                             
    thedata   :
                             
    1
                                       
    );

                   if 
    dqlength > *zeros;
                     
    read(ewindow1;
                   endif;


                   if *
    in03;
                     
    clear @scrn1;
                   endif;


                 
    enddo;



                 if %
    open(@AD);
                   
    close @AD;
                 endif;

                
    // delete the display file override

                 
    monitor;
                 
    cmdstring 'DLTOVR @AD';
                 
    cmdlength = %len(%trim(cmdstring));
                 
    $command (cmdstring:cmdlength);
                 
    on-error;
                 
    endmon;


                
    // delete the dataq

                 
    monitor;
                 
    cmdstring 'DLTDTAQ QTEMP/AUTODQ';
                 
    cmdlength = %len(%trim(cmdstring));
                 
    $command (cmdstring:cmdlength);
                 
    on-error;
                 
    endmon;


                 *
    inlr = *on;
            
    //--------------------------------------------------------
            // *inzsr - initial one time run subroutine
            //--------------------------------------------------------

                 
    begsr *inzsr;

                
    // delete the dataq

                 
    monitor;
                 
    cmdstring 'DLTDTAQ QTEMP/AUTODQ';
                 
    cmdlength = %len(%trim(cmdstring));
                 
    $command (cmdstring:cmdlength);
                 
    on-error;
                 
    endmon;

                
    // create the dataq

                 
    monitor;
                 
    cmdstring 'CRTDTAQ DTAQ(QTEMP/AUTODQ) MAXLEN(80)';
                 
    cmdlength = %len(%trim(cmdstring));
                 
    $command (cmdstring:cmdlength);
                 
    on-error;
                 
    endmon;


                 
    cmdstring 'OVRDSPF FILE(@AD) TOFILE(@AD) ' +
                             
    'DTAQ(QTEMP/AUTODQ) ';
                 
    cmdlength = %len(%trim(cmdstring));
                 
    $command (cmdstring:cmdlength);

                 if 
    not%open(@AD);
                   
    open @AD;
                 endif;


                 
    endsr;
          /
    End-Free 
    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: Free Format RPG - Call program

      I know they developed free format RPG in 1995 but I can't believe they forgot to include the call function with parms. Unbelievable! This is one question I am going to ask IBM when I am at Common next spring.

      Thanks,

      DAC

      Comment


      • #4
        Re: Free Format RPG - Call program

        I guess you just get used to it........
        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


        • #5
          Re: Free Format RPG - Call program

          I don't understand your example. If I am calling a selection program with a 4 character Parm. Would I put the called program into a string with the parm and call it with $command (cmdstring:cmdlength); cmdstring = program and cmdlength = parm?

          DAC

          Comment


          • #6
            Re: Free Format RPG - Call program

            If I had this code that I am trying to convert to free format:
            // Select Agency Code
            C Call 'AGCYSELR'
            C Parm AgcySel

            DAC

            Comment


            • #7
              Re: Free Format RPG - Call program

              PHP Code:
               *                                                          
               * 
              Variable Definition                                      
               
              *                                                          
              D Agency          s              4                          
                
              //                                                        
                //  external calls                                        
                //                                                        
                                                                          
              d $selecter       pr                  extpgm('AGCYSELR')    
              d   AgencyX                      4                         
                                                                          
                                                                          
               
              /Free                                                      
                    $selecter 
              (Agency);                                   
                    *
              inlr = *on;                                          
               /
              End-Free 
              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


              • #8
                Re: Free Format RPG - Call program

                dcutaia,

                The free-form that came out in 1995 was a third party product requiring a pre-compiler. IBM's only had it a couple of years.

                The reason there is no Call/Parm is because IBM expects you will use the procedure interface and call the pgm using a BIF like jaime is doing.

                BTW: If you are using lpex editor, you have a one-click option to convert your pgm to free-form. It's not gonna fix stuff like this, but it does do 85% of the work for you.

                Comment


                • #9
                  Re: Free Format RPG - Call program

                  Code:
                         // Select Agency Code
                       C                    Call      'AGCYSELR'
                       C                    Parm      AgcySel

                  Code:
                       D SelAgcyCde      pr                  ExtPgm('AGCYSELR')         
                       D  Parm1                              like(AgcySel)             
                        /Free
                  
                          // Select Agency Code
                          Callp SelAgcyCde(AgcySel);
                    
                        /End-free
                  "Time passes, but sometimes it beats the <crap> out of you as it goes."

                  Comment

                  Working...
                  X