top of page

Structured Programming

—Structured programming is an approach to design and coding that makes programs easy to understand, debug and modify

—Structures commonly used in every computer program

  •    Sequential Operation

  •    —Conditional Branching

  •    —Repeating an operation based on certain conditions

 

The structured programming operations are :

—ANDxx   (And)

—CASxx  (Conditionally invoke subroutine)

—DO  (Do)

—DOUxx  (Do Until)

—DOWxx  (Do While)

—ELSE    (Else)

ENDyy  (End)

—IFxx  (If/Then)

—ITER   (Iterate)

—LEAVE  (Leave a DO group)

—ORxx  (Or)

—OTHER  (Otherwise Select)

—SELEC   (Begin a select group)

—WHxx   (When true then select)

—

In the ANDxx, CASxx, DOUxx, DOWxx, Ifxx, ORxx, and WHxx operations, xx can be :

 

 xx  Meaning

— GT  Factor 1 is greater than Factor 2

— LT  Factor 1 is less than Factor 2

— EQ  Factor 1 is equal to Factor 2

 —NE  Factor 1 is not equal to Factor 2

— GE    Factor 1 is greater than or equal to Factor 2

— LE  Factor 1 is less than or equal Factor 2

— Blanks  Unconditional processing (CASxx only)

—

In the ENDyy operation, yy can be :

 

 yy  Meaning

— CS  End for CASxx operation

 —DO  End for DO, DOUxx, DOWxx operation

— IF  End for IFxx operation

— SL  End for SELEC operation

— Blanks  End for any structured operation

 

  • —If a structured group, contains another complete structured group, together they form a nested structured group

  • —They can be nested to a maximum depth of 100 levels

—

Example of nested structured group 3 levels deep :

+-----------------------------  DO

|  +-------  DO

|  +-------ENDDO

|  +----------------IFxx

|  |  +-------SELEC

|  |  |  WHxx

|  |  +-------ENDSL

|  +----------------ELSE

|  +----------------ENDIF

+-----------------------------ENDDO

 

—In RPG/400 IF-THEN-ELSE Constructs are IFxx, ELSE, END

C*

C  FLDA  IFEQ  FLDB

C  ....

C  ELSE

C  ....

C  END

—Other Ways to Create Conditional Branches

—CASxx, GOTO, CABxx operations

 

—Repeating an operation, RPG/400 implements three repeat operations Do While, Do Until and Do by DOWxx, DOUxx, DO, and END

—

Example

—Do While

C*  

C  FLDA  DOWLT  FLDB

C  ... 

C  ADD A    FLDB         

C  ...

C  END

 

—Do Until

C*

C  FLDA  DOUGT  FLDB

C  ....

C  ADD   INC  FLDA

C  ....

C  END

—Do

C*

C  1  DO  101  INDEX

C  ....

C  INDEX  ADD  TOTAL  TOTAL

C  ....

C  END   2

 

bottom of page