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



Hi Don,

if the fields are already defined with varying length (in DDS). You only
have to read the records and concatenate the contents of the long field. You
may trim off leading and trailing blanks from the JRDDTA field.
You should define rJsonString also as varying length character (Varchar)
field and instead of initializing it with *BLANKS (all 30000 possible
characters are set to *Blank), you should use the CLEAR OpCode.

rJsonString = *blanks ;
%len(rJsonString) = 100000 ;

setll jrdunq issjrdpf ;
reade jrdunq issjrdpf ;
dow not %eof(issjrdpf) and overflow = *off ;
jrdFound = *on ;
if %len(jrddta) > *zero ;
RJsonString += %Trim(jrddta);
reade jrdunq issjrdpf ;
else ;
overflow = *on ;
rSuccess = *off ;
rMessage = 'String exceeds 100000 characters' ;

endif ;
else ;
rSuccess = *off ;
rMessage = 'Unexpected zero length string' ;
leave ; // Should not get a zero length rlddta field !!!

ENDIF;
ENDDO;

BTW if you'd working with a CLOB field in your table and access your data
with embedded SQL, you could store the complete JSON document (up to 2 GB)
in a single row.

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> On Behalf Of Don Brown
Sent: Mittwoch, 9. Mai 2018 06:38
To: Rpg400 Rpg400-L <rpg400-l@xxxxxxxxxxxx>
Subject: Variable length fields

System is V7R3.

I have recently started using variable length fields and a current project
required a large json string.

Can anyone suggest a good resource for examples with using variable length
fields. Especially where they are used a part of a return from a procedure
?


While the reasons why are not so important I have a temporary file where if
have a field defined with a length of 30000 character

JRDDTA 30000 VARLEN

There can be multiple records in this file making up a json string currently
with a maximum length of 100000 (but this may increase)

My question is how would you read multiple records from my work file and
construct the json string.

I ended up doing as follows but it seems not the best option ???

I initially set the length of my variable to the maximum and at the end
reset to the actual trimmed length.

rJsonString = *blanks ;
%len(rJsonString) = 100000 ;

setll jrdunq issjrdpf ;
reade jrdunq issjrdpf ;
dow not %eof(issjrdpf) and overflow = *off ;
jrdFound = *on ;
if %len(jrddta) > *zero ;
if start + %len(jrddta) < 100000 ;
%subst(rjsonstring : start : %len(jrddta)) =
%subst(jrddta : 1 : %len(jrddta)) ;
start += %len(jrddta) + 1 ;
reade jrdunq issjrdpf ;
else ;
overflow = *on ;
rSuccess = *off ;
rMessage = 'String exceeds 100000 characters' ;

endif ;
else ;
rSuccess = *off ;
rMessage = 'Unexpected zero length string' ;
leave ; // Should not get a zero length rlddta field !!!

ENDIF;
ENDDO;



Don Brown


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

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.