× 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.



Here would be a fine example of my point.   This logic flow is just not very
clear to me as a first-time viewer of the code.  

I'd bet that if you spent 30 minutes looking at what this code does and
forced yourself to rewrite it without the Leave and all of the If/else/endif
that you would reduce the lines of code by at least half and increase the
clarity dramatically.



 
---------------------------------
Booth Martin
http://www.martinvt.com
---------------------------------
-------Original Message-------
 
From: RPG programming on the AS400 / iSeries
Date: 01/31/05 16:11:10
To: 'RPG programming on the AS400 / iSeries'
Subject: RE: Suggested Technique
 
Booth;
 
This is a display driver for a multi screen maintenance program:
 
 
C                   DoU       exit or
 
C                               curScreen > maxScreen
 
 
 
C                   If        MSAG_match = *Off
Surrogate Keys do
C                   Eval      sndPM_Msg_Id = 'PVM0094'
not match.
  *MSAG data NOT current. No changes allowed. Press F8 in UPDATE mode to
refresh.
 
 
C                   Else
 
 
 
C                   If        editError
 
C                   If        screenChanged
 
C                   Eval      sndPM_Msg_Id = 'GEN0005'
 
 
 
C                   Else
 
C                   Eval      sndPM_Msg_Id = 'GEN0407'
 
C                   EndIf
 
 
 
C                   Else
 
C                   Eval      sndPM_Msg_Id = 'EDI0046'
 
C                   EndIf
 
 
 
C                   EndIf
 
 
 
  /Include QRPGCBSRC,CQMHSNDPM
 
 
 
C                   ExSr      displayScreen
 
  /Include QRPGCBSRC,CQMHRMVPM
 
 
 
C                   Select
 
 
 
C                   When      exit
 
C                   Leave
 
 
 
C                   When      cancel
F3
C                   If        curScreen > 1
Back up one screen
C                   Eval      curScreen = curScreen - 1
if necessary.
C                   Iter
 
 
 
C                   Else
 
C                   Leave
 
C                   EndIf
 
 
 
C                   When      prompt
F4
C                   ExSr      promptField
 
C                   ExSr      editScreen
 
 
 
C                   When      refresh
F5
C                   ExSr      loadScreens
 
 
 
C                   When      manualSend = *On
F7
C                   ExSr      manuallySend
 
 
 
C                   When      refreshMSAG = *On
F8
C                   ExSr      archiveRecord
 
 
 
C                   If        archiveRtnCode >= 0
 
C                   ExSr      defaultValues
 
C                   Eval      displayFields = PDDE911
 
C                   Eval      fKeys = *ALL'0'
 
C                   Eval      protectRecord = *Off
 
C                   Eval      curScreen = curScreen - 1
Display same screen
C                   ExSr      processData
 
C                   ExSr      loadScreens
 
C                   EndIf
 
 
 
C                   When      Not exit and Not cancel and
 
C                               Not protectRecord and
 
C                               Not prompt
 
C                   ExSr      editScreen
 
 
 
C                   EndSl
 
 
C                   If        Not screenChanged and
 
C                              Not editError and
 
C                              fKeys = *ALL'0'
 
C                   Eval      curScreen = curScreen + 1
 
C                   EndIf
 
 
 
C                   EndDo
 
 
 
-----Original Message-----
From: Booth Martin [mailto:booth@xxxxxxxxxxxx]
Sent: Monday, January 31, 2005 3:46 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Suggested Technique
 
 
That is the sort of thing that sets my teeth itching.  Would you have an
example of what code would always be done in every When block   (excepting,
of course, the When F3 block which we know we are resolving with a Leave in
this scenario)?
 
 
 
I am asking this question because of my interest, not in an effort to be a
wise guy.  It just is my experience that this sort of situation usually
means I've messed up the flow.
 
 
 
---------------------------------
 
Booth Martin
 
http://www.martinvt.com
 
---------------------------------
 
-------Original Message-------
 
 
 
From: RPG programming on the AS400 / iSeries
 
Date: 01/31/05 15:39:27
 
To: 'RPG programming on the AS400 / iSeries'
 
Subject: RE: Suggested Technique
 
 
 
<snip>
 
In my experience it
 
is almost always confusing to have additional code after the endsl,  At that
 
point we have done whatever we intended to do and the subroutine really is
 
at a logical end.
 
</snip>
 
 
 
Unless the code after the endsl should be performed for EVERY "When
 
block"...why duplicate the code for every block???
 
 
 
Thanks,
 
Tommy Holden
 
 
 
 
 
-----Original Message-----
 
From: Booth Martin [mailto:booth@xxxxxxxxxxxx]
 
Sent: Monday, January 31, 2005 3:28 PM
 
To: RPG programming on the AS400 / iSeries
 
Subject: RE: Suggested Technique
 
 
 
 
 
I have no issue with Leave as an opcode and even use it from time to time.
 
I have noticed though that generally after the exfmt mentioned in our
 
example we almost always have a select loop with the command keys,
 
validation, and entry choices.  Then we have an endsl.  In my experience it
 
is almost always confusing to have additional code after the endsl,  At that
 
point we have done whatever we intended to do and the subroutine really is
 
at a logical end.
 
 
 
 
 
 
 
In other words, it makes my teeth itch when I see code after the endsl, so I
 
would only rarely face the dilema you mention.
 
 
 
 
 
 
 
---------------------------------
 
 
 
Booth Martin
 
 
 
http://www.martinvt.com
 
 
 
---------------------------------
 
 
 
-------Original Message-------
 
 
 
 
 
 
 
From: RPG programming on the AS400 / iSeries
 
 
 
Date: 01/31/05 15:16:28
 
 
 
To: RPG programming on the AS400 / iSeries
 
 
 
Subject: RE: Suggested Technique
 
 
 
 
 
 
 
Because with DOU you will keep processing until the ENDDO.  Why do all the
 
processing until the ENDDO when you can just LEAVE?
 
 
 
 
 
 
 
Michael Tobey
 
 
 
Applications Analyst
 
 
 
Foremost Farms USA
 
 
 
mike.tobey@xxxxxxxxxxxxxxxxx
 
 
 
IBM Certified AS/400 RPG IV Developer & RPG IV Programmer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-----Original Message-----
 
 
 
From: Booth Martin [mailto:booth@xxxxxxxxxxxx]
 
 
 
Sent: Monday, January 31, 2005 3:09 PM
 
 
 
To: RPG programming on the AS400 / iSeries
 
 
 
Subject: Re: Suggested Technique
 
 
 
 
 
 
 
 
 
 
 
While I understand the idea of DO *hival coupled with a leave, why not just
 
 
 
say it in the first place, and have a DOU F3 and avoid the extra lines of
 
 
 
coding?  DOU F3 is pretty clear, too, isn't it?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
---------------------------------
 
 
 
 
 
 
 
Booth Martin
 
 
 
 
 
 
 
http://www.martinvt.com
 
 
 
 
 
 
 
---------------------------------
 
 
 
 
 
 
 
-------Original Message-------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
From: RPG programming on the AS400 / iSeries
 
 
 
 
 
 
 
Date: 01/31/05 15:03:41
 
 
 
 
 
 
 
To: rpg400-l@xxxxxxxxxxxx
 
 
 
 
 
 
 
Subject: Re: Suggested Technique
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Hi Alan,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<snip>
 
 
 
 
 
 
 
There are some brilliant programmers here, however, who advocate avoiding
 
 
 
 
 
 
 
use of the "iter" and "leave" op-codes. I find it hard to avoid using them
 
 
 
 
 
 
 
myself, but am still open on that issue.
 
 
 
 
 
 
 
</snip>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Now there's a statement! :-)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
I would be VERY interested to hear the reasons why LEAVE and ITER have
 
 
 
 
 
 
 
entered the "Hall of Shame" along with CABxx and GOTO.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Personally, I find them very useful and would need a very, very hard sell to
 
 
 
 
 
 
 
convince me to stop using them. They do not preclude well structured code,
 
 
 
 
 
 
 
they have definite branching end-points, and they do not make code less
 
 
 
 
 
 
 
readable to a developer: All long-standing accusations levelled at CABxx and
 
 
 
 
 
 
 
GOTO.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
For example - a classic screen loop:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// Display screen...
 
 
 
 
 
 
 
do *hival
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
exfmt screen
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// If user presses F3, leave screen loop...
 
 
 
 
 
 
 
if F3_pressed
 
 
 
 
 
 
 
leave
 
 
 
 
 
 
 
endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// Validate user input...
 
 
 
 
 
 
 
validateInput()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// If user enters invalid data, re-display screen, displaying error
 
 
 
 
 
 
 
message...
 
 
 
 
 
 
 
if userEntersInvalidData
 
 
 
 
 
 
 
iter
 
 
 
 
 
 
 
endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// If user elects to update current valid data, update and leave screen...
 
 
 
 
 
 
 
if F8_update
 
 
 
 
 
 
 
updateData()
 
 
 
 
 
 
 
leave
 
 
 
 
 
 
 
endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
enddo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
For me this code is simple - you can only leave the screen if you press F3
 
 
 
 
 
 
 
or update valid data. How do I know??? There's only two ways to leave the
 
 
 
 
 
 
 
screen - via the two LEAVE op-codes. If the code goes beyond the enddo then
 
 
 
 
 
 
 
F3 or F8 MUST have been pressed. In the case of F8, valid data MUST have
 
 
 
 
 
 
 
been entered. If the user enters invalid data then I force a re-display of
 
 
 
 
 
 
 
the screen (ITER) before any update code is reached - this forms a nice code
 
 
 
 
 
 
 
buffer, beyond which I am assured that the input data is valid.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
I also prefer using "do *hival" because I do not want any "implicit" exits
 
 
 
 
 
 
 
of the loop. I want to see the exit strategy EXPLICITLY coded within the
 
 
 
 
 
 
 
screen loop. My time is more precious than the CPU cycle time. If I can
 
 
 
 
 
 
 
read/modify the code faster because there are large marker flags in front of
 
 
 
 
 
 
 
me then my company saves money. It's the old adage - KISS!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Just my preference.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Cheers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Larry Ducie
 
 
 
 
 
 
 
--
 
 
 
 
 
 
 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
 
 
 
 
 
 
 
To post a message email: RPG400-L@xxxxxxxxxxxx
 
 
 
 
 
 
 
To subscribe, unsubscribe, or change list options,
 
 
 
 
 
 
 
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
 
 
 
 
 
 
 
or email: RPG400-L-request@xxxxxxxxxxxx
 
 
 
 
 
 
 
Before posting, please take a moment to review the archives
 
 
 
 
 
 
 
at http://archive.midrange.com/rpg400-l.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
....
 
 
 
--
 
 
 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
 
 
 
To post a message email: RPG400-L@xxxxxxxxxxxx
 
 
 
To subscribe, unsubscribe, or change list options,
 
 
 
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
 
 
 
or email: RPG400-L-request@xxxxxxxxxxxx
 
 
 
Before posting, please take a moment to review the archives
 
 
 
at http://archive.midrange.com/rpg400-l.
 
 
 
 
 
 
 
 
 
 
 
--
 
 
 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
 
 
 
To post a message email: RPG400-L@xxxxxxxxxxxx
 
 
 
To subscribe, unsubscribe, or change list options,
 
 
 
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
 
 
 
or email: RPG400-L-request@xxxxxxxxxxxx
 
 
 
Before posting, please take a moment to review the archives
 
 
 
at http://archive.midrange.com/rpg400-l.
 
 
 
 
 
 
 
 
 
 
 
...
 
--
 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
 
To post a message email: RPG400-L@xxxxxxxxxxxx
 
To subscribe, unsubscribe, or change list options,
 
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
 
or email: RPG400-L-request@xxxxxxxxxxxx
 
Before posting, please take a moment to review the archives
 
at http://archive.midrange.com/rpg400-l.
 
--
 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
 
To post a message email: RPG400-L@xxxxxxxxxxxx
 
To subscribe, unsubscribe, or change list options,
 
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
 
or email: RPG400-L-request@xxxxxxxxxxxx
 
Before posting, please take a moment to review the archives
 
at http://archive.midrange.com/rpg400-l.
 
 
 
 
 
..
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
 
 
 
NOTICE: This electronic mail transmission may contain confidential
information and is intended only for the person(s) named.  Any use, copying
or disclosure by any other person is strictly prohibited. If you have
received this transmission in error, please notify the sender via e-mail.
 
 
 
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
 
 

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.