Remove hard coding AS/400 RPG

85 pts.
Hi, I have a program that will be used in different countries. Each country have different selection criteria. How do I design my program such that I do not hard code the selection criteria? Note: Selection criteria could be more than 1 fields or from more than 1 file.

Answer Wiki

Thanks. We'll let you know when a new response is added.


It’s a little bit hard to answer with this information…

You can store your selection criteria on :

– DB file with country code as key
– MSGF where prefix could be country code
– DtaAras
– User Spaces
(may I forgetting something?)

But then … I’m not sure how you proceed
– Use OPNQRYF to select records
– Use Dynamic SQL to select records

I’m thinking that you have 4 valid values when you say “A,B,C,D”
In RPGLE you might load the valid values into an array and

RejectRec = *on
* test case 1 Category
When %lookup(Category : CatArray) <> 0 and Category <> *blanks
RejectRec = *off
…. continue tests


If Not RejectRec
Perhaps something like this…

DBF – you can make single long fields for values like age
and place age repeatedly as a three character value in it or make seperate fields for each.

Country Code CTYCDE
rAge <– is it a range BEGAGE ENDAGE or multiple fields
AGE1, AGE2, AGE3 …

GoodAge = *off
when ageIn = *zero
GoodAge = *off
when ageIn = rAge1
GoodAge = *on
when ageIn = rAge2
GoodAge = *on


Discuss This Question: 6  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • JoBi
    Hi Wilson, Thanks for your reply. Can you give example on how to go about it. My biggest problem is how to proceed after I have defined from the DBF. For exampe, I need to select all records with category A,B,C,D. But I don't want to hardcode A,B,C,D from my program because other countries may use different category code. Then how do I define the selection from DBF if for example I have more than 1 selection criteria? Please help. Thanks.
    85 pointsBadges:
  • Sloopy
    As Wilson suggests, it's down to using files to store the information specific to the countries. So you would have a country file, and you would store the categories for each country in a country categories file, which would be keyed on country code - so your program load the category codes associated with the specific country, nad (as Phil suggests) you store those categories in an array and use it to look up the valid category code from the incoming data. If the incoming DB record has a country code that is not the one you are looking for, reject it anyway. If it has a category code that is not in the list you loaded, reject it. This is all quite usual programming in most databases. Sloopy
    2,195 pointsBadges:
  • JoBi
    Hi Everyone, Thanks for sharing your inputs. The suggestions given are for example 1 field out of (let say) 10 fields from 1 file. What if I have more than 1 fields to be selected? Or other selections from other files? Do I need to define the fields and the file from the BDF as well? For Example: File ABCD Field 1 = Age Field 2 = Type Field 3 = Salary Range etc. File EFGH Filed 1.2. = Officer Code Field 2 = Group etc. I'm reading file 1 and select age 15,16,17,18 and type 1,2,3,4. Read File 2 and select officer code xyz, abc, fgh. How to define in DBF? And how to process? Thansk.
    85 pointsBadges:
  • Sloopy
    I'm finding this a bit mysterious. Why would you have a program that is selecting a set of records from one file, and a set of records from another file which has no connection at all? As for the general case in which you have, for example, radically different processing requirements for data from different companies - usually this is done by checking the company first, and then calling programs specific to that country's requirements. Otherwise you end up with a huge program that is almost impossible to maintain. You see, once the requirements get beyond a certain level of complexity, it's a losing battle to keep ONE program to do so may different things. And then someone adds a new country, and the whole thing is just spaghetti.... Sloopy
    2,195 pointsBadges:
  • Rpgking
    JoBi, you seriously need to get some training or mentoring or complete your degree at IIT.
    20 pointsBadges:
  • philpl1jb
    Yes. I don't know where these people have been. You are spot on, you need a control file to contain the rules. The rule name becomes the first field of the key, country code the second, the value third . for some fields you might have a value2 so you can enter a range, then for some fields you will need a text all of these fields are character. So the AgeControl file Key Country Value Description AGE USA 19 AGE USA 20 AGE USA 21 AGE CAN 4 AGE CAN 8 OUTQ USA PRT05 OUTQ CAN PRT06 In the processing programs you can load these into arrays and do a lookup or you can chain into the control file or you can get the values from the file to do a dynamic sql.
    54,090 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: