Hi,
How to position the record in CL based on the key value?
I have tried this.my CL program is as follows...
***************************
PGM
DCLF FILE(PMS90/EMPMST90)
OVRDBF FILE(EMPMST90) POSITION(*KEY 1 EMPREC 101)
RCVF
SNDUSRMSG MSG(&EMPNAM)
DLTOVR FILE(EMPMST90)
ENDPGM
****************************
Position(*key 1 emprec 101)
Starting position in file:
Retrieve order . . . . . . . . > *KEY
*RRN-rcd nbr *KEY-nbr key flds > 1
*KEY-rec format having key . . > EMPREC
*KEY-key value . . . . . . . . > 101
i am getting error in this statement...
*key-key equal records will be retrieved
*key nbr key flds-here what i have to specify.i specified as '1'.Is this right.In my physical file "EMPMST",i had one key field-'EMPCDE'...
"EMPREC"-rec format name...
101 is one of the records in my file EMPMST...
Please correct my mistake in my program displayed above and explain about the parameters in POSITION...
Software/Hardware used:
AS400
ASKED:
January 9, 2011 6:51 AM
UPDATED:
January 12, 2011 10:59 PM
i am getting error in this statement…
What is the message identifier of the error? The text isn’t helpful to us, but the message identifier will let us look at the same message.
However, you are requesting to position by key and you specify that a single key field exists and that you want to retrieve a record with a key value of “101″. But we have no way of knowing if that’s correct because you haven’t shown us the file key description.
Tom
My error msg and its description is as follows..
CPF4137 received by OVRDBF11 at 301.
Position option for member EMPMST90 not valid…
EMPMST90:- MY PF
R EMPREC
A EMPCDE 5S0
A EMPNAM 30A
K EMPCDE
RECORDS;
101 ARUN
102 BALA
103 DEVA
OVRDBF COMMAND -IN POSITION I AM GETTING ERROR…I HAVE SHOWN MY FILE AND DATA…NOW HELP ME TO GET 101 th RECORD…
MY CL PROGRAM:
PGM
DCLF FILE(PMS90/EMPMST90)
OVRDBF FILE(EMPMST90) POSITION(*KEY 1 EMPREC 101)
RCVF
SNDUSRMSG MSG(&EMPNAM)
DLTOVR FILE(EMPMST90)
ENDPGM
A EMPCDE 5S0
According to that, you have a key that is five bytes long. However, you are only passing three bytes into your positioning value:
POSITION(*KEY 1 EMPREC 101)
Try this:
POSITION(*KEY 1 EMPREC ’00101′)
The key-value element is a character parameter. When you pass in (101), it becomes ’101bb’ as the key value — two blanks will essentially be assumed in the last two positions.
As long as you always treat the key-value element as a series of bytes, you should always be able to determine what values will work.
Tom
For some investigation, look at the output from this command:
You should see that the actual key value is ’00101′.
Keys may be ‘compound keys’. The indexes will hold effectively character data structures. Even packed-decimal and binary values will appear to be represented as bytes in memory rather than values formatted for external viewing.
CL is not a database language, so it doesn’t have a full set of features like those provided in HLLs such as ILE RPG or COBOL. You need to use the limited capabilities if you use a language that isn’t full-featured.
Tom
OVRDBF FILE(EMPMST90) POSITION(*KEY 1 EMPREC ’00101′)
Thanks Tom Sir its working…
But how to retrieve by RRN…
OVRDBF FILE(EMPMST90) POSITION(*RRN 1)
I cant able to get the first record
Thanks Tom Sir its working…
You’re welcome. Note that the <help> text for POSITION() parameter says this:
The information was available by using the F1=Help key.
But how to retrieve by RRN…
The OVRDBF looks fine, but the rest of the CL is needed in order to know if it’s correct. For example, if the file was previously opened and not closed, the override will not be effective.
Also, what is OS version/release? Current releases of i5/OS have some capabilities that earlier releases didn’t have.
Tom