Assume your string is in variable var1 then the new string in variable var2.

If your original string does not contain spaces you could also do the following:
var2=translate(compbl(translate(strip(var1)," ","_")),"_"," ");

If your original string contains spaces you would have to replace them by something exotic and replace them back after.
var2=translate(translate(compbl(translate(translate(strip(var1),"§"," ")," ","_")),"_"," ")," ","§");