Re: string manipulation in SPL
Posted in 1994
Topics: Stored Procedures & SPL, Data Types & Schema Design
Jack Parker (jparker@hpbs3645.boi.hp.com) wrote: : : A new topic for me. Any pointers? : : Essentially I am: : : create procedure get_strg(var1 char(18), var2 char(8), var3 char(18)) : returning VARCHAR(255); : : DEFINE txt_strg VARCHAR(255); : DEFINE var4 CHAR(8); : : LET txt_strg=''; : : FOREACH : SELECT variable4 : INTO var4 : FROM table : WHERE variable1 = var1 : AND variable2 = var2 : AND variable3 = var3 : ORDER BY variable4 : : # Los problem: : LET txt_strg = txt_strg || varaible4 : : end foreach; : : RETURN txt_strg; : : end procedure; : : I cannot seem to clip. I keep getting the full 255 characters in txt_strg : which makes appending the second variable moot. I've considered writing a : sub procedure, but if it always returns 255 characters, whats the point. I : also don't seem to be able to subscript. TFM is of course a great help. I believe Jim Gordon is correct in his response that subscripting character variables using variable subscripts is not currently allowed. Unfortunately, it seems you are only left with the brute force method to accomplish what you need. Try substituting the following for your let statement: if length(variable4) = 1 then let txt_strg = txt_strg || variable4[1,1]; elif length(variable4) = 2 then let txt_strg = txt_strg || variable4[1,2]; elif length(variable4) = 3 then let txt_strg = txt_strg || variable4[1,3]; elif length(variable4) = 4 then let txt_strg = txt_strg || variable4[1,4]; elif length(variable4) = 5 then let txt_strg = txt_strg || variable4[1,5]; elif length(variable4) = 6 then let txt_strg = txt_strg || variable4[1,6]; elif length(variable4) = 7 then let txt_strg = txt_strg || variable4[1,7]; elif length(variable4) = 8 then let txt_strg = txt_strg || variable4[1,8]; end if Hope this helps. -- ############## __ ######################################################## ########### / / ############ Ron Whiteleather # ######### / / ######### Boise Printer Div. - Formatter Engr. # ####### / /___ ______ ####### # ###### / __ // __ / ###### email: ronw@hpbs3398.boi.hp.com # ###### / / / // /_/ / ###### US Mail: 11411 Chinden Blvd., MS 567 # ####### /_/ /_// ____/ ####### Boise, Idaho 83707 # ######## / / ######### Telnet: 1-396-3476 # ######### / / ########### FAX: (208) 396-5277 # ############ /_/ ##########################################################