Search code examples
filecommandibm-midrange

AS400 cpyf not copying a character record


I am trying to copy all of the records from a data file (STUDMARKS) into my physical file (MARKS) using the CPYF command.

 A          R MARKSR                    TEXT('Marks Records')
 A            STUDENTID      9S 0       COLHDG('Student' 'ID')
 A            COURSE_CD      6A         COLHDG('Course' 'Code')
 A            FINAL_MARK     3S         COLHDG('Final' 'Mark')
 A            DATERUN         L         COLHDG('Date' 'Run')
 A          K STUDENTID
 A          K COURSE_CD 

This is what I currently have in my MARKS.pf. The STUDMARKS.pf-dta file has the first three records already defined, the DATERUN record get filled with the date of use.

CPYF FROMFILE(IBC233LIB/STUDMARKS) TOFILE(DS233B32/MARKS) MBROPT(*REPLACE) FMTOPT(*MAP *DROP)

The above is the CPYF command that I ran after creating MARKS.pf, and after doing a RUNQRY to see all the records I've noticed that all but the COURSE_CD have been filled. COURSE_CD is completely blank.

I did some research before hand and did a DSPFFD on both members to ensure that the record lengths and types were all the same, which they were. I did notice, however, that in STUDMARKS.pf-dta that all the records had a buffer length which was equivalent to the field length. The STUDENTID field in MARKS.pf was the only one to not share this property, where the field length is 9, but the buffer length is only 5. I'm not sure if it's the reason why I'm having such difficulty, and the matter is almost certainly less so than what I'm making it out to be, but I've been at this for quite some time and a just can't seem to copy records from one member to another.

It's incredibly frustrating, and help would be greatly appreciated


I took screen shots of the DSPFFD commands for both files

For STUDMARKSScreen Shot of DSPFFD StudMarks

And For MARKSenter image description here

EDIT Just now seeing the spelling error! Smashing my head against the desk but I almost guarantee that is the problem. All of your answers were very informative and helpful though, so thank you very much

EDITEDIT for others, despite the fact that I did change the names when recompiling the program, it will not work unless you delete the file first and THEN compile it. Very frustrating, but that's just how it is...

So DLTF [file name] and then recompile


Solution

  • What you are experiencing is the difference between a packed and a signed decimal field.

    More than likely you forgot to specify a datatype in position 35 of the DDS specification for the STUDENTID field in the MARKS file.

    For example:

    A            STUDENTID      9S 0       COLHDG('Student' 'ID')   
    
               Data        Field  Buffer    Buffer        Field    Column  
    Field      Type       Length  Length  Position        Usage    Heading 
    STUDENTID  ZONED        9  0       9         1        Both     Student 
                                                                   ID
    

     

    A            STUDENTID      9  0       COLHDG('Student' 'ID')   
    
               Data        Field  Buffer    Buffer        Field    Column  
    Field      Type       Length  Length  Position        Usage    Heading 
    STUDENTID  ZONED        9  0       5         1        Both     Student 
                                                                   ID
    

     

    A            STUDENTID      9P 0       COLHDG('Student' 'ID')   
    
               Data        Field  Buffer    Buffer        Field    Column  
    Field      Type       Length  Length  Position        Usage    Heading 
    STUDENTID  PACKED       9  0       5         1        Both     Student 
                                                                   ID
    

    The explanation for this behaviour can be found in the DDS reference in the section Data type for physical and logical files (position 35):

    For physical files, if you do not specify a data type or duplicate one from a referenced field, the operating system assigns the following defaults:

    • A (character) if the decimal positions 36 through 37 are blank.
    • P (packed decimal) if the decimal positions 36 through 37 contain a number in the range 0 through 63.

    Because the data types are different the FMTOPT(*MAP *DROP) tells the CPYF command to silenty drop and default any non-matching fields.

    The odd thing is the file field description identifies the field as ZONED when it is really PACKED.