reading a pf in reverse order using cl program

1590 pts.
Tags:
CL
Hi,

How to read a physical file in reverse order using cl program ny example with coding would ne much helpful.

Thanks.

any sample code would be verymuch helpful

Answer Wiki

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

yes , its has to be read using cl only no rpg and reverse order only and there is not any such business requirement but just wanted to check if that can be done then how it can be done using logical file with * descend is fine and we can use rcvf command and read it but is there any other approach possible?

Thanks

Discuss This Question: 34  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
  • philpl1jb
    Can you build a logical that is in the order that you need?
    50,205 pointsBadges:
    report
  • CharlieBrowne
    Does it have to be a CL program? You can do it easily in RPG
    41,380 pointsBadges:
    report
  • TomLiotta
    Is there a business reason it must be read in reverse? And with CL? Tom
    125,585 pointsBadges:
    report
  • 6r
    Any CL program which can meet this requirement apart from logical file approach? Thanks
    1,590 pointsBadges:
    report
  • 6r
    yes , its has to be read using cl only no rpg and reverse order only and there is not any such business requirement but just wanted to check if that can be done then how it can be done using logical file with * descend is fine and we can use rcvf command and read it but is there any other approach possible? Thanks
    1,590 pointsBadges:
    report
  • WoodEngineer
    Possible but very messy. Ask your teacher to give you a real world assignment.
    6,680 pointsBadges:
    report
  • 6r
    my assignment is thisone only i have been hinted that using opnqryf and ovrdbf it could be possible if somebody could paste real code of this cl program from beginning to end then it would be much helpful. thanks
    1,590 pointsBadges:
    report
  • philpl1jb
    Yes .. OPNQRY file has *DESCEND which can be appied to a key field. Do you have a key field in this file that you want to order this file on?
    50,205 pointsBadges:
    report
  • philpl1jb
    Logical file would also need a key field to *DESC on.
    50,205 pointsBadges:
    report
  • TomLiotta
    OPNQRY file has *DESCEND which can be appied to a key field. And OPNQRYF can generate its own keys via *MAPFLDs and specify *DESCEND. It can also use *FILE to use arrival sequence, but *DESCEND can't be used with *FILE. Tom
    125,585 pointsBadges:
    report
  • 6r
    lets say physical file id1 i want to read in reverse order i am trying to write following cl program- DCLF FILE(ID1) DCL VAR(&TRCD) TYPE(*DEC) LEN(10 0) dcl var(&rrn) type(*char) RTVMBRD FILE(ID1) NBRCURRCD(&TRCD) CHGVAR VAR(&RRN) VALUE(&TRCD) OVRDBF FILE(ID1) TOFILE(ID1) POSITION(*RRN 18) IF COND(&RRN *NE 0) RCVF RCDFMT(REC1) CHGVAR VAR(&RRN) VALUE('RRN-1') ELSE ENDPGM but its not working any advise pls? thanks
    1,590 pointsBadges:
    report
  • TomLiotta
    There is no useful method of reading a file in reverse order using CL. It can be done, but it's not trivial nor is there any reason to do it. -- Tom
    125,585 pointsBadges:
    report
  • 6r
    but even if i want to write that program to meet this requirement then i googled and found previouly mentioned cl program code but that is showing too many errors and any other link where sommeone can provide me the exact code to fulfill this requirement.i understand it could require considerable logic to meet this requirement.but since i am unable to think this logic so asking help of experts in AS/400 for this CL program code.
    1,590 pointsBadges:
    report
  • TomLiotta
    I asked earlier if there was a business requirement for this, but that hasn't been answered yet. If there is no business requirement, I can't see a good reason we should put the effort into it. -- Tom
    125,585 pointsBadges:
    report
  • 6r
    There was not any business requirement but just for knowledge purpose i asked if it could have been possible then how can we write that program code logic in CL.?
    1,590 pointsBadges:
    report
  • 6r
    So any other updates from as/400 experts ?
    1,590 pointsBadges:
    report
  • 6r
    or any paid other site/portal where i can directly put any query related to programming assignments and their solutions in cl/rpg/as400??????
    1,590 pointsBadges:
    report
  • TomLiotta
    CL is not intended for processing database file records (nor for streamfiles). It has some basic built in capabilities for reading and none for direct writing. Nobody has example code because nobody uses CL to read files in reverse. There is no reason to.   Code could be created in various ways. For example, ILE C has library functions to open, read and close database files. ILE CL can bind and call ILE C functions. The _Rreadp() function will "read previous" records. That does require at least V5R4 to handle the pointer variables.   Code could also be created to use the SQL CLI APIs. That would allow you to create a cursor and fetch rows in reverse order. Again, it requires V5R4 for pointers.   If you want pure CL, you can use OVRDBF to position to a record number. The RCVF command will read the record that you position at. You could write two CL programs. The first would cycle through record numbers from highest to lowest. It would call the second program and pass the record number as a parm. The second program would have OVRDBF and RCVF to read one record each time it was called.   There are multiple methods, but there is no point in doing it. It's far easier in languages that have support for data base files. You can go to a number of other places such as the comp.sys.ibm.as400.misc newsgroup or the midrange.com mailing list and ask the same question. You might get additional answers. But if you're so deep into learning, you can go to the IBM Information Center and read everything there is about CL or you can go to school to learn CL.   It's unlikely, though, that anyone has time to look up all of the information for you and then copy/paste it into a reply. It's also unlikely that anyone has time to write a bunch of program code that has no purpose.   Tom
    125,585 pointsBadges:
    report
  • nuccio
                 PGM                                                                        DCL        VAR(&OBJAMG) TYPE(*CHAR) LEN(6)                                 DCLF       FILE(QAFDBASI) /* file output DSPFD member +                                 list */                                                       DLTF       FILE(QTEMP/QAFDBASILF)                                          MONMSG     MSGID(CPF0000)                                                  DSPFD      FILE(QGPL/*ALL) TYPE(*BASATR) +                                              OUTPUT(*OUTFILE) OUTFILE(QTEMP/QAFDBASILF)                    MONMSG     MSGID(CPF0000)                                                  DSPFD      FILE(QUSRSYS/*ALL) TYPE(*BASATR) +                                           OUTPUT(*OUTFILE) +                                                         OUTFILE(QTEMP/QAFDBASILF) OUTMBR(*FIRST *ADD)                 MONMSG     MSGID(CPF0000)                                                  OPNQRYF    FILE((QTEMP/QAFDBASILF)) KEYFLD((ATFCDT +                                    *DESCEND))                                                    OVRDBF     FILE(QAFDBASI) TOFILE(QTEMP/QAFDBASILF) +                                    MBR(*FIRST) SHARE(*YES)                           LOOPINI:    RCVF       /* read */                                                      MONMSG     MSGID(CPF0864 CPF4101) EXEC(GOTO +                                           CMDLBL(Loopend))                                   CHGVAR     VAR(&OBJAMG) VALUE(&ATFCDT)                          GOTO       CMDLBL(Loopini)                          Loopend:                                                        FINE:       ENDPGM                                            
    290 pointsBadges:
    report
  • 6r
    Thanks for suggestions but.... Pasted code is not showing any record.?
    1,590 pointsBadges:
    report
  • nuccio
    Hellois only an axamples to read in reverse mode a pf file.Bye
    290 pointsBadges:
    report
  • 6r
    I was expecting a solid example on running which could produce results.
    1,590 pointsBadges:
    report
  • 6r
    ..any other solid example please?
    1,590 pointsBadges:
    report
  • TomLiotta
    No solid example exists because no one ever had a reason to do it. And everybody has work to do so, so there's no time to write programs that will never be used. Remember that everyone volunteers their time here. -- Tom
    125,585 pointsBadges:
    report
  • Splat
    I've used CL to process a file in a particular sequence (most recently to order libraries by descending size).  The examples provided in this thread are more than sufficient to form a basis for what you say you need.  Now, if you want someone to write it for you, indicate what rate you're willing to pay and see if there are any takers.
    7,305 pointsBadges:
    report
  • TomLiotta
    ...(most recently to order libraries by descending size).   Yes, if columns are available for ordering, it's easy to read in forward or reverse order. The question so far has not indicated anything but "arrival sequence", and that implies that there are no columns that can be used for ordering.   The order would need to be by relative record number in descending sequence. That is what makes the procedure meaningless. So far, there is no reason to do it.   To get it done "in CL" from a basic system starting point is neither trivial nor obvious. It takes effort and a fairly strong understanding of the whole system. Without a solid foundation of general knowledge already in place, it would take far too much to cover all of the various needed sub-topics.
    125,585 pointsBadges:
    report
  • TomLiotta
    ...Once again, for no particularly visible reason, my last comment had the final couple of paragraphs truncated away. I'd 'Edit' to add them back in if 'Edit' would work. -- Tom
    125,585 pointsBadges:
    report
  • 6r
    Dear All , this physical file(it could be any simple physical file like abc which has suppose 3 fields x,y,z and i want to read this abc pf's all 3 fields data to be read from last record to first record) needs to be read in reverse order rrnwise means from last record to first record. It could improve my cl programming logic if someone could post eaxct code to fulfill this requirement. By seeing the program code i will develope some understanding how t thanks
    1,590 pointsBadges:
    report
  • 6r
    ..to write code for such requirements in cl. Thanks
    1,590 pointsBadges:
    report
  • TomLiotta
    You should understand that this isn't a training site. That's what schools and paid trainers are for. There are far too many things to train people in. If we do training for one person, then we need to do training for everyone who asks. (And there are millions of people who would start asking.)   We would never be finished. And we wouldn't have time to do what this site is intended to do -- to help IT professionals solve real problems.   Now, if this was an actual business problem, help would be easier to give. But this is just curiosity. When it's your own curiosity, you need to do experimenting on your own. The manuals are available in the Information Center.   Everything you need to know has already been given. Every command that you need has been given. If you want to try coding the experiment, and you run into a problem, then you can post your code and someone will probably help explain what is going wrong.   But without a business reason, you need to begin on your own. That's how you will develop more understanding.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    And seeing an example won't help your understanding of CL. It's not a CL function. If you want to read a database file in reverse, then use a database language; don't use CL. -- Tom
    125,585 pointsBadges:
    report
  • bvining
    Assuming that your file is named ArrSeqFile, the record length is 50 bytes of character data, and you have installed the no-charge runtime base option of Control Language for Files (found at http://www.powercl.com/clf/clfdownloads) then the following program will read ArrSeqFile in reverse RRN order and display the contents of each record. If the record has three fields defined (as you suggest in an earlier append) you can either %sst them out (if character) or use *defined storage within my declared &Text variable (which represents the record buffer).Pgm Dcl Var(&Text) Type(*Char) Len(50) Dcl Var(&EOF) Type(*Lgl) OpnFCLF FileID(ArrSeqFile) LvlChk(*No) PosDBFCLF FileID(ArrSeqFile) Type(*End) ReadRcdCLF FileID(ArrSeqFile) Type(*Prv) EOF(&EOF) + RcdBuf(&Text) DoWhile Cond(*Not &EOF) SndPgmMsg Msg(&Text) ToPgmQ(*Ext) ReadRcdCLF FileID(ArrSeqFile) Type(*Prv) + EOF(&EOF) RcdBuf(&Text) EndDo CloFCLF FileID(ArrSeqFile) EndPgm If the preceding source is in member RdReverse of source file QCLSRC then you can compile it with CRTBNDCL RDREVERSE. To run it CALL RDREVERSE. Bruce Vining
    6,510 pointsBadges:
    report
  • 6r
    I tried writing following code but its not working:- PGM DCLF FILE(JKJK1/ID6) OPNID(A) DCLF FILE(JKJK1/DID6) OPNID(B) DCL VAR(&RRN) TYPE(*DEC) LEN(10 0) top: RTVMBRD FILE(JKJK1/ID6) NBRCURRCD(&RRN) OVRDBF FILE(ID6) POSITION(*RRN &RRN) IF COND(&RRN *NE 0) THEN(GOTO CMDLBL(READ)) READ: RCVF OPNID(A) MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END)) SNDRCVF DEV(*FILE) RCDFMT(REC4) OPNID(B) CHGVAR VAR(&RRN) VALUE(&RRN-1) GOTO CMDLBL(top) END: ENDPGM means its not reading an recod from id6(pf) which i wanted to display on did(which is based on id6) any suggestions/corrections? Thanks
    1,590 pointsBadges:
    report
  • TomLiotta
    It reminds me of a story...   A brunette tells her doctor "It hurts wherever I touch... my arm, my side, my leg, everywhere."   Doc says "You colored your hair, right?"   "Why, yes! How'd you know?"   "Because you've broken your finger."   These two lines in your program need to be thought about:   top: RTVMBRD FILE(JKJK1/ID6) NBRCURRCD(&RRN)...GOTO CMDLBL(top)   As soon as you GOTO TOP, the RTVMBRD command sets &RRN back to the number of records in the member. That puts it right back where the program started. It doesn't matter if you subtract before the GOTO. After the GOTO gets back to RTVMBRD, you reset &RRN and wipe out the subtraction.   And this line:   OVRDBF FILE(ID6) POSITION(*RRN &RRN)   That's only going to work once in this program. When you run RCVF, the file is opened. If you loop back to run OVRDBF again, it won't have any effect. You have to close the file, then run OVRDBF, then open the file again.   I haven't tested with i 6.1 to see how the CLOSE command might be used with this form of OVRDBF. You might try it to see what happens, if you have i 6.1 or later. (You haven't told us what version of CL you are using.)   If you can't make it work, you will need to put the RCVF command into a second program and call that program inside your loop. Each time the second program returns to the loop, the file can close automatically.   Bruce Vining's comment highlights the feature of CL that lets you extend the CL language. He has written programming that he accesses through new CL commands that he also wrote. By installing his new commands, you can use them in your own CL programs. You could create commands to do the same things, but you have to know how to call the functions that can read a file in reverse first.   But think about the problems I mentioned above. See if it gives you any ideas on how to make changes to your test program. You already have pretty much all of the parts.   And if you try to do more and run into a problem, tell us what the problem is. You have to tell us more than just "It doesn't work." You have to tell us what it does that is not correct.   Tom
    125,585 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