ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Remove all hex values less than x'40'

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

  • Remove all hex values less than x'40'

    I found this on the internet....I'd like to give credit but the user signed on with Anonymous
    This is the technique we use to clean up all unprintable characters (< X'40').
    Code:
     * convert hex values < x'40' to blanks                                
    D fld01           s             15    inz(x'0001023B3C3D')              
    D from            C                   X'000102030405060708090A0B0C0D0E0 
    D                                     101112131415161718191A1B1C1D1E1F- 
    D                                     202122232425262728292A2B2C2D2E2F- 
    D                                     303132333435363738393A3B3C3D3E3F' 
    D to              c                   '                                 
    D                                                                     ' 
                                                                            
     /FREE                                                                  
                                                                            
          FLD01 = %xlate(from:to:FLD01);                                    
          *inlr = *on  ;                                                    
                                                                            
     /END-FREE
    Best of Luck
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

  • #2
    Re: Remove all hex values less than x'40'

    How to use this tool?
    Suppose i have a PF and in one two column lot of hex character are there. Now how to use this program to remove thosecharacters?
    Originally posted by GLS400
    I found this on the internet....I'd like to give credit but the user signed on with Anonymous


    Code:
     * convert hex values < x'40' to blanks                                
    D fld01           s             15    inz(x'0001023B3C3D')              
    D from            C                   X'000102030405060708090A0B0C0D0E0 
    D                                     101112131415161718191A1B1C1D1E1F- 
    D                                     202122232425262728292A2B2C2D2E2F- 
    D                                     303132333435363738393A3B3C3D3E3F' 
    D to              c                   '                                 
    D                                                                     ' 
                                                                            
     /FREE                                                                  
                                                                            
          FLD01 = %xlate(from:to:FLD01);                                    
          *inlr = *on  ;                                                    
                                                                            
     /END-FREE
    Best of Luck
    GLS

    Comment


    • #3
      Re: Remove all hex values less than x'40'

      How to use this tool?
      Suppose i have a PF and in one two column lot of hex character are there. Now how to use this program to remove thosecharacters?
      Originally posted by GLS400
      I found this on the internet....I'd like to give credit but the user signed on with Anonymous


      Code:
       * convert hex values < x'40' to blanks                                
      D fld01           s             15    inz(x'0001023B3C3D')              
      D from            C                   X'000102030405060708090A0B0C0D0E0 
      D                                     101112131415161718191A1B1C1D1E1F- 
      D                                     202122232425262728292A2B2C2D2E2F- 
      D                                     303132333435363738393A3B3C3D3E3F' 
      D to              c                   '                                 
      D                                                                     ' 
                                                                              
       /FREE                                                                  
                                                                              
            FLD01 = %xlate(from:to:FLD01);                                    
            *inlr = *on  ;                                                    
                                                                              
       /END-FREE
      Best of Luck
      GLS

      Comment


      • #4
        Re: Remove all hex values less than x'40'

        You either read each record with native I/O and translate your column content (FLD1) with the %XLATE built-in-function.

        An other way would be to use SQL directly, i.e. tranlaste all hex values lower than x'40' into x'00' with the SQL scalar function TRANSLATE. Remove all x'00' values from the converted string with the scalar function replace. (If you only want to replace the invalid hex values with blanks without removing them, it can be done with a single TRANSLATE function:

        Example:
        Code:
        Update YourSchema/YourTable
           set Col1 = Replace(Translate(Col1, 
        x'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 
        x'000102030405060708090A0B0C0D0E101112131415161718191A1B1C1D1E202122232425262728292A2B2C2D2E303132333435363738393A3B3C3D3E'),
              x'00', ''),
                 Col2 = Translate(col2, ' ', 
        x'000102030405060708090A0B0C0D0E101112131415161718191A1B1C1D1E202122232425262728292A2B2C2D2E303132333435363738393A3B3C3D3E');
        Last edited by B.Hauser; April 5, 2014, 07:21 AM.

        Comment


        • #5
          Re: Remove all hex values less than x'40'

          Hi,

          I already tried REPACE and TRANSLATE function but its not working for me ,may be due to my older version of i series.

          I created on thread for this but still i am in search of solution

          http://www.code400.com/forum/showthr...racter-from-PF

          Can you please look into this thread and helpif youhave any idea.

          Originally posted by B.Hauser View Post
          You either read each record with native I/O and translate your column content (FLD1) with the %XLATE built-in-function.

          An other way would be to use SQL directly, i.e. tranlaste all hex values lower than x'40' into x'00' with the SQL scalar function TRANSLATE. Remove all x'00' values from the converted string with the scalar function replace. (If you only want to replace the invalid hex values with blanks without removing them, it can be done with a single TRANSLATE function:

          Example:
          Code:
          Update YourSchema/YourTable
             set Col1 = Replace(Translate(Col1, 
          x'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 
          x'000102030405060708090A0B0C0D0E101112131415161718191A1B1C1D1E202122232425262728292A2B2C2D2E303132333435363738393A3B3C3D3E'),
                x'00', ''),
                   Col2 = Translate(col2, ' ', 
          x'000102030405060708090A0B0C0D0E101112131415161718191A1B1C1D1E202122232425262728292A2B2C2D2E303132333435363738393A3B3C3D3E');

          Comment


          • #6
            Re: Remove all hex values less than x'40'

            You should understand that asking the same question in different threads doesn't help. It might even irritate some people and influence them to ignore the question.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment


            • #7
              Re: Remove all hex values less than x'40'

              I am sorry Tom......!! I will keep this in mind in future...
              Originally posted by tomliotta View Post
              You should understand that asking the same question in different threads doesn't help. It might even irritate some people and influence them to ignore the question.

              Comment

              Working...
              X