|
I found a solution that allows me to what I wanted to do. It's rather simplistic, but it requires that I specify each column in the SQL fetch statement rather than using the data structure directly. Using grouping data structures doesn't work if the subfields you specify were already defined previously from an external data structure (duh!). Here's my code now that works: * Data structure to receive SQL records * Fields HSMCAT and HSMTYP are defined in file CUIMHSWK starting at position 8 dC1Rec e ds extname(CUIMHSWK) d C1CatTyp 8 11a c/exec SQL c+ declare C1 cursor for c+ select HSPAIDG, HSMDAT, HSMTIM, HSJRNFSQ, HSMCAT, HSMTYP, c+ HSSTYL, HSUQTY, HSMQTY, HSLOCN, HSAREA, HSZONE, HSAISL, c+ HSBAY, HSLEVL, HSPOSN c+ from CUIMHSWK c/end-exec c/exec SQL c+ open C1 c/end-exec c/exec SQL c+ fetch C1 into :HSPAIDG, :HSMDAT, :HSMTIM, :HSJRNFSQ, :HSMCAT, c+ :HSMTYP, :HSSTYL, :HSUQTY, :HSMQTY, :HSLOCN, :HSAREA, c+ :HSZONE, :HSAISL, :HSBAY, :HSLEVL, :HSPOSN c/end-exec * Now I can say this... c if C1CatTyp = 'IRCV' * ...instead of saying this... ***** if HSMTYP = 'I' and HSMCAT = 'RCV' I suppose I could have defined a separate data structure to use for the SQL fetch, then maybe defined a copy of it with the groups the way I wanted, and then just simply move or eval one data structure to the other after each fetch. But I thought the way I chose would be more efficient and consume less memory, however if I needed to add a column to CUIMHSWK later, I would have to modify my code. Thanks for everyone's input! Ben CWilt@xxxxxxxxxxxx Sent by: To: rpg400-l@xxxxxxxxxxxx rpg400-l-bounces@m cc: idrange.com Subject: RE: Grouping predefined fields? 03/31/2004 09:45 AM Please respond to RPG programming on the AS400 / iSeries Ben, I've run into SQL's complaints in a similar situation involving arrays. One way around it, is to specify the individual fields instead of the DS on the fetch into. HTH, Charles > -----Original Message----- > From: Ben_Pforsich@xxxxxxxxxxxx [mailto:Ben_Pforsich@xxxxxxxxxxxx] > Sent: Tuesday, March 30, 2004 12:03 PM > To: rpg400-l@xxxxxxxxxxxx > Subject: Grouping predefined fields? > > > > > > > On V5R2, is there any easy way to group predefined fields in a data > structure or something similiar? > > I have two fields called HSMTYP and HSMCAT from an external > file that I > wish to always compare as one field (the two concatenated). These two > fields are defined as part of an externally-defined data > structure which > I'm using to fetch data directly from an SQL cursor. I've > tried creating a > new subfield within the same data structure and using the > overlay keyword, > but the SQL fetch fails because there are "too many host variables." > What's the best way to do this? > > I feel like I'm missing something obvious. Thanks! > > Ben > > > Here's a code snippet which doesn't run correctly: > > * Data structure to receive SQL records > * Fields HSMCAT and HSMTYP are defined in file CUIMHSWK starting at > position 8 > dC1Rec e ds extname(CUIMHSWK) > d C1Buffer 1 159 > d C1CatTyp 4 overlay(C1Buffer:8) > > c/exec SQL > c+ declare C1 cursor for > c+ select * > c+ from CUIMHSWK > c/end-exec > > c/exec SQL > c+ open C1 > c/end-exec > > c/exec SQL > c+ fetch C1 into :C1Rec > c/end-exec > > * Instead of saying this... > ***** if HSMTYP = 'I' and HSMCAT = 'RCV' > * I want to say this... > c if C1CatTyp = 'IRCV' > * ...without having to do this explicitly > ***** eval C1CatTyp = HSMCAT + HSMTYP > > _______________________________________________ > 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) 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.
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.