DB2/400 count physical file record

3790 pts.
Tags:
DB2/400
how to count the physical file records using RPGLE program....

Software/Hardware used:
as400 v5r3

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is for count number of records in physical file member….

using file information data structure in RPGLE…

Femp1 if e k disk usropn extmbr(E1)
F infds(aaa)
DE1 s 5a inz(’EMP12′) —>pf member name
Daaa ds
Drecordno 156 159b 0
C open emp1
C recordno dsply
C close emp1
C eval *inlr = *on

Discuss This Question: 25  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    In general, you do it like you would do it in any procedural language -- read records in a loop and increment a counter each iteration. But that's not a RPG question; that's a novice programming question. What exactly are you needing to know? And why do you need to ask something so basic? RPG has some characteristics that make the question unclear, e.g., you can use the cycle for procedural control or use explicit I/O for reading/counting a fully procedural file. CharlieBrowne's additional variations show that there are numerous alternatives. Circumstances can guide which one is appropriate. Tom
    125,585 pointsBadges:
    report
  • pdsathishkumar
    i need to count the 10 physical file record in single rpg program.... so we have any opcode for count record in rpg...............
    3,790 pointsBadges:
    report
  • TomLiotta
    so we have any opcode for count record in rpg… Actually, it's two opcodes. READ reads records and ADD adds to a counter. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    If you want to know how many records are in a file, it's not necessary to count them. As Charllie Brown said there are a number of options. When an RPG program opens an F - spec it can know the starting number of records in the file through the file information data structure http://itknowledgeexchange.techtarget.com/itanswers/what-do-numbers-in-infdssds-declaration-signify/ When I need only the record count in an RPG program I write a few line CL program to use the RTVMBRD which includes the number of records and return that value. The RPG program passes the cl the filename and receives the count back from it. The SQL Select Count(*) from .. can be handy, because you can use the flexibility of SQL to count the number of records by one or more subsets of the data. One SQL command could get you the totals of each of 10 or the total of all 10 although 10 SQL commands would be simplier. And as Tom said, you can set up a read loop for each file with a counter in it. Phil
    49,960 pointsBadges:
    report
  • TomLiotta
    i need to count the 10 physical file record in single rpg program…. Additional explanation of how some answers are given might be needed. This task looks like an exercise. It looks like an assignment from school. It doesn't seem like anything anyone would need to do in a work environment, and it is so fundamental that it feels like a learning task. We cannot supply direct answers for this kind of question unless a clear business case is presented. We can help guide someone's learning, and we can help explain things that are difficult. If you run into a problem, we can describe solutions. But we can't show how a task is done. Generally, we need to see your work. We can discuss problems that we see with your work but can't fix it for you. So, if this is an actual business problem, please explain why it needs to be done. And if it is a school problem, show the work that has been done. Show things that you have tried. We'll see what can be done. Tom
    125,585 pointsBadges:
    report
  • pdsathishkumar
    May i know, how to retrieve number of record in physical file using file information data structure.....
    3,790 pointsBadges:
    report
  • philpl1jb
    Question indicated above: http://itknowledgeexchange.techtarget.com/itanswers/what-do-numbers-in-infdssds-declaration-signify/ That question includes this link: http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c092508378.htm No books, no library, no effort, terrible disappointment. Phill
    49,960 pointsBadges:
    report
  • TomLiotta
    how to retrieve number of record in physical file using file information data structure….. You define an Open feedback area and associate it with the file. Retrieve the "Number of records in the member at open time" from the data structure. It's up to you to write the programming. Show us what you have tried. Without showing your work, that's as much as can be said. We can't do the programming for you. Tom
    125,585 pointsBadges:
    report
  • pdsathishkumar
    Mr. Tomliotta, you gave me some answer about open feedback area.... but i don't know about that... becaz i m beginner in as400... if u have possible... explain me....
    3,790 pointsBadges:
    report
  • pdsathishkumar
    i got the answer to count record in physical file using file information data structure.... Femp if e k disk infds(aaa) Daaa ds Drecordno 156 159b 0 C recordno dsply C eval *inlr = *on it will show the accurate answer.....
    3,790 pointsBadges:
    report
  • TomLiotta
    but i don’t know about that… The link that I gave for the open feedback area tells what the data structure subfields can be defined as. Entering { open feedback area rpg } into the search field of the Information Center brings up a list of related items. The first item in the list includes a subtopic that shows an example of how to code an INFDS in RPG. Tom
    125,585 pointsBadges:
    report
  • tedsoh
    Hi, If you want, you can even use the CL Command to do that. RTVMBRD FILE(&LIB/&FILE) NBRCURRCD(&COUNT)
    210 pointsBadges:
    report
  • TomLiotta
    No matter how you do it, you need to be very aware that there can be a very large difference between "the number of records in a file" and "the number of records in a member of a file". Tom
    125,585 pointsBadges:
    report
  • pdsathishkumar
    i am asking only about 'number of record in file'.... but i got the answer... now i got little confusion about.. how can i find 'number of records in physical file member...
    3,790 pointsBadges:
    report
  • Yorkshireman
    >>asking only about ‘number of record in file’…. but i got the answer… now i >>got little confusion about.. how can i find ‘number of records in physical file >> member… The start point is surely to use the systems existing knowledge about what data is in what file, and this would be the RTVMBRD command. AFAIK this makes a single access to the system data , and tells you the basic information stored in the object header. You absolutely wouldn't want to read a file, adding 1 to a counter, if this info is already known. So costly in time and i/o Equally, if you need to know more about whether a PF has one or more members, and how many records in each, the departure gate would be the commands. A suitable and simpole bit of CLLE will access all you need to know, without the overhead of file i/o Once you understand the basiocs, you could look at using the API's which underpin these commands, which are generally faster to execute, but demand a more searching knowledge and somewhat complicated interface.
    5,580 pointsBadges:
    report
  • TomLiotta
    now i got little confusion... You don't need to be concerned about it for this thread. Yorkshireman is right. But for anyone who reads information like this in the future, it should always be clear that there are differences between files and members of files. This thread is going to be around for a long time. It needs to be noted that a direct RTVMBRD command will not always give the complete answer if the question is "How many records are in this file?" The RTVMBRD command is 'Retrieve Member Description' and it retrieves information about a "member" of a file, not about a "file". Eventually, that will be important to you. But not today. Tom
    125,585 pointsBadges:
    report
  • pdsathishkumar
    No... i want to count number of record in PF file member using RPG only.... i don't want in cl...
    3,790 pointsBadges:
    report
  • Teandy
    No… i want to count number of record in PF file member using RPG only…. i don’t want in cl… Then you need to use either the INFDS, read the file member and count the records or look into using an API like QCMDEXC, QCAPCMD or QUSRMBRD.
    5,860 pointsBadges:
    report
  • Yorkshireman
    >>No… i want to count number of record in PF file member using RPG only…. >>i don’t want in cl… Well, if you'rre determined, you need an RPG program which has Open file loop: read record If last record, exit else add 1 to count go to loop It's pretty much the same in any language - only the syntax differs. Some languages make it more opaque than others. IBM i and its rich instruction set gives you more choice than other machines. Oh - in case the file has a hundred million records or so - common on this box - it's still quicker to ask the operating system - it KNOWS what records are in a file - that's its job - that's what we bought it for. 'A million dollars of computer and you have to add up the records in a file.... ' .
    5,580 pointsBadges:
    report
  • philpl1jb
    If the file onlly has one member this is trival. A few changes to your program are requested to get the number of records in a member. 1. F spec keyword USROPN .. file will not open until you request it 2. F spec keyword EXTMBR( MBRNAME') identifies specific member to use 3. D spec D MBRNAME 10 INZ( 'MYMEM' ) <-- this should be the member neame 4. C spec Open filename <-- this should be the file name 5. then you can use the binary field thats in the IFSDS to get the number of records in the member. Phil
    49,960 pointsBadges:
    report
  • pdsathishkumar
    i got the answer to count number of records in physical file member.... using file information data structure... Femp1 if e k disk usropn extmbr(E1) F infds(aaa) DE1 s 5a inz('EMP12') --->pf member name Daaa ds Drecordno 156 159b 0 C open emp1 C recordno dsply C close emp1 C eval *inlr = *on
    3,790 pointsBadges:
    report
  • Yorkshireman
    Phil - that's getting advanced - USROPN indeed! I still have a problem knowing why you would possibly want to use RPG, and incur the overhead of the Database opening a file when a rtvobjd does the job - even if you called it from within rpg, it must surely be less resource intensive.. Ah well - not my concern.. .
    5,580 pointsBadges:
    report
  • philpl1jb
    Yorkshireman, Not my choice. This was the choice of the person asking the question and writing the program. if the program is going to do more processing with that file/member it make sense. Phil
    49,960 pointsBadges:
    report
  • Yorkshireman
    Phil Sorry - not the intended interpretation. I think I was (trying to be) sardonic, or ironic, or one of those type of things. Doesn't come across well in hurried print. We seem to agree on the absence of reality in the whole thread. of course there *may* be good reasons to do all kinds of stuff, but a simple enquiry for number of records is best met with the tools that the system has. Still, onward to better things... .
    5,580 pointsBadges:
    report
  • pdsathishkumar
    [...] Users help count files in DB2, but complain about the absence of reality in the basic question. Are they tackling the right [...]
    0 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following