Hi,

the SQLTYPE(CLOB:1000000) that you are using, is implemented as a data structure with 2 sub fields in RPG - LENGTH and DATA - so IMHO you have to code:

Responses.Base64Doc_LENGTH = Base64_LEN;
Responses.Base64Doc = %subst(Base64_DATA:1:Base64_LEN);

HTH and kind regards,
Daniel


Am 23.05.2025 um 15:40 schrieb (WalzCraft) Jerry Forss <JForss@xxxxxxxxxxxxx>:

Hi All

First, Thank you to Marco to getting me to this point!

I need to take a PDF on the IFS, convert it to a Base64 and return it back through a web service.

I am getting the Base64 and looks correct but when it is sent back to the service it is adding weird characters to the beginning of the field.
Variable length info? The field is NOT defined as a variable length field.

When converting back to a PDF it fails because of the garbage characters.

What the H.....eck am I doing wrong?

Relevant PRG code

// ===================================================================================
// Data Stuctures
// ===================================================================================

Dcl-DS Response Qualified Template Inz;
Base64Doc_LENGTH Int(10);
Base64Doc Char(1000000);
End-Ds;

// ===================================================================================
// Input Parameters
// ===================================================================================

Dcl-pr WOMDocDspR;
Envir Char(2);
CustNo Packed(8 : 0);
Order Char(7);
DocSeq Packed(9 : 0);
Responses LikeDS(Response);
Fail Char(100);
End-pr;

Dcl-pi WOMDocDspR;
Envir Char(2);
CustNo Packed(8 : 0);
Order Char(7);
DocSeq Packed(9 : 0);
Responses LikeDS(Response);
Fail Char(100);
End-pi;

// ===================================================================================
// Global Variables
// ===================================================================================

Dcl-S Base64 SQLType(CLOB : 1000000);
Dcl-S DocPath VarChar(200);

EXEC SQL SET OPTION COMMIT = *NONE;

exec Sql VALUES QSYS2.BASE64_ENCODE((SELECT LINE FROM TABLE(
QSYS2.IFS_READ_BINARY(PATH_NAME => :DocPath ))))
INTO :Base64;

Responses.Base64Doc_LENGTH = %Len(%Trim(Base64));
Responses.Base64Doc = Base64;

From debug

EVAL Base64
BASE64_LEN OF BASE64 = 278400
BASE64_DATA OF BASE64 =
....5...10...15...20...25...30...35...40...45...50...55...60
1 'JVBERi0xLjcgCiXi48/TIAoxIDAgb2JqIAo8PCAKL1R5cGUgL0NhdGFsb2cg'
61 'Ci9QYWdlcyAyIDAgUiAKL1BhZ2VNb2RlIC9Vc2VOb25lIAovVmlld2VyUHJl'
121 'ZmVyZW5jZXMgPDwgCi9GaXRXaW5kb3cgdHJ1ZSAKL1BhZ2VMYXlvdXQgL1Np'
181 'bmdsZVBhZ2UgCi9Ob25GdWxsU2NyZWVuUGFnZU1vZGUgL1VzZU5vbmUgCj4+'

What is returned

"RESPONSES": {
"BASE64DOC":"oe"mJVBERi0xLjcgCiXi48/TIAoxIDAgb2JqIAo8PCAKL1R5cGUgL0NhdGFsb2cgCi9QYWdlcyAyIDAgUiAKL1BhZ2VNb2RlIC9Vc2VOb25lIAovVmlld2VyUHJlZmVyZW5jZXMgPDwgCi9GaXRXaW5kb3cgdHJ1ZSAKL1BhZ2VMYXlvdXQgL1NpbmdsZVBhZ2UgCi9Ob25GdWxsU2NyZWVuUGFnZU1vZGUgL1VzZU5vbmUgCj4+IAo+PiAKZW5kb2JqIAo1IDAgb2JqIAo8PCAKL0xlbmd0aCAzMzMyIAovRmlsdGVyIFsgL0ZsYXRlRGVjb2RlIF0gCj4




Subject to Change Notice:

WalzCraft reserves the right to improve designs, and to change specifications without notice.

Confidentiality Notice:

This message and any attachments may contain confidential and privileged information that is protected by law. The information contained herein is transmitted for the sole use of the intended recipient(s) and should "only" pertain to "WalzCraft" company matters. If you are not the intended recipient or designated agent of the recipient of such information, you are hereby notified that any use, dissemination, copying or retention of this email or the information contained herein is strictly prohibited and may subject you to penalties under federal and/or state law. If you received this email in error, please notify the sender immediately and permanently delete this email. Thank You

WalzCraft PO Box 1748 La Crosse, WI, 54602-1748
www.walzcraft.com<http://www.walzcraft.com> Phone: 1-800-237-1326
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2025 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.