Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unexpected THEN or ELSE error, not sure why I'm getting this...

241 views
Skip to first unread message

coryss...@gmail.com

unread,
Sep 8, 2007, 10:38:44 PM9/8/07
to
/*This program will spit out a file*/


/*USEAGE: readFile.REXX fileToRead [fileToWrite] */

Arg fileName outputFile

IF outputFile == '' THEN
outputFile = 'QBGLK.DDL'
ELSE
SAY "Writing .DDL to: " outputFile

DO WHILE Lines(fileName)
line = LineIn(fileName)
IF Pos('Class Name',line) >< 0 THEN
PARSE VALUE line WITH className colon target
SAY target
ELSE IF Pos('Field Name') >< 0 THEN
PARSE VALUE line WITH fieldName colon target
SAY target
ELSE IF Pos('Field Type') >< 0 THEN
PARSE VALUE line WITH fieldType colon target
SAY target
ELSE
SAY line
END

EXIT

I'm getting the following errors and i'm not sure why aftering looking
up the IF/IF ELSE/ELSE branching in rexx...

C:\Regina>regina readFile.rexx QBGLK
Error 8 running "C:\Regina\readFile.rexx", line 19: Unexpected THEN or
ELSE
Error 8.2: ELSE has no corresponding THEN clause

NOTE: Line 19 is the following line:
ELSE IF Pos('Field Name') >< 0 THEN

The file i'm reading in looks like this:
/*this is QBGLK */

Class Name : bridgeLink

Field Name : 1.3.18.0.0.3315.8.7.2
Field Type : CharVar
Field Value :

Field Name : 1.3.18.0.0.5273
Field Type : CharVar
Field Value :

Field Name : 1.3.18.0.0.3573
Field Type : ObjectLink
Field Value :

Field Name : 1.3.18.0.0.3579
Field Type : Smallint
Field Value : 4


Any help would be great!

coryss...@gmail.com

unread,
Sep 8, 2007, 10:50:10 PM9/8/07
to


What I was wanting my program to do was to open the text file and read
each line of the file while the file still has lines,
if the line of the file read in has the string "Class Name" then I
would like it to parse that string in the following manner:


PARSE VALUE line WITH className colon target

now className will have the className
colon will just be the ":"
and the target will be the value I'm after.
I would then like it to output the value. (in the long run i'm going
to write that value to a different file).

once it does that I would like it to read the next line of the file,
if that line contains either the className, or Field name or field
type, dependning on which line is read in, I would like it to also
output the value.

POS() should return a 0 if the string is not found, thats why i put
<> 0, meaning that string is found.

Arthur T.

unread,
Sep 8, 2007, 11:06:26 PM9/8/07
to
In
Message-ID:<1189305524.2...@r34g2000hsd.googlegroups.com>,
coryss...@gmail.com wrote:

<snip>


>DO WHILE Lines(fileName)
> line = LineIn(fileName)
> IF Pos('Class Name',line) >< 0 THEN
> PARSE VALUE line WITH className colon target
> SAY target
> ELSE IF Pos('Field Name') >< 0 THEN
> PARSE VALUE line WITH fieldName colon target
> SAY target
> ELSE IF Pos('Field Type') >< 0 THEN
> PARSE VALUE line WITH fieldType colon target
> SAY target
> ELSE
> SAY line
>END

<snip>


>
>I'm getting the following errors

<snip>


>C:\Regina>regina readFile.rexx QBGLK
>Error 8 running "C:\Regina\readFile.rexx", line 19: Unexpected THEN or
>ELSE

<snip>


>NOTE: Line 19 is the following line:
>ELSE IF Pos('Field Name') >< 0 THEN

The THEN clause takes a single statement. If you want more
than one statement in the THEN, you have to use a DO ... END
construct. Thus, the THEN is the PARSE command; the SAY is
independent of the THEN, and the ELSE has no corresponding THEN.

Also, you might want to make sure you use two operands in
your last two POS functions.

--
Arthur T. - ar23hur "at" intergate "dot" com
Looking for a z/OS (IBM mainframe) systems programmer position

coryss...@gmail.com

unread,
Sep 8, 2007, 11:41:36 PM9/8/07
to
ahh!
Thanks a ton!

Worked great!

Any ideas on why I'm getting this issue now?

'0' is not recognized as an internal or external command,
operable program or batch file.
30 *-* LineOut(outputFile,target)
+++ RC=1 +++


Here's my code:

Arg fileName outputFile

IF outputFile == '' THEN
outputFile = 'QBGLK.DDL'
ELSE
SAY "Writing .DDL to: " outputFile

/*constants for the SQL DDL*/

CREATE = "CREATE TABLE"


DO WHILE Lines(fileName)
line = LineIn(fileName)
IF Pos('Class Name',line) >< 0 THEN

DO
PARSE VALUE line WITH . . . target
LineOut(outputFile,CREATE)
LineOut(outputFile,target)
LineOut(outputFile,'(')
SAY target
END
ELSE IF Pos('Field Name',line) >< 0 THEN
DO
PARSE VALUE line WITH . . . target
LineOut(outputFile,target)
SAY target
END
ELSE IF Pos('Field Type',line) >< 0 THEN
DO
PARSE VALUE line WITH . . . target
LineOut(outputFile,target)
LineOut(outputFile,',')
SAY target
END
ELSE
say line
END

EXIT

It doesn't like any of the LineOut functions...

I looked up LineOut and its the following syntax:
LINEOUT(testdata.txt,VarString)
writes the contents of VarString as a line at the current write
position in "testdata.txt"


What I would like my program to do is the following:
/*If the line of text contains 'Class Name' then I would like to
write to another file, the following string
CREATE TABLE <target> (
Here's my code that would do that:

IF Pos('Class Name',line) >< 0 THEN

PARSE VALUE line WITH . . . target
LineOut(outputFile,CREATE)
LineOut(outputFile,target)
LineOut(outputFile,'(')


It seems to be i'm following the syntax correctly.

Thanks again!

Mr Coffee

unread,
Sep 9, 2007, 12:04:43 AM9/9/07
to
Ahhh!


It seems the format is:
CALL LineOut outputFile,"CREATE TABLE"
CALL LineOut outputFile,target
CALL LineOut outputFile,'('


Not sure why this book tells me a different syntax!

>_<;;

Arthur T.

unread,
Sep 9, 2007, 12:25:08 AM9/9/07
to
In
Message-ID:<1189310683....@19g2000hsx.googlegroups.com>,
Mr Coffee <coryss...@gmail.com> wrote:

Because you can also use
x = LineOut(outputFile,target)

>'0' is not recognized as an internal or external command,
>operable program or batch file.
> 30 *-* LineOut(outputFile,target)
> +++ RC=1 +++

The messages you got were because it *was* executed and
evaluated to a 0 (the return code); it then tried to execute that
'0'.

BTW, you might want to try to keep your nyms the same, at
least within the same thread.

Mr Coffee

unread,
Sep 9, 2007, 2:09:08 AM9/9/07
to
On Sep 9, 12:25 am, Arthur T. <art...@munged.invalid> wrote:
> In
> Message-ID:<1189310683.112757.78...@19g2000hsx.googlegroups.com>,

Thanks Arthur for the info.

Whats an nyms?


Jeremy C B Nicoll

unread,
Sep 9, 2007, 5:44:26 AM9/9/07
to
coryss...@gmail.com wrote:

> /*This program will spit out a file*/
>
>
> /*USEAGE: readFile.REXX fileToRead [fileToWrite] */
>
> Arg fileName outputFile

Can I make a comment on your code? For someone other than the author (and
that's everyone on this list that bothers to look at posted code) who is
looking at it, they've mentally got to remember four file-related variable
names already. You've mentioned

fileToRead
fileToWrite

(admittedly as example positional arguments), and

fileName
outputFile

It's much much clearer, in my opinion, if you pick sensible variable names
and use them in the example call and all other commenst as well as in the
code. So in this case there'd just be two names to remember.

Since REXX doesn't need you to use mixed-capitalisation names like
"fileToRead", personally I wouldn't do it. Every time you type that var
name rexx won't require you to get the capitalisation right - you could just
as easily type 'FILETOREAD' in one statement and 'filetoread' in another and
it will still work... but suppose you do type some one way and some another.
If you later use search & replace to revise some vars' names and you forget
to make that process case-insensitive, you might miss some of them. I think
effort spent keeping the capitalisation right is a waste of time.

I also dislike pairs/groups of var names like

fileName
outputFile

Why does one of them start with "file" while the other ends with that?

What's wrong with eg: inputfile or infile or ifile
and: outputfile outfile ofile

To have 'fileName' as one var name makes me wonder if we're also going to
have 'fileSize', 'fileDate' etc?

Finally, noting that "USEAGE" is not the way to spell that word... I'd be
more likely to have something like:

> /*USAGE: readFile.REXX ifile [ofile] */
>
> Arg ifile ofile


> DO WHILE Lines(fileName)
> line = LineIn(fileName)
> IF Pos('Class Name',line) >< 0 THEN
> PARSE VALUE line WITH className colon target
> SAY target

How you indent code is your business, but my experience says that using a
6-character indent is too much. Very soon some of your more deeply nested
lines of code are going to be so far over to the righthandside of the line
that (on most terminals/ editor windows) you'll have to scroll the window to
see them, and then won't see the stuff at the lefthandside. You'll not do
yourself any favours that way.

Also unless you print on landscape paper you'll have lines truncated, or if
the print process wraps the long lines that will ruin the visual indenting.

And, if you post code snippets here and lines wrap in the short-line-length
windows that most people use to read news posts - typically only 70-75
characters long - that'll not help. In fact even if you use only 2- or 3-
character indents you may still need manually to reformat sample code before
posting it here to make it comprehensible to other people's news readers.


--
Jeremy C B Nicoll - my opinions are my own.

Mr Coffee

unread,
Sep 9, 2007, 6:24:14 AM9/9/07
to
Thanks for the programmming tips.

I'm use to programming in Java/C++ mainly and I've been taught using
camel/pascal notation where everything is case-sensitive.
So local varables look like localVar, constants look like CONSTANTS,
Functions look like Functions();
I'm also use to IDE's auto indenting for me, so I just use TAB with
REXX.

This is my first program in REXX so its pretty sloppy :)

If I end up doing more programming projects in REXX I'm sure I'll find
out that TAB will be too big of a indent.

ML

unread,
Sep 9, 2007, 6:22:53 AM9/9/07
to

>> Arg fileName outputFile

PARSE ARG, if case-sensitivity should be maintained.

Your book, IIRC, also mentions a way to use long filenames. Use it.
It's the example with: IF Left(filename,1)='"' THEN DO ...

---

ML

unread,
Sep 9, 2007, 6:34:01 AM9/9/07
to

> constants look like CONSTANTS, Functions look like Functions();

That doesn't explain your use of "CALL STRIP string"... :-)

---

Oleg Lego

unread,
Sep 9, 2007, 11:08:35 AM9/9/07
to
On Sat, 08 Sep 2007 23:09:08 -0700, Mr Coffee posted:

"nyms" = pseudonyms. You posted under your gmail address and then as
Mr. Coffee. No real biggie, but it's confusing for those trying to
help out.

Mr Coffee

unread,
Sep 9, 2007, 12:52:25 PM9/9/07
to

Thanks for the tip.

I've only used these once before.

PS: how do you get a signature at the bottom of your post?

Oleg Lego

unread,
Sep 9, 2007, 11:32:51 PM9/9/07
to
On Sun, 09 Sep 2007 09:52:25 -0700, Mr Coffee posted:

It depends entirely on your newsreader program. If you are reading
through Google Groups or GMail, I can't help you.

Arthur T.

unread,
Sep 9, 2007, 11:58:38 PM9/9/07
to
In Message-ID:<4le9e31hkv9a7qh06...@4ax.com>,
Oleg Lego <r...@atatatat.com> wrote:

>On Sun, 09 Sep 2007 09:52:25 -0700, Mr Coffee posted:

<huge snip>


>>PS: how do you get a signature at the bottom of your post?
>
>It depends entirely on your newsreader program. If you are reading
>through Google Groups or GMail, I can't help you.

Also, when you do find out how, make sure it meets the
standard. One very important thing is that the first line be
exactly "-- "; that is, dash dash space, with nothing following.
Many newsereaders recognize that standard and won't try to quote
the sig. (You'll also find some people who'll make nasty comments
if you have more that 4 lines following that separator line. The
RFC suggests a max of 4 lines.)

Mr Coffee

unread,
Sep 10, 2007, 4:04:02 AM9/10/07
to
On Sep 9, 11:58 pm, Arthur T. <art...@munged.invalid> wrote:
> In Message-ID:<4le9e31hkv9a7qh06rulficg4kfqgj3...@4ax.com>,

Thanks for the tips guys!
Yah I just use groups.google.com

Mickey

unread,
Sep 13, 2007, 10:14:46 AM9/13/07
to

IF Pos('Class Name',line) >< 0 THEN
PARSE VALUE line WITH className colon target
SAY target

ELSE IF Pos('Field Name') >< 0 THEN
PARSE VALUE line WITH fieldName colon target
SAY target
ELSE IF Pos('Field Type') >< 0 THEN
PARSE VALUE line WITH fieldType colon target
SAY target
ELSE
SAY line

This should be replaced with a Select statement. What you have here is
a case, you should use case logic, it is FAR more readable....

Select
When Pos('Class Name',line) >< 0 THEN


PARSE VALUE line WITH className colon target
SAY target

When Pos('Field Name') >< 0 THEN


PARSE VALUE line WITH fieldName colon target
SAY target

When Pos('Field Type') >< 0 THEN


PARSE VALUE line WITH fieldType colon target
SAY target

Otherwise
SAY line
End

Mickey

Gerard Schildberger

unread,
Sep 13, 2007, 12:05:37 PM9/13/07
to
| Mickey wrote:

You still need a DO---END for each of the
WHEN---THEN structures since you have more than one
REXX statement for the "THEN". Also, I reduced
the PARSE statements to a more simplier form:

========================================================
select
when pos('Class Name',line)\==0 then
do
parse var line classname colon target
say target
end
when pos('Field Name',line)\==0 then
do
parse var line fieldname colon target
say target
end
when pos('Field Type',line)\==0 then
do
parse var line fieldtype colon target
say target
end
otherwise say line
end
========================================================

I also corrected the two WHEN POS ... to have both
arguments specified. __________________________Gerard S.

Mr Coffee

unread,
Sep 13, 2007, 10:49:57 PM9/13/07
to

thanks for the responce...

WHen do you know when to use >< 0 or \== 0? do the evaluate to the
same thing?

Gerard Schildberger

unread,
Sep 13, 2007, 11:48:59 PM9/13/07
to
| Mr Coffee wrote:

No, they aren't the same thing. x \== y does an exact compare,
while x >< y is the same as x \= y

The POS function always returns a a non-negative integer, never
0.0 +2 or 3e2, so for those functions which return an
integer, you can always use exact comparisons for equal/not equal.
__________________________________________________________Gerard S.


Mr Coffee

unread,
Sep 14, 2007, 9:57:03 AM9/14/07
to

Thanks for the explanation!

I like that syntax a lot better than >< as well.

--
IBM Intern

0 new messages