Consultor Eletrônico



Kbase P113194: What is the size limit on the length parameter of the SUBSTRING function when its source is a CHARAC
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/3/2006
Status: Unverified

GOAL:

What is the size limit on the length parameter of the SUBSTRING function when its source is a CHARACTER data type?

FIX:


9.1E and lower the maximum length parameter of the SUBSTRING function is allowed to take to reach before an error is generated is 32767. If the length parameter exceeds this limit the following error is generated.

** The length argument value must be greater or equal to -1. (83)

Even though the length parameter is allowed to exceed 31991, the size of the returned character string is limited to 31991 characters which is the size limit of the 4GL CHARACTER data type.

In 10.x, the length parameter of the SUBSTRING function is allowed to exceed the 32767 limit without generating an error. However, the size of the returned character string is also limited to the maximum size limit of the 4GL CHARACTER data type of 31991. The following code may be run to illustrate this solution:
DEFINE VARIABLE cSource AS CHARACTER NO-UNDO.
DEFINE VARIABLE iPosition AS INTEGER NO-UNDO.
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
DEFINE VARIABLE cType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cResult AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
ASSIGN
cSource = FILL("x", 31991)
iPosition = 1
cType = "CHARACTER".
DO iLength = 1 TO LENGTH(cSource) + 999999.:
ASSIGN
cResult = SUBSTRING(cSource, iPosition, iLength, cType) NO-ERROR.
IF ERROR-STATUS:ERROR THEN LEAVE.
END.
MESSAGE iPosition iLength LENGTH(cResult) ERROR-STATUS:ERROR
VIEW-AS ALERT-BOX INFO BUTTONS OK.