× 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.



On Wed, 2005-08-24 at 16:51 -0700, Tony Carolla wrote:
> I have a account memo file that is uniquely keyed by account# and memo 
> sequence number. When I want to add a record to an account, I do the 
> following:
> 
> - SetGT using the account number
> - ReadPE using the account number
> - If a record was found, add one to the sequnece number
> - If a record was not found, use 1 as the sequence number
> - Write the memo with the error extender
> - If there was a write error, repeat the loop (somebody added a memo during 
> the above steps)
> 
> So this works beautifully until today -- The account being added to was the 
> last in the memo file. The SETGT fails, 1 is used, and the write fails 
> repeatedly. I am trying to find an efficient way to determine what memo 
> number to add. Perhaps I have to resort to SETLL/READE to the end, add one 
> to the seq#. Any ideas? 

Tony,

I can't duplicate your problem.  I think setgt/readpe works fine, even
at the end of the file.

See test code, which works just fine on V5R2.

Note that test code isn't complete and can loop infinitely if you run
out of sequence numbers, or if %error is being set for a reason _other_
than a duplicate key.  Not production ready code.

Physical file MEMO:
     A                                      UNIQUE
     A          R MEMOA
     A            MACCT#        11P 0
     A            MSEQ#          5P 0
     A            MTEXT         35
     A          K MACCT#
     A          K MSEQ#

RPGLE program MEMOR:
     h dftactgrp(*no)
     h option(*srcstmt:*nodebugio)

     fmemo      if a e           k disk

     d addmemo         pr             5p 0
     d   acct#                       11p 0 const
     d   text                        35    const

      /free
         addmemo(1: 'memo 1-1');
         addmemo(1: 'memo 1-2');
         addmemo(1: 'memo 1-3');

         addmemo(3: 'memo 3-1');
         addmemo(3: 'memo 3-2');
         addmemo(3: 'memo 3-3');

         addmemo(2: 'memo 2-1');
         addmemo(2: 'memo 2-2');
         addmemo(2: 'memo 2-3');

         addmemo(4: 'memo 4-1');
         addmemo(4: 'memo 4-2');
         addmemo(4: 'memo 4-3');

         *inlr = '1';
      /end-free
      * Add a memo to the account
     p addmemo         b

     d addmemo         pi             5p 0
     d   acct#                       11p 0 const
     d   text                        35    const

     d success         s               n
     d result          s              5p 0

      /free
         mseq# = 0;
         setgt acct# memo;
         readpe acct# memo;

         success = '0';
         dow success = '0';
             macct# = acct#;
             mseq# = mseq# + 1;
             mtext = text;
             write(e) memoa;
             success = not %error;
         enddo;

         result = mseq#;
         return result;

      /end-free
     p                 e


Regards,
Rich


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.