ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Char to ASCII

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Char to ASCII

    Hi Friends,

    I have a string say ABCDEF, in my program I need to find the ASCII equvalent of each charecter in the string, please let me know how can I do that.

    Regards
    Uday

  • #2
    Re: Char to ASCII

    Hi,

    you may try the API QDCXLATE with table QASCII.

    Birgitta

    Comment


    • #3
      Re: Char to ASCII

      Hi Hauser,

      could u please try to give me a code snippet, I tried using that API but after the call to that API I got a blank value in the second parameter i.e. data to be converted.

      Initially I sent 'A' ideally I should have recieved its ASCII equivalent 65 but I recieved Blank in that field. Please suggest whether hat is the way to do or any other ??


      Thanks in Advance
      Uday

      Comment


      • #4
        Re: Char to ASCII

        What you are actually looking for is the decimal value of the hex equivilent of the ascii field. In order to convert a string to a hex equivilent string, you can use the cvthc program.


        Code:
             d ToHex           pr                  ExtProc('cvthc')
             d  HexString                 65534a   options(*varsize) varying
             d  CharacterString...
             d                            32767a   const options(*varsize) varying
             d  HexStringLength...
             d                               10i 0 value
        The hex value you would get from an Ascii "A" character is 41. Now you have to convert the hex to decimal. The decimal number for a 2 character hex field can be anything from 0 to 255, so you'll need a 3 digit number field to convert the hex value to decimal.

        I havent checked to see if there is a hex to decimal program available (I'm sure there is.) Another method would be to assign the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F to an array, and perform a lookup to see which element of the array the character is in. Then Subtract 1 from this value. For the first charcter of the hex value, multiply it by 16, then add the second characters value.

        IE The ASCII hex value of "A" is 41. Take the first digit of 4, multiply by 16, and you get 64. Add the value of the second digit of one, and you have 65.



        So, to do what you ultimately want to do, you have to perform three steps.

        1) Convert the Ebcdic string to Ascii
        2) Convert the ascii string to hex
        3) Convert the hex value to deimal

        I have all of this bundled in a service program. Wth the service program, I can most all of this in one step:

        Code:
        HexValue =  Xlate_ToHex( Xlate_EbcdicToAscii ( EbcdicField ) );
        StartPosition = 1;
        
        for TimesToLoop = 1 to %len( EbcdicField );
          
          DecimalValue = Xlate_ToDecimal( %substr( HexValue : StartPosition : 2 );
          StartPosition += 2;
        
        endfor;
        If you still cant figure it out, let me know and I'll post my service program. It may take some time to strip out the irrelevant stuff in it, or else I would just post the whole thing.
        Last edited by MichaelCatalani; March 1, 2009, 12:14 PM.
        Michael Catalani
        IS Director, eCommerce & Web Development
        Acceptance Insurance Corporation
        www.AcceptanceInsurance.com
        www.ProvatoSys.com

        Comment


        • #5
          Re: Char to ASCII

          Hi Michael... could u please help me out to get the code more detailedly...??

          Thanks in Advance
          Uday

          Comment


          • #6
            Re: Char to ASCII

            Copied from an Italian AS/400 forum

            Someone has already written a program to convert from EBCDIC to ASCII and can make available?

            Here is a procedure that is for you:

            Code:
                  // Ebcdic -> Ascii
                 PEbcdic2Ascii     B
                 DEbcdic2Ascii     PI
                 D from                            *   Value
                 D len                           10i 0 Value
                  // Convert a Graphic Character String API
                 DCDRCVRT          PR                  extpgm('CDRCVRT')
                 D CCSID1                        10I 0 const
                 D ST1                           10I 0 const
                 D S1                           256    const
                 D L1                            10I 0 const
                 D CCSID2                        10I 0 const
                 D ST2                           10I 0 const
                 D GCCASN                        10I 0 const
                 D L2                            10I 0 const
                 D S2                           256
                 D L3                            10I 0
                 D L4                            10I 0
                 D FB                            12
                  // xlateb MI
                 Dxlateb           PR                  EXTPROC('_XLATEB')
                 D                                 *   VALUE
                 D                                 *   VALUE
                 D                               10u 0 VALUE
                  // conversion tables and CDRCVRT rtn flds
                 DTbl280           s            256    inz(*allx'ff')
                 DTbl819           s            256    inz(*allx'ff')
                 DL3               s             10i 0
                 DL4               s             10i 0
                 DFB               s             12
                  // conversion binary - hex
                 dxValue           ds
                 d bValue                         3U 0
                  /free
                    // create a conversione table
                    for bValue = 0 to 254;
                      %subst(Tbl280:bValue+1:1) = xValue;
                    endfor;
                    CDRCVRT (280:0:Tbl280:256:819:0:0:256:Tbl819:L3:L4:FB);
                    // convert
                    xlateb (from:%addr(Tbl819):len);
                  /end-free
                 PEbcdic2Ascii     E

            Comment


            • #7
              Re: Char to ASCII

              Originally posted by uj41724 View Post
              Hi Michael... could u please help me out to get the code more detailedly...??

              Thanks in Advance
              Uday
              Sure, give me a few hours and I'll post the service program and a sample program that does what you are looking for.
              Michael Catalani
              IS Director, eCommerce & Web Development
              Acceptance Insurance Corporation
              www.AcceptanceInsurance.com
              www.ProvatoSys.com

              Comment


              • #8
                Re: Char to ASCII

                The following is the code for the service program, as well as the code for a sample program that shows how to do what you were looking to do.

                I'n the instructions below, I'm using a library called "EXAMPLE". If you are using a different library, make sure to change the library in the compile commands.


                ProtoType for Service Program (copy into a member called XLATE_P with a type of rpgle in QRPGLESRC)

                Code:
                
                      /if defined(Xlate_p)
                      /eof
                      /endif
                
                      /define Xlate_p
                
                      /copy *libl/qrpglesrc,ApiError
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      *  ConvertType - Data Structure For QDCXLATE api
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     d ConvertType     ds
                     d  Type                         10I 0 Inz(1)
                     d  CCSID                        10I 0 Inz(0)
                     d  ConvertTo                    10I 0 Inz(0)
                     d  Reserved                     10A   Inz(*allx'00')
                
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      *  XLATE_Translate - Wrapper for QDCXLATE api
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     d XLATE_Translate...
                     d                 pr                  ExtPgm('QDCXLATE')
                
                     d  TranslateLength...
                     d                                5p 0 const
                     d  TranslateData             32766a   options(*varsize)
                     d  TranslateTable...
                     d                               10a   const
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      *  XLATE_EbcdicToAsci - Translate Ebcdic To Ascii
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     d XLATE_EbcdicToAscii...
                     d                 pr         32766a   varying
                     d  TranslateData             32766a   options(*varsize) const varying
                
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      * XLATE_ToHex - Translate a character string to hex
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     d XLATE_ToHex     pr         65532a   varying
                     d  CharacterString...
                     d                            32766a   const options(*varsize) varying
                
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      * ToHex - Wrapper for cvthc api
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     d ToHex           pr                  ExtProc('cvthc')
                     d  HexString                 65532a   options(*varsize)
                     d  CharacterString...
                     d                            32766a   const options(*varsize)
                     d  HexStringLength...
                     d                               10i 0 value
                
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      * XLATE_HexToDecimal - Translate Hex To Decimal
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     d Xlate_HexToDecimal...
                     d                 pr             5p 0
                     d  HexString                     4a   const  options(*varsize)
                Service Program Code and Procedure Interface (Copy into a member called XLATE_S with a type of rpgle in QRPGLESRC)

                Code:
                     h nomain bnddir('QC2LE')
                
                      /copy *libl/qrpglesrc,xlate_p
                
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      *  XLATE_EbcdicToAsci - Translate Ebcdic To Ascii
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     p XLATE_EbcdicToAscii...
                     p                 b                   export
                     d XLATE_EbcdicToAscii...
                     d                 pi         32766a   varying
                     d  TranslateData             32766a   options(*varsize) const varying
                     d  ConvertedData  s          32766a   varying
                     d  DataToConvert  s          32766a
                
                      /free
                
                        DataToConvert = TranslateData;
                
                        XLATE_Translate( %len( TranslateData ) : DataToConvert : 'QTCPASC' );
                        ConvertedData = %subst( DataToConvert  : 1 : %len( TranslateData ) );
                
                        return ConvertedData;
                
                      /end-free
                
                     p                 e
                
                
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *
                      * XLATE_ToHex - Translate a character string to hex
                      *
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     p XLATE_ToHex     b                   export
                     d XLATE_ToHex     pi         65532a   varying
                     d  CharacterString...
                     d                            32766A   const options(*varsize) varying
                
                     d  HexString      s          65532a   varying
                     d  ApiString      s          32766a
                     d  ApiHex         s          65532a
                
                      /free
                
                        ApiString = CharacterString;
                
                        ToHex( ApiHex : ApiString : %len( CharacterString ) * 2);
                        HexString = %subst( ApiHex : 1 : %len( CharacterString ) * 2 );
                
                        return  HexString;
                
                      /end-free
                     p                 e
                
                
                        //* * * * * * * * * * * * * * * * * * * * * * * * * * * *
                        //
                        // XLATE_HexToDecimal
                        //
                        //* * * * * * * * * * * * * * * * * * * * * * * * * * * *
                     p XLATE_HexToDecimal...
                     p                 b                   export
                     d XLATE_HexToDecimal...
                     d                 pi             5p 0
                     d  HexString                     4a   const options(*varsize)
                     d
                     d
                     d                 ds
                     d HexCharacters                 16a   inz('0123456789ABCDEF')
                     d HexArray                       1a   overlay(HexCharacters) dim(16)
                     d Value1          s              2p 0
                     d Value2          s              2p 0
                     d Value3          s              2p 0
                     d Value4          s              2p 0
                     d DecimalValue    s              5p 0
                     d FourByteHex     s              4a
                     d Looper          s              1p 0
                      /free
                
                        FourByteHex = %trim( HexString );
                
                        // If less than 4 bytes were received, right adjust and pad
                        // the left hand side with Zeros
                        for Looper = 4 downto %len(%trim( FourByteHex ));
                          FourByteHex = '0' + FourByteHex;
                        endfor;
                
                        // find the decimal value for each hex byte
                        Value1 = %lookup( %subst( FourByteHex : 1 : 1) : HexArray );
                        Value2 = %lookup( %subst( FourByteHex : 2 : 1) : HexArray );
                        Value3 = %lookup( %subst( FourByteHex : 3 : 1) : HexArray );
                        Value4 = %lookup( %subst( FourByteHex : 4 : 1) : HexArray );
                
                        // check for an invalid hex code passed
                        if Value1 = 0 OR Value2 = 0 OR Value3 = 0 OR Value4 = 0;
                          return 0;
                        endif;
                
                        // reduce each value by one so that the value reflects the actual
                        // numeric value and not the array index
                        Value1 -= 1;
                        Value2 -= 1;
                        Value3 -= 1;
                        Value4 -= 1;
                
                        // multiply out each position to determine the decimal number
                        DecimalValue = ( Value1 * 4096 ) +
                                       ( Value2 *  256 ) +
                                       ( Value3 *   16 ) +
                                         Value4 ;
                
                        return DecimalValue;
                
                      /end-free
                     p                 e

                Binder Language (copy into member XLATE_S in QSRVSRC with a type of bnd)

                Code:
                             STRPGMEXP  PGMLVL(*CURRENT)
                             EXPORT     SYMBOL(XLATE_EBCDICTOASCII)
                             EXPORT     SYMBOL(XLATE_TOHEX)
                             EXPORT     SYMBOL(XLATE_HEXTODECIMAL)
                             ENDPGMEXP
                -Compile the module

                CRTRPGMOD MODULE(EXAMPLE/XLATE_S) SRCFILE(EXAMPLE/QRPGLESRC) DBGVIEW(*ALL)

                -Create The Service Program
                CRTSRVPGM SRVPGM(EXAMPLE/XLATE_S)

                -Create a binding directory called "EXAMPLE"
                CRTBNDDIR BNDDIR(EXAMPLE/EXAMPLE)

                -Add Service Program to the binding directory
                ADDBNDDIRE BNDDIR(EXAMPLE/EXAMPLE) OBJ((EXAMPLE/XLATE_S))


                ---------------------------------------------------------------------------

                Sample Program

                Display File (copy into member CHARTODECD in QDDSSRC)


                Code:
                
                
                     A*%%TS  SD  20090303  103227  QPGMR       REL-V6R1M0  5761-WDS
                     A*%%EC
                     A                                      DSPSIZ(24 80 *DS3)
                     A                                      CF03(03)
                     A          R SCREEN01
                     A*%%TS  SD  20090303  103227  QPGMR       REL-V6R1M0  5761-WDS
                     A                                  1  2DATE
                     A                                      EDTCDE(Y)
                     A                                      COLOR(PNK)
                     A                                  2  2TIME
                     A                                      COLOR(PNK)
                     A                                  1 21'XLATE Service Program Example'
                     A                                      COLOR(BLU)
                     A                                  1 70USER
                     A                                      COLOR(PNK)
                     A                                 23  3'F3-Exit'
                     A                                      COLOR(WHT)
                     A                                  6  3'Character To Convert:'
                     A                                      COLOR(BLU)
                     A                                  8  3'Ebcdic Hex Code.....:'
                     A                                      COLOR(BLU)
                     A                                  9  3'Ebcdic Decimal......:'
                     A                                      COLOR(BLU)
                     A                                 11  3'Ascii  Hex Code.....:'
                     A                                      COLOR(BLU)
                     A                                 12  3'Ascii  Decimal......:'
                     A                                      COLOR(BLU)
                     A            CHARACTER      1A  B  6 25COLOR(WHT)
                     A                                      CHECK(LC)
                     A            EHEX           2A  O  8 25COLOR(PNK)
                     A            EDECIMAL       5Y 0O  9 25COLOR(PNK)
                     A                                      EDTCDE(Z)
                     A            AHEX           2A  O 11 25COLOR(PNK)
                     A            ADECIMAL       5Y 0O 12 25COLOR(PNK)
                     A                                      EDTCDE(Z)


                Sample Program Code
                (copy into member CHARTODEC in QRPGLESRC)


                Code:
                
                
                     h BndDir( 'EXAMPLE' )  dftactgrp(*no)
                
                     fCharToDecDcf   e             workstn
                
                      /copy XLATE_p
                
                      /free
                
                        dow NOT *in03;
                
                          exfmt Screen01;
                          if *in03;
                            leave;
                          endif;
                
                          Ehex = XLATE_ToHex( Character );
                          Edecimal = XLATE_HexToDecimal( XLATE_ToHex( Character ));
                          Ahex = XLATE_ToHex( XLATE_EbcdicToAscii( Character ));
                          Adecimal = XLATE_HexToDecimal( XLATE_ToHex(
                                                         XLATE_EbcdicToAscii( Character )));
                
                        enddo;
                
                         *inlr = *on;
                Last edited by MichaelCatalani; March 3, 2009, 10:56 AM.
                Michael Catalani
                IS Director, eCommerce & Web Development
                Acceptance Insurance Corporation
                www.AcceptanceInsurance.com
                www.ProvatoSys.com

                Comment


                • #9
                  Re: Char to ASCII

                  Thanks a lot Miachel, let me try that once i reach my office tomorrow..!!!

                  Regards
                  Uday

                  Comment


                  • #10
                    Re: Char to ASCII

                    Hi Miachell Hats off to your help.... the code worked perfectly as intended.... Once again thanks a lot for the help...!!!!


                    Regards
                    Uday

                    Comment


                    • #11
                      Re: Char to ASCII

                      Originally posted by MichaelCatalani View Post
                      The following is the code for the service program, as well as the code for a sample program that shows how to do what you were looking to do.

                      I'n the instructions below, I'm using a library called "EXAMPLE". If you are using a different library, make sure to change the library in the compile commands.


                      ProtoType for Service Program (copy into a member called XLATE_P with a type of rpgle in QRPGLESRC)

                      Code:
                      
                            /if defined(Xlate_p)
                            /eof
                            /endif
                      
                            /define Xlate_p
                      
                            /copy *libl/qrpglesrc,ApiError
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            *  ConvertType - Data Structure For QDCXLATE api
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           d ConvertType     ds
                           d  Type                         10I 0 Inz(1)
                           d  CCSID                        10I 0 Inz(0)
                           d  ConvertTo                    10I 0 Inz(0)
                           d  Reserved                     10A   Inz(*allx'00')
                      
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            *  XLATE_Translate - Wrapper for QDCXLATE api
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           d XLATE_Translate...
                           d                 pr                  ExtPgm('QDCXLATE')
                      
                           d  TranslateLength...
                           d                                5p 0 const
                           d  TranslateData             32766a   options(*varsize)
                           d  TranslateTable...
                           d                               10a   const
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            *  XLATE_EbcdicToAsci - Translate Ebcdic To Ascii
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           d XLATE_EbcdicToAscii...
                           d                 pr         32766a   varying
                           d  TranslateData             32766a   options(*varsize) const varying
                      
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            * XLATE_ToHex - Translate a character string to hex
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           d XLATE_ToHex     pr         65532a   varying
                           d  CharacterString...
                           d                            32766a   const options(*varsize) varying
                      
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            * ToHex - Wrapper for cvthc api
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           d ToHex           pr                  ExtProc('cvthc')
                           d  HexString                 65532a   options(*varsize)
                           d  CharacterString...
                           d                            32766a   const options(*varsize)
                           d  HexStringLength...
                           d                               10i 0 value
                      
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            * XLATE_HexToDecimal - Translate Hex To Decimal
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           d Xlate_HexToDecimal...
                           d                 pr             5p 0
                           d  HexString                     4a   const  options(*varsize)
                      Service Program Code and Procedure Interface (Copy into a member called XLATE_S with a type of rpgle in QRPGLESRC)

                      Code:
                           h nomain bnddir('QC2LE')
                      
                            /copy *libl/qrpglesrc,xlate_p
                      
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            *  XLATE_EbcdicToAsci - Translate Ebcdic To Ascii
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           p XLATE_EbcdicToAscii...
                           p                 b                   export
                           d XLATE_EbcdicToAscii...
                           d                 pi         32766a   varying
                           d  TranslateData             32766a   options(*varsize) const varying
                           d  ConvertedData  s          32766a   varying
                           d  DataToConvert  s          32766a
                      
                            /free
                      
                              DataToConvert = TranslateData;
                      
                              XLATE_Translate( %len( TranslateData ) : DataToConvert : 'QTCPASC' );
                              ConvertedData = %subst( DataToConvert  : 1 : %len( TranslateData ) );
                      
                              return ConvertedData;
                      
                            /end-free
                      
                           p                 e
                      
                      
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                            *
                            * XLATE_ToHex - Translate a character string to hex
                            *
                            * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           p XLATE_ToHex     b                   export
                           d XLATE_ToHex     pi         65532a   varying
                           d  CharacterString...
                           d                            32766A   const options(*varsize) varying
                      
                           d  HexString      s          65532a   varying
                           d  ApiString      s          32766a
                           d  ApiHex         s          65532a
                      
                            /free
                      
                              ApiString = CharacterString;
                      
                              ToHex( ApiHex : ApiString : %len( CharacterString ) * 2);
                              HexString = %subst( ApiHex : 1 : %len( CharacterString ) * 2 );
                      
                              return  HexString;
                      
                            /end-free
                           p                 e
                      
                      
                              //* * * * * * * * * * * * * * * * * * * * * * * * * * * *
                              //
                              // XLATE_HexToDecimal
                              //
                              //* * * * * * * * * * * * * * * * * * * * * * * * * * * *
                           p XLATE_HexToDecimal...
                           p                 b                   export
                           d XLATE_HexToDecimal...
                           d                 pi             5p 0
                           d  HexString                     4a   const options(*varsize)
                           d
                           d
                           d                 ds
                           d HexCharacters                 16a   inz('0123456789ABCDEF')
                           d HexArray                       1a   overlay(HexCharacters) dim(16)
                           d Value1          s              2p 0
                           d Value2          s              2p 0
                           d Value3          s              2p 0
                           d Value4          s              2p 0
                           d DecimalValue    s              5p 0
                           d FourByteHex     s              4a
                           d Looper          s              1p 0
                            /free
                      
                              FourByteHex = %trim( HexString );
                      
                              // If less than 4 bytes were received, right adjust and pad
                              // the left hand side with Zeros
                              for Looper = 4 downto %len(%trim( FourByteHex ));
                                FourByteHex = '0' + FourByteHex;
                              endfor;
                      
                              // find the decimal value for each hex byte
                              Value1 = %lookup( %subst( FourByteHex : 1 : 1) : HexArray );
                              Value2 = %lookup( %subst( FourByteHex : 2 : 1) : HexArray );
                              Value3 = %lookup( %subst( FourByteHex : 3 : 1) : HexArray );
                              Value4 = %lookup( %subst( FourByteHex : 4 : 1) : HexArray );
                      
                              // check for an invalid hex code passed
                              if Value1 = 0 OR Value2 = 0 OR Value3 = 0 OR Value4 = 0;
                                return 0;
                              endif;
                      
                              // reduce each value by one so that the value reflects the actual
                              // numeric value and not the array index
                              Value1 -= 1;
                              Value2 -= 1;
                              Value3 -= 1;
                              Value4 -= 1;
                      
                              // multiply out each position to determine the decimal number
                              DecimalValue = ( Value1 * 4096 ) +
                                             ( Value2 *  256 ) +
                                             ( Value3 *   16 ) +
                                               Value4 ;
                      
                              return DecimalValue;
                      
                            /end-free
                           p                 e

                      Binder Language (copy into member XLATE_S in QSRVSRC with a type of bnd)

                      Code:
                                   STRPGMEXP  PGMLVL(*CURRENT)
                                   EXPORT     SYMBOL(XLATE_EBCDICTOASCII)
                                   EXPORT     SYMBOL(XLATE_TOHEX)
                                   EXPORT     SYMBOL(XLATE_HEXTODECIMAL)
                                   ENDPGMEXP
                      -Compile the module

                      CRTRPGMOD MODULE(EXAMPLE/XLATE_S) SRCFILE(EXAMPLE/QRPGLESRC) DBGVIEW(*ALL)

                      -Create The Service Program
                      CRTSRVPGM SRVPGM(EXAMPLE/XLATE_S)

                      -Create a binding directory called "EXAMPLE"
                      CRTBNDDIR BNDDIR(EXAMPLE/EXAMPLE)

                      -Add Service Program to the binding directory
                      ADDBNDDIRE BNDDIR(EXAMPLE/EXAMPLE) OBJ((EXAMPLE/XLATE_S))


                      ---------------------------------------------------------------------------

                      Sample Program

                      Display File (copy into member CHARTODECD in QDDSSRC)


                      Code:
                      
                      
                           A*%%TS  SD  20090303  103227  QPGMR       REL-V6R1M0  5761-WDS
                           A*%%EC
                           A                                      DSPSIZ(24 80 *DS3)
                           A                                      CF03(03)
                           A          R SCREEN01
                           A*%%TS  SD  20090303  103227  QPGMR       REL-V6R1M0  5761-WDS
                           A                                  1  2DATE
                           A                                      EDTCDE(Y)
                           A                                      COLOR(PNK)
                           A                                  2  2TIME
                           A                                      COLOR(PNK)
                           A                                  1 21'XLATE Service Program Example'
                           A                                      COLOR(BLU)
                           A                                  1 70USER
                           A                                      COLOR(PNK)
                           A                                 23  3'F3-Exit'
                           A                                      COLOR(WHT)
                           A                                  6  3'Character To Convert:'
                           A                                      COLOR(BLU)
                           A                                  8  3'Ebcdic Hex Code.....:'
                           A                                      COLOR(BLU)
                           A                                  9  3'Ebcdic Decimal......:'
                           A                                      COLOR(BLU)
                           A                                 11  3'Ascii  Hex Code.....:'
                           A                                      COLOR(BLU)
                           A                                 12  3'Ascii  Decimal......:'
                           A                                      COLOR(BLU)
                           A            CHARACTER      1A  B  6 25COLOR(WHT)
                           A                                      CHECK(LC)
                           A            EHEX           2A  O  8 25COLOR(PNK)
                           A            EDECIMAL       5Y 0O  9 25COLOR(PNK)
                           A                                      EDTCDE(Z)
                           A            AHEX           2A  O 11 25COLOR(PNK)
                           A            ADECIMAL       5Y 0O 12 25COLOR(PNK)
                           A                                      EDTCDE(Z)


                      Sample Program Code
                      (copy into member CHARTODEC in QRPGLESRC)


                      Code:
                      
                      
                           h BndDir( 'EXAMPLE' )  dftactgrp(*no)
                      
                           fCharToDecDcf   e             workstn
                      
                            /copy XLATE_p
                      
                            /free
                      
                              dow NOT *in03;
                      
                                exfmt Screen01;
                                if *in03;
                                  leave;
                                endif;
                      
                                Ehex = XLATE_ToHex( Character );
                                Edecimal = XLATE_HexToDecimal( XLATE_ToHex( Character ));
                                Ahex = XLATE_ToHex( XLATE_EbcdicToAscii( Character ));
                                Adecimal = XLATE_HexToDecimal( XLATE_ToHex(
                                                               XLATE_EbcdicToAscii( Character )));
                      
                              enddo;
                      
                               *inlr = *on;
                      hi MichaelCatalani,
                      i have a question

                      PHP Code:
                      Binder Language  (copy into member XLATE_S in QSRVSRC with a type of bnd)


                                   
                      STRPGMEXP  PGMLVL(*CURRENT)
                                   
                      EXPORT     SYMBOL(XLATE_EBCDICTOASCII)
                                   
                      EXPORT     SYMBOL(XLATE_TOHEX)
                                   
                      EXPORT     SYMBOL(XLATE_HEXTODECIMAL)
                                   
                      ENDPGMEXP 
                      XLATE_S with type BND

                      is a BND not have to compile to be an object ???

                      thx u

                      Comment


                      • #12
                        Re: Char to ASCII

                        binding directory is a list of module / service program

                        what is the different CRTPGM with Binding Directory?

                        CRTPGM can add multiple Module too

                        thx u all

                        Comment


                        • #13
                          Re: Char to ASCII

                          Originally posted by rx_b10 View Post
                          binding directory is a list of module / service program

                          what is the different CRTPGM with Binding Directory?
                          A binding directory contains a list of service programs / modules. Instead of listing each service program / module on the compile command, you can simply list the binding directory.

                          An even better approach is to specify the binding directory on the control specification in your application. That way neither you, nor anyone else that changes the application behind you, will need to specify any compiler commands that have to do with modules, service programs, or binding directories. All of the modules and service programs will be located and bound to automatically by the compiler by searching the binding directory(s).

                          CRTPGM can add multiple Module too
                          yes, but not as easily as specifying a binding directory on the control spec.

                          For example:

                          h BndDir( 'CF' ) dftactgrp(*no)

                          With this control spec in the application, I am telling the compiler that any export I need is located in a servce program or module located in the CF binding directory. I dont need to list anything on the compile command. Even if an application needs to bind to 300 procedures located in 40 service programs or modules, I dont have to list anything on the compile command as long as those service programs or modules are located inside the binding directory I reference on the control spec. ( you can specify multiple binding directories as well.)

                          Binding directories GREATLY simply compiling of programs that bind to many modules or service programs. If I needed to make a quick change to an application that did, I could spend some time on simply keying in the module / service program parameters on the compile command. Even worse, I may have to RESEARCH each procedure to see what module / service program they were located in if the application did not have this documented. By using a binding directory on the control spec, I'm telling the compiler that anything it needs to bind to will be in a module or service program thats listed in the binding directory; and that the compiler can go find them itself and bind to them without anything else needed from me. So that allows me to make a quick change, and a blind compile with no parameters needed.

                          The last thing I want to have to do when making a quick 30 second change is to spend 2 hours researching where all of the exports are located, and getting the parameters on my compile command correct so that everything can bind correctly.
                          Michael Catalani
                          IS Director, eCommerce & Web Development
                          Acceptance Insurance Corporation
                          www.AcceptanceInsurance.com
                          www.ProvatoSys.com

                          Comment


                          • #14
                            Re: Char to ASCII

                            Originally posted by rx_b10 View Post
                            hi MichaelCatalani,
                            i have a question

                            PHP Code:
                            Binder Language  (copy into member XLATE_S in QSRVSRC with a type of bnd)


                                         
                            STRPGMEXP  PGMLVL(*CURRENT)
                                         
                            EXPORT     SYMBOL(XLATE_EBCDICTOASCII)
                                         
                            EXPORT     SYMBOL(XLATE_TOHEX)
                                         
                            EXPORT     SYMBOL(XLATE_HEXTODECIMAL)
                                         
                            ENDPGMEXP 
                            XLATE_S with type BND

                            is a BND not have to compile to be an object ???

                            thx u
                            BND source is not a compiled object. it's used by the CRTSRVPGM command that tells the compiler to expose only those procedures defined in the binder source for entry points. in order words the only procedures in the service program that can be called externally. all other procedures in the service program can only be used/called by procedures within the service program itself. clear as mud?
                            I'm not anti-social, I just don't like people -Tommy Holden

                            Comment


                            • #15
                              Re: Char to ASCII

                              Originally posted by tomholden View Post
                              BND source is not a compiled object. it's used by the CRTSRVPGM command that tells the compiler to expose only those procedures defined in the binder source for entry points. in order words the only procedures in the service program that can be called externally. all other procedures in the service program can only be used/called by procedures within the service program itself. clear as mud?
                              thx u tomholden i understand now

                              if i add a new procedure in XLATE_S say it procedure XLATE_A.

                              so i need to add

                              PHP Code:
                                           STRPGMEXP  PGMLVL(*CURRENT)
                                           
                              EXPORT     SYMBOL(XLATE_EBCDICTOASCII)
                                           
                              EXPORT     SYMBOL(XLATE_TOHEX)
                                           
                              EXPORT     SYMBOL(XLATE_HEXTODECIMAL)
                              [
                              B]             EXPORT     SYMBOL(XLATE_A) [/B]
                                           
                              ENDPGMEXP 
                              when bnd source have change, so just recompile a service program only? is it right ????

                              thx u

                              Comment

                              Working...
                              X