3,740 pts.
 DB2/400 count physical file record
how to count the physical file records using RPGLE program....

Software/Hardware used:
as400 v5r3
ASKED: December 2, 2011  2:52 PM
UPDATED: February 28, 2012  3:47 PM
  Help
 Approved Answer - Chosen by pdsathishkumar (Question Asker)

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.....

ANSWERED:  Dec 5, 2011  11:51 AM (GMT)  by pdsathishkumar

 
Other Answers:

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

Last Wiki Answer Submitted:  December 8, 2011  8:42 am  by  pdsathishkumar   3,740 pts.
Latest Answer Wiki Contributors:  pdsathishkumar   3,740 pts. , CharlieBrowne   32,825 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 107,975 pts.

 

i need to count the 10 physical file record in single rpg program…. so we have any opcode for count record in rpg……………

 3,740 pts.

 

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

 107,975 pts.

 

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

 44,130 pts.

 

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

 107,975 pts.

 

May i know, how to retrieve number of record in physical file using file information data structure…..

 3,740 pts.

 

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

 44,130 pts.

 

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

 107,975 pts.

 

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,740 pts.

 

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

 107,975 pts.

 

Hi,

If you want, you can even use the CL Command to do that.
RTVMBRD FILE(&LIB/&FILE) NBRCURRCD(&COUNT)

 210 pts.

 

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

 107,975 pts.

 

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,740 pts.

 

>>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,505 pts.

 

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

 107,975 pts.

 

No… i want to count number of record in PF file member using RPG only…. i don’t want in cl…

 3,740 pts.

 

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,830 pts.

 

>>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,505 pts.

 

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

 44,130 pts.

 

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,740 pts.

 

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,505 pts.

 

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

 44,130 pts.

 

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,505 pts.