× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



COBOL & RPG are pretty much the same regarding IF  ...  ENDIF.

RPG is always catching up to COBOL over the years, but RPG is now pretty
close.

Unfortunately RPG is still behind in many areas.  In your example, in RPG
you cannot test the first four bytes of a field without moving to another
field (as far as I know).

For example to test the first 4 bytes of your VNCOMPANY field in RPG, you
would have to 

EVAL TestWord = %subst(VNCOMPANY:1:4)

'0123456789'    check          TestWord               91
If *in91 = *on
*    code to process non-numeric data goes here
endif

These lines are not intuitive, and require a new variable and an indicator
to accomplish the simple task of testing for numeric.

In COBOL, it is very intuitive:

If VNCOMPANY (1:4) is numeric
*    code to process non-numeric data goes here
end-if

Regarding the IF ... ENDIF, RPG & cobol are pretty close.

Cobol has supported indented IF's for decades, RPG just started supporting
last year.

But the endif support is pretty much the same.

Most people would never suggest ending an IF stmt with a period.  Periods
are too hard to see, they can be commented out and seem to be there but are
just comments, and they arent so reliable.

When you have a nasty nested 
IF lots of code    
IF more code  
IF more code.

and someone deletes the last line (with the period), the entire program
behaves erroneously.  END-IFs prevent lots of these types of errors from
occurring.


Each IF should have a corresponding ENDIF in both RPG (ENDIF) and Cobol
(END-IF).

Not sure what you mean that Cobol can have multiple IF's on one stmt.  Are
you defining one stmt as one source line?  No one ever puts multiple IF's on
one source line I dont think.

But RPG supports the same nested IF's that COBOL does.  Cobol does have the
option of ending all the nested IFs with one period, but most would consider
that bad style.  It is too hard to tell what is going on.

Most would consider more than 1 or 2 levels of IF's bad style anyways!!  I
try to use RPG's SELECT or Cobol's EVALUATE to avoid nexted IF's, or use
separate procedures or subroutines.



-----Original Message-----
From: Dan [mailto:dbcerpg@xxxxxxxxx]
Sent: Tuesday, June 17, 2003 8:38 AM
To: COBOL Programming on the iSeries/AS400
Subject: RE: Testing for valid numeric in an alpha field


--- "Stone, Joel" <StoneJ@xxxxxxxxxxxxxxxx> wrote:
> Actually I think your RPG test is not reliable.  I think that TESTN will
let
> certain non-numerics slip through, only to explode sometime later
(probably
> in the middle of the night)!
> 
> In RPG it is much safer to use '0123456789' CHECK  variable_name to ensure
> numerics.
> 
> In COBOL, if you only want to test the first part of a field, try
> 
> If VNCOMPANY (1:4) is numeric
>    move VNCOMPANY to ws-vnd-company
> else
>    move zeros     to ws-vnd-company
> end-if. 

Thanks Joel.  The idea behind TESTN is that you have a value in an alpha
field that can be safely
moved into a numeric field without triggering a DDE.  Once TESTN blesses the
value and it is moved
into the numeric field, that's when we would test for negative values.  But
I like your idea using
the CHECK, I'll tuck that one away for next time.

Your example using the "end-if".  Is that essentially a no-op?  Does it
provide any more function
than if you'd just put the period at the end of the previous statement?  One
of the things I'm
still trying to get comfortable with in Cobol is the idea that you can have
multiple IF's in one
statement.  (As opposed to RPG, every IF has its own ENDIF.)  What about
nested IF's?  Does Cobol
support that?  (My brief exposure to Cobol 20 years ago left me with the
impression that the way
to accomplish that is to break it up into more sub-procedures.)

TIA, Dan

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
_______________________________________________
This is the COBOL Programming on the iSeries/AS400 (COBOL400-L) mailing list
To post a message email: COBOL400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/cobol400-l
or email: COBOL400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/cobol400-l.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.