+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: subprocedures and the LIKE keyword

  1. #1
    Guest.Visitor Guest

    Default subprocedures and the LIKE keyword

    You could code an external DS in the D-Spec that references the file to pull in the field definitions. Then use BASED(NoMemoryBlahBlah) so the DS defintion doesn't actually take up any memory. Then your LIKE should work. Opening and closing files is definitely a performance bottleneck. Don't open and close files unless you really need to. If Not(%Open(MYFILE)); Open MYFILE; EndIf; If your activation group keeps getting destroyed after each call, then the file may very well get closed for you between calls - not desireable. Use an AG of *CALLER if possible, but not *NEW. Chris

  2. #2
    Guest.Visitor Guest

    Default subprocedures and the LIKE keyword

    You could code a D spec like this: D dsPolMst E DS ExtName(PolMst) D Prefix(P_) This will go get the record definition for this file POLMST and load it with the P_ prefix. As far as opening and closing the file in the subprocedure, could you put this sub-proc in a service program, open it (say, every morning, and leave it open until sometime later?). I would try that. Hope this helps.

  3. #3
    K.Forsythe Guest

    Default subprocedures and the LIKE keyword

    The other suggestions are great, I would add that a Named activation group might be a good choice for this sort of service program, so that it would be loaded once and remain loaded until the user signed off or reclaimed it.

  4. #4

    Default subprocedures and the LIKE keyword

    Chris Ringer wrote: > > You could code an external DS in the D-Spec that references the file to pull in the field definitions. Then use BASED(NoMemoryBlahBlah) so the DS defintion doesn't actually take up any memory. Then your LIKE should work. > It would be a good idea to put this E-DS definition in the same /copy file as the prototype. And use PREFIX or QUALIFIED, to avoid name conflicts.

  5. #5
    K.Forsythe Guest

    Default subprocedures and the LIKE keyword

    Rather than making the Copy book file specific as discussed earlier. If you have a reference file that contains all the field definitions for your application, simply code one externally described data structure that pulls in all the definitions for your app, and then use the prefix as Barbara suggested to avoid conflicts. Also use the BASED keyword to avoid allocating memory for this large data structure. This simple statement can be included in every module you write, making LIKE statements universally available throughout your app.

  6. Default subprocedures and the LIKE keyword

    What is the recommended method of passing these data structures back to the called program ? As the return value like the code below ? Or, by using BASED and using a pointer ?
    Code

  7. Default subprocedures and the LIKE keyword

    What is the recommended method of passing these data structures back to the called program ? As the return value like the code below ? Or, by using BASED and using a pointer ?
    Code

  8. #8
    K.Forsythe Guest

    Default subprocedures and the LIKE keyword

    In general it will not make much difference. Parameters are usually passed by reference (meaning that its the pointer to the data structure that gets passed - not the data), which means that either way you code it the basic result is the same. The address of the data structure is passed. As long as both procedures involved have the same definition for the data structure it will make little difference. Using the pointer method does allow for a couple enhancements: 1) By using the BASED keyword, one of the procedures does not allocate memory for the variable, saving some amount of memory. 2) If both procedures do not know the exact length of the data being passed, then a null terminated string could be used with the pointer to handle that situation. In my opinion those are fairly minor reasons to use that technique, so if you prefer the more traditional non-pointer logic, that should be fine, and may be less intimidating to your pointer challenged colleagues. Have fun with it, Kevin

  9. Default subprocedures and the LIKE keyword

    I am using an external data structure to get all of the fields from the field reference files ( which is rather large ) to make the fields universally available. I have a /COPY member for this so I can use independently of my procedure prototype and application specific fields. Are all of the fields from the field reference external DS getting memory allocated in every module if I don't use the BASED keyword ?

  10. #10
    Guest.Visitor Guest

    Default subprocedures and the LIKE keyword

    We have a file containing a code field, its description plus a couple of other associated fields that is used in just about every program we write (for anybody in the know, it's the JBA file INP15). It seemed like an ideal candidate for a subprocedure that would return the description to any report or enquiry program that used the subprocedure in an Eval statement. Unfortunately, removing the file from any of these programs now causes certain instances of the Like keyword to fail becase the field referenced is no longer available for the Like to get its details from. I could hard code the lengths of those fields, but that removes all of the advantages gained by using Like. How has anybody else coded themselves out of a situation like this? A second point is that in the subprocedure I have to open and close the file manually which is reasonably easy to do, but what effect does this have on performance as the file is continually opened and closed?

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Subprocedures and Debug
    By Guest.Visitor in forum RPG
    Replies: 7
    Last Post: 08-08-2007, 06:25 AM
  2. Organizing Subprocedures
    By Guest.Visitor in forum RPG
    Replies: 1
    Last Post: 10-21-2003, 10:43 AM
  3. MCH3601 and Subprocedures.
    By Guest.Visitor in forum Programming
    Replies: 2
    Last Post: 12-20-2000, 07:04 AM
  4. SubProcedures & DFTACTGRP(*YES)
    By Guest.Visitor in forum Programming
    Replies: 6
    Last Post: 11-30-2000, 05:26 AM
  5. Procedures or subprocedures?
    By T.Holt in forum Programming
    Replies: 1
    Last Post: 12-14-1998, 08:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts