Menu

SEARCH problem

2025-06-09
2025-06-24
  • Maurizio Bongini

    Hi
    Env: Ubuntu 24.04 Gnucobol 3.2
    Prb: I reproduce with this small pgm the problem i get using SEARCH
    ( in the main problem i need both CURSOR and AT clause)
    here the code

           IDENTIFICATION DIVISION.
           PROGRAM-ID. searc.
            ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
              CURSOR IS CURS.
           INPUT-OUTPUT SECTION.
           FILE-CONTROL.
           DATA DIVISION.
           FILE SECTION.
           WORKING-STORAGE SECTION.
           01 CURS .
               02 LINEA    PIC 99.
               02 COLONNA  PIC 99.  
           01 DEBUG1 PIC X .
           01 PGM-ID PIC X(8). 
           01 MSG PIC X(40) USAGE IS DISPLAY. 
           01 CAUSALE                PIC X(04).
           01 CAUSALI.
              05 FILLER PIC X(04) VALUE '0010'.                   
              05 FILLER PIC X(22) VALUE 'CARICO DA FORNITORE'.
              05 FILLER PIC X(04) VALUE  '0510'.
              05 FILLER PIC X(02).
              05 FILLER PIC X(04) VALUE '0020'.
              05 FILLER PIC X(22) VALUE 'VENDITA A CLIENTE '.
              05 FILLER PIC X(04) VALUE  '0520'.
              05 FILLER PIC X(02).
           01 CAUSALI-T REDEFINES CAUSALI.
              05 T-CAUSALI OCCURS 002 INDEXED BY IDX1.
               10 T-CAUSALE-CODE   PIC X(04).
               10 T-CAUSALE-DESC   PIC X(22). 
               10 T-CAUSALE-STORNO PIC X(04). 
               10 FILLER           PIC X(02).
          01 LC0835 PIC X(22) VALUE ALL '-'. 
           LINKAGE SECTION.
           SCREEN SECTION.
           01 S-CLEAR.     
            02 S-BLANK BLANK SCREEN.
    
           PROCEDURE DIVISION.
           MOVE 'searc' TO PGM-ID.    
           DISPLAY S-CLEAR.
           PERFORM ACCETTA-CAUSALE. 
           STOP RUN.     
    
           ACCETTA-CAUSALE. 
            MOVE 'CODICE CAUSALE' TO MSG.
            DISPLAY MSG                                     AT 2441.
            ACCEPT CAUSALE                                  AT 0101.
            SET IDX1 TO 1 
            SEARCH T-CAUSALI
              AT END
                DISPLAY LC0835                              AT 0835
          *      ACCEPT DEBUG1                               AT 2480
                GO TO ACCETTA-CAUSALE
              WHEN CAUSALE = T-CAUSALE-CODE(IDX1)
                      DISPLAY T-CAUSALE-DESC(IDX1)          AT 0835
            END-SEARCH.
           EXIT.
           DEBUG.
                ACCEPT DEBUG1 AT 2480.
                STOP RUN .
           EXIT.            
          * EXIT PROGRAM.
           END PROGRAM searc.
          *
    

    i describe the problem ...
    if accepting a wrong value in the CAUSALE input field , different from 0010 or 0020 , SEARCH arrives at END and pull back again to ACCETTA-CAUSALE , but cursor instead to go at position 0101 goes to 0104
    and also if you move cursor to 0101 , inserted input is blanked ...
    I Bypass all inserting an ACCEPT DEBUG1 AT 2480, in this way program behave correctly...
    I performed problem determination and The culprit is CURSOR IS CURS
    if you do not use it , program behave correctly ... in this small pgm is not needed , but i need it in the main big program ... another bypass i tested succesfully without inserting ACCEPT DEBUG1
    is to MOVE 0101 to CURS and then ACCEPT CAUSALE AT CURS
    Let me know your opinion , if i do something wrong or it is a hole in the code
    Regards
    Maurizio

     

    Last edit: Maurizio Bongini 2025-06-09
  • Maurizio Bongini

    I attach here the code to reproduce prb

     
  • Chuck Haatvedt

    Chuck Haatvedt - 2025-06-09

    Hello Maurizio,

    our native languages are different, so I will try to be clear in my explanation so as to not cause any misunderstanding.

    The behavior you are encountering is not a bug but rather a function of the ACCEPT verb. Hopefully the following will make it more clear.

    the "CURSOR IS" clause in the SPECIAL-NAMES area is used to to give access to the cursor position on the screen. One critical item to remember is that the DISPLAY statement does NOT move the position of the cursor.

    Another thing to consider is that the ACCEPT verb has a TIME OUT capability which allows an ACCEPT verb to be interrupted after a time interval and then continued via another ACCEPT verb.

    To accomplish this the ACCEPT statement first checks to see if the cursor position is within the bounds / scope of the AT clause and if so positions the cursor at the value of the CURSOR IS variable, if that variable is NOT within the bounds / scope, then the cursor is positioned at the location of the AT clause.

    So when using an ACCEPT verb at the same position as a previous ACCEPT verb, you should set the value of the CURSOR IS variable outside of the AT clause to ensure that the cursor is positioned at the beginning of the AT clause position.

    I have include a modified version of your program to demonstrate the behavior of the ACCEPT ... AT position verb.

    If you have any questions, I will try to answer them.

                  Chuck Haatvedt
    
     
    • Anonymous

      Anonymous - 2025-06-24

      Perfect explanation!

       
  • Michael F Gleason

    deja vu.
    been there before. (This happened to me while updating my version of Star_Trek)
    I knew somebody other than me was going to have this happen to them too.

    Michael :-(

     

    Last edit: Michael F Gleason 2025-06-09
  • Maurizio Bongini

    Hi Chuck
    Thanks for the answer..
    it works as designed
    i downloaded your modified code .. and i will study it together with your answer ..
    i open threads only to signl you potential problems and I'm happy that all misunderstandig is over .
    Have a nice day
    Maurizio

     
  • Maurizio Bongini

    Hi Chuck
    Thanks for spending your time to explain me with text and with a code example how the process works ... with this info i think the correct way to preceed is to modify code with the following instructions to all the accepts of my pgm

               MOVE 0101 TO CURS.  
               ACCEPT CAUSALE                                      AT CURS.
    
     
  • Chuck Haatvedt

    Chuck Haatvedt - 2025-06-11

    Thanks Maurizio,

    That is the change I would make

    PS, I'm working on the MicroFocus / Fujitsu CBL_xxx Screen callable functions which gives the programmer direct control of the screen and keyboard. Are you familiar with the ISPF editor on the IBM mainframes ? We are working on a GNUCOBOL clone of that.

            Chuck Haatvedt
    
     
    👍
    1
  • Maurizio Bongini

    Hi Chuck
    Yes, i worked many years with ISPF

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.