How to sort the reord in CPYTOIMPF command?

115 pts.
Tags:
AS/400
Hi, I have written text file records by using CPYTOIMPF command. When I saw my final output reord then the total field value display at the top. So it cause due to sorting process. So how can I avoid this menas I want the total valu at bottom. Ex:--- Name Add NO A aaaaa 1 B bbbbb 2 C ccccc 3 After Command Execution CPYTOIMPF Output is Name Add NO ' ' ' ' 6 A aaaaa 1 B bbbbb 2 C ccccc 3 The first record shows total of no ... That is just exapmle I have givan so ... can we use any paramer so that that the order of record is changed. Or any one can gove me solution for this problem. For ur info command paramete I have used CPYTOIMPF FROMFILE(File) TOSTMF(&FILET) MBROPT(*ADD) STMFCODPAG(*PCASCII) RCDDLM(*CRLF) + DTAFMT(*DLM) STRESCCHR(*STRDLM) FLDDLM(',')

Software/Hardware used:
yes

Answer Wiki

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

 

Hi,

A Small suggestion.. Assuming your from file is keyed in necessasry order …Do copy the from file to a temp file (in qtemp at run time) and then do a CPYTOIMPF with the temp file.

Hope this was helpful..:)

Discuss This Question: 7  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
    Is the to-file keyed?  Is the from-file keyed?Is there an Override of the from-file when it's copied?Use DSPPFM to see each files. 
    51,355 pointsBadges:
    report
  • TomLiotta
    ...it cause due to sorting process. So how can I avoid this menas I want the total valu at bottom.   There is no "sorting process" for CPYTOIMPF. Any sorting is done by your file definitions. How is your FROMFILE() defined?   Also, you don't show that your 'totals' record is in your input file. You show that you only have three records, but your final stream file has four lines. You also show that you are using MBROPT(*ADD) and you don't show what was in the streamfile before you ran the command. We don't have any way to know what the final result should be.   Tom
    125,585 pointsBadges:
    report
  • ssssssssssssssss
    Hi Tom, Actually my fromf is one of the Physical file in which no key field define. I just pick that file in CL override it in qtemp and from qtemp I just pick that file records and move to Tofile into this CPYTOIMPF command. In Physical file reord shown ok also total value shows at bottom but why this sequence shows reverse in output file. I just want to ask in previous example Name is first field so CPYTOIMPF command automatically sort record or we can define it. Bcoz in my last Record Name and address fields are blank only total of no should display , So I guess it happen bcoz blank character shows first thats why it shows first. For output purpose I have moved 'D' value in Name field for last reord then the Output shows proper means total value shows at last. So the same thing i want to write without using that "D" or anything. I just wnat my reord and its totdal at bottom.   I  
    115 pointsBadges:
    report
  • TomLiotta
    ...in my last Record Name and address fields are blank only total of no should display   So, what you showed us is not what was actually in the file. That makes it harder to help.   For output purpose I have moved ‘D’ value in Name field for last reord then the Output shows proper means total value shows at last.   If you change the data in the file, you change the order of the result in the final streamfile. I don't see the file definition yet, so there isn't much that I can say except that I get the correct result when I use the data that you showed. There are only a couple likely reasons.   First, your version of CPYTOIMPF might run differently.than mine. I can't be sure what version yours is because you didn't include anything about your environment. I can see you're at least at V5R4 because you show the STRESCCHR() parameter, but it might be 6.1 or 7.1 with numerous PTF possibilities.   But second, your file definition is almost certainly different from mine. I created a basic table that I know has no inherent data ordering, and it works fine. If yours doesn't work, we need to know what it is about it that affects the result.   That's about all anyone can say for now.   Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Sorry to take so long to respond: SQL does not guarantee the order in which records are returned unless an ORDER BY clause is specified. The CPYTOIMPF command uses SQL under the covers (with no ORDER BY). Therefore, the order of the records in the destination file was not guaranteed. This is still true for release V5R4 and prior releases.At V6R1 and V7R1 , the CPYTOIMPF has been enhanced by PTFs with a new option ORDERBY :CPYTOIMPF ORDERBY(*NONE) CPYTOIMPF ORDERBY(*ARRIVAL) CPYTOIMPF ORDERBY(Col1, Col2) "Flying is learning how to throw yourself at the ground and miss." Douglas Adams      
    51,355 pointsBadges:
    report
  • philpl1jb

    From IBM Bulletin

     

    SQL does not guarantee the order in which records are returned unless an ORDER BY clause is specified. The CPYTOIMPF command uses SQL under the covers (with no ORDER BY). Therefore, the order of the records in the destination file was not guaranteed. This is still true for release V5R4 and prior releases.

     

    At V6R1 and V7R1 , the CPYTOIMPF has been enhanced by PTFs with a new option

    ORDERBY :CPYTOIMPF

    ORDERBY(*NONE) CPYTOIMPF

    ORDERBY(*ARRIVAL) CPYTOIMPF ORDERBY(Col1, Col2)

     

    51,355 pointsBadges:
    report
  • ShajiMohan
    Hi, A Small suggestion.. Assuming your from file is keyed in necessasry order …Do copy the from file to a temp file (in qtemp at run time) and then do a CPYTOIMPF with the temp file. Hope this was helpful..:)
    45 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