Searching records in a subfile on COBOL ILE

60 pts.
Tags:
AS/400
Hi all, I' just new in learning COBOL with subfiles. My COBOL program can display records in subfile but I wanted to search the name within the subfile records. Can someone post a sample code or can help me with my problem. Below is the screen looks like:
SEARCH: _______ (to search the name in the subfile)
option    ID    NAME
------------------------
_99xxxxxxxxx
_99xxxxxxxxx
_99xxxxxxxxx 


Your help means a lot to me...Thanks!


Software/Hardware used:
software
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • CharlieBrowne
    Assuming your SFL is not the complete set of data from the file because you are using the page keys to get more information; It is a little more complex that just searching the SFL.
    I would recommend the you use SQL to populate the SFL when using the search capability.
    You can use the LIKE '%xxx%' function in SQL to retrieve the records and fill the SFL.
    62,385 pointsBadges:
    report
  • Radycal
    i even moved the value of search-field to my keyed file and successfully located the record and write again in the subfile. but upon displaying still displaying the 1st record. how can i make my search-field be the 1st record on my subfile.  
    60 pointsBadges:
    report
  • anandx
    1. Subfile is a transient file which gets created by the program at runtime and gets destroyed when program terminates. Records are written to the subfile by the program either by pulling out some selected records from the database or user may input data to subfile to be later written to database. Subfile is organized as a relative file and not as an indexed file. Subfile can be accessed only thru relative record number and not by any field value in the record. Hence, searching a subfile by Name or Id cannot be done. Nonetheless, if your intention is to display on a subfile some database records having some user given search criteria for name or number then that criteria must first be applied to the database first, move those records from the database to subfile and display the subfile. As an example, if user wants all records having names starting with ‘S’, then select those records from database, write them into subfile and then display those selected records. By the way, subfile concept is same whether it is COBOL or RPG. 

    Subfile displays only those records that were written to it by the program. If the subfile is not cleared (emptied) (SFLCLR KW) prior to writing a new set of records then on display, the sufile will display not just the current set but the previous set as well (provided SFLSIZ allows).

    765 pointsBadges:
    report
  • GregManzo
    It's not clear whether you want to build a subfile with only names that match your search (ie 'filter' or 'subset') or build the list such that the entered name appears at the top of the subfile (ie 'position to'). Different techniques are required for each. The subfile itself however is a DDS construct independent of RPG or COBOL - that is, your code will differ for the syntax of COBOL or RPG, but the logic is the same.
    2,950 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: