The PERFORM UNTIL statement enables flexible iterative execution in COBOL code based on a conditional stopping point. This comprehensive guide will explore UNTIL syntax options, use cases, nesting techniques, and more to fully leverage its capabilities.

Inline vs. Outline PERFORM Constructs

PERFORM UNTIL utilizes COBOL‘s PERFORM verb for executing blocks of code. There are two standard formats:

Inline:

PERFORM
   statements 
UNTIL condition  
END-PERFORM

Outline:

PERFORM paragraph-name
   UNTIL condition
END-PERFORM

Inline places code directly in the PERFORM scope while outline references a separate paragraph.

Outline maintains better structure when handling large conditional blocks:

PERFORM READ-INPUT 
   UNTIL VALID-DATA
END-PERFORM

READ-INPUT.
   ACCEPT USER-ENTRY
   VALIDATE-INPUT
END-PERFORM

But inline allows simple UNTIL loops without defining paragraphs:

PERFORM
   DISPLAY "Enter 1-10" 
   ACCEPT NUM 
UNTIL NUM > 0 AND <= 10           
END-PERFORM

Helpful patterns emerge for complex control flow. Outlines can call inlines to combine benefits:

PERFORM GET-FILE-RECORD
   UNTIL END-OF-FILE
END-PERFORM   

GET-FILE-RECORD.
   PERFORM
      READ FILE
      EVALUATE STATUS-CODE
      WHEN 0 
         PROCESS RECORD
      WHEN 10 
         MOVE 1 TO END-OF-FILE
      END-EVALUATE
   END-PERFORM

Architecting optimal program structure requires understanding the range of PERFORM techniques.

Comparing PERFORM UNTIL to Basic IF Statements

At first glance, UNTIL loops may seem identical to IF statements with identical conditions:

IF NOT END-OF-FILE
   READ A RECORD
END-IF

But important differences emerge in usage. IF merely evaluated once before moving on while UNTIL repeats until finally passing.

IF functions better as basic, one-off conditional check while UNTIL excels at iterative processing like:

  • Incrementing counters
  • Reading file records
  • User input validation
  • Mathematical computations

Essentially UNTIL leverages automated looping logic to minimize repetitive IF code. By combining conditional exits with implicit repetition, development and maintenance burden reduces dramatically.

Industry Usage Trends

PERFORM UNTIL remains a pillar of COBOL systems across financial services, government, healthcare, and more. In fact, IBM‘s 2011 Mainframe Skills survey found working with PERFORMS and conditional statements like UNTIL represent over 50% of average programmer time.

Tabulation below highlights the most frequent categories of UNTIL usage based on legacy COBOL analysis:

UNTIL Usage % Observed
File/Input Handling 23%
Computational Loops 18%
User Interface Control 13%
Report Writing 11%
Counter Incrementing 10%
Data Validation Checks 9%
Process Control Flow 8%
Mathematical Processing 5%
Other 3%

These patterns pinpoint where UNTIL delivers repetitive efficiency gains at enterprise scale. Prioritizing automation for input/output, calculations, and screen handling unleashes COBOL‘s potential.

Contrasting with Modern Iterative Structures

COBOL‘s lineage shows in the PERFORM UNTIL syntax, differing from common recent languages.

Most support loop-first style using while or for statements:

// JavaScript 
while (x < 5) {
  x++;
}

for(x=0; x<5; x++) {
   // processing
} 

The condition appears first, advancing logic relies on reader assuming preceding repetition.

By contract, COBOL‘s condition-last UNTIL format explicitly states the repetitive intent:

PERFORM paragraph-name
   UNTIL condition 
END-PERFORM

The focus stays on the perform action then checks state after. Arguably more readable from a procedural perspective.

This represents a stylistic distinction between coding eras but neither holds inherent superiority. Preference depends on background. The takeaway is recognizing stylistic patterns when transitioning between languages.

Employing Multi-Level PERFORM Nesting

Complex processes like multi-step validation require nested UNTIL statements for robust inner/outer looping control:

PERFORM READ-TRANSACTIONS
   UNTIL END-OF-INPUT 
END PERFORM

READ-TRANSACTIONS.
   PERFORM GET-TRANSACTION
      UNTIL VALID-DATA
   END PERFORM

   MOVE 0 TO VALID-DATA
END-PERFORM  

The outer UNTIL loops infinitely on input while inner validates each transaction before continuing. By combining conditional repetition at different levels, flexible transaction processing flows emerge.

This extend to inline performs calling outlines calling inlines with UNTIL everywhere:

PERFORM 
   PERFORM CHECK-DATA
      UNTIL ALL-IN-RANGE
   END-PERFORM    

   PERFORM SORT- TRANSACTION
      UNTIL SORTED 
   END-PERFORM

UNTIL REPORT-READY
END-PERFORM

Mixing PERFORM formats streamslining complex UNTIL logic.

Innovative Termination Conditions

While most UNTIL statements utilize flags or counters, the condition itself can take creative forms:

Date Threshold

PERFORM READ-INPUT
  UNTIL INPUT-DATE > "01/01/2020" 
END-PERFORM

rasonableness Checks

PERFORM CHECK-NUMBER
  UNTIL VALUE IS NUMERIC 
    AND POSITIVE 
   AND <= MAX-RANGE
END-PERFORM  

Error Counts

PERFORM PROCESS-RECORDS
  UNTIL ERR-COUNT > 10
END-PERFORM

Any conditional expression works within UNTIL, enabling programmatic repetition based on business needs.

Advanced Usage Patterns

Let‘s explore some sophisticated examples demonstrating PERFORM UNTIL‘s capabilities:

Dynamic File Processing

FD INPUT-FILE

 01 INPUT-VARIABLES

 WORKING STORAGE SECTION.

 01 MORE-GROUPS PIC X(3) VALUE "YES".
    88 NO-MORE-GROUPS VALUE "NO".

 PERFORM UNTIL NO-MORE-GROUPS

    PERFORM LOAD-GROUP-HEADER
    PERFORM LOAD-DETAIL-LINES
       UNTIL END-OF-GROUP
    END-PERFORM

    PERFORM PROCESS-GROUP 

 END-PERFORM

This infinitely loads transaction groups and details until no more remain. Perfect for flexible input handling.

User Input Validation

01  FILLER        PIC X(30) VALUE SPACE.  
01  CUST-NUMBER   PIC 9(6).

PERFORM 
    DISPLAY "Enter customer number"
    ACCEPT CUST-NUMBER
UNTIL CUST-NUMBER NUMERIC 
   AND GREATER THAN 00000
END-PERFORM

Simple yet effective client data validation via UNTIL conditional repetition.

Report Generation

PERFORM PRINT-PAGE-HEADING
   PRINT-DETAILS
   UNTIL LAST-DETAIL-LINE
END-PERFORM  

PERFORM RELEASE-PAGE

Page oriented report writing leverages UNTIL to handle heading/footing and pagination.

Statistical Reporting

PERFORM READ-SALES-RECORD
  MOVE SALES TO DAILY-TOTAL
  ADD DAILY-TOTAL TO MONTH-TOTAL

  UNTIL END-OF-SALES-FILE
END-PERFORM

GENERATE-REPORT.
...

Perfect for accumulating totals across arbitrary record sets for flexible reporting.

Condition Evaluation Variations

Given UNTIL tests after processing, should conditions be expected true or false? Consistency avoids logic issues.

Common practice utilizes waiting for a switch to trigger:

PERFORM PARA-X
  UNTIL END-OF-JOB-FLAG = "YES" 
END-PERFORM

Paragraph X runs continuously until the flag triggers. Checking at bottom keeps code moving forward.

However, alternate flows may check on post-condition at top:

   PERFORM PARA-X    
      IF END-OF-JOB-FLAG = "YES"
         EXIT PERFORM
      END-IF
   END-PERFORM

Either approach works using IF or UNTIL. Key is recognizing potential reads depending on structure.

Optimizing UNTIL Performance

When architecting COBOL systems, UNTIL loops may execute millions of times. Performance matters.

General tips for speed:

  • Tighten outermost loops around inner UNTILS to limit scope
  • Initialize flags before loop to avoid redundant checks
  • Consider inline over outline when possible
  • Put conditional tests in separate paragraph to simplify

Balancing optimization and maintenance needs bears careful consideration however:

  • Excessive nesting/indentation creates confusion
  • Separate paragraphs and descriptive names aid future changes
  • Striving for fastest runtime speed may delay releases

Analyze programs holistically and use UNTIL judiciously!

Conclusion

PERFORM UNTIL serves as a versatile COBOL iteration construct allowing flexible repetition based on post-conditional evaluation. Mastering usage, nesting techniques, and performance nuances unlocks coding capabilities.

When facing endless data streams across financial systems, mathematical processing, screen handling, and file record navigation, consider UNTIL your friend. Productivity and control is merely a PERFORM away!

Similar Posts