Question

As known Progress provides 4 large object datatypes data types MEMPTR,CLOB,BLOB,LONGCHAR.

But the string functions Can't be used either on CLOB or LONGCHAR datatypes.

How to use perform string operations on these LOB Datatypes. "string operations" means substring ,replace,trim etc. functions which can be performed on the strings.To be more clear

Define vChar as Character INITIAL "ashdbi" NO_UNDO. MESSAGE SUBSTRING(vChar,1,1) VIEW-AS ALERT_BOX .

The same way can we perform string operations on LOB's?

Was it helpful?

Solution

A CLOB is stored in the database and LONGCHAR is the datatype used to manipulate it locally. If you store a BLOB you must use a MEMPTR if you want to handle it locally.

Since your asking about STRING-related functions I assume that CLOBS and LONGCHARs are what you're after (CLOB = Chararcter Large Object as supposed to BLOB = Binary Large Object).

Several (or some) string manipulation methods and functions can be used on LONGCHARS, for instance SUBSTRING. Regardless if you're using a CHARACTER or LONGCHAR the syntax is displayed. If you want to

Example - SUBSTRING, INDEX and COPY-LOB

DEFINE VARIABLE cStart  AS LONGCHAR    NO-UNDO.
DEFINE VARIABLE cEnd    AS LONGCHAR    NO-UNDO.
DEFINE VARIABLE cString AS CHARACTER   NO-UNDO.

DEFINE VARIABLE i       AS INTEGER     NO-UNDO.

/* Fill the variable with lots of bogus data */
DO  i = 1 TO 10000:
    cStart = cStart + "ABCDEFGHIJKLMN".
    /* Insert a _ once in 100 */
    IF RANDOM(1, 100) = 100 THEN cStart = cStart + "_".
END.

DISPLAY LENGTH(cStart).

/* SUBSTRING */
cEnd = SUBSTRING(cStart, 1, 100000).

DISPLAY LENGTH(cEnd).

/* Is there a _ in the string - most likely! */
DISPLAY INDEX(cStart, "_").

/* SUBSTRING will convert output to CHARACTER if the length is less than roughly 32k */
cString = SUBSTRING(cStart, 1, 30000).

DISPLAY cString.

/* Lets save the CLOB so we can look at it */
COPY-LOB FROM cStart TO FILE "c:\temp\testing.txt".

/* Actually you can DISPLAY a LONGCHAR as well but why would you really? */
DISPLAY cStart 
    VIEW-AS EDITOR LARGE INNER-LINES 300 INNER-CHARS 300 
    WITH FRAME x1 WIDTH 320 .

OTHER TIPS

There were some exceptions in older releases but "string functions" work very well on longchar data.

To get data between the various large objects (CLOB, BLOB, MEMPTR and files) and into a LONGCHAR and vice-verse you need to use the COPY-LOB statement. Is suspect that that is the "secret sauce" that you are missing.

For instance:

define variable cfgData as longchar no-undo.

assign file-info:file-name = search( "etc/stomp.cfg" ).
copy-lob from file file-info:full-pathname to cfgData no-error.

stompCfg = new dotr.Stomp.StompConfig().
assign
  stompCfg:StompPort   = "61613"
  stompCfg:StompServer = entry( 1, cfgData, ":" )
  stompCfg:StompPort   = entry( 2, cfgData, ":" ) when num-entries( cfgData, ":" ) > 1
  stompCfg:LargeMessageSupport = yes
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top