# Examine... Translate

**URL:** <https://techcommunity.softwareag.com/t/examine-translate/99746>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [February 21, 2012, 2:28pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746 "2012-02-21T14:28:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mishra](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mishra](https://techcommunity.softwareag.com/u/Mishra)\
**Post date:** [February 21, 2012, 2:28pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/1 "2012-02-21T14:28:42Z")

</div>

Hi,

I am little confused if the following can be acomplished with the help of EXAMINE…TRANSLATE statement

Display all the customer names and set the first character of every word into upper case, the rest to lower case and connect separate words by ‘-‘

Input: MR JOHN SMITH

OUTPUT-SAMPLE : Mr-John-Smith

I have done EXAMINE #STRING FOR ’ ’ REPLACE WITH ‘-’. This gives me MR-JOHN-SMITH.

Now how can I only translate the first character of each word to Upper case? If I use TRANSLATE TO LOWER CASE, it will make the entire string to lower case.

Is it possible to translate a specific character to upper case?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 21, 2012, 2:43pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/2 "2012-02-21T14:43:07Z")

</div>

```auto
EXAMINE SUBSTRING(#STRING,1,1) TRANSLATE INTO UPPER CASE
```

---

<div class="post-metadata">

**Author:** ![Mishra](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mishra](https://techcommunity.softwareag.com/u/Mishra)\
**Post date:** [February 21, 2012, 2:55pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/3 "2012-02-21T14:55:27Z")

</div>

Hi Wolfgang,

It will only translate the first character of the first word to upper case. How about my remaining words in the string?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 21, 2012, 2:58pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/4 "2012-02-21T14:58:28Z")

</div>

That won’t work without parsing the string in one or the other way.

The easiest way would probably be to SEPARATE the string into words,  
translate the first character of every word to upper case, then COMPRESS  
them again with ‘-’ as the filler character.

---

<div class="post-metadata">

**Author:** ![Mishra](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mishra](https://techcommunity.softwareag.com/u/Mishra)\
**Post date:** [February 21, 2012, 3:11pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/5 "2012-02-21T15:11:00Z")

</div>

Thanks Wolfgang… I was just wondering if there is something that we can do with only help of EXAMINE statement…

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 21, 2012, 3:15pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/6 "2012-02-21T15:15:03Z")

</div>

Afraid not, EXAMINE is a VERY powerful statement, but that’s just asking a bit too much 😉

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [February 21, 2012, 3:51pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/7 "2012-02-21T15:51:34Z")

</div>

I love a good puzzle. As an exercise in the EXAMINE statement, here is one solution. I’m not sure if I would recommend it or not.

```auto

DEFINE DATA LOCAL                                                 
1 #A (A15) INIT <'MR JOHN DOE'>                                  
1 #LC (A2/26) INIT <' a',' b',' c',' d',' e',' f',' g',' h',      
                    ' i',' j',' k',' l',' m',' n',' o',' p',' q', 
                    ' r',' s',' t',' u',' v',' w',' x',' y',' z'> 
1 #UC (A2/26) INIT <' A',' B',' C',' D',' E',' F',' G',' H',      
                    ' I',' J',' K',' L',' M',' N',' O',' P',' Q', 
                    ' R',' S',' T',' U',' V',' W',' X',' Y',' Z'> 
1 #I (I4)                                                        
END-DEFINE                                                        
*                                                                 
EXAMINE #A TRANSLATE INTO LOWER CASE               
EXAMINE SUBSTRING(#A,1,1) TRANSLATE INTO UPPER CASE               
FOR #I = 1 TO 26                                                  
  EXAMINE #A FOR #LC(#I) REPLACE WITH #UC(#I)                     
END-FOR                                                           
EXAMINE #A FOR ' ' REPLACE WITH '-'                               
DISPLAY '=' #A                                                    
END                                                               
```

Actually, that might not be too bad.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [February 21, 2012, 4:19pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/8 "2012-02-21T16:19:03Z")

</div>

> [@Wolfgang Winter](#):
>
> Afraid not, EXAMINE is a VERY powerful statement, but that’s just asking a bit too much 😉

I think, a real regexp-implementation would be much more powerful and a big help for Mishra’s task…

And here is my workaround:

```auto
define data local
01 #string (A50) init <'MR JOHN SMITH'>
01 #i1 (i1)
end-define
display #string
examine substr(#string,2) translate into lower
repeat
  EXAMINE #STRING FOR ' ' REPLACE first with '-' giving position #i1
  if #i1 > 0
    examine substr(#string,#i1,2) translate into upper
  else
    escape bottom
  end-if
end-repeat
end
```

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [February 21, 2012, 5:07pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/9 "2012-02-21T17:07:31Z")

</div>

“The people are silent” 🙂

These are the concluding words of the last scene of the tragedy “Boris Godunov” (1825), Alexander Pushkin

Thank you, Matthias! I did not expect the EXAMINE statement was that powerful

---

<div class="post-metadata">

**Author:** ![Mishra](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mishra](https://techcommunity.softwareag.com/u/Mishra)\
**Post date:** [February 21, 2012, 5:18pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/10 "2012-02-21T17:18:49Z")

</div>

Thank you Jerome and Matthias. Both the work arounds are great help to me. The approches are good enough.

Hats off to all forum members for the help you extend in times of my need. This is the place where I learn Natural stuffs.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 21, 2012, 5:31pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/11 "2012-02-21T17:31:14Z")

</div>

> [@Jerome LeBlanc](#):
>
> ```auto
> 
> DEFINE DATA LOCAL                                                 
> 1 #A (A15) INIT <'MR JOHN DOE'>                                  
> 1 #LC (A2/26) INIT <' a',' b',' c',' d',' e',' f',' g',' h',      
> ' i',' j',' k',' l',' m',' n',' o',' p',' q', 
> ' r',' s',' t',' u',' v',' w',' x',' y',' z'> 
> 1 #UC (A2/26) INIT <' A',' B',' C',' D',' E',' F',' G',' H',      
> ' I',' J',' K',' L',' M',' N',' O',' P',' Q', 
> ' R',' S',' T',' U',' V',' W',' X',' Y',' Z'> 
> 1 #I (I4)                                                        
> END-DEFINE                                                        
> *                                                                 
> EXAMINE #A TRANSLATE INTO LOWER CASE               
> EXAMINE SUBSTRING(#A,1,1) TRANSLATE INTO UPPER CASE               
> FOR #I = 1 TO 26                                                  
> EXAMINE #A FOR #LC(#I) REPLACE WITH #UC(#I)                     
> END-FOR                                                           
> EXAMINE #A FOR ' ' REPLACE WITH '-'                               
> DISPLAY '=' #A                                                    
> END                                                               
> ```
> 
> Actually, that might not be too bad.

Not too bad, but can be simplified a bit 😉

```auto

DEFINE DATA LOCAL                                                
1 #A (A15) INIT <'MR JOHN DOE'>                                 
1 #LC (A2/26) INIT <' a',' b',' c',' d',' e',' f',' g',' h',     
                    ' i',' j',' k',' l',' m',' n',' o',' p',' q',
                    ' r',' s',' t',' u',' v',' w',' x',' y',' z'>
1 #UC (A2/26) INIT <'-A','-B','-C','-D','-E','-F','-G','-H',     
                    '-I','-J','-K','-L','-M','-N','-O','-P','-Q',
                    '-R','-S','-T','-U','-V','-W','-X','-Y','-Z'>
1 #I (I4)                                                       
END-DEFINE                                                       
*                                                                
EXAMINE #A TRANSLATE INTO LOWER CASE              
EXAMINE SUBSTRING(#A,1,1) TRANSLATE INTO UPPER CASE              
FOR #I = 1 TO 26                                                 
  EXAMINE #A FOR #LC(#I) REPLACE WITH #UC(#I)                    
END-FOR                                                          
DISPLAY '=' #A                                                   
END                                                              
```

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [February 22, 2012, 12:03pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/12 "2012-02-22T12:03:12Z")

</div>

Never mind; read the rest of the posts, and this is the same as Matthias’s solution. Looks like the most efficient as well as the most innovative.

will try later today for efficiency test.

steve

I do not have time to try this, and have to leave soon, so perhaps someone else could try this.

Define something like:

1 #extra (a51)  
1 redefine #extra  
2 #fill (a1) init \<’ '\>  
2 #string (a50) init \<‘MR. JOHN BROWN’\>

examine and translate #extra to lower case  
examine and translate first character of #string to upper case  
repeat loop  
examine #string for a blank giving number and position replace with ‘-’  
if number is zero, escape, you are done  
else  
add 1 to position  
examine and translate one character at position (after adding the one) to upper case

steve

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:01pm UTC](https://techcommunity.softwareag.com/t/examine-translate/99746/13 "2021-04-02T15:01:34Z")

</div>


