![]() |
|
Natural Tip of Week of May 12, 2008 |
||
|
Subject:
Natural string handling This is came up with one of Boston Univerity's programmers. Because I knew his exceptionable understanding of Natural, I was surprised to find out the approach that was used to address answering this question. The program scenario was for one field only. Let's use the following definition: 01 #ALPHA-FIELD (A40) Natural provides the ability to mask characters and test for attributes. MASK(P) is good for asking if a character is printable. For Natural, by definition that the MASK(P) is true if the character is (U)pper case, (L)ower case, (N)umeric digit or (S)pecial character. More on the MASK (S) later. The technique used by my colleague was the following: 01 #ALPHA-FIELD (A40) The first surprise was to see that a FOR loop was used. This is totally unnecessary; one should use array analysis vs looping through one character at a time. In other words, the proper coding technique is to eplace the FOR loop & IF statement with this IF statement: IF #ALPHA-CHAR (*) NE MASK(P) This is equivalent to Natural asking: IF #ALPHA-CHAR (1) NE MASK(P) AND However, this article is not quite done. I was surprised to discover that the character '!' (exclamation mark) did not qualify as a printable character. This had to mean that it was not considered a special character. Indeed, here is a program to test all 256 hex values from X'00' to X'FF'. DEFINE DATA LOCAL After investigation I realized that Natural did not consider the exclamation mark a special and therefore a printable character. I asked myself "Why?" Once again a Sag-l expert - Helmut Spichtinger - explained that the macro named NTSCTAB defined in the NATCONFG module is responsible defining what is special and what is not. I have an issue that Natural differs from what I consider printable for several characters. To change this one would either re-build the NTSCTAB table or dynamically override with the SCTAB parameter. |
||
Here are three sponsors who have more materials on Natural & Adabas tips and techniques:
![]() |
![]() |
![]() |