sbehera00 wrote: ↑Wed Dec 11, 2024 12:30 pm
i was able to manage so far by converting this "^POI" to "^PON" by opening ifs file with ccsid 37 and converting value while sending content to printer but now some other system going to use this ifs file so the content in the ifs needs to be replaced with "^PON".
I would very much discourage you from converting the data to CCSID 37 (or any other flavor of EBCDIC.) Keep the character encoding the same as the original document.
Here are steps i am doing:
HTTP call returns data in variable B64In, base64 encoded. I am using base64_decode to ZplOut
zplLen = base64_decode( %addr(B64In:*data)
: %len(B64In)
: %addr(ZplOut)
: %size(ZplOut) );
Because ZplOut is in binary i am not able to replace "^POI" with "^PON" directly in the variable ZplOut. So first i am writing to ifs
When we talked earlier I recommended creating hex constants and doing the find/replace on those. But now you say you're "not able to because it's binary". That doesn't make sense. You can't scan/replace EBCDIC values because the data is not EBCDIC. But you should be able to use the hex constants I discussed. Or use UTF-8 support in RPG, as I originally suggested -- but you said you are on an extraordinarily out of date machine that doesn't support this -- can you explain what release of the OS you are on? I don't want to spend time giving you a solution only to find out it won't work for you, so it's important to understand what your situation is.
callp write(fd: %addr(ZplOut): zplLen); -- TempIfsFile
TempIfsFile content: After writing to ifs file content looks like this
^FX ZPL generated by V1.0.0.0 ^FS
^XA
^PW812
^POI
^PR8,8,8
I don't understand why you are writing to disk prior to changing the ^POI to ^PON. But, writing to disk doesn't hurt anything (aside from performance, perhaps) provided that you don't enable translation. Knowing the write() statement isn't very helpful to knowing what you're doing to keep the data as binary, as that is defined in the open() API -- and you didn't include that.
I am reading TempIfsFile and writing same content to FinalIfsFile and during this process replacing "^POI" with "^PON"
fd = open( %Trim(FinalIfsFile)
: O_CREAT + O_EXCL + O_WRONLY + O_INHERITMODE
+ O_CCSID
: 0
: 1208
: 0 );
fdi = open( %Trim(TempIfsFile)
: O_RDONLY + O_TEXTDATA + O_CCSID :
S_IRGRP : 37) ;
Len = Read(fdi:%addr(Data):%size(Data)) ;
#strpos = %Scan('^POI':Data);
If #strpos > 0;
Data = %SubSt(Data:1:#strpos-1) + '^PON' +
%SubSt(Data:#strpos+4:(%Len(Data)- (#strpos+9)
-- Looking through debug value of variable Data looks good "^FX ZPL generated by V1.0.0.0 ^FS^XA^PW812^PON^PR8"
EndIf;
callp write(fd: %addr(Data): Len);
Not impressed at all. You're doing exactly what I recommended against... you are converting the data to EBCDIC. Please don't do that. Furthermore, you're doing something odd and providing permissions and CCSID to be assigned to a file that you aren't creating here... that code will be ignored, but... its confusing to the next programmer to code it. They might incorrectly assume that it works.
Please don't do this. Do the work in the original ASCII/UTF-8 don't convert it to EBCDIC.
My FinalIfsFile content looks junk. Possibly issue is i am opening "TempIfsFile" with CCSID 37 and "FinalIfsFile" with CCSID 1208 causing this issue?
Please help how to address this issue or if there is any better way to achieve this?
You are converting the data to EBCDIC. Then you say to the system "Create FinalIfsFile and mark it as ccsid 1208 aka UTF-8. I will provide UTF-8 data to put in the file". After saying that you promptly provide EBCDIC data instead of UTF-8 data, causing it to look like junk.