IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

change report from ASCII to base64


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
yincw

New User


Joined: 15 Jan 2009
Posts: 6
Location: China

PostPosted: Fri Jan 09, 2015 7:29 pm
Reply with quote

Dear everyone,

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"


And the email step is as below:
Code:
FROM:     aaa@aaa.com                       
TO:       bbb@aaa.com
SUBJECT:  subject
MIME-VERSION: 1.0                                             
CONTENT-TYPE: MULTIPART/MIXED; BOUNDARY="---- =MIMEPART"       
                                                               
THIS MESSAGE IS IN MIME FORMAT. SINCE YOUR MAIL READER DOES NOT
UNDERSTAND                                                     
THIS FORMAT, SOME OR ALL OF THIS MESSAGE MAY NOT BE LEGIBLE.   
                                                               
                                                               
------ =MIMEPART                                               
CONTENT-TYPE: TEXT/PLAIN; CHARSET="US-ASCII"                   
CONTENT-TRANSFER-ENCODING: 7BIT                               
                                                               
report
                                                               
------ =MIMEPART                                       
CONTENT-TYPE: APPLICATION/OCTET-STREAM;                 
              NAME="report.CSV"
CONTENT-TRANSFER-ENCODING: BASE64                       

rexx program output is here
------ =MIMEPART
.               
QUIT           
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Fri Jan 09, 2015 8:00 pm
Reply with quote

Mainframes use EBCDIC, so what is the relevance of this post about ASCII in a mainframe forum?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Jan 10, 2015 4:10 am
Reply with quote

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.
Back to top
View user's profile Send private message
yincw

New User


Joined: 15 Jan 2009
Posts: 6
Location: China

PostPosted: Sun Jan 11, 2015 4:37 pm
Reply with quote

prino wrote:
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.
Back to top
View user's profile Send private message
yincw

New User


Joined: 15 Jan 2009
Posts: 6
Location: China

PostPosted: Sun Jan 11, 2015 4:44 pm
Reply with quote

Robert Sample wrote:
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.


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
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Jan 11, 2015 7:38 pm
Reply with quote

Quote:
change report from ASCII to base64

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 icon_evil.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sun Jan 11, 2015 10:04 pm
Reply with quote

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.
Back to top
View user's profile Send private message
nevilh

Active User


Joined: 01 Sep 2006
Posts: 262

PostPosted: Sun Jan 11, 2015 11:57 pm
Reply with quote

if you have access to omvs you can convert directly from EBCDIC to BASE64.
Back to top
View user's profile Send private message
yincw

New User


Joined: 15 Jan 2009
Posts: 6
Location: China

PostPosted: Mon Jan 12, 2015 11:47 am
Reply with quote

Robert Sample wrote:
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!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jan 12, 2015 5:26 pm
Reply with quote

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Need help on formatting a report DFSORT/ICETOOL 14
No new posts 3270 personal communications. Can't c... TSO/ISPF 2
No new posts Creating Report using SORT DFSORT/ICETOOL 7
No new posts SELECT from data change table DB2 5
No new posts Trying to change copybook in online c... CICS 4
Search our Forums:

Back to Top