× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



The routine I am creating will be used by serveral ILE programs. Most of the subprocs I've created dont return lists of information. I am trying to figure which technique would be best for this.

There are 3 techniques:

1) Break it into multiple functions. Have an _open() function that starts the list that you're returning, A _read() function that returns one element, and a _close() function at the end. For example:

      ORDER_open(12345);

      dow (ORDER_read(12345: LineItem) = SUCCESS);

        // perform code that operates on one item of
        // the list returned from the srvpgm

      enddo;

      ORDER_close();

2) Return an array.  For example:

     D ORDER_DETAIL    DS                  qualified
     D                                     based(template)
     D   ItemNo                       5P 0
     D   Desc                        25A
     D   Price                        7P 2

     D Order_load      PR             1N
     D   OrderNo                      5P 0 value
     D   Array                             likeds(ORDER_DETAIL)
     D                                     dim(32767)
     D                                     options(*varsize)
     D   Max                         10I 0 value

Order_Load would load only as many elements into the array as the "Max" parameter specified. That way, you don't require the caller to always define all 32k elements. He can declare 100 if he likes, like this:

     D myArray         S                   likeds(ORDER_DETAIL)
     D                                     dim(100)

      /free
          Order_Load(12345: MyArray: %elem(MyArray));

In that case, it's really important that the service program never try to access data beyond the 100th element of the array.


3) Use a callback. This is where you specify a subprocedure in your program that the service program should call for each elemnt of the list. For example:


     D Order_load      PR             1N
     D   OrderNo                      5P 0 value
     D   Callback                      *   procptr value

     P Order_Load      B                   export
     D Order_load      PI             1N
     D   OrderNo                      5P 0 value
     D   Callback                      *   procptr value

     D doCallback      PR                  ExtProc(Callback)
     D   ItemNo                       5P 0 const
     D   Desc                        25A   const
     D   Price                        7P 2 const

      /free

          setll OrderNo ORDDETAIL;
          reade OrderNo ORDDETAIL;

          dow not %eof(ORDDETAIL);
             doCallback( odItem
                       : odDesc
                       : odPrice );
             reade OrderNo ORDDETAIL;
          enddo;

          return SUCCESS;;

      /end-free

I've used all three different methods, and depending on what I'm doing I like to use different things. So, just consider it food for thought...


would call a program and pass back arrays with the information I need. Now with subproc, its appears to be a little different. Thats why I was asking about pointers and arrays. I've seen some API code that used pointers to pass back large amounts of info. If you have a suggestion that doesnt use pointers or arrays, I would love to hear it.

None of my examples used pointers (which I think is better). Only example 2 used an array. The others always work with only one element at a time, which is much more efficient on memory consumption. You don't NEED to define one big huge spot in memory.


But, of course, when you need to sort the data, you're probably going to want to have it all in memory, anyway -- so I use the array techniques for those.

The other two techniques are basically unlimited in the amount of data that they can return.

Anyway... food for thought.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.