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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 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

Related questions

1 answer 68 views
1 answer 92 views
1 answer 258 views
1 answer 292 views
292 views asked Sep 17, 2020 by avibootz
1 answer 91 views
91 views asked May 18, 2025 by avibootz
...