× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Mike,

This procedure has worked for me many times in the past.  It will
convert ASCII data to the CCSID of the job executing it.  What follows
is first the RPG prototype, then the C wrapper function that does the
actual conversion.  Ideally it would all be RPG, but I took the wimp's
way out and used some C.  Some code to run it could be: (assuming
SomeData is an alpha field and Len is defined as 10I0).  The current
limitiation is only converting 2048 bytes of data per call, but that
could be lengthened without much effort.

/free
  Len = %len(SomeData);
  ConvertedData = CvtToEbcdic(%addr(SomeData):%addr(Len));
/end-free


***********************************************************************
**                                                                     
**  int CvtToEBCDIC(PCHAR peIn,       // Data to Convert               
**              PINT peInLen)         // Length of Data                
**                                                                     
**  This function converts ASCII (437) data to EBCDIC data             
**                                                                     
**  Returns:                                                           
**           -1 in the case of an error                                
**                                                                     
D CvtToEbcdic     PR            10I 0 ExtProc('CvtToEBCDIC')           
D   peIn                          *   Value                            
D   peInLen                       *   Value                            

############### Warning --- C code follows :) ################
/*                     
 * System Includes     
 */                    
#include <string.h>    
#include <stdio.h>     
#include <errno.h>     
#include <stdlib.h>    
#include <sys/types.h> 
#include <sys/socket.h>
#include <sys/time.h>  
#include <arpa/inet.h> 
#include <netdb.h>     
#include <iconv.h> 

#define CNV_BUF_LEN 2048    
/*                                                
                                                  
   int CvtToEBCDIC(PCHAR Input, PINT InLen)       
                                                  
   This function converts ASCII to EBCDIC         
                                                  
   Input           : Input buffer to be converted 
   InLen           : Length of Input Buffer       
   Returns: -1 for error                          
                                                  
*/                                                
int CvtToEBCDIC(PCHAR,PINT);                      

int CvtToEBCDIC(PCHAR Input, PINT InLen)                        
{                                                               
                                                                
    PCHAR       Ascii_Buf = Input;                              
    INT         Ascii_Len = *InLen;                             
    CHAR        Ebcdic_Buf[CNV_BUF_LEN];                        
    INT         Ebcdic_Len = CNV_BUF_LEN;                              
    PCHAR       Sav_Buf = NULL;                                        
    iconv_t     edc;                                                   
    CHAR        from_code[32];                                         
    CHAR        to_code[32];                                           
    int         rc = 0;                                                
                                                                       
    Sav_Buf = (PCHAR) &Ebcdic_Buf;                                     
    memset((PCHAR) &from_code, 0, sizeof(from_code));                  
    memset((PCHAR) &to_code, 0, sizeof(to_code));                      
    strncpy((PCHAR) &from_code, "IBMCCSID004370000000", 20);           
    strncpy((PCHAR) &to_code, "IBMCCSID00000", 13);                    
    /* Code Conversion Allocation API */                               
    edc = iconv_open((PCHAR) &to_code, (PCHAR) &from_code);            
                                                                       
    rc = iconv(edc, (const char**) &Ascii_Buf, (unsigned int*)
&Ascii_Len,
                    &Sav_Buf, (unsigned int*) &Ebcdic_Len);            
                                                             
    /* If there is no error, copy into input parameter */    
    if (rc != -1)                                            
        memcpy(Input, &Ebcdic_Buf, sizeof(char) * (*InLen)); 
                                                             
    /* Code Conversion Deallocation API */                   
    iconv_close(edc);                                        
    return (rc);                                             
}                                                            

                        
Andy Holmer
World Class Information Systems, Inc.
1095 Nimitzview Drive
Suite 403
Cincinnati, OH 45230
(513) 232-9100
f-(513) 232-9249



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-2024 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.