litrax
6th July 2007, 17:08
Here is my try to get rid of the annoying task to display (and maintain) all jobs in all companys:


|******************************************************************************
|* tccom9100.0000 0 VRC B40C c4 mef1
|* Multicompany Jobs verwalten
|* 2006-04-19
|******************************************************************************
|* Main table tccom000 Firmen, Form Type 1
|******************************************************************************

|****************************** declaration section ***************************
declaration:

|****************************** tables ****************************************

table ttccom000 | Firmen
table tttaad500 | Jobdaten
table tttadv300 | Forms
table ttccom903 | Temptabelle Jobs

|****************************** form variables ********************************

extern domain tcmcs.str5 ltim, stim

|****************************** prog variables ********************************

long day_local, time_local, day_temp, time_temp
long day_now, time_now, h_temp, m_temp, s_temp
long ok, ret, i
long l_ltim, l_stim
long input.ok

long l_comp_t, l_comp_s
extern domain tcmcs.str3 s_comp_t, s_comp_s
extern domain tcncmp start_comp |Startfirma
extern domain tcncmp urs_comp |Ursprungsfirma
extern domain tcncmp akt_comp |aktuelle Firma
extern domain tcmcs.long check_switch |Firmenwechsel ok?
|1 = ok

long flag.extension

|****************************** zoom variables ********************************

|****************************** defines **************************************

| #define ADD update.status = add.set
#define MODIFY update.status = modify.set
| #define DELETE update.status = mark.delete

|****************************** includes **************************************
| #pragma used dll ottdllconvert
#pragma used dll "ottdllinputstr" | DLL to handle inputstrings
#pragma used dll "ottdllbw" | DLL to handle bw- functions

|****************************** program section *******************************
before.program:
flag.extension = 0
l_comp_s = get.compnr()
change_company(1, l_comp_s)

| get.jobdata()
initialise.tccom903()
|****************************** form section **********************************

|****************************** choice section ********************************
choice.user.0:
on.choice:
initialise.tccom903()
| for i = 1 to filled.occ
| do.occ.without.update (i, refresh)
| endfor

do.all.occ(refresh)
execute(first.set)

choice.user.1:
on.choice:
zoomsession("tt", "aad", "5100m0001")

choice.user.2:
on.choice:

zoomsession("tt", "aad", "5204m0001")

choice.user.3:
on.choice:

zoomsession("tt", "aad", "5511m0001")

choice.user.4:
on.choice:

zoomsession("tt", "aad", "5101m0001")

choice.user.5:
on.choice:
if flag.extension = 0 then
flag.extension = 1
query.extension = "tccom903.jsta = tcjsta.queue or tccom903.jsta = tcjsta.active or tccom903.jsta = tcjsta.runtime.error"
to.key(2)
rebuild.query()
| initialise.tccom903() |not really needed!?!
else
flag.extension = 0
query.extension = "" |????
rebuild.query()
| initialise.tccom903() |not really needed!?!
endif

do.all.occ(refresh)
execute(first.set)
execute(find.data)

choice.end.program:
before.choice:
clear.temp.table()
exit(1)

choice.abort.program:
before.choice:
clear.temp.table()
exit(0)
|****************************** form section **********************************

|****************************** field section *********************************
field.tccom903.comp:
before.input:
if MODIFY then
attr.input = false
endif

field.tccom903.cjob:
before.input:
if MODIFY then
attr.input = false
endif

field.ltim:
before.display:
if tccom903.ltim >= 2300 then
l_ltim = tccom903.ltim - 2200
else
l_ltim = tccom903.ltim + 200
endif

ltim = str$(l_ltim)

if len(shiftl$(strip$(ltim))) = 3 then
ltim = "0" & ltim
endif

if len(shiftl$(strip$(ltim))) = 1 then
ltim = "0" & ltim & "00"
endif

ltim = ltim(1;2) & ":" & ltim(3;2)

field.stim:
before.display:

if tccom903.stim >= 2300 then
l_stim = tccom903.stim - 2200
else
l_stim = tccom903.stim + 200
endif

stim = str$(l_stim)

if len(shiftl$(strip$(stim))) = 3 then
stim = "0" & stim
endif

if len(shiftl$(strip$(stim))) = 1 then
stim = "0" & stim & "00"
endif

stim = stim(1;2) & ":" & stim(3;2)

field.tccom903.edte:
before.input:
if MODIFY then
if tccom903.jsta = tcjsta.not.active
or tccom903.jsta = tcjsta.interrupted then
attr.input = true
else
attr.input = false
endif
endif
before.display:
if tccom903.stim >= 2300 then
tccom903.edte = tccom903.edte + 1
endif

field.tccom903.ldat:
before.display:
if tccom903.ltim >= 2300 then
tccom903.ldat = tccom903.ldat + 1
endif

field.tccom903.jsta:
before.input:
if MODIFY then
enum2()
endif
|****************************** function section ******************************
functions:
function initialise.tccom903()
{
db.retry.point()

select tccom903.*
from tccom903 for update
selectdo
db.delete(ttccom903, db.retry)
commit.transaction()
endselect

get.jobdata()
}

function get.jobdata()
{
select tccom000.*
from tccom000
where tccom000.ncmp in (100, 110, 115, 120, 125, 140, 165, 190)
selectdo
select ttaad500.*
from ttaad500
where ttaad500._compnr = :tccom000.ncmp
selectdo
fill.tccom903()
endselect
endselect
}

function fill.tccom903()
{

long status

db.retry.point()

select tccom903.*
from tccom903 for update
where tccom903._index1 = {:tccom000.ncmp, :ttaad500.cjob}
selectdo
tccom903.comp = tccom000.ncmp
tccom903.cjob = ttaad500.cjob
tccom903.desc = ttaad500.desc
tccom903.ldat = ttaad500.ldat
tccom903.ltim = ttaad500.ltim
tccom903.edte = ttaad500.edte
tccom903.stim = ttaad500.stim
status = etol(ttaad500.jsta)
tccom903.jsta = ltoe(status)
db.update(ttccom903, db.retry)
commit.transaction()
selectempty
tccom903.comp = tccom000.ncmp
tccom903.cjob = ttaad500.cjob
tccom903.desc = ttaad500.desc
tccom903.ldat = ttaad500.ldat
tccom903.ltim = ttaad500.ltim
tccom903.edte = ttaad500.edte
tccom903.stim = ttaad500.stim
status = etol(ttaad500.jsta)
tccom903.jsta = ltoe(status)
db.insert(ttccom903, db.retry, db.skip.dupl)
commit.transaction()
endselect
}

function clear.temp.table()
{
db.retry.point()

select tccom903.*
from tccom903 for update
| where tccom903._index1 = {:tccom000.ncmp, :ttaad500.cjob}
selectdo
db.delete(ttccom903, db.retry)
commit.transaction()
endselect
}

function enum2()
{
on case tccom903.jsta
case tcjsta.not.active:
set.enum.values(tcjsta.not.active, tcjsta.queue,
tcjsta.blocked)
break
case tcjsta.waiting:
attr.input = false
break
case tcjsta.active:
attr.input = false
break
case tcjsta.interrupted:
tccom903.jsta = tcjsta.not.active |!?
set.enum.values(tcjsta.interrupted, tcjsta.not.active,
tcjsta.queue, tcjsta.blocked)
break
case tcjsta.runtime.error:
tccom903.jsta = tcjsta.not.active |!?
set.enum.values(tcjsta.not.active,
tcjsta.interrupted, tcjsta.queue, tcjsta.blocked)
break
case tcjsta.queue:
set.enum.values(tcjsta.queue, tcjsta.not.active,
tcjsta.interrupted, tcjsta.blocked)
break
case tcjsta.blocked:
set.enum.values(tcjsta.blocked, tcjsta.not.active,
tcjsta.interrupted, tcjsta.queue)
break
endcase
}

function long ascii.input.string(string mwindow.title(80),
string label(80),
long p.width,
ref string s_comp_t() )
{
long win_id
long height, width, row, col
long attrs(WINMAXSIZE)

long new_color, red_int, green_int, blue_int

mwindow.title = strip$(mwindow.title)
label = strip$(label)


new_color = rgb(0,0,0)
red_int = red.component( new_color ) | 46
green_int = green.component( new_color ) | 139
blue_int = blue.component( new_color ) | 87

height = 5
width = max(len(mwindow.title), len(label) + p.width + 2) + 4

win_id = current.window()

get.window.attrs(win_id, attrs)
row = win.height(attrs)
col = win.width(attrs)
row = int(row / 2.0) - int(height / 2.0)
col = int(col / 2.0) - int(width / 2.0)

win_id = sub.window(win_id, height, width, row, col )

box(1, 1, width, height, 1)

row = 1
col = 3
if not isspace( mwindow.title) then
print cp$(col, row) & " " & mwindow.title & " "
endif

row = 3
if not isspace(label) then
print cp$(col, row) & label
col = col + len(label) + 2
endif
data.input(sprintf$("%d %d 0 %d L='\E'", col, row, p.width),
s_comp_t,
s_comp_t)

cl.screen(1, 1, width, height)
del.window(win_id)
refresh()

return (s_comp_t <> chr$(27))
}

function long change_company(long mode, long target_comp)
{
if mode = 1 then
start_comp = get.compnr()
endif
urs_comp = get.compnr()
check_switch = switch.to.company(target_comp)
if check_switch <> 1 then
mess("tcmcss0000",1, target_comp) |Sie haben keine Berechtigung für Firma...
return(false)
else
akt_comp = get.compnr()
return(true)
endif
return(false)
}

function long check_job_status(long target_comp, domain tccjob job, long status)
{
| status = etol(ttaad500.jsta)

select ttaad500.*
from ttaad500
where ttaad500._index1 = {:job}
and ttaad500._compnr = :target_comp
selectdo
if ttaad500.jsta = ltoe(status) then
return(true)
endif
endselect
return(false)
}
function zoomsession(string package(2), string module(3), string formnumber(9))
{
s_comp_t = ""

string formname(60)
string sess(13)
sess = package & module & formnumber

select ttadv300.*
from ttadv300
| where ttadv300._index1 inrange {"3", :package, :module, :formnumber, "", "", ""}
| and {"3", :package, :module, :formnumber, "ZZZZ", "ZZ", "ZZZZ"}
| and ttadv300._compnr = "000"
| as set with 1 rows
| where ttadv300._index1 = {"3", :package, :module, :formnumber, "", "", ""}
where ttadv300.clan = "3"
and ttadv300.cpac = :package
and ttadv300.cmod = :module
and ttadv300.cfrm = :formnumber
and ttadv300._compnr = "000"
selectdo
formname = ttadv300.desc
endselect

if graphical.mode then
input.ok = input.string(formname, "Geben Sie die Zielfirma an...", 3, 3, s_comp_t)
else
input.ok = ascii.input.string(formname, "Geben Sie die Zielfirma an...", 3, s_comp_t)
endif
if input.ok and not isspace(s_comp_t) then
l_comp_t = lval(s_comp_t)
if change_company(2, l_comp_t) then
zoom.to$(sess,z.session,"","",0)
change_company(2, l_comp_s)
endif
else
|abort()
endif

do.all.occ(refresh)
}


Some remarks:


UTC: The times in the job tables are in UTC- format. I couldn't manage it to convert the times to the local format because of errors. If somebody got an idea what library to include, or elsehow got a clue, please let me know. So far the times are converted manually. Unfortunately one must change this, when summer- and wintertime changes.
The custom table tccom903 is used and the custom domain tcjsta, a copy of the domain ttaad.jsta with the same enum-values, is used.
The company numbers in the function get.jobdata() must be adjusted to your prefered company numbers.
The function check_job_status() is declared but not yet used.
A few remarks and messages are in german but they should be easily translated into english.
It usually was intended to maintain the dates, times, states etc. in this session (write it to tccom903 and ttaad500). Therefor there are some pieces of code that are not actually used/needed eg. field.tccom903.edte:
before.input:
if MODIFY then
if tccom903.jsta = tcjsta.not.active
or tccom903.jsta = tcjsta.interrupted then
attr.input = true
else
attr.input = false
endif
endif
Actually there is no documentation of this little thing, but I think one should figure out to handle it if he could read and understand the code...


Attached is a ZIP-file with the following tarballs:
dtcjsta.tar.gz - the dump of the domain tcjsta
tccom9100m000.tar.gz - the dump of the session
ttccom903.tar.gz - the dump of the table tccom903 including the labels

So try it out and let me know if you have any suggestions to improve the code, form, etc.