|
Begin with any random number. Assign that to your first record. Add 1 to that number and assign that to your second record. Keep going..... You can then keep the last used number in a data area for reference. Or you could just read the last record in the file using a logical keyed by this new id field. You accomplish this by doing a SETLL using *HIVAL and then doing a READP. you do not have to: 'read through the file and increment a counter, but that seems to have a huge overhead, not to mention that as time goes on, it'll take longer and longer to calculate. Thank you, Karen Hodge Senior System Analyst Genesys Health System 1000 Healthpark Blvd, Grand Blanc, Mi 48439 Office 810.606.5180, Fax 810.606.7204 khodge@xxxxxxxxxxx rpg400-l-request@ midrange.com Sent by: To rpg400-l-bounces@ rpg400-l@xxxxxxxxxxxx midrange.com cc Subject 03/10/2005 09:01 RPG400-L Digest, Vol 4, Issue 280 AM Please respond to rpg400-l@midrange .com Send RPG400-L mailing list submissions to rpg400-l@xxxxxxxxxxxx To subscribe or unsubscribe via the World Wide Web, visit http://lists.midrange.com/mailman/listinfo/rpg400-l or, via email, send a message with subject or body 'help' to rpg400-l-request@xxxxxxxxxxxx You can reach the person managing the list at rpg400-l-owner@xxxxxxxxxxxx When replying, please edit your Subject line so it is more specific than "Re: Contents of RPG400-L digest..." Today's Topics: 1. Re: Making sense of 4-byte binary fields (James H. H. Lampert) 2. Re: Suggestions (Raul Jager) 3. AW: Random number in VARPG (HauserSSS) 4. Re: AW: Random number in VARPG (Peter.Colpaert@xxxxxxxxxx) 5. Re: Suggestions (RPower@xxxxxxxxxx) 6. Re: Require help in RPG V (RPower@xxxxxxxxxx) 7. Re: Suggestions (rob@xxxxxxxxx) 8. Re: AW: Random number in VARPG (rob@xxxxxxxxx) ---------------------------------------------------------------------- message: 1 date: Wed, 09 Mar 2005 20:48:42 -0800 from: "James H. H. Lampert" <jamesl@xxxxxxxxxxx> subject: Re: Making sense of 4-byte binary fields In response to: > > I think you have a good point about the misleading documentation. Most > > other languages specify the integer types by names--e.g. short, int, > > long...and leave the number of bits to the implementation. Fortunately, > > it's mostly standardized. Scott Klement wrote: > Actually, that has caused a lot of problems. Particularly on Unix systems > where you typically want to write code on one system, but expect it to > compile and run on many completely different ones (including completely > differnt hardware architectures) Scott's right about the woes of leaving the number of bytes various names mean up to the implementation, but that's hardly confined to Unix, Linux, Aix, &c. It's a problem with ALL implementations of C. That's why Sun made it an inflexible standard in Java. Java has it right, at least in terms of consistency, although you have to RTFM to know that "int" is always 4 bytes, "short" and "char" are always 2, and "long" is always 8. Typical coffee-crazed C-jockey thinking. Oh, if Java had only been designed by a lover of PL/I. . . But FORTRAN had it right a long time ago, with INTEGER*2 and INTEGER*4. Just as PL/I had it right a long time ago with BIN FIXED (15,0) for a 2-byte (15 bits + sign, get it?) integer, and BIN FIXED (31,0) for a 4-byte integer. And of course, MI got it right with explicitly giving the number of bytes, almost the same way as Fortran. Anybody have any idea what the RPG designers were smoking when they decided to make it the number of decimal digits, and to actually generate the extra code to clamp it to that specified number of decimal digits? -- James H. H. Lampert Professional Dilettante http://www.hb.quik.com/jamesl http://members.hostedscripts.com/antispam.html http://www.thehungersite.com Help America's Passenger Trains. http://www.saveamtrak.org Read My Lips: No More Atrocities! ------------------------------ message: 2 date: Thu, 10 Mar 2005 07:35:07 -0300 from: Raul Jager <raul@xxxxxxxxxx> subject: Re: Suggestions This program returns the number of records in the file. Just add 1 and use as the key, unless you decide to begin teh keys with zero. ___________________________________________________________________________________________ 0001.00 PGM PARM(&NAME &LIBR &SIZE) 0002.00 DCL VAR(&NAME) TYPE(*CHAR) LEN(10) 0003.00 DCL VAR(&LIBR) TYPE(*CHAR) LEN(10) 0004.00 DCL VAR(&SIZE) TYPE(*DEC) LEN(10) VALUE(0) 0005.00 DCL VAR(&NBRCURRCD) TYPE(*DEC) LEN(10) VALUE(0) 0006.00 DCL VAR(&NBRDLTRCD) TYPE(*DEC) LEN(10) VALUE(0) 0007.00 RTVMBRD FILE(&LIBR/&NAME) NBRCURRCD(&NBRCURRCD) + 0008.00 NBRDLTRCD(&NBRDLTRCD) 0009.00 MONMSG MSGID(CPF9812) EXEC(DO) /* 'Archivo no esta' */ 0010.00 CHGVAR VAR(&SIZE) VALUE(-1) 0011.00 RETURN 0012.00 ENDDO 0013.00 CHGVAR VAR(&SIZE) VALUE(&NBRCURRCD + &NBRDLTRCD) 0014.00 ENDPGM ______________________________________________________________________________ Raul Buck Calabro wrote: >>I have a physical file that will hold >>gas type information, but one of the >>fields needs to be an integer id field. >> >> > >Search the archives for SQL IDENTITY and you'll probably come up with >a bunch of useful examples. http://archive.midrange.com There are >several native RPG ways to go about this. > >1) Use a data area to store the last number used >*lock in lastno > add 1 lastno > out lastno > >2) Get the highest key by looking at the last record >*hival setll > readp > add 1 key >... > >3) Store the last number used in another database file > >Hope this gets you started. > --buck > > > > > ------------------------------ message: 3 date: Thu, 10 Mar 2005 14:22:12 +0100 from: "HauserSSS" <Hauser@xxxxxxxxxxxxxxx> subject: AW: Random number in VARPG Hi Peter, is it possible to use embedded SQL in VARPG? If so you could determine a random number with embedded SQL. Birgitta -----Ursprungliche Nachricht----- Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]Im Auftrag von Peter.Colpaert@xxxxxxxxxx Gesendet: Donnerstag, 10. Marz 2005 13:27 An: rpg400-l@xxxxxxxxxxxx Betreff: Random number in VARPG Hi group, I'm working on a personal project, my first experiment with VisualAge RPG. My intention is to make a flash-card program that my son can use to train his multiplication & division tables. As I don't have an iSeries at home, it has to be completely PC-based. The problem I'm encountering is that I need to randomize the array with questions, and I have no clue as to how to start this. I tried including the microsecond part of the timestamp into the array and sorting by that, but the program is so fast that there are only 3 distinct values over 220 elements... On the iSeries, I know I can call an API or the rand() function from QC2LE, but is there an equivalent available from VARPG? Or can anybody give me a clue as to how to write a pseudo-random number generating procedure? Thanks in advance, Peter Colpaert Application Developer Massive - Kontich, Belgium ----- Yoda of Borg are we. Futile is resistance, assimilated will you be. ----- -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. ------------------------------ message: 4 date: Thu, 10 Mar 2005 14:34:34 +0100 from: Peter.Colpaert@xxxxxxxxxx subject: Re: AW: Random number in VARPG Hi Brigitta, I guess it is possible, but that brings me to a different problem, namely that I'd need an SQL database of some sort on his PC. But I'll keep your suggestion in mind. Thanks, Peter Colpaert Application Developer Massive - Kontich, Belgium ----- Yoda of Borg are we. Futile is resistance, assimilated will you be. ----- "HauserSSS" <Hauser@xxxxxxxxxxxxxxx> Sent by: rpg400-l-bounces@xxxxxxxxxxxx 10/03/2005 14:22 Please respond to RPG programming on the AS400 / iSeries To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx> cc: Subject: AW: Random number in VARPG Hi Peter, is it possible to use embedded SQL in VARPG? If so you could determine a random number with embedded SQL. Birgitta ------------------------------ message: 5 date: Thu, 10 Mar 2005 10:02:39 -0330 from: RPower@xxxxxxxxxx subject: Re: Suggestions What we do here, is make one unique id(7963535) and use that record the placeholder of your current unique id number. Usually we have at least one date field, so use the date field to hold the next unique id number, and make the record that holds the unique id number have a unique id of 7963535 or something like that. Ron Power Programmer Information Services City Of St. John's, NL P.O. Box 908 St. John's, NL A1C 5M2 Tel: 709-576-8132 Email: rpower@xxxxxxxxxx Website: http://www.stjohns.ca/ ___________________________________________________________________________ Success is going from failure to failure without a loss of enthusiasm. - Sir Winston Churchill "Douglas W. Palme" <dpalme@xxxxxxxxxxxxxxxxxxxxx> Sent by: rpg400-l-bounces@xxxxxxxxxxxx 09/03/2005 04:27 PM Please respond to RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> To RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> cc Subject Suggestions I have a physical file that will hold gas type information, but one of the fields needs to be an integer id field. My experience with other db formats is that I could set that field to auto generate so that as each record is written it will increment the count by 1. we will be using this for cross referencing to some other files and must be unique. I know I can read through the file and increment a counter, but that seems to have a huge overhead, not to mention that as time goes on, it'll take longer and longer to calculate. Does anyone have a viable suggestion on how to accomplish this? Douglas -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. ------------------------------ message: 6 date: Thu, 10 Mar 2005 10:04:12 -0330 from: RPower@xxxxxxxxxx subject: Re: Require help in RPG V Wouldn't that be a phantom menace LOL. Ron Power Programmer Information Services City Of St. John's, NL P.O. Box 908 St. John's, NL A1C 5M2 Tel: 709-576-8132 Email: rpower@xxxxxxxxxx Website: http://www.stjohns.ca/ ___________________________________________________________________________ Success is going from failure to failure without a loss of enthusiasm. - Sir Winston Churchill "Rusling, John B. (Alliance)" <jbrusling@xxxxxxxxxxxxxxx> Sent by: rpg400-l-bounces@xxxxxxxxxxxx 09/03/2005 04:27 PM Please respond to RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> To <rpg400-l@xxxxxxxxxxxx> cc Subject Re: Require help in RPG V Or rename it and start over at "I" ! John B. >message: 1 >date: Wed, 9 Mar 2005 10:02:11 -0800 >from: Tony Carolla <carolla@xxxxxxxxx> >subject: Re: Require help in RPG V ><snip> >On Wed, 9 Mar 2005 17:24:59 -0000, Colin Williams <colin.williams@xxxxxxxxxxxx> wrote: >>> Im waiting for RPG VI, the revenge! >> ></snip> >EGADS MAN! If they don't get it in five tries, ABANDON SHIP! -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. ------------------------------ message: 7 date: Thu, 10 Mar 2005 08:45:34 -0500 from: rob@xxxxxxxxx subject: Re: Suggestions There are LOTS of problems with this technique. Suppose your key's are 1,3,4,7,8,9 (with some having been deleted). Now you RGZPFM and get rid of the deleted records. Using your technique, the current high key would be 6. Nice try with counting the number of deleted records though. Rob Berendt -- Group Dekko Services, LLC Dept 01.073 PO Box 2000 Dock 108 6928N 400E Kendallville, IN 46755 http://www.dekko.com Raul Jager <raul@xxxxxxxxxx> Sent by: rpg400-l-bounces@xxxxxxxxxxxx 03/10/2005 07:35 AM Please respond to RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> To RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> cc Subject Re: Suggestions This program returns the number of records in the file. Just add 1 and use as the key, unless you decide to begin teh keys with zero. ___________________________________________________________________________________________ 0001.00 PGM PARM(&NAME &LIBR &SIZE) 0002.00 DCL VAR(&NAME) TYPE(*CHAR) LEN(10) 0003.00 DCL VAR(&LIBR) TYPE(*CHAR) LEN(10) 0004.00 DCL VAR(&SIZE) TYPE(*DEC) LEN(10) VALUE(0) 0005.00 DCL VAR(&NBRCURRCD) TYPE(*DEC) LEN(10) VALUE(0) 0006.00 DCL VAR(&NBRDLTRCD) TYPE(*DEC) LEN(10) VALUE(0) 0007.00 RTVMBRD FILE(&LIBR/&NAME) NBRCURRCD(&NBRCURRCD) + 0008.00 NBRDLTRCD(&NBRDLTRCD) 0009.00 MONMSG MSGID(CPF9812) EXEC(DO) /* 'Archivo no esta' */ 0010.00 CHGVAR VAR(&SIZE) VALUE(-1) 0011.00 RETURN 0012.00 ENDDO 0013.00 CHGVAR VAR(&SIZE) VALUE(&NBRCURRCD + &NBRDLTRCD) 0014.00 ENDPGM ______________________________________________________________________________ Raul Buck Calabro wrote: >>I have a physical file that will hold >>gas type information, but one of the >>fields needs to be an integer id field. >> >> > >Search the archives for SQL IDENTITY and you'll probably come up with >a bunch of useful examples. http://archive.midrange.com There are >several native RPG ways to go about this. > >1) Use a data area to store the last number used >*lock in lastno > add 1 lastno > out lastno > >2) Get the highest key by looking at the last record >*hival setll > readp > add 1 key >... > >3) Store the last number used in another database file > >Hope this gets you started. > --buck > > > > > -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. ------------------------------ message: 8 date: Thu, 10 Mar 2005 09:01:13 -0500 from: rob@xxxxxxxxx subject: Re: AW: Random number in VARPG Would you really need an SQL database? Many people use the 'dummy' file method when they don't need to. For example select current time into :myvar from sysibm/sysdummy1 When they could do values current time into :myvar http://publib.boulder.ibm.com/infocenter/iseries/v5r3/ic2924/info/db2/rbafzmstvalinto.htm#valinto Granted, the example for RAND does use the dummy file method. However (and I would use your own multiplication factor!) this works: D myRandNum s 10i 0 C/exec sql C+ values (rand() * 1000) into :myRandNum C/end-exec /free *inlr=*on; return; /end-free Rob Berendt -- Group Dekko Services, LLC Dept 01.073 PO Box 2000 Dock 108 6928N 400E Kendallville, IN 46755 http://www.dekko.com Peter.Colpaert@xxxxxxxxxx Sent by: rpg400-l-bounces@xxxxxxxxxxxx 03/10/2005 08:34 AM Please respond to RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> To RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> cc Subject Re: AW: Random number in VARPG Hi Brigitta, I guess it is possible, but that brings me to a different problem, namely that I'd need an SQL database of some sort on his PC. But I'll keep your suggestion in mind. Thanks, Peter Colpaert Application Developer Massive - Kontich, Belgium ----- Yoda of Borg are we. Futile is resistance, assimilated will you be. ----- "HauserSSS" <Hauser@xxxxxxxxxxxxxxx> Sent by: rpg400-l-bounces@xxxxxxxxxxxx 10/03/2005 14:22 Please respond to RPG programming on the AS400 / iSeries To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx> cc: Subject: AW: Random number in VARPG Hi Peter, is it possible to use embedded SQL in VARPG? If so you could determine a random number with embedded SQL. Birgitta -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. ------------------------------ -- This is the RPG programming on the AS400 / iSeries (RPG400-L) digest list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. End of RPG400-L Digest, Vol 4, Issue 280 ****************************************
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.