[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: Hard-coded values and instr() command



Parijit,

   I'm in a bit of a cantankerous mood at the moment! Let's have some
fun! :)

   First of all, I had a typo and posted a correction on 01/18/1999. I
also stated several times to avoid quotes and commas if possible. You
missed it because your message is dated 01/19/1999. This code actually
worked on the version of SQR I was running at a client-site... I tested
it before posting... On my workstation at home it didn't work (4.0)...
PLUS I never said Don was wrong... He was absolutely correct... I
started out by saying we can expand on this a bit further... JUST TO SEE
HOW QUOTES COULD BE USED - I WOULDN'T DO IT MYSELF - BUT IF I NEEDED TO
FOR SOME DOPEY REASON! Now let me correct one of your statements...

You state confidently...

> The substitution variable (!!), mgr_codes, will not be substituted by
> the compiler during parsing coz it has been placed within quotes. The
> compiler will treat it as a string.

This is false... Ever see this before:

#define FILEPREFIX C:\TEMP\
let $FileName = '{FILEPREFIX}' || 'test.dat'

This would yield C:\TEMP\test.dat even with the quotes.... this is
proven as it's a standard PeopleSoft Convention... The files don't
appear as {FILEPREFIX}test.dat

Now I'm going to run a little experiment... As I mentioned the code I
posted didn't work in the 4.0 version I have on my workstation at
home... let's get it to work though shall we... Here's some code... I'll
run it and post the results...

  #define mgr_codes ''''MM'''',''''MA'''',''''VA''''
  let $mgr_code  = 'MM'
  let $mgr_codes = '{mgr_codes}'
  display $mgr_codes
  if instr($mgr_codes, $mgr_code, 1)
     display 'Okay'
  else
     display 'Oops'
  end-if

Notice the 4-quotes for 1-quote nonsense we now need to use...

RESULTS:
----------------------------------------------------------------
   As Of Date: 1999-01-19
Starting Time: 16.06.32
TDTEST SQR Test

''MM'',''MA'',''VA''      <=== Contents of $mgr_codes variable
Okay                      <=== Results of Instr Function

  Ending Time: 16.06.32

SQR: End of Run.
----------------------------------------------------------------

How about that! A slight modification and presto... this code is now
working as it did in the prior version! This is the actual SQR.LOG
file... It did work...

You also mentioned...

> There's no need for those extra quotes. They just complicate the
> readability of the program.

I agree and have always said that on this Users Group...
see article 'Re: Insert a single quote in to a variable. -Reply'
            'Tony DeLia' 12/11/1998


> In the second case, comma won't confuse the
> instr() function coz it has been placed inside quotes.

The original problem was due to substitution variable with embedded
commas - even though they were enclosed in quotes.

That's about all I have on this tired subject... as you can see I have
an answer for everything! I really enjoy this User Group! Good Day!

                   -Tony DeLia

PS - I shall reveal one of my biggest pet peaves...

You also included this tidbit:
> In fact, by using a variable, you're eating up extra memory.

I'm an expert in Assembler Language... I've been writing Assembler
programs for over 15 years... Always looking for the most efficient
instructions, reclaiming storage space at every turn, using R13 as both
the savearea pointer AND first base register, blah, blah, blah..
I laugh at the notion of 'eating up extra memory' using a variable
instead of a literal or substitution variable. If a substitution
variable is used does that mean it doesn't take up memory somewhere?
What's the difference in bytes between these 2 sections of code?

A: let $test = 'ABCDEFGHI'
   if instr($test,'G',1) ...

B: if instr('ABCDEDFGHI','G',1)

Are you saying the second example isn't using up memory. There most
likely is a pointer to a literal area where 'ABCDEFGHI' resides. The
variable assignment in A will take up some extra memory... But if you
asked me I would say it's pretty insignificant...


Parijat Sahai wrote:
>
> Tony,
>
> Firstly, the following code isn't correct:
>   let $mgr_codes = '{mgr_codes}'
>
> The substitution variable (!!), mgr_codes, will not be substituted by
> the compiler during parsing coz it has been placed within quotes. The
> compiler will treat it as a string. You could write
>   let $mgr_codes = {mgr_codes}
> But, it actually doesn't make a difference whether you use the string
> variable or the substitution variable in instr() function. In fact, by
> using a variable, you're eating up extra memory. What Don says is
> perfectly correct. The best solution is to use
>   #DEFINE mgr_codes 'MM;MA;VA'
> or, maybe,
>   #DEFINE mgr_codes 'MM,MA,VA'
> There's no need for those extra quotes. They just complicate the
> readability of the program. In the second case, comma won't confuse the
> instr() function coz it has been placed inside quotes.
>
> Parijat.
>
> >Date:         Sat, 16 Jan 1999 09:57:40 -0500
> >Reply-To: SQR-USERS@USA.NET
> >From: Tony DeLia <tdelia@EROLS.COM>
> >Subject:      Re: Hard-coded values and instr() command
> >To: Multiple recipients of list SQR-USERS <SQR-USERS@list.iex.net>
> >
> >Jason,
> >   We can expand on this a little further... when using a substitution
> >variable you have to be careful... it doesn't perform as a variable...
> >BUT if you move it to a variable first (in an Init procedure) then use
> >the variable for the INSTR...
> >
> >Like this:
> >
> >#define mgr_codes 'MM','MA','VA'
> >
> >let $mgr_codes = '{mgr_codes}'
> >
> >....
> >if  instr($mgr_codes, &jobcode, 1)
> >    do mgr_stuff
> >end-if
> >
> >This would work because the embedded commas won't interfere with the
> >syntax of the INSTR command... AND you can still define your jobcodes
> >with a substitution variable... I'm not too crazy about using commas as
> >delimeters when you don't need to...
> >
> >I'd rather use:
> >#define mgr_codes *MM*MA*VA* to be safe...
> >
> >
> >                                       -Tony DeLia
> >
> >
> >Don Mellen wrote:
> >>
> >> On Fri, 15 Jan 1999, Jason Penney wrote:
> >> ....
> >> > #DEFINE mgr_codes 'MM''MA''VA'
> >> ....
> >> > Examples of variables that resulted in instr() syntax errors:
> >> > #DEFINE mgr_codes 'MM','MA','VA'
> >> > #DEFINE mgr_codes 'MM';'MA';'VA'
> >> ....
> >> > So, the only way I've made it work is to have one quote at the
> >> > beginning of the list and double quotes between each value.
> Anybody
> >> > know why?
> >>
> >> Do any of the following look correct?
> >>   IF INSTR('MM','MA','VA',&jobcode,1) > 0
> >>   IF INSTR('MM';'MA';'VA',&jobcode,1) > 0
> >>
> >> The first one worked because it evaluated to
> >>   IF INSTR('MM''MA''VA',&jobcode,1) > 0
> >> when it compiled (which is a single string with a single quote
> seperating
> >> the elements). It would also work if you defined mgr_codes like
> >>   #DEFINE mgr_codes 'MM;MA;VA'
> >> resulting in
> >>   IF INSTR('MM;MA;VA',&jobcode,1) > 0
> >> when it is compiled.
> >>
> >> HTH,
> >>
> -----------------------------------------------------------------------
> >> Donald Mellen  | Ray Ontko & Co. - Richmond, IN -
> http://www.ontko.com/
> >> donm@ontko.com |  "In the beginning, there was nothing, which
> exploded"
> >
> >--
> >Tony DeLia
> >AnswerThink Consulting Group
> >PeopleSoft Solutions Practice - Delphi Partners
> >tdelia@erols.com
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com

--
Tony DeLia
AnswerThink Consulting Group
PeopleSoft Solutions Practice - Delphi Partners
tdelia@erols.com