|
I am having a devil of a time debugging a what should be a simple thing: Eval nPos = %scan(OneQ : InString : nPos ) OneQ is defined as a single apostrophe: D OneQ C Const('''') The program blows up on this statement whenever the last non-blank character in the InString variable is an apostrophe, with the following error: Message ID . . : RNX0100 Severity . . : 50 Message type . : Escape Date sent . . : 01/29/03 Time sent . : 14:28:16 Message . . : Length or start position is out of range for the string operation. Cause . . . : One of the following has occurred in RPG procedure ENQUOTE in program DEVDB/AA1A2: - A numeric length or start position is less than 1 or too large for the string operation. - The search-argument parameter of the %SCAN built-in function has zero length or is longer than the source-string parameter. - The maximum-length parameter of the %STR built-in function is not a value between 1 and 32767. The program is shown in its entirety below: (If the list wraps the source, I can email it "straight" directly to anyone who desires to try it out.) H DFTACTGRP(*NO) debug Fqprint o f 132 printer D EnQuote PR 4096A VARYING D InString 2048A VALUE VARYING d Strings s 100 DIM(11) CTDATA PERRCD(1) d Result s 132a inz(' ') c eval *inLR = *On c Do 11 x 3 0 C* ************** EVAL Result = EnQuote( %TRIM(Strings( x )) + ' ' ) C EVAL Result = EnQuote( %TRIM(Strings( x )) ) c except c enddo Oqprint e 1 O '.' O e 1 O Strings(x) O e 1 O Result P EnQuote B d EnQuote PI 4096A VARYING D InString 2048A VALUE VARYING D nPos S 5I 0 D OneQ C Const('''') D TwoQ C Const('''''') C Eval nPos = %scan(OneQ:InString) C Dow nPos > 0 C Eval InString = %replace(TwoQ: InString: nPos: 1) C Eval nPos = nPos + 2 C Eval nPos = %scan(OneQ : InString : nPos ) C enddo C Eval InString = OneQ + InString + OneQ C Return InString P E ** Them's original's are deader than dead, don't you think? What if there were no single quotes in the sentence? What if someone got goofy and put a bunch of single quotes together like this: ''''' (5) 'A' 'B C' D' E 'F 'G' What if there's a single apostrophe that ends the string?' *** the above statement is the end of the source file *** You may note that the source has one line commented out. Appending a space character to the %trimmed string being passed to the procedure was the difference between the program bombing or working. Unfortunately, the commented-out statement had the adverse effect of adding a blank to the end of the string being encapsulated in quotes. In the particular case I am dealing with, I am using the procedure to build a 50-character TEXT parameter that needs to be encapsulated in quotes. This procedure also scans for apostrophes within the string and doubles them as necessary. When I pass a TEXT string that has a non-blank in the 50th position, the commented out code would make the string 51 bytes long, which, when I try to run a command with this TEXT parameter, it bombs because it is longer than 50 bytes. TIA, Dan __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com
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.