× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: opnqryf
  • From: "Scott Klement" <infosys@xxxxxxxxxxxx>
  • Date: 03 Feb 2000 18:02:56 -0600

Hi Bill,

"bill totz" <robsurge@hotmail.com> wrote:
> (I apologize if this was already sent)
> I need to sort a 6 digit field (CN#) for a report based on the last
> three digits of cn then the first three.  I would like to do this
> with my opnqry which i believes requires me to create a map field
> and substring the first three digits into the field then add the
> last three digits-including this field in the keyfield parm of
> opnqryf.
>
> I apologize if this is a bit sketchy but I am fairly new to opnqryf.
> Thanks-Bill

You're correct, thats what you have to do (if you're going to do it
this way)

Two things that you might not be taking into account:

1) In order to use a MAPFLD as a keyfield, it has to be a field thats
       in your record format.  You might, therefore, need to create
       a special "format" (an empty PF just for the record format)
       that contains your new keyfield...

       You may be able to get around this, however, if you don't
       intend to update the file and if theres a character field
       that you don't need to use in your program...  It may not
       be the best way to do it, but it'll work :)

2) If your 6-digit field (CN#??) is numeric, you'll need to also
       make a MAPFLD specification to convert it to character
       before you can substring it.


Your query will probably look something like this:

       OPNQRYF FILE((MYFILE)) +
           MAPFLD((CHRFLD '%DIGITS(CN#)') +
                  (NEWFLD '%SST(CHRFLD 4 3) *CAT %SST(CHRFLD 1 3)')) +
           KEYFLD((NEWFLD))

the %DIGITS converts from numeric to character.  If you're field is
already character, you can skip that part...

the %SST(CHRFLD 4 3) *CAT %SST(CHRFLD 1 3)   takes the 3 characters
starting with position 4 and concatenates them to the 3 characters
starting at position 1.

As I mentioned above, NEWFLD needs to be in your record format.  If
its not, you can make an empty PF thats the same as the original,
but adds that one field -- then do it like this:

       OPNQRYF FILE((MYFILE)) FORMAT(MYLIB/MYNEWFILE MYRECFMT) +
           MAPFLD((CHRFLD '%DIGITS(CN#)') +
                  (NEWFLD '%SST(CHRFLD 4 3) *CAT %SST(CHRFLD 1 3)')) +
           KEYFLD((NEWFLD))


Hope that helps....

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.