ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Calling a program using /FREE

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

  • Calling a program using /FREE

    Hi all. I am trying to learn /FREE, but i have a roadblock:

    In most of our programs, we call a program that emulates a window and shows stuff from an iseries table. The code is like this:

    Code:
         C                   MOVE      '00114'       PARM1             5
         C                   MOVE      *BLANKS       PARM2            15
         C                   MOVE      *BLANKS       PARM3            50
         C                   CALL      'UTPD12'
         C                   PARM                    PARM1
         C                   PARM                    PARM2
         C                   PARM                    PARM3
         C                   MOVE      PARM2         CODPAR
         C                   MOVEL     PARM3         DESPAR
         C                   ELSE
         C                   MOVE      *BLANKS       ACTIAR
         C                   MOVE      *BLANKS       ACARGU
         C                   Z-ADD     114           ACTIAR
         C                   MOVE      CODPAR        ACARGU
    1    C     KEYTAB        CHAIN     CTRALTAB                           13
         C  N13              MOVEL     ACFUNC        DESPAR
         C   13              MOVE      *BLANKS       CODPAR
    Fine, MOVE isn't supported, i can work around that, but i can't call the program UTPD12 from free, i get an error. I have read that for every program, i must declare a prototype or something, but really don't understand how to do so.

    Could someone explain me, how can i call a program with parameters and without parameters from /free? I just wanted to do something like:

    Code:
    parm1=114;
    parm2=*BLANKS;
    parm3=*BLANKS;
    call utpd12(parm1:parm2:parm3);
    codpar=parm2;
    despar=parm3;
    Thanks in advance.

  • #2
    Re: Calling a program using /FREE

    Here's a short example of how you might prototype the QCMDEXC API.

    You prototype in the D specs. This API has two parms, cmd and len.
    PHP Code:
    D ExcCmd          pr                  EXTPGM('QCMDEXC')
    D   Cmd                       3000A   OPTIONS(*VARSIZE)
    D                                     CONST
    D   Len                         15P 5 CONST 

    D gCmd            s           3000A 
    And here's how I might call this API in my /free C specs
    PHP Code:
    // Make gCmd = to the CL command you wish to call
    gCmd 'CHKOBJ OBJ(TEST) OBJTYPE(*LIB)';
    CallP(eExcCmd(gCmd:%len(%trim(gCmd))); 
    Ben

    Comment


    • #3
      Re: Calling a program using /FREE

      Thanks for your answer, i tried that to my understanding but i can't make it work:

      Here's what i did:

      Code:
      D MIPROGRAMA      PR                  ExtPgm('UTPD12')
      D   TABLA                        6
      D   ACTIAR                      15
      D   ACFUNC                      50
      I am using websphere btw. I dont get a problem in the D spec, but when actually calling the program:

      Code:
            /FREE
                 CALLP MIPROGRAMA('00114':*BLANKS:*BLANKS);
                 *INLR=*ON;
            /END-FREE
      I have tried with and without CALLP. I must be declaring the D spec with some errors. How does the D spec recognize when i finish declaring the parameters to the procedure?

      What's that parameter E you are using in your callP statement?

      Thanks in advance

      Comment


      • #4
        Re: Calling a program using /FREE

        I had to put CONST everytime in the parameters in the D spec and now it works. I don't understand why...

        The UTPD12 program works by reading a table with the first parameter, and returns a number and a text in the second and third parameters.

        Thanks for your help

        Comment


        • #5
          Re: Calling a program using /FREE

          I should have elaborated on this before.

          This is very old code, and calling programs with parameters are used to look up something in a table, and return something in the same parameters used to make the call.

          Now with /FREE i don't know how to return the values since i am not really declaring variables to store them, and even if i did, i wouldn't know how to retrieve the results from the program.

          Is there a way to do this without using a subprocedure or changing the original utpd12 program?

          Comment


          • #6
            Re: Calling a program using /FREE

            Well the only way i could come up with is to declare the variables in the D specs that get modified in the UTPD12 program. In the old method, i could declare PARM1 PARM2 and PARM3 just as i were calling the program, which is better because i didn't need to do it in the D spec, but at least it works now.

            Comment


            • #7
              Re: Calling a program using /FREE

              The (e) is for error - if their is an error in the call (any error)
              then the program will not explode.....it just moves on...

              you must put code in to trap error

              if %error

              <then panic>

              endif


              You need to put const on the D spec parms so that you can pass literals.

              you dont need a callP
              MIPROGRAMA('00114':*BLANKS:*BLANKS);
              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: Calling a program using /FREE

                Yeah i figured that already, but haven't read on that previously Thanks

                Now i only need to find out if there is a way that the prototype is able to return values instead of needing to declare separate variables in the d specs.

                Comment


                • #9
                  Re: Calling a program using /FREE

                  This is what i do;
                  PHP Code:
                  D CheckRecursive  PR                  ExtPgm('DEV8072'
                  D                               10                      
                  D                                1                      
                    
                  //----------------------------------------------------
                  D PCRProgram      S             10                      
                  D PCRError        S              1 
                  Then in code;
                  PHP Code:
                  PCRProgram 'INV892';                                             
                  PCRError   ' ';                                                  
                  CheckRecursive PCRProgram :                                      
                                   
                  PCRError   );                                     
                                                                                     
                  If 
                  PCRError 'N';                                                 
                      
                  PItemInq Df_Item;                                            
                      
                  ItemInquiry(PItemInq);                                         
                      
                  QM_msgtxt ' ';                                               
                      
                  ExSr @WrtMsg;                                                  
                  Else;                                                              
                      
                  QM_msgtxt ' You came from the Item Inquiry, cant go there.'
                      %
                  SubSt(Qm_MsgTxt:01:01) = X'3B';                               
                      %
                  SubSt(Qm_MsgTxt:46:01) = X'22';                               
                      
                  ExSr @WrtMsg;                                                  
                  EndIf; 
                  HTH
                  Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

                  Comment


                  • #10
                    Re: Calling a program using /FREE

                    Yeah, that's the method i am using , thanks.

                    Comment

                    Working...
                    X