Scrolling Logic Help?

Hi, I hope I can get some help on this website!
I need to just browse a file and have scrolling with PF8 and PF7. I am using a map, not a display since I will also have the Add and Delete capabilities.
Please let me know if it was listed previously or if you have any advice on how to do that.

Thank you so much!!!

Your map should have an array defined that will hold the values to display and an action code. The READ/FIND loop will load data into the array. When the array is full or end of data is reached, execute the INPUT statement and process the response.

You can implement backward scrolling in a number of ways:

  • use READ DESCENDING and load the array bottom-up (typically the first choice)
  • keep an array of values for the top of each page viewed
  • other options would depend on your data and selection criteria for what is being browsed

Thank you. I now have something to think about this weekend…
thank you for the quick reply. I will ask again if I have any other specific question!
Have a good weekend.

Just a couple of things to add to Douglas’s reply:

First, you mentioned you will be doing ADDs and DELETEs. Clearly, you could be on page three and ADD a record that would be on page three, or after page three, or before page three. The user would probably like to see such changes, which means that you would have to “refresh” the data array.

Second, you said you were using INPUT because you wanted to be able to do ADDs and DELETEs. You could also use DISPLAY to do this. You could have the user position the cursor on a line, then have the user hit a PF key labeled DELET. You can do this in an AT END OF PAGE clause (probably could also do it in an AT TOP OF PAGE clause, but it would be trickier), then use an INPUT to let the user confirm the delete. *CURS-LINE would tell you the record to be deleted.

steve

Here is some code which just has logic for adding a record

DEFINE DATA LOCAL
1 MYVIEW VIEW OF EMPLOYEES
2 NAME
2 FIRST-NAME
1 #ADDER (L)
END-DEFINE
*
FORMAT PS=20
SET KEY PF3 NAMED ‘add’
READ (100) MYVIEW BY NAME
IF #ADDER = TRUE
MOVE FALSE TO #ADDER
INPUT 3/10 ‘enter data for ADD’

  • insert code to add record to file
    END-IF
    DISPLAY NAME FIRST-NAME
    END-READ

AT END OF PAGE
INPUT / ‘pf key options - e.g. pf3 for ADD’
IF *PF-NAME = ‘add’
MOVE TRUE TO #ADDER
END-IF
END-ENDPAGE
END

Instead of just #ADDER and PF3, you would have additional logic for deleting (using *CURS-LINE) and changing direction

steve

Thank you so much both of you!
I am not the most experienced with Natural since all my years I have been a Cobol CICS programmer… so I understand exactly what you are saying and need to fit that into my program, but I dont see the flow… the examples of programs I have seen have a Repeat loop on everything or Set Control to ‘N’ with a comment saying its like hitting return.
The program I am looking at also has a table of keys with the starting key of each page but I dont think I need that since the table might be updated and I have to start again.
Dont I have to do the Input statement first to see if a PFkey was hit, and then do the read for x number of times to fill the map?
Can u give me an example for the flow of whole program, not just the Add?
Thank you again. It is wonderful to get support for this!!!

After reading it more closely I have more questions:

  1. Is it OK to you a display instead of a map?
  2. You can get a cursor position on a display ?
  3. What does this mean? INPUT 3/10 ‘enter data for ADD’ - what is 3/10?

Thank you again.

Questions from your last post:

  1. Depends on what you have to do.

  2. Yes. Try the following code:
    format ps=20
    read (50) employees
    display name first-name
    end-read /* (or loop)
    at end of page
    input ‘position cursor and hit enter’
    write *cursor *curs-line *curs-col
    end-endpage
    end

  3. 3/10 is shorthand for /// 10t (skip 3 lines tab to col 10)

steve

Disclaimer: without knowing the application, number of records, number of fields, frequencies of adding, deleting, changing scroll direction, ad nauseum, it is quite impossible to comment on whether you are looking at good code or bad; and whether the following code is even practical.

define subroutine fill-array
** here you would have the READ or FIND that acquires the records for the arrays
** I would also (maybe) have an array of the ISNs.
end-subroutine
*
perform fill-array
*
for #loop = #start to #end
display #field1 (#loop) #field2 (#loop)
end-for
*
at end of page
input ‘position cursor and hit pf5 for delete’ / ‘hit pf3 to do an add’
*
If the user wants to do a delete pick up #isn (#line) and null out that entry in the arrays. you could also “close ranks” in a variety of ways. You could have logic in the display loop to skip blank entries, or you could actually do a series of moves to overlay the blank entry (there are many efficient ways to do this using strings).
*
If the user wants to do an add, and the add could go anywhere based on some field value, you will almost certainly have to perform fill array after the add. if array position can be specified by the user (e.g. add a record after this one (cursor)) you may be able to add the record and manipulate the array without accessing the records (as per with the delete).

I could go on, but there are too many variables involved, as noted earlier.

steve

Steve,
It looks like there are lots of ways to do things… My table is simple (a State Table) and a good practice… I also figured out yesterday that for PF8, either I can store the last entry of the page and start the read from there, or I can keep the read in a loop and pf8 will continue reading.
I will definitely have to try out all these suggestions.
Thank you again and good luck with your business (I checked out your website)

Carol