Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

dcl substitution

ocasio
Occasional Contributor

dcl substitution

I have attempted using the quote counting method using the following:$ WRITE WRITELINE "(TO_DATE("'"''BEG_CUR_MON'"'", 'YYYYMMDD')) AND "
$ WRITE WRITELINE "(TO_DATE("'"''END_CUR_MON'"'", 'YYYYMMDD'));"

and it produces:
(TO_DATE(", 'YYYYMMDD')) AND
(TO_DATE(", 'YYYYMMDD'));

what I need it to write is out put like the following:
(TO_DATE('03/01/2006', 'MM/DD/YYYY')) AND
(TO_DATE('03/31/2006', 'MM/DD/YYYY'));

I am uncertain as how to set up a sysmbol with ascii value - any advice would be greatly appreciated

thanks in advance
13 REPLIES
Willem Grooters
Honored Contributor

Re: dcl substitution

F$FAO is your friend here ;-)

$ dd=f$cvtime(,,"DAY") ! day as a string
$ mm=f$cvtime(,,"MONTH") ! month as a string
$ yyyy=f$cvtime(,,"YEAR") ! year as a string
$ WD=F$FAO("TO_DATE(''''!AS-!AS-!AS'''', MM/DD/YYYY)",mm,dd,yyyy)
$! The result
$ sho symb wd
WD = "TO_DATE('04-20-2006', MM/DD/YYYY)"

which can be used to create the string to write.
Willem Grooters
OpenVMS Developer & System Manager
ocasio
Occasional Contributor

Re: dcl substitution

Thanks so much - I'll look into trying that lexical; however, I'm not certain I will be able to use this because what I need to do is read a parameter file which contains the beginning & ending dates of the month along with federal fiscal year - each is stored as a symbol
ocasio
Occasional Contributor

Re: dcl substitution

on second thought I might be able to use F$EXTRACT and some how do it that way - I think I'll give it a whirl - thanks again - got to check out the f$fao first
Karl Rohwedder
Honored Contributor

Re: dcl substitution

Ocasio,

to insert a ' character you may have to split the WRITE into several parts, see the attached example (I've attached an example in order to better distinguish between " and ''.

regards alle
Alan Bruns
Occasional Visitor

Re: dcl substitution

How about this:

$ WRITE WRITELINE "(TO_DATE(""''BEG_CUR_MON'"",""YYYYMMDD"")) AND "
$ WRITE WRITELINE "(TO_DATE(""''END_CUR_MON'"",""YYYYMMDD""));"

There's a space between the "AND" and the double quote. (Gotta love this stupid short textbox...)

The double single quotes before and single single quote after cause symbol substitution within the WRITE command, and the double double quotes cause a single double quote to be written in the output. (Got that? ;-)
Alan Bruns
Occasional Visitor

Re: dcl substitution

Great. What displays in this font doesn't look like what I typed. So we'll do it in text...

This: "(TO_DATE(
is followed by two double quotes and two single quotes.

BEG_CUR_MON
is followed by one single quote and two double quotes, a comma, and two double quotes.

YYYYMMDD
is followed by two double quotes, two close parens, a space, the word AND, and a double quote.

Follow the same pattern in the 2nd statement.
ocasio
Occasional Contributor

Re: dcl substitution

Thanks for your attempt to assist - I don't know if our system differences would cause this but the output which I get is:
23 TO_DATE(TO_CHAR(P.POST_DATE, 'YYYYMMDD'), 'YYYYMMDD') BETWEEN
24 (TO_DATE("20060401","YYYYMMDD")) AND
25 (TO_DATE("20060430","YYYYMMDD"));
(TO_DATE("20060430","YYYYMMDD"))

I need single quotes and I've tried numerous combinations - yours was very close -and I very much appreciate your attempt to assist
Jan van den Ende
Honored Contributor

Re: dcl substitution

ocasio,

the postings using single, double, and/or doubkle-single quotes in the forum display are VERY confusing.
They become MUCH clearer if you cut-and-paste them into some fixed-font editor, such as (being VMS :-) ) TPU or EDT. But *UX vi or even M$ notepad are also well suited.

On building complex, multi-quoted lines, I usually get results easiest by either using a symbol where I want that character to appear, or by having one write with multiple concatenated strings.
Example of the latter"
$ WRITE LINE """" + "XYZ''some_symbol'" + """blablabla" + ....(etc)

hth

Proost.

Have one on me (maybe in May in Nashua?)

jpe



Don't rust yours pelled jacker to fine doll missed aches.
Hein van den Heuvel
Honored Contributor

Re: dcl substitution

ocasio,

Normally you can output a single quote by just writing a single quote.
Two adjacent single quotes are the intro for a string substitution request: ''var'
A third single quote finishes this sequence, whether the variable name was found or not or even absent.

Your dcl gets specifically tricky because that simple simple single quote meant to be output, gets 'eaten' by the two single quotes leading in the variable name to be substituted.
I actually think there may be a bug in this space in DCL, but would recommend simply not going there for maintainability and readability reason. The solution then is to just concatenate the pieces of string with variables using either a + sign in an assignment statement.
In a write statement you can actually choose between + and ,
They have the same effect, but work differently.

As Karl suggests:

$ WRITE WRITELINE "(TO_DATE('","''BEG_CUR_MON'","','DD/MM/YYYY'))"

And that works, but is a still a little hard to read.

May I suggest a construction like:

write x "string", variable, "other string"

In your example:

$write WRITELINE " (TO_DATE('", BEG_CUR_MON, "', 'MM/DD/YYYY')) AND"
$write WRITELINE " (TO_DATE('", END_CUR_MON, "', 'MM/DD/YYYY'));"

because you have commas in your strings I would suggest using the +

$write WRITELINE " (TO_DATE('" + BEG_CUR_MON + "', 'MM/DD/YYYY')) AND"
$write WRITELINE " (TO_DATE('" + END_CUR_MON + "', 'MM/DD/YYYY'));"




Regards,
Hein.
John Yu_1
Valued Contributor

Re: dcl substitution

$ WRITE WRITELINE "(TO_DATE('"+"''BEGIN_CUR_MON'','YYYYMMDD')) AND"

will get you the first piece.

Hope this helps
-john
Artificial intelligence is rarely a match for natural stupidity.
John Yu_1
Valued Contributor

Re: dcl substitution

Sorry, the code gets butchered by the site
Artificial intelligence is rarely a match for natural stupidity.
Ken Robinson
Valued Contributor

Re: dcl substitution

I see this this is an old thread, but if the OP is still looking for a solution, here's one that I use:

Define two symbols, one for a single quote and one for a double quote, then use those when needed, instead of trying to figure out the right number of single or double quotes needed to produce on one the output.

Example:

$!
$! This is a sample command procedure which
$! demonstrates how to include single and double
$! quotes into a string
$!
$ single_quote :== "'
$ double_quote :== """
$ write sys$output single_quote
$ write sys$output double_quote
$ write sys$output "this string has a single quote (",single_quote,") and double quote (", double_quote,") in it"
$ new_sym = "this new string has a single quote (" + single_quote + ") "
$ new_sym = new_sym + "and double quote (" + double_quote + ") in it also."
$ write sys$output new_sym

The sample procedure is also attached.

Ken
Hein van den Heuvel
Honored Contributor

Re: dcl substitution

Ayup, that's what I use also when it gets too confusing.
'xcept that I use the symbols "q" and "qq" :-).

Hein.