2

So i'm trying to make a form-like screen where the user inputs his data and saves it in a .txt file. I'm using OpenCobolIDE and i'm currently going through problems in the clearing screen process. i have a kind of form that i made in the console screen and when the user enters his data im refreshing it with the new values of the variables, but the cursor position is screwing me up because after i clear the screen it gets reseted to the beginning of the console screen, and i want it to go to the end of the text that i'm displaying after this process. My explanation may look confusing but i hope you get my point with the code:

IDENTIFICATION DIVISION.
PROGRAM-ID.PGM001.

ENVIRONMENT DIVISION.

DATA DIVISION.

WORKING-STORAGE SECTION.
01 WS-DATA
    02 WS-ID    PIC X(03) VALUE SPACES.
    02 WS-NAME  PIC A(15) VALUE SPACES.
    02 WS-PHONE PIC X(09) VALUE SPACES.
SCREEN SECTION.
01 CLEAR-SCREEN.
    02 BLANK SCREEN.
PROCEDURE DIVISION.
MENU.
    DISPLAY "ID........:" WS-ID.
    DISPLAY "NAME......:" WS-NAME.
    DISPLAY "PHONE.....:" WS-PHONE.
    DISPLAY "-----------".

    DISPLAY "ID:".
    ACCEPT WS-ID FROM CONSOLE.

    DISPLAY CLEAR-SCREEN.
    DISPLAY "ID........:" WS-ID.
    DISPLAY "NAME......:" WS-NAME.
    DISPLAY "PHONE.....:" WS-PHONE.
    DISPLAY "-----------".

    DISPLAY "NAME:".
    ACCEPT WS-NAME FROM CONSOLE.

    DISPLAY CLEAR-SCREEN.
    DISPLAY "ID........:" WS-ID.
    DISPLAY "NAME......:" WS-NAME.
    DISPLAY "PHONE.....:" WS-PHONE.
    DISPLAY "-----------".

    DISPLAY "PHONE:".
    ACCEPT WS-PHONE FROM CONSOLE.

    DISPLAY CLEAR-SCREEN.
    DISPLAY "ID........:" WS-ID.
    DISPLAY "NAME......:" WS-NAME.
    DISPLAY "PHONE.....:" WS-PHONE.
    DISPLAY "-----------".

    STOP RUN.
END-PROGRAM PGM001.

So you'll notice that i keep clearing the screen and displayin the form but as i do it the cursor goes to the beginning of the screen and i can't keep inputing the data. Can someone help me please? Is there any command in cobol that moves the cursor?

Levi Moraes
  • 57
  • 1
  • 8
  • If you use a recent version of OCIDE for Windows you likely already use GnuCOBOL 1.1 (you can check this in the preferences and in the about dialogue). If not I suggest to ad least upgrade to GnuCOBOL 1.1 (or a recent development snapshot). – Simon Sobisch Sep 13 '16 at 18:42

2 Answers2

3

In COBOL, there are two types of DISPLAY statement: those for a device and those for a screen.

In OpenCOBOL, device and screen DISPLAYs cannot be used at the same time; if you try to, you will find that there is no output from the device DISPLAYs after the first screen DISPLAY. This is what is happening your example: CLEAR-SCREEN is defined in the screen section, so DISPLAY CLEAR-SCREEN is a screen DISPLAY.

You can fix this by defining the entry form in the screen section:

SCREEN SECTION.
01  form BLANK SCREEN.
    03  VALUE "ID.........".
    03  COL + 2, PIC X(03) TO WS-ID.
    03  LINE + 1, VALUE "NAME.......".
    03  COL + 2, PIC A(15) TO WS-NAME.
    03  LINE + 1, VALUE "PHONE......".
    03  COL + 2, PIC X(09) TO WS-PHONE.
    03  LINE + 1, VALUE "-----------".

As well as working, this has the extra advantage that the procedure division can be reduced to

 DISPLAY form
 ACCEPT form

as all the form data can be entered in one go.

If, however, you want to keep data entry as it is, you can turn the device DISPLAYs into screen DISPLAYs by adding AT LINE <line-num>:

DISPLAY "ID........:" WS-ID AT LINE 1
DISPLAY "NAME......:" WS-NAME AT LINE 2
DISPLAY "PHONE.....:" WS-PHONE AT LINE 3
DISPLAY "-----------" AT LINE 4

DISPLAY "ID:" AT LINE 5
ACCEPT WS-ID AT LINE 5, COL 5
Edward H
  • 576
  • 3
  • 8
  • I've tried the second method but the cursor is still waiting for the input at the first line not at the end of the screen. Do i have to specify the line in the ACCEPT statement as well or something like it? – Levi Moraes Sep 15 '16 at 00:45
  • @levi-moraes Yes, you will: ACCEPT ... AT LINE 5, COLUMN 5 should work. – Edward H Sep 15 '16 at 12:50
1

In a current project that could not use "extended screens" (the underlying curses CALLs done by GnuCOBOL reset the output and you don't the the end result after the program ends; other vendor's "terminal managers" do quite the same) I wanted to "still kind-of-clear" the screen.

Possible options include: DISPLAY WORKING-STORAGE-PIC-X-2080-ITEM (you may want to adjust this depending on the expected screen size) or (less portable) CALL 'SYSTEM' USING 'clear' (I didn't tried this but this may work).

As @edward-h already pointed out: If you use the "extended" SCREENs for the complete program much of this will be done automatically and you have additional options like BLANK SCREEN clauses or CURSOR IS key-item in SPECIAL-NAMES allowing you to both get and set the cursor.

But as the screen will be removed on program exit: you mostly want to add an ACCEPT OMITTED (or, if the version you use doesn't support this extension ACCEPT PIC-X-ITEM-DUMMY) before the program exits.

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38