how to decode base64 encoded zpl data back to ASCII/EBCDIC

Other open source tools published on
Scott Klement
Site Admin
Posts: 305
Joined: Sun Jul 04, 2021 5:12 am

Re: how to decode base64 encoded zpl data back to ASCII/EBCDIC

Post by Scott Klement »

sbehera wrote: Tue Jan 25, 2022 8:55 pm data written to ifs file i do see as zpl data but when i check value of variable ZplOut using debug, after base64_Decode is called it still shows as binary or hexadecimal.
The data is not EBCDIC. If you view it as ASCII or UTF-8 instead of EBCDIC, you'd be able to see it. Alternately, if you need it in EBCDIC, you can translate it.
sbehera wrote: Tue Jan 25, 2022 8:55 pm IFS file shows data in UTF-8 because file is created with CCSID 1208?
In my example, I created the file as CCSID 1208, which is the CCSID number for UTF-8. I don't know if that's what it should be -- but, it's certainly closer than the EBCDIC you seem to be using. Can you please find out what it's supposed to be? I've asked this a couple of times now.

Notice that when I created the IFS file, I specified O_CCSID and 1208 to specify that the file is 1208. However, I did NOT specify O_TEXTDATA or O_TEXT_CREAT, which means that the IFS APIs will not translate it from the program's EBCDIC to the file's UTF-8. I did it that way because the data is already in UTF-8, so translating would cause problems.
sbehera wrote: Tue Jan 25, 2022 8:55 pm I need to print this zpl data to spool file to send to printer. How to do that? Here what i am doing (after zpl data written to ifs) to achieve what i need:
- Created a physical file DMYPRTFL with as400 default CCSID 65535: CRTPF FILE(TEST1/DMYPRTFL) RCDLEN(132)
Depends on how your printer is set up, et al. One easy way to preserve the values would be to use a *USERASCII spooled file -- then you can just write the data to it without converting it to EBCDIC first. The disadvantage to this approach, however, is that you can't see the contents in the spool.
sbehera wrote: Tue Jan 25, 2022 8:55 pm cmd = 'CPY OBJ(' + #Quote + stmf + #Quote + ') ' +
'TOOBJ(' + #Quote + '/qsys.lib/test1.lib/' +
'dmyprtfl.file/dmyprtfl.mbr' +
#Quote + ') FROMCCSID(*OBJ) ' +
You are telling it to convert from the CCSID of the stream file (i.e. 1208, or UTF-8) to the job's CCSID. That means you are converting it to EBCDIC. If that's what you want, why not do it in the RPG program?

Are you on a recent release of RPG? (One where UTF-8 fields are allowed?) Or would you have to use APIs to translate it?
Post Reply