Topic
18 replies Latest Post - ‏2011-01-13T09:32:01Z by Prithiviraj
Prithiviraj
Prithiviraj
60 Posts
ACCEPTED ANSWER

Pinned topic Soft Coded ILE procedures : is it Possible??

‏2011-01-04T13:39:25Z |
Experts,

I would like to do something like the below snippet. I know for fact that %Paddr only accepts a Prototype name as paramter. But is there a way to achieve the following ?

H DFTACTGRP(*NO)
D ProcA PR Extproc(Proc_ptr)
D *
D 1A
D ProcB PR Extproc(Proc_ptr)
D *
D 1A
D Dummy PR Extproc(Proc_ptr)
D *
D 1A

D Proc_ptr S * ProcPtr
D Data_Ptr S *
D Huge_Parm S 1000A
D Error S 1A
D Proc_Array S 25A Dim(2)
D Proc_Name S 25A
D I S 5I 0
/Free
*Inlr = *On;
Proc_Array(1) = 'ProcA';
Proc_Array(2) = 'ProcB';

For I = 1 to 2;
Proc_name = Proc_Array(I);
Proc_ptr = %PAddr(Proc_name);
Data_ptr = %Addr(Huge_Parm);
Dummy(Data_Ptr:Error);
EndFor;
/End-Free
Updated on 2011-01-13T09:32:01Z at 2011-01-13T09:32:01Z by Prithiviraj
  • Prithiviraj
    Prithiviraj
    60 Posts
    ACCEPTED ANSWER

    Re: Soft Coded ILE procedures : is it Possible??

    ‏2011-01-04T13:42:17Z  in response to Prithiviraj
    
    H DFTACTGRP(*NO) D ProcA           PR                  Extproc(Proc_ptr) D                                 * D                                1A D ProcB           PR                  Extproc(Proc_ptr) D                                 * D                                1A D Dummy           PR                  Extproc(Proc_ptr) D                                 * D                                1A D Proc_ptr        S               *   ProcPtr D Data_Ptr        S               * D Huge_Parm       S           1000A D Error           S              1A D Proc_Array      S             25A   Dim(2) D Proc_Name       S             25A D I               S              5I 0 /Free *Inlr = *On; Proc_Array(1) = 
    'ProcA'; Proc_Array(2) = 
    'ProcB'; For I = 1 to 2; Proc_name  = Proc_Array(I); Proc_ptr   = %PAddr(Proc_name); Data_ptr   = %Addr(Huge_Parm); Dummy(Data_Ptr:Error); EndFor; /End-Free
    
  • Rick_C
    Rick_C
    13 Posts
    ACCEPTED ANSWER

    Re: Soft Coded ILE procedures : is it Possible??

    ‏2011-01-04T14:34:05Z  in response to Prithiviraj
    Take a look at some of the program API's like QBNLSPGM and QleGetExp. We use these in a service program to call a list of procedures defined in a database table.

    The service program is activated using _RSLVSP2 and QleActBndPgm. The procedure pointers are then retrieved from the service program and placed into an array with the associated procedure name.

    When a record is read from the table the procedure name is located in the array and the associated procedure called via the pointer.

    We used a standard pre-defined parm list instead of a pointer as in your message.

    HTH,

    Rick
  • JonParis
    JonParis
    110 Posts
    ACCEPTED ANSWER

    Re: Soft Coded ILE procedures : is it Possible??

    ‏2011-01-04T19:28:08Z  in response to Prithiviraj
    "I would like to do something like the below snippet. I know for fact that %Paddr only accepts a Prototype name as parameter."

    Well your "fact" is wrong. You can use either the name of a prototype or the literal string name of the procedure. What you cannot do is to place the name of a procedure in a variable and resolve it with %PAddr. As has been noted you can use APIs to dynamically resolve procedure pointers in Service Programs - I have found I can usually get the flexibility I need without doing that - see this article for an example. http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/18392p1.aspx - the basic design was for a customer who needed database drive calculation sequences but the principal is generic.
  • scott_klement
    scott_klement
    241 Posts
    ACCEPTED ANSWER

    Re: Soft Coded ILE procedures : is it Possible??

    ‏2011-01-04T19:37:25Z  in response to Prithiviraj
    > Prithiviraj wrote:
    > I would like to do something like the below snippet. I know for fact that %Paddr only
    > accepts a Prototype name as paramter. But is there a way to achieve the following ?

    Something like this should work:

    
    H DFTACTGRP(*NO) D Dummy           PR                  Extproc(Proc_ptr) D * D                                1A D Proc_ptr        S               *   ProcPtr D Data_Ptr        S               * D Huge_Parm       S           1000A D Error           S              1A D Proc_Array      S               *   procptr Dim(2) D Proc_Name       S             25A D I               S              5I 0 /Free *Inlr = *On; Proc_Array(1) = %paddr(
    'PROCA'); Proc_Array(2) = %paddr(
    'PROCB'); For I = 1 to 2; Proc_name  = Proc_Array(I); Data_ptr   = %Addr(Huge_Parm); Dummy(Data_Ptr:Error); EndFor; /End-Free
    


    When the parameter to %paddr() has quotes, such as %paddr('PROCA') it's looking for an ILE procedure export with that name (and is case sensitive). When it doesn't have quotes, such as %paddr(ProcA) it's looking for a prototype name instead of an ILE procedure export... in which case you have to have a matching PR.

    Let's call that "solution #1".

    But, because you didn't explain what you're trying to do, I don't really know if that answers your question. You told us how you're trying to do it (and posted code that can't work) rather than telling us what you need to accomplish. That leaves it wide open to different interpretations.

    Another approach would be to use the QleGetExp() API. Unlike %paddr(), you can use a variable for QleGetExp()'s parameters, so you can find a procedure name at run-time instead of at compile-time. That's solution #2.

    You could extend the QleGetExp() approach to use _RSLVSP (or RSLVSP2, RSLVSP4, et al) to locate the *srvpgm at run-time, and load it into memory with QleActBndPgm (as Rick describes). Then you'd make a completely "unbound" call to the service program. (Solution #3) I posted an example of that, here:
    Link: http://forums.systeminetwork.com/isnetforums/showpost.php?p=594291&postcount=22

    You could also use the QZRUCLSP API to make an "unbound call" to a service program procedure... solution #4. It has parameter limitations, though... but is a lot easier than RSLVSP/QleActBndPgm/QleGetExp approach, especially if the parameters vary from call to call.

    You could also call the procedure via SQL's stored procedure or UDF interface. This is easily modifyable at run-time with dynamic SQL statements, so you could call different procedures that way. (Solution #5.)

    Or maybe you just need to wrap an RPG SELECT/WHEN group in a subprocedure. (Solution #6)

    Or, you can activate a *PGM object, and that *PGM object can pass procedure pointers back to you so you can subsequently call it's procedures... solution #7. This doesn't let you choose the procedure name at run-time, but it does let select the program object name at run-time -- so if it's a group of procedures that's always related, this is a simple and powerful approach.

    That's already 7 possibilities, and I could keep going.

    The truth is, which tool you use depends on what you want to accomplish. And since I don't know that, I could spend all day writing up possibilities and posting them. Please, in the future, describe what you want to accomplish, instead of showing us the way you want to accomplish something.
    • Bob Genis
      Bob Genis
      6 Posts
      ACCEPTED ANSWER

      Re: Soft Coded ILE procedures : is it Possible??

      ‏2011-01-05T18:54:20Z  in response to scott_klement
      Scott,

      Very interesting tidbit about how %paddr('X') is working. But I'm a little confused about the code you posted. How does Dummy's pointer get set to the procptr stored in Proc_Array? Wouldn't we need the line below?

      
      H DFTACTGRP(*NO) D Dummy           PR                  Extproc(Proc_ptr) D                                 * D                                1A D Proc_ptr        S               *   ProcPtr D Data_Ptr        S               * D Huge_Parm       S           1000A D Error           S              1A D Proc_Array      S               *   procptr Dim(2) D Proc_Name       S             25A D I               S              5I 0 /Free *Inlr = *On; Proc_Array(1) = %paddr(
      'PROCA'); Proc_Array(2) = %paddr(
      'PROCB'); For I = 1 to 2; Proc_name  = Proc_Array(I); Proc_ptr = Proc_Array(I);   
      // <<--- need this line?? Data_ptr   = %Addr(Huge_Parm); Dummy(Data_Ptr:Error); EndFor; /End-Free
      
      • scott_klement
        scott_klement
        241 Posts
        ACCEPTED ANSWER

        Re: Soft Coded ILE procedures : is it Possible??

        ‏2011-01-05T19:15:50Z  in response to Bob Genis
        Sorry, Bob... made a typo.

        (Remember... this is really just an illustration. It's not a real program I can compile or test, so I have no "safety net" if I a make a "duh" mistake.)
        Remove this line from the code I posted, as it makes no sense:

        
        Proc_name  = Proc_Array(I);
        


        Replace it with this line:

        
        Proc_ptr   = Proc_Array(I);
        
        • Prithiviraj
          Prithiviraj
          60 Posts
          ACCEPTED ANSWER

          Re: Soft Coded ILE procedures : is it Possible??

          ‏2011-01-07T14:37:19Z  in response to scott_klement
          Thanks Rick, Scott for the answers.

          I apologize for not giving the actual requirements. But as Rick pointed out in his post, I would like to have a table driven business logic execution as a part of my Quasi-MvC architecture, I will be having a layout like the one below and read/call procedures dynamically. They will share one common parameter signature. I am doing this because my product has to customizable. We can think of the license type *CUSTOM as some code the end user wants to run.

          Where Mod ID Refers to a UI (Green / Web)
          Trn ID Refers to a user action

          
          Mode Id Trn Id  Seq   Proc Type       Proc Name     License type 001  001     1       VLD     Proc 1          *BASE 001       001     2       VLD     Proc 2          *BASE 001       001     3       VLD     Proc 3          *BASE 001       001     4       VLD     Proc 3          *CUSTOM 001     001     5       ADD     Proc 4          *BASE
          


          Looks like i have to know the service program name also in this table.
          But we have a H-spec copy book and our system has only one BNDDIR with all SRVPGM inside it coded inside. This copy book is included in every program that runs in our system. So even if one program runs all the SRVPGMs will be loaded in memory, so no need for QleActBndPgm and i can directly use
          QleGetExp.
          1.) Is my assumption correct ? It works for me but though !!
          2.) One disadvantage i see is everything **thing** has to be externalized even a 2 line code if qualifies as a business logic and can be reused.Any inputs on how to finalize the granularity of these procedures ??
          • scott_klement
            scott_klement
            241 Posts
            ACCEPTED ANSWER

            Re: Soft Coded ILE procedures : is it Possible??

            ‏2011-01-07T21:44:57Z  in response to Prithiviraj
            Hello,

            > Looks like i have to know the service program name also in this table.
            > But we have a H-spec copy book and our system has only one BNDDIR with all SRVPGM
            > inside it coded inside.

            A binding directory is only used during the binding step. I.e. when you run the CRTPGM, CRTSRVPGM or CRTBNDxxx command. It's not used at run-time. Indeed, if you develop your code on a separate system from the one you run it on, the binding directory would probably only be necessary on the development machine. (Unless, for some reason, you re-bind your programs on the production system?)

            So... I guess I don't understand what a binding directory has to do with this discussion. You are trying to bypass the binding step!
            > This copy book is included in every program that runs in our system. So even
            > if one program runs all the SRVPGMs will be loaded in memory, so no need for
            > QleActBndPgm and i can directly use QleGetExp.

            That's not how binding directories work!

            A binding directory is a "search list". When a program calls a subprocedure, the system has to find the *SRVPGM that contains that subprocedure! So it searches the binding directory until it finds the subprocedure.

            It only binds (loads) the *SRVPGMs that it needs. Not all of them!

            If you soft-code your procedures (put them in a PF, apparently...) the system won't search the BNDDIR for them, and it therefore won't load those *SRVPGMs into memory. So you will still need to call QleActBndPgm to load them. (Unless you're using them for something else!)

            > 1.) Is my assumption correct ? It works for me but though !!

            Not sure which assumption you're referring to, here.
            > 2.) One disadvantage i see is everything **thing** has to be externalized even
            > a 2 line code if qualifies as a business logic and can be reused.Any inputs on
            > how to finalize the granularity of these procedures ??

            I'm not sure that I follow that.

            Obviously, anything you want to call would have to be externalized... but... you'll still have routines that only used internally, within a module, that shouldn't be exported... so... not sure what you're saying, here.
            The table you posted... I understand that it's a list of procedures that should be called in sequence... but I don't understand why someone would want to have a table like that. What value does it offer? It's essentially a very simple program, isn't it? So why not write it as a program, instead of writing it as data?
            • Rick_C
              Rick_C
              13 Posts
              ACCEPTED ANSWER

              Re: Soft Coded ILE procedures : is it Possible??

              ‏2011-01-10T14:18:51Z  in response to scott_klement
              Scott,

              >The table you posted... I understand that it's a list of procedures that should >be called in sequence... but I don't understand why someone would want to have >a table like that. What value does it offer? It's essentially a very simple >program, isn't it? So why not write it as a program, instead of writing it as >data?

              In our case the business logic changes periodically. Our change process is very involved. Business approval, project committee approval, placed onto the project list, business requirements written, technical requirements written, development, QA testing, user acceptance testing, implementation. All for a fairly small logic change. Placing the pieces of the process into a table allows us to make the same changes at the table level without all of the overhead. It still has to be requested by the business and the changes still get tested. The response time to the request though is light years faster than the old method.

              With the older set of code even minor changes would involve a large amount of regression testing due to the intertwining of logic between processes. We also separated the logic while reusing common pieces which eliminated regression testing for all practical purposes. We only regression test now if a change is made to one of the logic procedures. Rearranging the order doesn't trigger regression testing.

              IN short, better response to business needs with less time and resourced involved.

              Note: I would not recommend this as a solution for everything. It fit a need for our business.

              Rick
          • Rick_C
            Rick_C
            13 Posts
            ACCEPTED ANSWER

            Re: Soft Coded ILE procedures : is it Possible??

            ‏2011-01-10T14:07:13Z  in response to Prithiviraj
            As Scott pointed out you will still need to activate the service program at run time. Your 'driver' program won't know which procedures it needs when it starts so no service programs will be started.

            Yes, you will have to create procedures for everything. No matter how small. That can be a bit frustrating when it takes more lines of code to define the procedure than to perform the actual logic. If you want the flexibility of dynamically ordering the processing logic though it's a requirement.

            A couple of tips that may or may not apply to your situation.
            1) Create a constructor procedure to hold your startup logic for the service program and have it called from every procedure if it hasn't already been called. You never know where the entry point will be so if something has to happen before every procedure is called be sure to handle getting it called. We use a global indicator to determine if the constructor has already been run or not.

            2) Look into CEE4RAGE for handling normal shutdown of your service program when the activation group ends. This ensures an orderly cleanup of your service program because you won't know when it ends unless a shutdown call is made to a 'destructor' type procedure.

            I have also become a big fan of the ILE condition handler API's. I use them to catch unexpected errors, capture program information like dumps and screen shots, and notify the programming group of the error. This is part of our standard program/module template now.

            Hope this helps.

            Good luck with the project.

            Rick
  • Prithiviraj
    Prithiviraj
    60 Posts
    ACCEPTED ANSWER

    Re: Soft Coded ILE procedures : is it Possible??

    ‏2011-01-08T15:55:39Z  in response to Prithiviraj
    "The table you posted... I understand that it's a list of procedures that should be called in sequence... but I don't understand why someone would want to have a table like that. What value does it offer? It's essentially a very simple program, isn't it? So why not write it as a program, instead of writing it as data?"

    As i said before I am planning to write a flavor of a MvC architecture. In our shop we have 2 sets of business logics one for Green Screen and another set only to support Web. Every code change is a maintenance night mare as it has to be done and 2 places or more. And practically we couldn't come up with a way to maintain a X-ref for which green screen program is the equivalent for which web program, we tried a spreadsheet which became outdated and hard to update in no time.

    So i decided to have a unified logic to support any Application End point, be it a Green Screen, Web Screen, Thick Client, Web Service or any other possible invocation.

    The typical layout looks like one below:
    Green Screen

    ---> E DS based flat data ---> One Generic Business Rule Orchestrator ----> One Generic Data Access Object
    (Table Driven Procedure calls) (Table Driven SQL based Data Access, QSQPRCED And/Or plain Old dynamic SQL)
    Web Screen
    • The Question and Table i posted is for the Generic Business Rule Orchestrator****
    =================================================

    1. ) I wanted to represent each screen/view of our application with a Unique Module Id/ Transaction Id as depicted in the previous post.
    2.) Each Screen packs user inputted screen data in a predetermined E DS format and sends to the Generic Business Rule Orchestrator
    3.) Generic Business Rule Orchestrator
    A. Manipulates the data
    B. Calls the Business logic procedures soft coded in a table
    C. Returns error to the caller in case needed
    D Returns results/result sets in case needed
    E. In turn calls Data access object with a Query ID to run and give results for it
    5.) All procedures soft coded are reusable business components which are reusable across the applications
    6.) I would like to keep the orchestrator light weighted and business changes will only impact one or more procedures.
    7.) There could be a least a 1000 screens each of them will go into this table as Module/Transaction with the required business logic procedure sequence.
    8.) Customers of this application wants provision to customize the business rules if so they want can add one procedure to this table at a appropriate sequence for the appropriate Mod/Trn
    This is my thought. Your Inputs, comments ??
    • Prithiviraj
      Prithiviraj
      60 Posts
      ACCEPTED ANSWER

      Re: Soft Coded ILE procedures : is it Possible??

      ‏2011-01-08T15:57:51Z  in response to Prithiviraj
      Sorry the layout was messed up

      {Code}

      Green Screen
      ---> E DS based flat data ---> One Generic Business Rule Orchestrator ----> One Generic Data Access Object
      (Table Driven Procedure calls) ( Table Driven SQL based Data Access, QSQPRCED And/Or plain Old dynamic SQL)
      Web Screen

      {Code}
      • Prithiviraj
        Prithiviraj
        60 Posts
        ACCEPTED ANSWER

        Re: Soft Coded ILE procedures : is it Possible??

        ‏2011-01-08T16:02:32Z  in response to Prithiviraj
        Sorry dont know why the markups didnt work this time..!

        Green Screen / Web Screen ---> E DS based flat data ---> One Generic Business Rule Orchestrator ----> One Generic Data Access Object
        One Generic Business Rule Orchestrator - (Table Driven Procedure calls)
        One Generic Data Access Object - (Table Driven SQL Query based Data Access, QSQPRCED for SELECTs as it can cache them in a SQL Package for performance and
        plain Old dynamic SQL for DELETE, UPDATE, INSERT )
    • scott_klement
      scott_klement
      241 Posts
      ACCEPTED ANSWER

      Re: Soft Coded ILE procedures : is it Possible??

      ‏2011-01-10T22:20:23Z  in response to Prithiviraj
      @Prithiviraj:

      If I understand you correctly, the main reason you want to soft-code all of the procedure calls is to ensure that your x-ref is up-to-date? In other words, if the routines are called because the program read the routine names from a file, then that file must be up-to-date.

      This isn't really an MVC architecture. In MVC, you have a controller routine (the C in MVC stands for "Controller") That routine is what determines which routines to call. So what you're doing is not MVC at all, because you're looking to soft-code the control logic -- no controller, but rather a soft-coded set of instructions.

      Please be advised that the controller from a web-based application is usually very different from that of a green-screen app. Therefore, you may need separate code in your file for the web-based vs. green-screen programs. (Which is probably not a big deal, but I thought I'd point it out, anyway...)

      Anyway... have you got all the answers you'll need with regard to how to implement this?
      • Prithiviraj
        Prithiviraj
        60 Posts
        ACCEPTED ANSWER

        Re: Soft Coded ILE procedures : is it Possible??

        ‏2011-01-12T09:33:48Z  in response to scott_klement
        Scott,

        --> The main reason I want to orcehstrate business logic thru a table driven approach is the same reason as pointed out by Rick.

        1.) Change becomes inexpensive and fast.
        2.) Testing smaller units is easy and fast.



        --> I agree this is not a True MvC (I have always mentioned as Quasi-MvC or a flavour of MvC becuase I havent baptised the methodology that i am using)


        --> If am not wrong In traditional MvC a controller is tight coupled with a screen or view. So in iSeries world typically one UI will have 3 programs or 2 programs if we can club controller logic with view as you have demonstrated.

        One small drawback i saw with your MvC idea is

        1.) Ours is a iSeries based product that I have to package , ship and get installed. The customers base is pretty large and each one is at different version level, The idea of having one Model or Business logic sub-proceudre for Green Screen programs and having a wrapper procedure (For converting the DIM DS to MODS and setting a result set.) and Creating Stored procedure around wrapper procedure is wonderful but makes too many procedures for me to create during install as i cant ship the Stored proceudre objects and restore unlike the stored procedures written in SEQUEL.

        2.) In my case I can have a One Generic Stored procedure around the Orchestrator. So during install/upgrade time I have to run only One CREATE PROCEUDRE statement even doing it manually doesnt hurt.



        Thanks I got most of the answers.

        One Stumbling block that I am trying to workout is how to soft coded a Externally Described DS as opposed to pre-compiling it in a program.Because even though orcehstrator can be generic i have to pre-compile each of the Screen layout as an E DS which is a pain.

        A wishful thinking would be why not ETNAME keyword take a variable as parameter

        
        D fileName      S            10A D Dummy      E DS                EXTNAME(fileName)
        
        • scott_klement
          scott_klement
          241 Posts
          ACCEPTED ANSWER

          Re: Soft Coded ILE procedures : is it Possible??

          ‏2011-01-12T19:15:07Z  in response to Prithiviraj
          > --> The main reason I want to orcehstrate business logic thru a table driven approach is the same reason as pointed out by Rick.
          >
          > 1.) Change becomes inexpensive and fast.
          > 2.) Testing smaller units is easy and fast.

          ...but this is also true when it's not table-driven!

          The idea of writing small, reusable code, and testing each routine independently has been used and praised heavily for the past 30+ years, in all languages and on all platforms. How many of them are using a table-driven approach? (I don't know of any.)

          That's not to say that your idea doesn't have merit. Nothing wrong with being an innovator! I just don't understand how putting it in a table improves the situation.
          >
          > A wishful thinking would be why not EXTNAME keyword take a variable as parameter
          >

          How would the compiler know how big to make the data structure? How would it know which subfields to put in the data structure? When you're writing the rest of your code, and you want to set a subfield in the DS, or get data from a subfield in the DS, what would you code?

          The whole idea doesn't make sense to me. The EXTNAME needs to be known at compile-time because the RPG compiler has to generate variables for all of the fields in the record. If it doesn't know the name of the file at compile-time, how could the rest of the code possibly use that data structure?
          • Prithiviraj
            Prithiviraj
            60 Posts
            ACCEPTED ANSWER

            Re: Soft Coded ILE procedures : is it Possible??

            ‏2011-01-13T09:32:01Z  in response to scott_klement
            --> Absolutely yes Small, resuable programs/procedures are existing and it serves the purpose. But see below

            Traditional World:

            We need to write individual programs for orcehstrating each and every business flow. These programs can be a combination of reusable logic and localized
            logics.

            Order Processing Pgm
            Reusable proc 1
            Reusable proc 2
            Reusable proc 6
            Reusable proc 7
            Reusable proc 8
            Local Proc 1

            Staging & Shipping Pgm
            Reusable proc 9
            Reusable proc 1
            Reusable proc 6
            Reusable proc 3
            Reusable proc 100
            Local Proc

            Table Driven world:

            In this world both Order Processing and Staging/Shipping Control are 2 different business flows.

            A Single carefully written piece with good exception handling and logging abilitites using a table driven approach can handle any business flow !!

            _This exactly the BPEL4WS does in a Web service based SOA world !!.
            web services are business logics orchestrated using a BPEL ( a flavour of XML ). I want the closest in iSeries world thats all._
            --> Totally agree Scott, I was just trying convey that ability to build DS on the fly based on file structures would be a nice feature to have. didnt say that extname with variables is the solution.

            Do you have any inputs on building DS on the fly ??
        • SystemAdmin
          SystemAdmin
          535 Posts
          ACCEPTED ANSWER

          Re: Soft Coded ILE procedures : is it Possible??

          ‏2011-01-13T08:07:05Z  in response to Prithiviraj
          The package RNG Input Providers ( http://www.rpgnextgen.com/index.php?content=input ) uses "soft coded ile procedures". Perhaps you can get some ideas from that one. If you need an example on how to use the package just drop me a mail ( mihael at rpgnextgen dot com ). API documentation can be found at http://iledocs.sourceforge.net/docs/ .