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
}

patvdv
14th March 2003, 23:14
Looks like a very handy little tool indeed, but is it not easier to use the '+date' notation in the job sessions so that Baan always uses a data relative to the system date?

lbencic
14th March 2003, 23:45
Oo this is so handy, just for the reason you mention. The Baan Job can handle incrementing dates, but I think it has a problem incrementing Periods.

Thanks Francesco :)

Francesco
14th March 2003, 23:51
Well, yes, but that would make sense.

Actualy, in this particular case it changes the period, not the date.

Felt very stupid there for a second. ;)

patvdv
14th March 2003, 23:53
Lisa, thanks for pointing out the mistake to me. Francesco, my fault, accept my humble apologies for questioning the usefulness of your code :)

Francesco
15th March 2003, 00:02
And Lisa, glad you find it useful.

Francesco
16th December 2003, 02:01
This just in.

Somebody pointed out to me that the session as listed above was now causing data corruption.

It caused me some headaches, but I finally figured out what the issue is. The first three numbers that lead the fieldnames (like 016ncmp.f) indicate the length of the stringpart to follow.

Consequently, when we went from September to October, the changed datestring became one character longer (9 -> 10) and the leading "checksum" should have been updated accordingly.

I will post an updated version this week, unless somebody beats me to it. Just thought I'd let y'awl know.

Francesco
16th December 2003, 17:52
Well, I won't get any style-points on this one, but it does the trick.


|* Rev.No. 5 ceB50obuat 26 Nov 03 rmcmilli
|* This is to revert back to the original code set.[revision number = 5]
|* Rev.No. 6 ceB50obuat 26 Nov 03 rmcmilli
|* |
|* Rev.No. 7 ceB50obuat 15 Dec 03 ffrentro
|* Changed job parameter for testing purposes
|* Rev.No. 8 ceB50obuat 15 Dec 03 ffrentro
|* Changed job parameters for testing
|* Rev.No. 9 ceB50obuat 15 Dec 03 ffrentro
|* Parameter change for testing
|* Rev.No. 10 ceB50obuat 15 Dec 03 ffrentro
|* Replaced spaces with 0 in 029seak.f
|******************************************************************************
|* 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!!
|* ffrentro
|* 03-13-03 [10:35]
|******************************************************************************
|* Script Type: 123
|******************************************************************************

|****************************** DECLARATION SECTION ***************************
declaration:
#ident "@(#)cecusadmin001 ceB50obuat uscobrmfa-ug-36 Rev.No. 11 15 Dec 03 ffrentro"

table tttaad503 | Display Job Input Variables



|****************************** FORM SECTION ***************************

|****************************** CHOICE SECTION ***************************
choice.cont.process:
on.choice:
| execute(print.data)
|
|choice.print.data:
|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), tempstring(200)
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:="" 0"""
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"""
| This is where it gets double tricky. We are changing values and therefore, we will also have
| to change the leading three-digit number that indicates the total length of the relevant
| string part. To do so, the string value is stored in a temporary string without the leading
| number and is then dressed up using the dress.up function that adds the 3-digit lead.
tempstring = "last.inv.year:=""" & currentyear & """"
dress.up(tempstring)
newvalue = newvalue & tempstring

newvalue = newvalue & "021tfgld003.psep:=""/"""

tempstring = "last.inv.period:=""" & currentperiod & """"
dress.up(tempstring)
newvalue = newvalue & tempstring

newvalue = newvalue & "022last.paym.date:=""0"""

tempstring = "last.paym.year:=""" & currentyear & """"
dress.up(tempstring)
newvalue = newvalue & tempstring

newvalue = newvalue & "021tfgld003.psep:=""/"""

tempstring = "last.paym.period:=""" & currentperiod & """"
dress.up(tempstring)
newvalue = newvalue & tempstring

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 = "MAPAG2"
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
}

function void dress.up(ref string base.string())
{
string string.length(3)

string.length = str$(len(base.string) + 3)
while len(string.length) < 3
string.length = "0" & string.length
endwhile

base.string = string.length & base.string

}

ltannous
26th October 2004, 17:07
I am getting compilation errors for the \ expressions.
Error( 49):Error: '\" not exptected. It repeats this up to line 81

lbencic
26th October 2004, 17:31
There's just a little typo on the ident - remove the '\' from the ident line.

~Vamsi
26th October 2004, 19:21
It is my fault. The code styling I wrote seems to fail on this forum. Patrick, could you please remove the "HTML allowed" on this forum. We may have to redo some of the postings though.

gfasbender
26th October 2004, 19:52
I don't think it's the HTML setting in this forum. I think it's the "[code=baan]" interpreter. Pat, has something with this changed recently?

patvdv
26th October 2004, 20:55
It is indeed a conflict between HTML parsind and the enscript code styling. I have switched HTML off as we don't really need it anyway and it is safer as well. Any volunteers to redo and update the code Index thread in the Wiki?

~Vamsi
27th October 2004, 02:30
Gordon,

The syntax highlighting is done using enscript. When we migrated from version 2 to version 3 of the vBulletin software I ported the integration. What I did miss was support for HTML based forums.

When I saw the problem reported, we had two options.
- Go fix the enscript integration
- Reevaluate our need for HTML

Again I apologize for not having done a better job at coding the integration and testing it.

As for maintaining the index on Wiki - count me out :).