PDA

View Full Version : Initializing a field with the value of '



Guest.Visitor
01-01-1995, 02:00 AM
This is problably RPG IV "101", but how do I set a field called field_1 and intialize the value to be ' ? (single Apostrophe) For example, like this (although this does not work): d field_1 s 1 inz(''') Thanks

J.Wells
02-21-2001, 08:24 AM
Add one more '. <pre> D x s 1 inz('''') </pre> I have never understood this! HTH, Joe

Guest.Visitor
02-21-2001, 08:25 AM
You could probably initialize the field with the hex value of '. I'm not sure what hex code that is though.

Guest.Visitor
02-21-2001, 08:30 AM
Don't know if RPG can deal with Hex but a quote is Hex'7D' bobh

Guest.Visitor
02-21-2001, 08:34 AM
Joe, You're right, it does seem weird, but the concept is that inside of single quotes, it takes 2 single quotes to make 1. '(''for what it''s worth'')' = ('for what it's worth') Kevin

Guest.Visitor
02-21-2001, 10:08 AM
This works as well using the hex code: D Field_1 S 1A Inz(x'7D')

D.Handy
02-21-2001, 10:20 AM
Dave, <font color=blue>You could probably initialize the field with the hex value of '</font> Indeed you could, and as Bob points out you could try x7D. But there is a downside to doing it this way: if you ever have to deal with various code pages for multinational support or translation (who knows who will buy the company?), using the hex constant will not necessarily translate correctly. Using a constant of '''' (four single quotes) will translate to a single quote in other pages, regardless of what hex value that turns out to be. Since RPG only allows the single quote as a string constant delimiter, embedded single quotes as in o'clock must be doubled so the language parser knows it was intentional rather than an error. Thus o'clock becomes o''clock or 'o''clock' as a string constant. Remove the letters and what remains are four single quotes. Looks weird to someone who hasn't seen it before, but then so does RPG. <g> Doug

Guest.Visitor
02-21-2001, 01:08 PM
Thanks to all for your help

Guest.Visitor
02-21-2001, 02:39 PM
<font color=blue>Looks weird to someone who hasn't seen it before, but then so does RPG.</font> <pre> D oug W hy(do) y o u S aytha t:'?' </pre>

Guest.Visitor
02-21-2001, 02:52 PM
Doug is right barbara. Its weired for rpg when it sees a " ' " somewhere inbetween the string. How will it interpret the " ' " as part of the string or end of " ' ". Isn't it weired for RPG?? Elan

D.Handy
02-21-2001, 05:37 PM
Elan, <font color=blue>"How will it interpret the " ' " as part of the string or end of " ' ". Isn't it weired for RPG??"</font> The reason the compiler wants the second quote is precisely to interpret between an embedded single quote and the ending delimiter. When it sees two consecutive quotes within a string it knows a single quote is desired instead of the first quote denoting the end of the string. IMHO, it would be weird for RPG to *not* use some escape mechanism for the embedded delimiter. In the early days of punch cards and 48-character belts on impact printers, using a second quote probably made alot more sense than a character like . And you also (at the time) didn't have a double quote character on the print belt, so it didn't make sense to allow your choice of either a single or double quote as the beg/end delimiter with the opposite available as an embedded character. Doug