Link to home
Start Free TrialLog in
Avatar of mustish1
mustish1

asked on

Out of sequence

I am not understanding this error, can any one please help me out?

Thanks
Screenshot.png
Screenshot2.png
ASKER CERTIFIED SOLUTION
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mustish1
mustish1

ASKER

Listing of the code. I am sorry I am not understanding it where exactly the error is

Encl: Listing
rpgcode.txt
Personally, when faced with this kind of error, I find it best to print out the code on paper and use a pencil to "match" the beginning and ending of all blocks (DOx, IF, subroutines, etc).

Almost always, that points me to the problem.

HTH,
DaveSlash
I wish I had time to go through and debug your code every time you hit an error like this, but I just don't.  You need to learn how to solve these problems yourself, so I suggest you do just what DaveSlash and I suggest:

Print out a copy, and desk check your code blocks.  Make sure that for every BEGSR there is an ENDSR.  For every IF or IF/ELSE there is an ENDIF.  For every DOx there is an ENDDO.

That is the cause of your problem.  Someplace you have more BEGSR than ENDSR, or more IF than ENDIF or more DO than ENDDO.  Or maybe you have too many ENDxx.

Either way, match them up and you'll find your problem.  Start from the inside out.

This is a very, very basic programming problem that happens in just about every programming language.  

A good way to avoid it is to always code your block start/end statements together, and then fill the code in between them.

When I code a "DO" block, I immediately code the ENDDO, like this:

DO
ENDDO

Then I go back an insert the code that goes between them.
 
When I code an IF block, I do this:

IF
ENDIF

or

IF
ELSE
ENDIF

and then fill in the code that goes in each section.  Doing that will eliminate these kinds of errors, which are usually just caused by having the wrong number of ENDxx statements.
Even better .... code in modern "free-format" ILE RPG and use indentation in a logical way to indicate "blocks".

HTH,
DaveSlash
Thanks