Search code examples
sortingjclsyncsort

Subtract value in columnA of file A from ColumnB of fileB, through JCL sorting/syncsort. DISPLAY RESULT IN FILE3 (new file)


Have input file1:

 C1   C2        C3
 5102;22680372 =0000000001
 5111;21840112 =0000000002
 5363;21980235 =0000000002
 5363;22700216 =0000000001

Input File 2:

 5111;21840112 =0000000002
 5363;21980235 =0000000001
 5363;22700216 =0000000001  

Expected Output: should be sorted on below way,

   JOINKEYS FILES=F1,FIELDS=(1,04,A,6,8,A,16,10,a) 
   JOINKEYS FILES=F2,FIELDS=(1,04,A,6,8,A,16,10,a) 
   REFORMAT FIELDS=(F1:1,.. and... ) 

I need outputfile with this swquence

   File1 C1  File1 C2    file1C3     [file1C3 - file2 C3] value
   5102;     22680372   =0000000001  =00000             *(no records in second file for it)
   5111;     21840112   =0000000002  =00000             *(1-1 =0)
   5363;     21980235   =0000000002  =00001             *(2-1= 1)
   5363;      22700216  =0000000001  =00000             *(1-1 =0) 
  • is just to explain you trying this right now

    OPTION COPY
    JOINKEYS F1=INA,FIELDS=(1,4,A,6,8,A)
    JOINKEYS F2=INB,FIELDS=(1,4,A,6,8,A)
    REFORMAT FIELDS=(F1:1,25,F2:16,10)
    INREC BUILD=(1,25,26,10,SFF,SUB,36,10,SFF,EDIT=(STTTTTT))

Result:

   5060;22222222 =0000000001 (blank)  i just need 0001 - nothin(0) = 1 simply 1 here         
   5102;22680372 =0000000001;000000000
   5105;22222222 =0000000002 (blank)   need 2 here same 2-0 or nothing(unmatched) = 2         

Solution

  • You are close. However, SFF is not needed. This is Signed Free Format, and you have an unsigned fixed-format number. Use ZD. Your EDIT is not big enough for 10 digits. This is not a problem if your result can never, and I mean never, exceed six digits. With the "=", which you have no code to produce, it is unclear where you expect the sign to go (it is leading the field at the moment).

    With what you have so far, you will only get records which match between the two files. You will need:

     JOIN UNPAIRED,F1
    

    After the second JOINKEYS if you want unmatched records from F1 in your output.

    If you don't have a match, the subtraction will be problematic, so you'll need some code for that. How you code that depends on whether you have DFSORT or SyncSort.

    If either, or both, of the input files you should specify SORTED on the appropriate JOINKEYS statement. With DFSORT, but not SyncSort, you can specify NOSEQCHK as well.

    With further information, we progress:

      OPTION COPY 
      JOINKEYS F1=INA,FIELDS=(1,4,A,6,8,A) 
      JOINKEYS F2=INB,FIELDS=(1,4,A,6,8,A) 
    
      JOIN UNPAIRED,F1 
    
      REFORMAT FIELDS=(F1:1,25,F2:16,10),FILL=X'FF' 
    
      INREC IFTHEN=(WHEN=(35,1,CH,EQ,X'FF'), 
                     OVERLAY=(26:C'+',10C'0')), 
            IFTHEN=(WHEN=NONE, 
                         OVERLAY=(26:16,10,ZD,SUB,26,10,ZD, 
                                  EDIT=(STTTTTTTTTT),SIGNS=(+,-))) 
    

    UNPAIRED,F1 means that along with paired records (matches) unpaired records from F1 are presented to the Main Task.

    The REFORMAT statement defines the data record that the Main Task will use. In this example, the entire F1 record is included (F1:1,25) and just the 10-digit number from F2 (F2:16,10).

    The FILL= tells SORT what to set the values to for any missing record in the case of an unpaired record. In this case, the 26,10 of the REFORMAT record will be set to all X'FF'.

    IFTHEN=(WHEN=(logical-expression is then used to identify an X'FF' in position one of the number from the F2 data. If X'FF' is present, then there is no match. In that case, the bytes sourced from F2 are set to whatever default value you actually want.

    IFTHEN=(WHEN=NONE is active for any records which have not satisfied an IFTHEN=(WHEN=(logical-expression. The calculation is done, and the output of the calculation is formatted.

    If either of the input files is already in the order you want, look at the previous advice.

    If you want the output from the Main Task in a different order, you simply code a SORT statement, and remove the OPTION COPY.

    The exact output format you want is unclear, but you should be able to fix that up for what you want.

    You need to get hold of a SyncSort Manual. They are freely available as PDFs to sites with a SyncSort licence. If no-one knows how to give you one, then find out who is the point-of-contact with SyncSort and get them to request a manual through SyncSort Support. Supply just a couple of details, and you will have a copy, probably by return e-mail.