Francesco
14th March 2003, 22:20
Nothing spectacular, but a handy utility. Please note that this is not generic code. It will have to be modified for every specific situation. It's the idea that matters in this case.
What brought this up was a request to have a job to print a certain report that would always print last month data.
I put this script in a session and attached it to the existing job, so that after job completion, it would autmoatically set the parameters for next month run.
Have fun.
******************************************************************************
|* cecusadmin001 0 VRC B50o b uat
|* Update job parameters
|* This session changes the job parameters of job 'MAPAG' automatically.
|* This script contains hard coded values!!
|* Francesco Frentrop
|* 03-13-03 [10:35]
|******************************************************************************
|* Script Type: 4
|******************************************************************************
|****************************** DECLARATION SECTION ***************************
declaration:
table tttaad503 | Display Job Input Variables
|****************************** FORM SECTION ***************************
|****************************** CHOICE SECTION ***************************
choice.cont.process:
on.choice:
read.main.table()
|****************************** MAIN TABLE SECTION ***************************
functions:
function read.main.table()
{
| The tricky part is that the session variables are stored as a continuous string
| but in chunks of 200 characters in ttaad503.rcrd.
| There are multiple records in the table, distinguished by sequence number.
| Therefore, the first chunk of 200 characters will go in the record with seq. no. 0,
| the second 200 characters in seq. no. 1, etc.
| The code below first collects all of the session variables in the string newvalue,
| and then cuts it up in 200 char chunks. This means that the limit to the total string
| length is dictated by the maximum string variable size of 1024 bytes.
| Since it probably won't come down to 24 bytes, I limited it to 1000 characters for
| added ease and comfort.
| This assumption is good enough for this particular scenario and helps to keep the code
| down, but WHEN USING THIS CODE AS A BASIS FOR OTHER (SIMILAR) SCRIPTS, MAKE SURE TO
| VERIFY THAT THE 1000 CHAR LIMITATION IS NOT EXCEEDED!!
string newvalue(1000), currentperiod(2), currentyear(4)
long yearno, monthno, dayno, hours, mins, secs, refa, x
refa = utc.to.date( utc.num(), yearno, monthno, dayno, hours, mins, secs )
currentperiod = str$(monthno)
currentyear = str$(yearno)
newvalue = "" | empty newvalue as a precaution. note: "" in string = "
newvalue = newvalue & "016ncmp.f:=""100"""
newvalue = newvalue & "016ncmp.t:=""100"""
newvalue = newvalue & "016ccty.f:="" """
newvalue = newvalue & "016ccty.t:=""ZZZ"""
newvalue = newvalue & "016creg.f:="" """
newvalue = newvalue & "016creg.t:=""ZZZ"""
newvalue = newvalue & "016fisu.f:="" """
newvalue = newvalue & "016fisu.t:=""ZZZ"""
newvalue = newvalue & "022suno.f:="" """
newvalue = newvalue & "022suno.t:=""ZZZZZZZZZ"""
newvalue = newvalue & "029seak.f:="" """
newvalue = newvalue & "029seak.t:=""ZZZZZZZZZZZZZZZZ"""
newvalue = newvalue & "019form.hcur:=""USD"""
newvalue = newvalue & "024euro.translation:=""0"""
newvalue = newvalue & "023tfacp004.agan:=""020"""
newvalue = newvalue & "050tfacp004.desc:=""ACCT AGING WITH OVER 120 DAYS """
newvalue = newvalue & "016based.on:=""1"""
newvalue = newvalue & "020selection.on:=""2"""
newvalue = newvalue & "020print.status:=""1""021print.costinv:=""1"""
newvalue = newvalue & "019print.fully:=""2"""
newvalue = newvalue & "025print.anticipated:=""1""014step.f:=""0"""
newvalue = newvalue & "021last.inv.date:=""0"""
newvalue = newvalue & "024last.inv.year:=""" & currentyear & """"
newvalue = newvalue & "021tfgld003.psep:=""/"""
newvalue = newvalue & "023last.inv.period:=""" & currentperiod & """"
newvalue = newvalue & "022last.paym.date:=""0"""
newvalue = newvalue & "025last.paym.year:=""" & currentyear & """"
newvalue = newvalue & "021tfgld003.psep:=""/"""
newvalue = newvalue & "024last.paym.period:=""" & currentperiod & """"
newvalue = newvalue & "023as.on.date:=date()+0018as.on.year:=""0"""
newvalue = newvalue & "021tfgld003.psep:=""/"""
newvalue = newvalue & "020as.on.period:=""0"""
| newvalue now contains the string that we have to distribute over the 200 char records
| in ttaad503.
for x = 0 to (len(newvalue)/200)
db.retry.point()
select ttaad503.rcrd
from ttaad503 for update
where ttaad503.cjob = " MAPAG"
and ttaad503.seri = 1
and ttaad503.sequ = :x
selectdo
ttaad503.rcrd = newvalue(x * 200 + 1;200) | The x-th chunk of 200
db.update(tttaad503, db.retry)
commit.transaction()
endselect
endfor
}
What brought this up was a request to have a job to print a certain report that would always print last month data.
I put this script in a session and attached it to the existing job, so that after job completion, it would autmoatically set the parameters for next month run.
Have fun.
******************************************************************************
|* cecusadmin001 0 VRC B50o b uat
|* Update job parameters
|* This session changes the job parameters of job 'MAPAG' automatically.
|* This script contains hard coded values!!
|* Francesco Frentrop
|* 03-13-03 [10:35]
|******************************************************************************
|* Script Type: 4
|******************************************************************************
|****************************** DECLARATION SECTION ***************************
declaration:
table tttaad503 | Display Job Input Variables
|****************************** FORM SECTION ***************************
|****************************** CHOICE SECTION ***************************
choice.cont.process:
on.choice:
read.main.table()
|****************************** MAIN TABLE SECTION ***************************
functions:
function read.main.table()
{
| The tricky part is that the session variables are stored as a continuous string
| but in chunks of 200 characters in ttaad503.rcrd.
| There are multiple records in the table, distinguished by sequence number.
| Therefore, the first chunk of 200 characters will go in the record with seq. no. 0,
| the second 200 characters in seq. no. 1, etc.
| The code below first collects all of the session variables in the string newvalue,
| and then cuts it up in 200 char chunks. This means that the limit to the total string
| length is dictated by the maximum string variable size of 1024 bytes.
| Since it probably won't come down to 24 bytes, I limited it to 1000 characters for
| added ease and comfort.
| This assumption is good enough for this particular scenario and helps to keep the code
| down, but WHEN USING THIS CODE AS A BASIS FOR OTHER (SIMILAR) SCRIPTS, MAKE SURE TO
| VERIFY THAT THE 1000 CHAR LIMITATION IS NOT EXCEEDED!!
string newvalue(1000), currentperiod(2), currentyear(4)
long yearno, monthno, dayno, hours, mins, secs, refa, x
refa = utc.to.date( utc.num(), yearno, monthno, dayno, hours, mins, secs )
currentperiod = str$(monthno)
currentyear = str$(yearno)
newvalue = "" | empty newvalue as a precaution. note: "" in string = "
newvalue = newvalue & "016ncmp.f:=""100"""
newvalue = newvalue & "016ncmp.t:=""100"""
newvalue = newvalue & "016ccty.f:="" """
newvalue = newvalue & "016ccty.t:=""ZZZ"""
newvalue = newvalue & "016creg.f:="" """
newvalue = newvalue & "016creg.t:=""ZZZ"""
newvalue = newvalue & "016fisu.f:="" """
newvalue = newvalue & "016fisu.t:=""ZZZ"""
newvalue = newvalue & "022suno.f:="" """
newvalue = newvalue & "022suno.t:=""ZZZZZZZZZ"""
newvalue = newvalue & "029seak.f:="" """
newvalue = newvalue & "029seak.t:=""ZZZZZZZZZZZZZZZZ"""
newvalue = newvalue & "019form.hcur:=""USD"""
newvalue = newvalue & "024euro.translation:=""0"""
newvalue = newvalue & "023tfacp004.agan:=""020"""
newvalue = newvalue & "050tfacp004.desc:=""ACCT AGING WITH OVER 120 DAYS """
newvalue = newvalue & "016based.on:=""1"""
newvalue = newvalue & "020selection.on:=""2"""
newvalue = newvalue & "020print.status:=""1""021print.costinv:=""1"""
newvalue = newvalue & "019print.fully:=""2"""
newvalue = newvalue & "025print.anticipated:=""1""014step.f:=""0"""
newvalue = newvalue & "021last.inv.date:=""0"""
newvalue = newvalue & "024last.inv.year:=""" & currentyear & """"
newvalue = newvalue & "021tfgld003.psep:=""/"""
newvalue = newvalue & "023last.inv.period:=""" & currentperiod & """"
newvalue = newvalue & "022last.paym.date:=""0"""
newvalue = newvalue & "025last.paym.year:=""" & currentyear & """"
newvalue = newvalue & "021tfgld003.psep:=""/"""
newvalue = newvalue & "024last.paym.period:=""" & currentperiod & """"
newvalue = newvalue & "023as.on.date:=date()+0018as.on.year:=""0"""
newvalue = newvalue & "021tfgld003.psep:=""/"""
newvalue = newvalue & "020as.on.period:=""0"""
| newvalue now contains the string that we have to distribute over the 200 char records
| in ttaad503.
for x = 0 to (len(newvalue)/200)
db.retry.point()
select ttaad503.rcrd
from ttaad503 for update
where ttaad503.cjob = " MAPAG"
and ttaad503.seri = 1
and ttaad503.sequ = :x
selectdo
ttaad503.rcrd = newvalue(x * 200 + 1;200) | The x-th chunk of 200
db.update(tttaad503, db.retry)
commit.transaction()
endselect
endfor
}