Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use INSPECT to establish that LENGTH( is on the current record.</p> <p>Only if present, do the following: </p> <p>UNSTRING using LENGTH( as a delimiter with two receiving fields.</p> <p>UNSTRING second receiving field delimited by ) leaving you with the number.</p> <p>For example:</p> <pre><code>01 delimiting-field PIC X(7) VALUE "LENGTH(". 01 desitnation-field-1 PIC X. 01 destination-field-2 PIC X(18) JUST RIGHT. UNSTRING source-field DELIMITED BY delimiting-field INTO desitnation-field-1 destination-field-2 </code></pre> <p>Abandon destination-field-1. Use destination-field-2 for input to the second UNSTRING.</p> <p>Use meaningful names, rather than those I have shown to illuminate the example.</p> <p>So,</p> <pre><code> 01 WS-INPUT-RECORD PIC X(80). 01 NUMBER-OF-LENGTHS BINARY PIC 9(4). 01 DELIMITER-COUNT BINARY PIC 9(4). 88 NO-DELIMITERS VALUE ZERO. 88 ONE-DELIMITER VALUE 1. 01 LENGTH-OPEN-PAREN PIC X(7) VALUE "LENGTH(". 01 DATA-TO-IGNORE PIC X. 01 DATA-WITH-LENGTH-VALUE PIC X(80). 01 CLOSING-PAREN PIC X VALUE ")". 01 VALUE-OF-LENGTH-AN PIC X(18) JUST RIGHT. THE-STUFF. SET NO-DELIMITERS TO TRUE INSPECT WS-INPUT-RECORD TALLYING DELIMITER-COUNT FOR ALL LENGTH-OPEN-PAREN EVALUATE TRUE WHEN NO-DELIMITERS CONTINUE WHEN ONE-DELIMITER PERFORM GET-THE-DATA WHEN OTHER PERFORM OH-DEAR-MORE-THAN-ONE END-EVALUATE . GET-THE-DATA. UNSTRING WS-INPUT-RECORD DELIMITED BY LENGTH-OPEN-PAREN INTO DATA-TO-IGNORE DATA-WITH-LENGTH-VALUE UNSTRING DATA-WITH-LENGTH-VALUE DELIMITED BY CLOSING-PAREN INTO VALUE-OF-LENGTH-AN DISPLAY "THIS IS WHAT WE FOUND" DISPLAY "&gt;" VALUE-OF-LENGTH-AN "&lt;" . OH-DEAR-MORE-THAN-ONE. DISPLAY "THE FOLLOWING LINE HAS MORE THAN ONE LENGTH(" DISPLAY "&gt;" WS-INPUT-RECORD "&lt;" . </code></pre> <p>The technique with the INSPECT to see if the "string" is present can be applied to the other solution accepted so that only if the line contains the value desired is it "searched".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload