|
Rich I do this in RPG/400 from time to time. At the start of the program in the "E" specifications I define the Table or Array. It may be a TABLE that you want as opposed to an Array, even though an RPG Table functions similarly to what other langugages call an Array. The "E" specifications for a pair of tables let's say call them TABHLD for the 2 position legacy hold code and TABMHS for the 2 position hold code. When you are in the RPG program you can start the E line then F4 to be prompted to fill in the appropriate fields like is this alpha or numeric. Within the "C" specifications, the command is LOKUP Field 1 has the value you want to look up in the TABHLD "array" Field 2 has TABHLD (which table are you looking up, in a program that could have several. Field 3 has TABMHS name - sounds a bit redundant, but it works. You also have some indicator, like 90 in the = field This means "Find me the element in TABMHS that corresponds to this value I am looking up in the TABHLD" and indicator 90 goes *ON if there is a match. If 90 is in fact on, I move TABMHS contents (the one element) to some other work field, because what is in TABMHS is going to change every time I do another LOKUP. At the very end of the program is a line ** (two asterisks) meaning start of next table or array defined by the program then the data for the table or array. I like to do it in vertical column of HLD then MHS data for program readability but sometimes on small ones I do it on one line like an array called PER ** Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec which corresponds to periods (months of year) so that when I output Per,MM where MM is the current calendar month, the whole thing looks nice. The coding is a little different if your table or array is going to be populated as a result of reading some data into the program, or being the results of calculations, but same kind of format ... LOKUP is used to look up one HLD info so as to get at the corresponding entry in the MHS and when it really is an RPG array as opposed to matching tables, you use NAME (of array) comma ELEMENT (of array) to address individual elements. You can use LOKUP with an array in which if you are successful finding what you looking for, the ELEMENT is populated with whatever the address is. If you have a numeric array the XFOOT command can sum all elements into a grand total. Hope I have been helpful. I wrote this reply then did not send it right away & saw some more posts. There are many alternatives. One problem I have with reading stuff into an array when program is executing is I never know how big to make the array ... whatever I do, reality will change & it won't be big enough, so I am not too keen on that kind of architecture. With embedded SQL in RPG we can access the file that has the two codes, even if the file is not indexed (of course if you have a logical view over the HLD, you can CHAIN or other RPG access to matching HLD to get the corresponding MHS) ... at the time that we have one of the needed values, access to get just the matching field value. That makes sense to me if the program execution is not going to need access to all the values. Depending on how the data is flowing into a set of arrays in a program, there may be value in SORTA = sorting array so the data is sequenced before using it. In this case each element of the input array might be composed of both values, then after the sort, split it into the two working arrays. > I am having a problem with an array in RPG > (caused mainly by my ignorance where RPG is concerned > since I am a COBOL kind of guy!). What I am trying to > do is to read a file and load an array that will have > 2 elements - a legacy hold code (2 positions) and a > MHS hold code (2 positions). I then want to do a > lookup on this array by MHS hold code and find the > corresponding legacy hold code (later in the program). > > Could someone be kind enough to coach me through > this? I will be forever greatful. > > Rich MacWheel99@aol.com (Alister Wm Macintyre) (Al Mac) BPCS 405 CD Manager / Programmer @ Global Wire Technologies Incorporated http://www.globalwiretechnologies.com = new name same quality wire engineering company: fax # 812-424-6838
As an Amazon Associate we earn from qualifying purchases.
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.