|
Adding to what Joep said... You might consider a multiple occurrence data structure. But I would suggest that if you don't know how many elements you need at runtime and that number may be large you might consider using a based keyword with ALLOC and DeAlloc. If it is small, just add the OCCURS() keyword to the data structure and get all the storage you need without dealing with the pointer crap. If you need up to 50 occurrences, then you would code something like this: > D LDADS DS OCCURS(50) > D CusKeyErr 14 28 > D RefErr 29 38 > D MsgCode 39 45 > D ErrElmAry 46 93 > D ErrMsgAry 94 261 If you really want to use dynamic occurrences, use a point variable as follows: D pData S * D LDADS DS Occurs(32766) Based(pData) D CusKeyErr 14 28 D RefErr 29 38 D MsgCode 39 45 D ErrElmAry 46 93 D ErrMsgAry 94 261 D nByteCount S 10I 0 D nNumNeeded S 10I 0 C Eval nNumNeeded = 200 C Eval nByteCount = %Size(LDADS) * nNumNeeded C Alloc nByteCount pData C** I now have 200 occurrences of LDADS available C Eval nNumNeeded = 750 C Eval nByteCount = %Size(LDADS) * nNumNeeded C ReAlloc nByteCount pData C** I now have 750 occurrences of LDADS available Just remember, storage returned by ALLOC and REALLOC is not initialized, while it is usually blank, it is not guaranteed to be blank. Bob Cozzi cozzi@rpgiv.com Visit the on-line Midrange Developer forum at: http://www.rpgiv.com > -----Original Message----- > From: rpg400-l-admin@midrange.com [mailto:rpg400-l-admin@midrange.com] On > Behalf Of Joep Beckeringh > Sent: Tuesday, January 08, 2002 2:29 PM > To: rpg400-l@midrange.com > Subject: Re: Help a pointer Newbie out... > > I think you will have to supply some information: > > - What are you trying to achieve? > - Why do you think you need a linked list? > - Why do you think you need pointers to process this list? > (And while you're at it: What is wrong with using a file in QTEMP?) > > There are several ways to handle lists of information in RPG (arrays, > multiple occurrence data structures and, yes, files). Arrays and MODS > usually have a predefined size limit. When you don't want to define the > size at compile time, you will have to do your own memory housekeeping; in > that case you will have to deal with pointers. > > A list is a linked list when elements contain one or more links to other > elements. These links don't have to be pointers (in the technical sense); > in an array they could be indexes to other elements; in a MODS they could be > indexes to other occurrences; in a file they could be keys to other records. > > Joep Beckeringh > > > ----- Original Message ----- > From: <SCarter@rsrcorp.com> > To: <rpg400-l@midrange.com> > Sent: Tuesday, January 08, 2002 9:03 PM > Subject: Help a pointer Newbie out... > > > > I searched the archives and the FAQ for information on using pointers to > > linked lists > > and I did not find anything useful to ME... > > that having been said can some one give me an example of using pointers > for > > linked lists > > I have the classic list problem I know what type of data I need but i > don't > > know how much. > > I could write the data out to a file in QTEMP and just process the file > but > > I did not want to do > > that unless I can't wrap my brain around this pointer thing in a > reasonable > > amount of time. > > > > I want to be able to store this information in a list and then reprocess > > the list how would I > > do this with pointers... > > D LDADS DS > > D CusKeyErr 14 28 > > D RefErr 29 38 > > D MsgCode 39 45 > > D ErrElmAry 46 93 > > D ErrMsgAry 94 261 > > > > _______________________________________________ > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list > To post a message email: RPG400-L@midrange.com > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l > or email: RPG400-L-request@midrange.com > Before posting, please take a moment to review the archives > at http://archive.midrange.com/rpg400-l.
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.