I have a requirement to change a large report from ASCII to base64 format.
I found some sample code on the internet for base64 conversion and used in my code. As the report is very large, if I read the whole report in one time, the rexx program would abend at run time, with main storage exhausted error. So I read 10000 rows at one time and then do the conversion.
The program run OK, but the result is bad. I attached the output file as CSV file in an email with MIME format, and sent to my email address. But the attached CSV file has mess code after 36000 row. I don't know why. Could anyone help please? Thank you very much!
The REXX code is as below
Code:
char_set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
char_set = char_set||'abcdefghijklmnopqrstuvwxyz0123456789+/'
read_eof = 0
StartRec = 1
Nrecs = 10000
leftchar = ""
"EXECIO" Nrecs "DISKR SYSUT1" StartRec "(STEM filein."
erc = rc
if erc > 2 then do
say "Error reading SYSUT1"
exit 16
end
fileout_dd = "SYSUT2"
"EXECIO 0 DISKW "fileout_dd" (OPEN"
partsize = 0
Do while(erc <= 2 & read_eof = 0)
"newstack"
StartRec = StartRec + filein.0
file = ""
file = file||leftchar
do i = 1 to filein.0
file = file||filein.i
partsize = partsize + length(filein.i)
drop filein.i
end
drop filein.0
shortline = 0
if partsize < 3 then
shortline = 1
lineout = ""
partoff = 1
col_num = 0
do while partsize > 2
conv3char = substr(file,partoff,3)
partoff = partoff + 3
partsize = partsize - 3
conv3char_B = X2B(C2X(conv3char))
x1=X2D(B2X(SUBSTR(conv3char_B,1,6)))
x2=X2D(B2X(SUBSTR(conv3char_B,7,6)))
x3=X2D(B2X(SUBSTR(conv3char_B,13,6)))
x4=X2D(B2X(SUBSTR(conv3char_B,19,6)))
lineout = lineout||substr(char_set,x1+1,1),
||substr(char_set,x2+1,1),
||substr(char_set,x3+1,1),
||substr(char_set,x4+1,1)
col_num = col_num + 4
IF col_num = 76 THEN
DO
queue lineout
lineout = ""
col_num = 0
END
end /* end do while partsize > 2*/
select
when partsize = 1 then
do
leftchar = substr(file,partoff,partsize)
leftchar_B = X2B(C2X(leftchar))
x1=X2D(B2X(SUBSTR(leftchar_B,1,6)))
x2=X2D(B2X(SUBSTR(leftchar_B,7,2)||"0000"))
if src = 2 then
do
lineout = lineout||substr(char_set,x1+1,1),
||substr(char_set,x2+1,1)||"=="
queue lineout
end
end
when partsize = 2 then
do
leftchar = substr(file,partoff,partsize)
leftchar_B = X2B(C2X(leftchar))
x1=X2D(B2X(SUBSTR(leftchar_B,1,6)))
x2=X2D(B2X(SUBSTR(leftchar_B,7,6)))
x3=X2D(B2X(SUBSTR(leftchar_B,13,4)||"00"))
if src = 2 then
do
lineout = lineout||substr(char_set,x1+1,1),
||substr(char_set,x2+1,1),
||substr(char_set,x3+1,1)||"="
queue lineout
end
end
otherwise nop
end /* select */
"EXECIO * DISKW "fileout_dd
"DELSTACK"
if erc = 2 then
do
read_eof = 1
leave
end
else
do
"EXECIO" Nrecs "DISKR SYSUT1" StartRec "(STEM filein."
erc = rc
if erc > 2 then do
say "Error reading SYSUT1"
exit 16
end
end
end /* do while */
"EXECIO 0 DISKW "fileout_dd" (FINIS"
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
Quote:
I attached the output file as CSV file in an email with MIME format, and sent to my email address. But the attached CSV file has mess code after 36000 row. I don't know why.
We don't either -- especially since you did not bother to tell us what you're using to send the email. Is this really a mainframe issue? Mainframes rarely deal with ASCII since their native code set is EBCDIC. Yes, you used REXX but since REXX is available on many different platforms, that doesn't imply you're on a mainframe.
Mainframes use EBCDIC, so what is the relevance of this post about ASCII in a mainframe forum?
Yes, I know mainframe use EBCDIC. My requirement was to convert a report on mainframe to base64 format. The first step is to convert from EBCDIC to ASCII, the second step is to convert from ASCII to base64, which I have issue with.
I attached the output file as CSV file in an email with MIME format, and sent to my email address. But the attached CSV file has mess code after 36000 row. I don't know why.
We don't either -- especially since you did not bother to tell us what you're using to send the email. Is this really a mainframe issue? Mainframes rarely deal with ASCII since their native code set is EBCDIC. Yes, you used REXX but since REXX is available on many different platforms, that doesn't imply you're on a mainframe.
I'm pasting the step to send email, please check the code.
I didn't realize that I have to prove I'm running on mainframe to seek help from there.
Code:
//*send mail
//SENDM EXEC PGM=IEBGENER,COND=(4,LT)
//SYSIN DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSUT2 DD SYSOUT=(B,SMTPF)
//SYSUT1 DD * -- this is the part I have pasted before
the subject of Your question just makes everybody wonder ...
mainframes do not speak ASCII they speak EBCDIC
and with Your attitude You are reducing the chances of getting help
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
This is one of the situations for which you absolutely MUST contact your site support group. There is a limit on the number of bytes that can be sent in a single SMTP message -- the default is 512K for z/OS -- and that limit can be changed by the site support group. If you are exceeding that limit, your choices are limited:
1. get the site support group to increase the limit
2. break your message into shorter messages that don't exceed the limit
3. use another method to transfer the report
4. accept that what you want to do cannot be done with the restrictions you are putting on it and be assigned a different project
I repeat: nobody on this forum can resolve your issue since it involves an issue specific to your site. Only someone working at your site can possibly resolve it.
This is one of the situations for which you absolutely MUST contact your site support group. There is a limit on the number of bytes that can be sent in a single SMTP message -- the default is 512K for z/OS -- and that limit can be changed by the site support group. If you are exceeding that limit, your choices are limited:
1. get the site support group to increase the limit
2. break your message into shorter messages that don't exceed the limit
3. use another method to transfer the report
4. accept that what you want to do cannot be done with the restrictions you are putting on it and be assigned a different project
I repeat: nobody on this forum can resolve your issue since it involves an issue specific to your site. Only someone working at your site can possibly resolve it.
That's very helpful, thank you very much! No wonder I couldn't find issues in my REXX code, as the issue is with the SMTP, not REXX at all!
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
The biggest problem in debugging is usually the assumptions the programmer makes about what the problem is. Your post demonstrates this -- you assumed you had a REXX problem, rather than just describing what you were doing, the results you were getting, and what results you were expecting. SMTP was not mentioned for several posts, and there's no reason we should assume you were using SMTP since there are a number of ways to transfer data.