Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,783 answers

573 users

How to check if all strings in array of strings are in ascending order with COBOL

1 Answer

0 votes
IDENTIFICATION DIVISION.
PROGRAM-ID. COMPARE-STRINGS-IN-ARRAY.

DATA DIVISION.
    WORKING-STORAGE SECTION.
       78  MAX-ITEMS             value 3.
       77  i                     pic 9(2).
       01  ARRAY.
           05 array-items occurs MAX-ITEMS.
              10 item            pic x(3).
       01  RESULTS.
           05 filler             pic 9(1).
              88 ascending-order value 1 when set to false is 0.

PROCEDURE DIVISION.
       main.
           move "AA BB CC" to ARRAY
           perform strings_are_equal
           STOP RUN.
        
        strings_are_equal.
            display "array:" 
            set ascending-order to true
            perform varying i from 1 by 1 until i > MAX-ITEMS
                if item(i) <> spaces
                    display function trim(item(i)), " " no advancing
                    if i < MAX-ITEMS and item(i + 1) <> spaces
                        if item(i) > item(i + 1) 
                            set ascending-order to false            
                        end-if
                    end-if
                end-if
            end-perform
            display " "
            if ascending-order
                display "yes"
            else
                display "no"
            end-if
            display " "
            .
           
        
 
*> run:
*> 
*> array:
*> AA BB CC
*> yes
*> 

 





answered Aug 12, 2023 by avibootz
...