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



I love these "so simple" SQL responses that end up being more code (and in my opinion) less obvious than RPG ... <grin>


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jan 15, 2018, at 10:34 AM, Jose Perez <joseenocperez.jp@xxxxxxxxx> wrote:

it is so simple with Sql, just create below function(you can even create it
on green screen) and you will accomplish what you need.

CREATE FUNCTION Qgpl.SPLIT (@Data VARCHAR(32000), @Delimiter
VARCHAR(5))

RETURNS TABLE (ID INT, VALUE VARCHAR(256))


LANGUAGE SQL

DISALLOW PARALLEL

DETERMINISTIC

NOT FENCED

RETURN

WITH CTE_Items (ID,StartString,StopString) AS

(SELECT 1 AS ID, 1 AS StartString,

LOCATE(@Delimiter, @Data) AS
StopString

FROM SYSIBM.SYSDUMMY1


WHERE LENGTH(@Delimiter)>0 AND LENGTH(@Data)>0


UNION ALL


SELECT ID + 1,StopString + LENGTH(@Delimiter)


,LOCATE(@Delimiter, @Data, StopString +
LENGTH(@Delimiter))

FROM CTE_Items


WHERE StopString > 0)


SELECT ID, SUBSTRING(@Data,StartString,

CASE WHEN StopString=0 THEN LENGTH(@Data)


ELSE StopString-StartString

END)

FROM CTE_Items


This will split your record as rows and then you just have to populate your
array from each

row, be aware that the function should receive two parameters, first parms
should be your

delimited record as one big string and second parms should be the delimiter
in your case

it will be a comma. Hope this help.



On Mon, Jan 15, 2018 at 9:36 AM, Justin Taylor <JUSTIN@xxxxxxxxxxxxx> wrote:

No. It would be nice though. I suggest an RFE.



-----Original Message-----
From: Gad Miron [mailto:gadmiron@xxxxxxxxx]
Sent: Monday, January 15, 2018 1:33 AM
To: rpg400-l@xxxxxxxxxxxx
Subject: Built-in %split RPGLE function

Hello all

Is there a built-in RPGLE function to split a comma (or other delimiter)
separated record into an array?

I know it can be done by creating a suitable procedure - I'm just being
lazy.

TIA
Gad

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD


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.