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



James H H Lampert wrote:
> 
> Success! The data structure overlay gambit paid off.
> 
> There's one other issue, though: the file field the
> Unicode data is eventually going into is VARLEN. I've
> already discovered that I have to set the length of the
> field before putting the data into it, but does anybody
> know of a convenient, FAST way to determine the length to
> the last nonblank non-null character in a Unicode string?
> Something in RPG that I'm just not seeing? Something I can
> code in RPG easily? Something in the C runtime that I can
> call from RPG? Something simple I can do in the C server
> communication module that passes the unicode from the
> client to the RPG? At this point, I don't know whether I'm
> going to be dealing with null-terminated or blank-padded.
> 

James, I agree with Jon that you should just define the field as unicode
(type C).  It doesn't sound like you need the character version of the
data.

Then, to assign your parameter to the varying unicode field, just use
%TRIM where the second parameter for %TRIM is blank+null. The length
part of the varying field will be handled automatically.  (I'm assuming
you have unicode (double-byte) blanks.)

 D mypgm           pi
 D  parm                   18383c     const 
 D varUnicode      s       18383c     varying
  /free
       varUnicode = %TRIM(parm : u'00200000');

If the length of data passed in is not fixed, then you have to also use
substring (assuming you get the length passed in as a second parameter)

 D mypgm           pi
 D  parm                   18383c     const options(*varsize)
 D  numBytes                  10i 0   value
 D varUnicode      s       18383c     varying
 D numChars        s          10i 0
  /free
       numChars = numBytes / 2;
       varUnicode = %TRIM(%subst(parm : 1 : numChars) 
                        : u'00200000');

If the length is not fixed and you don't get the length passed in, then
I'm not sure how you could figure out the length if there might be
intermediate blanks in the data.  But assuming that intermediate blanks
are not possible, then I think the only way to get the length is to loop
through the data until you find either a null or a blank.

 D mypgm           pi
 D  parm                   18383c     const options(*varsize)
 D varUnicode      s       18383c     varying
 D i               s          10i 0
 D ch              s           1c
  /free
       %len(varUnicode) = 0;
       for i = 1 to 18383;
          ch = %subst(parm : i : 1);
          if ch = *blank or ch = u'0000';
             leave;
          endif;
          varUnicode += ch;
       endfor;


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.