RPG Next Gen
Wiki RSS Feed Weblog
Business picture

Parameter Evaluation

This module makes the processing of a multi user selection easier by passing the selection as one integer parameter which is the sum of all made selections.

Compressing Selection

Most people are familiar with this concept when it comes to unix / linux / IFS file permissions. Each permission has its own number.

  • 1 - Execute
  • 2 - Write
  • 4 - Read

Now all, some or no permissions can be put — compressed to — one value. For example:

  • 0 - no permissions
  • 5 - read and execute permissions
  • 7 - all (read, write and execute) permissions
# create file touch /tmp/my_file.txt # set permissions: # 7 = all for owner # 5 = read/execute for group # 5 = read/execute for other chmod 755 /tmp/my_file.txt

So far so good, but how does this makes life easier?

As far as we have come now in this article it makes life more complicated. But it will get much more easier as we proceed.

Passing multiple selections

The i5/OS API Retrieve Job Information can be used to retrieve the library list of the job. The library list is divided in various sections: System, Product, Current, User. If a procedure should return all or only some parts of the library list then multiple selections may be passed to that procedure. These selections could be coded as constants.

Such a procedure call would look like this:

D SYSTEM_LIBS... D C 1 D PRODUCT_LIBS... D C 2 D CURRENT_LIB... D C 4 D USER_LIBS... D C 8 /free ... listJobLibraryList(qualified_job_name : SYSTEM_LIBS + USER_LIBS); ... /end-free

Much easier to read and understand.

Selection Evaluation

Now that procedure has to know what part of the library list the calling program wants to have retrieved. A data structure with the possible selections is created with an overlay alpha field.

DlistSections... D DS qualified D system N D product N D current N D user N D allSections 4A overlay(listSections)

With the procedure evalParm the data structure gets filled with the following call:

/free ... // userSelection contains the value SYSTEM + USER = 9 // evalParm returns : '1001' listSections.allSections = evalParm(userSelection); ... /end-free

Keep in mind that the constants (and parameter for the evalParm procedure) value must be a number of the power of 2 (1, 2, 4, 8, 16, 32, 64, ...).

See the examples section for an example of using the evalParm procedure.