PK.RADKEY
A^prefix,
"PATS",@1,
END;

[1]::PATS
/ARGV[1]^DT,
2^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   ?(A)AAAI[ACT]^aa,
   "RAD",@2,
   nr+1^nr};

[2]::RAD
""^rt^RD,
DO{+?(R)RTP[RD,aa,rt]^rt "SEND",@3;
   +?(R)RTP[RD]^RD};

[3]::SEND
IF{"check report enter date against date from pk",
   $(R1)RT[rt]DT|0<DT;
   $(R1)RT[rt]|0^dept,(&(R)RD[dept]|3'="Y");
   "<Document>"^!,
   "<InstanceMnemonic>"_prefix_rt_"</InstanceMnemonic>"^!,
   "append x to key because t0 may be empty",
   "<Key>"_"x"_$(R1)RT[rt]T|0_"</Key>"^!,
   "<PersonMnemonic>"_$(A)AA[aa]|3_"</PersonMnemonic>"^!,
   "<EventEndDateTime>"_$(R1)RT[rt]DT|0_$(R1)RT[rt]DT|1_"</EventEndDateTime>"^!,
   "<EventSetMnemonic>RAD</EventSetMnemonic>"^!,
   "</Document>"^!};

