The v16 & v17 documents (all versions including the SAP Help one) imply that the input to Base64_encode() should be a string - which seems to miss the whole point of the exercise :) In fact it takes a long binary quite happily: create variable blah1 long binary; create variable blah2 long varchar; create variable blah3 long binary; set blah1 = xp_read_file('c:\tmp\mark.tif'); set blah2 = base64_encode(blah1); set blah3 = base64_decode(blah2); call xp_write_file('c:\tmp\markOUT.tif',blah3 );with an 8MB tiff I know that a related issue was discussed in this question back in 2014. But it would avoid a lot of confusion if the documentation for the relevant functions could make it clear when they can handle binary data. (I've just spent some time explaining to someone that thye don't need to convert their binary data to a string so they can convert it to a string so that they .... you get the idea!) |
I've recommended an update to the docs to help make this more clear. The difficulty with many of these functions is that they accept arguments of all sorts of types and then convert the input argument to whatever seems to be the most appropriate for that type. Thanks - that's great. Just an indication not to get too hung up on the word "string" would do the job!
(11 Jun '20, 13:49)
Justin Willey
Replies hidden
1
FWIW the EXPRTYPE function is useful to answer the question "Just exactly what is the data type at this point?" For grins and giggles, check the return data type for the STRING() function.
(11 Jun '20, 14:27)
Breck Carter
1
Yikes. That's the function that returns different things based on atmospheric pressure.
(11 Jun '20, 15:08)
JBSchueler
(11 Jun '20, 16:10)
Breck Carter
|
I agree on the doc topic. I have the impression that "strings" within the docs sometimes only refers to character strings and sometimes also includes binary strings, as here...
That being said, the sample for BASE64_ENCODE seems to hint that "real binary data" should be passed as argument:
FWIW, for non-ascii encodings, base64 is also required/helpful for "real character string" encoding, just to prevent problems with the most significant bit, think of SMTP and the like...