‎2007 Jun 13 11:31 AM
hi experts,
i have a internal table with 90000 enteries,it has got details of background jobs. itab will have currently only details of jobname and runtime, other fields are blank.
Eg : jobname | runtime | averageruntime | minruntime | maxruntime | Count
JOB1 | 28 | | | |
JOB1 | 14 | | | |
JOB2 | 10 | | | |
JOB2 | 5 | | | |
JOB3 | 8 | | | |
required is:
jobname | runtime | averageruntime | minruntime | maxruntime | Count
JOB1 | 28 | 21 | 14 | 28 | 2
JOB1 | 14 | 21 | 14 | 28 | 2
JOB2 | 10 | 7.5 | 5 | 10 | 2
JOB2 | 5 | 7.5 | 5 | 10 | 2
JOB3 | 8 | 8 | 8 | 8 | 1
Kindly suggest the code.
Thanks in advance
Bijal
‎2007 Jun 14 6:45 AM
Hi Bijal,
Do you remember the construct called At New ... EndAt.
It works like this -
1. The fields you are using in AT NEW clause show be inorder in table declaration.
2. The table should be sorted as per the field order, either sort table explicitly using SORT statement or modify your SELECT query itself to fetch sorted records.
Rest follow this code -
DATA: BEGIN OF gt_jobs OCCURS 0, "Assume appropriate declaration here
jobname TYPE char01,
runtime TYPE i,
averageruntime TYPE i,
minruntime TYPE i,
maxruntime TYPE i,
count TYPE i,
END OF gt_jobs.
DATA:
gv_totruntime TYPE i,
gs_job LIKE LINE OF gt_jobs.
* I assume sorted records as per job name here
LOOP AT gt_jobs.
gs_job-runtime = gt_jobs-runtime.
AT NEW jobname.
gs_job-count = 0.
gv_totruntime = 0.
gs_job-maxruntime = 0.
gs_job-minruntime = gs_job-runtime.
ENDAT.
IF gs_job-minruntime > gt_jobs-runtime.
gs_job-minruntime = gt_jobs-runtime.
ENDIF.
IF gs_job-maxruntime < gt_jobs-runtime.
gs_job-maxruntime = gt_jobs-runtime.
ENDIF.
ADD 1 TO gs_job-count.
ADD gt_jobs-runtime TO gv_totruntime.
AT END OF jobname.
gs_job-averageruntime = gv_totruntime / gs_job-count.
MODIFY gt_jobs FROM gs_job
TRANSPORTING averageruntime
minruntime
maxruntime
count
WHERE jobname = gt_jobs-jobname.
ENDAT.
ENDLOOP.
You can also view <b>zirt_table_control_events</b> at .91 / .83 server
Tell me if your problem is solved.
Regards,
Manish Joshi
‎2007 Jun 13 11:45 AM
Hi,
You can get and populate other data from table TBTCO.
Thanks and regards,
S. Chandra Mouli.
‎2007 Jun 13 11:50 AM
HI ..
Thanks
But TBTCO table does not give avg runtime, min , max
i found out runtime by subtracting strttime from endtime.
i have to calculate it
‎2007 Jun 13 11:48 AM
Hi,
try this logic.
take another itab itab2
<b>loop at itab1.</b>
clear: i, sumruntime, maxruntime, minruntime.
<b>loop at itab2 where jobname =itab1-jobname.</b>
i = i + 1.
if i = 1.
minruntime = itab2-runtime.
maxruntime = itab2-runtime.
endif.
if itab2-runtime GT maxruntime.
maxruntime = itab2-runtime.
endif.
if itab2-runtime LT minruntime.
minruntime = itab2-runtime.
endif.
sumruntime = sumruntime + itab2-runtime.
<b>endloop.</b>
itab1-minruntime = minruntime.
itab1-maxruntime = maxruntime.
itab1-count = i.
itab1-averageruntime = sumruntime / i.
modify itab1.
<b>endloop.</b>
---patil
Message was edited by:
Santhosh Patil
Message was edited by:
Santhosh Patil
‎2007 Jun 14 6:45 AM
Hi Bijal,
Do you remember the construct called At New ... EndAt.
It works like this -
1. The fields you are using in AT NEW clause show be inorder in table declaration.
2. The table should be sorted as per the field order, either sort table explicitly using SORT statement or modify your SELECT query itself to fetch sorted records.
Rest follow this code -
DATA: BEGIN OF gt_jobs OCCURS 0, "Assume appropriate declaration here
jobname TYPE char01,
runtime TYPE i,
averageruntime TYPE i,
minruntime TYPE i,
maxruntime TYPE i,
count TYPE i,
END OF gt_jobs.
DATA:
gv_totruntime TYPE i,
gs_job LIKE LINE OF gt_jobs.
* I assume sorted records as per job name here
LOOP AT gt_jobs.
gs_job-runtime = gt_jobs-runtime.
AT NEW jobname.
gs_job-count = 0.
gv_totruntime = 0.
gs_job-maxruntime = 0.
gs_job-minruntime = gs_job-runtime.
ENDAT.
IF gs_job-minruntime > gt_jobs-runtime.
gs_job-minruntime = gt_jobs-runtime.
ENDIF.
IF gs_job-maxruntime < gt_jobs-runtime.
gs_job-maxruntime = gt_jobs-runtime.
ENDIF.
ADD 1 TO gs_job-count.
ADD gt_jobs-runtime TO gv_totruntime.
AT END OF jobname.
gs_job-averageruntime = gv_totruntime / gs_job-count.
MODIFY gt_jobs FROM gs_job
TRANSPORTING averageruntime
minruntime
maxruntime
count
WHERE jobname = gt_jobs-jobname.
ENDAT.
ENDLOOP.
You can also view <b>zirt_table_control_events</b> at .91 / .83 server
Tell me if your problem is solved.
Regards,
Manish Joshi