zOs/REXX/ANAPOT2

//A540769Y JOB (CP00,KE50),'DB2 REO',                                   00010000
//         MSGCLASS=T,TIME=1440,                                        00020000
//         NOTIFY=&SYSUID,REGION=0M,                                    00030000
//         SCHENV=DB2,CLASS=M1                                          00040000
//*
//S1       EXEC PGM=IKJEFT01,DYNAMNBR=200,TIME=99,                      00020001
//             PARM='%WSH'
//SYSPROC   DD DSN=A540769.WK.REXX,DISP=SHR
//SYSPRINT  DD SYSOUT=*
//SYSUDUMP  DD SYSOUT=*
//SYSTSPRT  DD SYSOUT=*
//SYSTSIN   DD DUMMY
//WSH       DD *
$#@   $*(  copy anO/P and anR/P to tmp lib and generate calls
      $*)
$<~WK.TEXT(ANAPOBP1)
$>~WK.TEXT(ANAPOBP2)
cx = 13
cy = 22
$=p= A540769.TMP.ANAP
sx = 0
$for i $@[
    sx = right(sx + 1, 4, 0)
    if sx > 50 then leave
    j = strip($i)
    dbSy = substr(j, cx-5, 4)
    auf = substr(j, cx, 8)
    q4 = substr(j, cy, 4)
    qR = strip(substr(j, cy+4))
    if ddl.auf \== 1 & sysDsn("'DSN.DBX"dbSy".DDL("auf")'")==ok then $@[
        ddl.auf = 1
        call readDsn "DSN.DBX"dbSy".DDL("auf")", i.
        call writeDsn $p || dbSy".DDO(S"sx") ::f", i., , 1
        $$- 'PRE' dbSy auf ${p}dbSy".DDO(S"sx")" qR
        $]
    if q4 = 'ANP.' then
        f = 'ANA'
    else
        f = 'REC'
    call readDsn "DSN.DBY"dbSy"."auf"."left(q4,2)"O."substr(j, cy+4), i.
    call writeDsn $p || dbSy"."left(q4, 2)"O(S"sx") ::f", i., , 1
    call readDsn "DSN.DBY"dbSy"."auf"."left(q4,2)"P."substr(j, cy+4), i.
    call writeDsn $p || dbSy"."left(q4, 2)"P(S"sx") ::f", i., , 1
    $$- f dbSy auf ${p}dbSy"."left(q4, 2)"O(S"sx")" qR
    $]
$#out                                              20151109 16:47:12
$#out                                              20151109 16:45:55