Problem running tests for binary-search in cobol

Hi,

Running the test script for cobol exercise binary-search results in an error.

exercise code:

01 WS-ARRAY-TABLE. 
         02 WS-ARRAY               OCCURS 1 TO 20 DEPENDING ON WS-COUNT.
            05 ROWELEM             PIC 9(4).    

test code:

MOVE "1,3,4,6,8,9,11" TO WS-ARRAY.

The error: ‘WS-ARRAY’ requires one subscript

I doubt it is possible to fill a table with number elements with a “csv-string”. Can I apply a workaround here, or do the tests need to be adjusted first?

This would be a great opportunity for me to contribute as a contributor for the first time, but honestly, I’m not sure how to go about it.

Update
This is a workaround in the exercise code.

       01 WS-ARRAY                 pic x(80).
       01 h-array.
          03 rowelem               pic 9(4) occurs 20.

ws-array becomes a string var and a h-array is addes.
The program can unstring ws-array into the rowelem’s.

1 Like

I have just encountered the smae problem, which @jeroen77nl reported. Actually, the ws-array is declared differently in proof.ci.cob of this exercise:

     01 WS-ARRAY PIC(60).

So, binary-search.cob needs to be modified like:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. BINARY-SEARCH.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-ITEM                  PIC 9999.
       01 WS-RESULT                PIC 99.
       01 WS-ERROR                 PIC X(40).
       01 WS-COUNT                 PIC 99.       
       01 WS-ARRAY                 PIC X(60).

       PROCEDURE DIVISION.
       
       BINARY-SEARCH. 

@axtens What do you think?

1 Like

I think cooking up a PR to address the issue would be great. Are you volunteering? I hope so.

Yes, I’ll do it.

@axtens I am done with the PR. Please check it out.

Commented. Have asked for input from the other maintainer @kapitaali

I’m inclined to approve but I’m getting very cautious in my old age.