ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

CPYTOIMPF and MBROPT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CPYTOIMPF and MBROPT

    Hello,

    I have modified a program, which means that an output file (PF) can now be empty at the end of processing. Before this change there were always records in this file.

    The CL that calls this program then executes CPYTOIMPF to copy this PF to a stream file.

    Code:
    CPYTOIMPF  FROMFILE(MyPF) +                      
                 TOSTMF(&FICDES) +                       
                 MBROPT(*REPLACE) STMFCODPAG(*PCASCII) + 
                 RCDDLM(*CRLF) STRDLM(*NONE) +           
                 RMVBLANK(*TRAILING) FLDDLM(';') +       
                 DECPNT(*COMMA)
    I wanted to be sure that trying to copy an empty file would still work, in the sense that the stream file would be empty too. What I don?t understand is the IBM help for MBROPT which states

    Note: If *ADD is specified and the to-file contains no records, the copy operation completes normally. If *REPLACE is specified and the to-file contains no records, the copy operation ends abnormally.
    Applying this logic, if my stream file (the ?to-file?) is empty and I try to copy (with MBROPT *REPLACE) from a PF (which contains records) the operation should end abnormally?

    But when I test this scenario it works absolutely fine. What am I missing? Does the MBROPT parameter only apply when copying using TOFILE and not TOSTMF? Or should the IBM help say ?from-file? instead of ?to-file? ?

    The OS is V7R1

  • #2
    Re: CPYTOIMPF and MBROPT

    OK I?ll answer my own question. Unless I?m being really stupid (and I hope that you will tell me if I am !) I think that it is just an error in the IBM documentation for CPYTOIMPF (?to-file? specified instead of ?from-file?)

    For CPYF (as discussed in Kevin?s thread below) as we all know

    If *ADD or *UPDADD is specified and the from-file is empty (contains no records), the copy operation completes normally. If *REPLACE is specified and the from-file is empty, the copy operation ends abnormally.
    So I?m not quite sure why for CPYTOIMPF we find

    If *ADD is specified and the to-file contains no records, the copy operation completes normally. If *REPLACE is specified and the to-file contains no records, the copy operation ends abnormally.
    Anyway all my tests prove that the command behaves exactly as I want with *REPLACE.

    And contrary to the logic of CPYF if I copy an empty PF to a stream file with records, the stream file is cleared. So yippee...

    Comment

    Working...
    X