LVL or Goup by wise Sum
I have 4 column ca_code, ca_title, ca_lvl, trs_db
SQL> desc tb_all;
Name Null? Type
CA_CODE VARCHAR2(20)
CA_TITLE VARCHAR2(100)
CA_LVL NUMBER(1)
TRS_DB NUMBER(15,3)The data of this table
SQL> Select * from Tb_all order by ca_code ;
CA_CODE CA_TITLE CA_LVL TRS_DB
5 INCOME & REVENUES 1
51 INCOME & REVENUES 2
5101 SERVICES INCOME 3
510101 SERVICES INCOME 4
510101001 SERVICES & FACILITATION INCOME 5 140,000
510102 OTHER INCOME 4
510102001 WATER SUPPLY CHARGES 5 130,000
510103 PROFIT ON BANK DEPOSIT 4
510103001 PROFIT ON BANK DEPOSIT HMBL 5 120,000
510104 GAIN/LOSS ON INVESTMENT 4
510104001 UN-REALIZED CAPITAL GAIN ON INVESTM 5 110,000Trs_DB has values only where ca_LVL = 5
When I use this query
select ca_code,ca_title,ca_lvl,sum(trs_db) trs_db
from tb_all
group by ca_code,ca_title,ca_lvl;
Return these rows where trs_db is not null (only in ca_lvl =5)
510101001 SERVICES & FACILITATION INCOME 5 140,000
510102001 WATER SUPPLY CHARGES 5 130,000
510103001 PROFIT ON BANK DEPOSIT HMBL 5 120,000
510104001 UN-REALIZED CAPITAL GAIN ON INVESTM 5 110,000I need this query.
CA_CODE CA_TITLE CA_LVL TRS_DB
5 INCOME & REVENUES 1 500,000 --total of 5
51 INCOME & REVENUES 2 500,000 --total of 51
5101 SERVICES INCOME 3 500,000 --total of 5101
510101 SERVICES INCOME 4 140,000 --total of 510101
510101001 SERVICES & FACILITATION INCOME 5 140,000
510102 OTHER INCOME 4 130,000 --total of 510102
510102001 WATER SUPPLY CHARGES 5 130,000
510103 PROFIT ON BANK DEPOSIT 4 120,000 --total of 510103
510103001 PROFIT ON BANK DEPOSIT HMBL 5 120,000
510104 GAIN/LOSS ON INVESTMENT 4 110,000 --total of 510104
510104001 UN-REALIZED CAPITAL GAIN ON INVESTM 5 110,000CA-Lvl 5 sum in ca_lvl 4 and ca_lvl 4 sum should be in ca_lvl 3 and so on.
Thanks
I have not tested this code. It might work.
select ca_code, ca_title, ca_lvl, trs_db, case when ca_code = col_1
then sum(nvl(trs_db,0)) over(partition by col_1)
when ca_code = col_2
then sum(nvl(trs_db,0)) over(partition by col_2)
when ca_code = col_3
then sum(nvl(trs_db,0)) over(partition by col_3)
when ca_code = col_4
then sum(nvl(trs_db,0)) over(partition by col_4)
when ca_code = col_5
then sum(nvl(trs_db,0)) over(partition by col_5)
when ca_code = col_6
then sum(nvl(trs_db,0)) over(partition by col_6)
when ca_code = col_7
then sum(nvl(trs_db,0)) over(partition by col_7)
when ca_code = col_8
then sum(nvl(trs_db,0)) over(partition by col_8)
when ca_code = col_9
then sum(nvl(trs_db,0)) over(partition by col_9)
End Sum_value
from
select CA_CODE, CA_TITLE, CA_LVL, TRS_DB,
substr(ca_code,1,1) col_1,
substr(ca_code,1,2) col_2,
substr(ca_code,1,3) col_3,
substr(ca_code,1,4) col_4,
substr(ca_code,1,5) col_5,
substr(ca_code,1,6) col_6,
substr(ca_code,1,7) col_7,
substr(ca_code,1,8) col_8,
substr(ca_code,1,9) col_9
from tb_all
);Regards
Raj
Similar Messages
-
How to Calculate the row wise sum in pivot table to get the total value
Product AAA BBB CCC Total
Printer 23 35 11 69
Book 2 4 3 9
Regards792011 wrote:
Kranthi,
I already did those steps. I am able to see only the total if there are values for three rows. Here is the example. The report show show even there any no value in one of the rows
Product AAA BBB CCC Total
Printer 23 35 11 69
Book 2 4 3 9
Pencil 5 200 205
Pen 159 159
Bottle -30 -30
Appreicate Your Help
RegardsI'm going to take a shot and guess that you meant a total shows up only if there are values for each column. I am further going to guess that the example you gave is what you'd like to see, not what is actually going on. If so, then you need to modify your measure like this:
IFNULL(measurecolumn, 0)
Then you will get a sum even if one of you columns is null. -
How to find deptno wise sum(sal) using subquery
hi all,
how to find deptno wise sum(sal) using subquery.
can u tell me any one please.
thanks,
regards.If we are talking standard emp and dept tables ala scott schema then (say); -
select ename, sal, total_dept_salary
from emp,
(select sum(sal) as Total_Dept_Salary,
deptno
from empt
group by
deptno) saldept
where emp.deptno = saldept.deptno
Is that what you were after?? (I would advise against correlated sub-queries on all but the most modest of tables)
There are nicer ways of doing the subquery depending on which version of the db you are on... -
hi experts,
I have an itab where i have
delivno matnr weight
1 A 1000
1 A 500
1 B 2000
i need an output like this
delivno matnr weight
1 A 1500
1 B 2000
sort itab by delivno matnr.
loop at itab.
at new matnr.
sum.
write:/ itab-delivno,itab-matnr,itab-weight.
endat.
endloop.
but it is not working ..what mey be the reason ..
what shall i do to get the output.
regards,
maniHi Manik,
You can use the Collect Statement.
The collect statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key.
*So in your case the delivno matnr should be character*
and the weight field should be numeric.
and also the order of fields in the internal table should be like that
first character fields then all the numeric fields.
SELECT BUKRS LIFNR BELNR BLART WAERS WRBTR
FROM BSIK INTO CORRESPONDING FIELDS OF
TABLE ITAB FOR ALL ENTRIES IN FILETAB WHERE
BUKRS = FILETAB-BUKRS AND
LIFNR = FILETAB-LIFNR AND
BELNR = FILETAB-BELNR AND
BLART = 'KR'.
LOOP AT FILETAB.
LOOP AT ITAB WHERE LIFNR = FILETAB-LIFNR AND
BELNR = FILETAB-BELNR.
MOVE ITAB-BUKRS TO ITAB_FD-BUKRS.
MOVE ITAB-LIFNR TO ITAB_FD-LIFNR.
MOVE ITAB-BELNR TO ITAB_FD-BELNR.
MOVE ITAB-BLART TO ITAB_FD-BLART.
MOVE ITAB-WAERS TO ITAB_FD-WAERS.
MOVE ITAB-WRBTR TO ITAB_FD-WRBTR.
COLLECT ITAB_FD.
ENDLOOP.
Reward Points, if helpful.
Regards,
Manoj Kumar -
How to find group wise total in crystal report?
Dear All,
I have to find the total of a Quantity value based on the Item code.How to achieve that in Crystal report.
Scenario:
Itemcode orderno Qty
A 1 100
A 2 20
A 3 30
B 1 10
B 2 20
Now i have to find the group total based on the Item code: Like A:150 and B:30 which should come like mentioned below
A Total 150
A 1 100
A 2 20
A 3 30
B Total 30
B 1 10
B 2 20
Can anybody pls tell me how to solve this?Hi,,Raghavendra
I attach new image... Providing better understaning....
I want to try some steps which are defined above....
My basic Requirement is ITEMCODE WISE SUM OF QUANTITY. -
I have a SQL Server Reporting Services report that has a textbox within a Report with variations of the following expression
=Sum(IiF(Fields!RegisterID.Value = 6000, 1, 0)
and
Iif(Fields!PointID.Value = 500, 1, 0)) / Sum(Iif(Fields!PointID.Value = 500, 1, 0))
I see the following error when I try to preview the report:
The Value expression for the text box ‘Textbox2’ uses an aggregate expression without a scope. A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset.
What am I missing in this this expression to make it run incorrectlyCan you include dataset name in your sum functions? e.g. Sum(IiF(Fields!RegisterID.Value = 6000, 1, 0)
and
Iif(Fields!PointID.Value = 500, 1, 0)) should include your dataset name as Sum(IiF(Fields!RegisterID.Value = 6000, 1, 0) and Iif(Fields!PointID.Value = 500, 1, 0),"datasetname")Like wise Sum(Iif(Fields!PointID.Value = 500, 1, 0)) should also have dataset name Sum(Iif(Fields!PointID.Value = 500, 1, 0),"datasetname")
Gaur -
sir this is my data
whose deptid=0 that all father
Acid deptid amount
K2 0 0
K21 0 0
K2101 0 0
K210101 K17 1750378
K210102 K20 364578
K210103 K19 817415
K210104 K23 432684
K2102 0 0
K210201 K17 836750
K210202 K20 1993475
K210203 K19 2921924
K2103 0 0
K210301 K12 90960
K210302 K9 5500
K210303 K17 10238
K210303 K21 580
K210303 K23 2690
K2104 0 0
K210402 K25 3800
K210403 K6 3850
K22 0 0
K2201 0 0
K220101 0 0
K22010101 K18 77390
K22010102 K17 45000
K22010102 K18 1300
K220102 0 0
K22010201 K25 55800
K220103 0 0
K22010301 K21 67860
K22010302 K12 3000
K22010302 K9 3000
K220105 K5 73638
K2202 0 0
K220202 K17 43500
K220202 K19 15000
K220204 K5 35700
K2203 0 0
K220301 K15 106151
K220301 K21 90000
K220302 K15 11025
K220304 K10 2600
K220304 K12 1085
K2204 0 0
K220401 K12 50000
K220401 K15 1158860
K220401 K4 60000
K220402 K15 123500
K220403 K24 10250
K220403 K4 4000
K2205 0 0
K220501 K15 71620
K220501 K19 11000
K220501 K24 3000
K220501 K9 9453
K220502 0 0
K22050201 K27 12980
K2206 0 0
K23 0 0
K2301 0 0
K230101 K12 51854
K230101 K27 1186751
K230102 0 0
K23010201 K12 408140
K230103 0 0
K23010301 K3 454310
K23010302 K3 7500
K230104 0 0
K23010401 K22 333400
K230106 0 0
K23010601 K9 142929
K23010602 K9 4500
K230108 K34 -7491
K230108 K4 651820
K230109 0 0
K23010902 K7 81371
K230110 K10 148800
K230111 0 0
K23011101 K21 105488
K23011101 K6 104683
K230113 0 0
K23011301 K8 131608
K230114 0 0
K23011401 K15 138625
K2302 0 0
K230201 K7 12236
K230203 K12 3388
K230203 K21 1332
K230203 K27 1484
K230203 K3 2713
K230203 K4 23796
K230203 K5 2726
K230203 K6 2421
K230203 K9 14490
K230205 K4 49026
K2303 0 0
K230301 K27 4000
K230301 K4 178370
K230302 K27 5694
K2304 0 0
K230401 K27 2656
K230401 K4 54817
K230402 K4 7769
K230403 K27 2461
K2305 0 0
K230503 K4 236665
K230504 K16 7659
K230504 K4 3526
K2306 0 0
K230601 K12 1450
K230601 K13 7900
K230601 K15 3855
K230601 K16 830
K230601 K17 2000
K230601 K4 65763
K230601 K8 25325
K230602 K3 675
K230602 K4 26909
K230603 K4 251910
K230604 K10 18050
K230604 K12 25900
K230604 K15 6900
K230604 K18 7700
K230604 K21 3800
K230604 K24 23000
K230604 K3 9500
K230604 K4 27297
K230604 K5 3850
K230604 K6 11950
K230604 K8 400
K230604 K9 3300
K2308 0 0
K230801 K13 138500
K230801 K4 707850
K230802 K13 3000
K230803 K13 3700
K230803 K4 3880
K2309 0 0
K230901 K10 200
K230901 K12 20707
K230901 K13 200
K230901 K15 2000
K230901 K27 91510
K230901 K3 8521
K230901 K4 2075
K230901 K5 120
K2310 0 0
K231001 K13 1170
K231001 K4 22716
K231002 K12 12742
K231002 K16 9215
K231002 K4 6961
K231002 K9 1326
K231004 K13 14335
K231004 K15 31566
K231004 K16 372787
K231004 K24 2427
K231004 K27 6414
K231004 K34 8910
K231004 K4 385266
K2311 0 0
K231101 K27 116731
K231102 K4 223605
K2312 0 0
K231202 K4 60600
K231205 K4 32000
K2313 0 0
K231301 K13 254334
K231301 K3 2255
K231301 K4 1192833
K231301 K6 11035
K231302 K13 6800
K231302 K15 3500
K231302 K8 200
K231303 K18 3200
K231303 K4 500
K231303 K6 3700
K231305 K4 14000
K231306 K13 4200
K231306 K4 2550
K231307 K4 3205
K231308 K27 65182
K231308 K4 25075
K231310 K13 5650
K231310 K4 6500
K231311 K13 117363
K231311 K3 4395
K231311 K4 8635
K231312 K4 1600
K231313 K13 80524
K231313 K34 40444.39
K231313 K4 375507
K231314 K13 42300
K231314 K4 83620
K231315 K13 95550
K2314 0 0
K231401 K27 38370
K231401 K4 39102
K2315 K3 4000
K2316 0 0
K231602 K4 35000
K2318 K12 667
K2318 K15 10000
K2318 K8 19508
K2319 0 0
K231903 K13 3220
K231903 K23 18000
K231903 K3 4000
K231903 K4 55676
K231903 K7 153250
K231904 K13 5400
K231904 K4 6500
K231905 K13 53978
K231905 K16 26200
K231905 K4 122350
K231906 K22 990
K231906 K27 3990
K231906 K4 469644
K231906 K9 11000
K231907 K4 2000
K2320 0 0
K232001 K3 1012657
K2321 K3 2150
K2321 K8 7824
K2322 0 0
K232202 K10 3000
K232202 K13 3200
K232202 K25 35
K232202 K27 550
K232202 K3 1580
K232202 K4 35654
K232202 K5 882
K232206 K16 25160
sir my need is
all child amount sum and show in father group by deptid
such as acid K2 is a father all those amount sum that have start 2 word is K2 group by deptid
such as
sir I use case but that give only sum amount or only one value not give all deptid wise sum result
select deptid,acid,
case when deptid=0 then
(select sum(amount) from
(SELECT accid,'0' AS deptid,0 AS amount FROM CHARTOFACC WHERE SUBSTR(CHARTOFACC.accid,1,2)='K2' AND fstatus=1
UNION
SELECT mfa.accid,mfa.deptid,mfa.amount FROM (
SELECT VOUDETAIL.deptid,VOUDETAIL.accid,NVL(SUM(debit),0)-NVL(SUM(credit),0) AS AMOUNT
FROM VOUMASTER,VOUDETAIL,DEPARTMENTMFA WHERE VOUMASTER.vno=VOUDETAIL.vno AND SUBSTR(VOUDETAIL.accid,1,2)='K2' AND VOUDETAIL.deptid=DEPARTMENTMFA.deptid
AND VOUMASTER.entdate BETWEEN '01-jul-2006' AND '30-jun-2007'
GROUP BY VOUDETAIL.deptid,VOUDETAIL.accid) mfa)
where substr(acid,1,2)=’K2’ group by deptid)
from (SELECT accid,'0' AS deptid,0 AS amount FROM CHARTOFACC WHERE SUBSTR(CHARTOFACC.accid,1,2)='K2' AND fstatus=1
UNION
SELECT mfa.accid,mfa.deptid,mfa.amount FROM (
SELECT VOUDETAIL.deptid,VOUDETAIL.accid,NVL(SUM(debit),0)-NVL(SUM(credit),0) AS AMOUNT
FROM VOUMASTER,VOUDETAIL,DEPARTMENTMFA WHERE VOUMASTER.vno=VOUDETAIL.vno AND SUBSTR(VOUDETAIL.accid,1,2)='K2' AND VOUDETAIL.deptid=DEPARTMENTMFA.deptid
AND VOUMASTER.entdate BETWEEN '01-jul-2006' AND '30-jun-2007'
GROUP BY VOUDETAIL.deptid,VOUDETAIL.accid) mfa
Acid deptid amount
K2 K1 334
K2 K2 3111
K2 K3 748
K2 K4 33422
K2 K5 33411
K21 K1 334
K21 K2 3111
K21 K3 748
K21 K4 33422
K21 K5 33411
K2101 K1 334
K2101 K2 3111
K2101 K3 748
K2101 K4 33422
K2101 K5 33411
K2201 K1 334
K2201 K2 3111
K2201 K3 748
K2201 K4 33422
K2201 K5 33411
Sir how I get child result in father group by deptid
Can I use loop in query that run dept table and sum dept wise result
Please give me idea bow I get resutl
thank'smeaby a hint I can give you is you can do a grouping by on substr. example:
create table t(v varchar2(30), n number);
insert into t values('K201',5);
insert into t values ('K202', 10);
select sum(n)
from t
group by substr(v,0,3); => result: 15
But actually I think you need to rethink your data structure. Add a parent_id so you can use hierarchical queries, ... -
Need code for calculation of amount field(DMBTR)of BSEG table conditionally
Hi all,
I am selecting data for fields belnr(A/c doc.), dmbtr(Amount), hkont(G/L acc) from bseg cluster table giving the particular value for hkont in the selection screen.now there are some records fetched out of which there are few records in which same A/c no.(belnr) .So my requirement is to collect those same belnr records and do following calculation:
1. suppose for some record of same belnr , if all the value for field SHKZG is 'H' then summing up the values of field DMBTR.
2. suppose for some record of same belnr , if few value for the field SHKZG is 'H' and few are 'S' then the (summation the values of field DMBTR for all 'H' in field SHKZG -summation the values of field DMBTR for all 'S') and both the case the single record will fetched with belnr, sum(DMBTR) according to the condition, and hkont. Please provide me the reqd. code for the above problem.Thanks in advance.
regards
Anand.Hi Anand,
We can do like this.
This will take into account 'S', 'H' (debit/credit indicator) and BELNR wise sum.
1. Create new internal table, STAB with only two fields. (with header line)
BELNR "<------- refer below statement
HKONT "<------ Whatever unique combination of field(s) you want, you can put here 1,2,
DMBTR "<----
Numeric field
If you want only HKONT wise SUM, then remove BELNR
2. Now write this code.
Loop at Itab.
Clear STAB.
IF ITAB-SHKZG = 'H'.
STAB-DMBTR = ITAB-DMBTR.
else.
STAB-DMBTR = - ITAB-DMBTR. "<----- Negative Sign
endif.
STAB-BELNR = ITAB-BELNR.
STAB-HKONT = ITAB-HKONT.
COLLECT STAB. "<------ Important.
Endloop
Note:
Based upon the alphanumeric fields combination (BELNR and HKONT), the sum will be done.
Similar to group by in a select query
regards,
amit m.
Edited by: Amit Mittal on Jan 22, 2010 2:14 PM -
Query getting alphabetical neighbours of chars in a strings
10gR2
Hello,
Can anybody give me a Select for getting the neighbour-chars (by Ascii-Code) of a simple source-string for a certain number of iterations?
E.g. the source-string is "M" and the number of iterations is 7 then the Select's should give seven rows like:
"M"
"LM"
"MN"
"LMN"
"KLM"
"MNO"
"KLMNO"
"M" is the starting char; the next iteration gives the alphabetically preceding char "L" and concats with the starting char; the next iteration gives the alphabetical successor of the starting char (and concats it); the next iteration results the next the alphabetically preceding char of the most left-sided char of the last result; the next iteration gives the next alphabetical successor of the most right-sided char of the last iteration's result... and so on...
2nd example, when starting with "DE":
"DE"
"CDE"
"DEF".....
Any ideas / hints ?Well, I don't see any business logic in that requirement, but here we go :
SQL> var letter varchar2(10)
SQL> var occ number
SQL> exec :letter:='M'
PL/SQL procedure successfully completed.
SQL> exec :occ:=7
PL/SQL procedure successfully completed.
SQL> select str
2 from (select lvl,
3 decode(lv,1,(select replace(max(sys_connect_by_path(chr(ascii(letter)-(nb-level+1)),',')),',')||letter from dual connect by level <= nb),
4 2,letter||(select replace(max(sys_connect_by_path(chr(ascii(substr(letter,-1,1))+level),',')),',') from dual connect by level <= nb),
5 (select replace(max(sys_connect_by_path(chr(ascii(letter)-(nb-level+1)),',')),',')||letter from dual connect by level <= nb)
6 ||(select replace(max(sys_connect_by_path(chr(ascii(substr(letter,-1,1))+level),',')),',') from dual connect by level <= nb)) str
7 from (select letter, level lvl, mod(level,3) lv, sum(decode(mod(level,3),1,1)) over (order by level) nb
8 from (select :letter letter, :occ occ from dual)
9 connect by level <= occ-1)
10 where :occ > 1
11 union all
12 select 0,:letter from dual where :occ>0)
13 order by lvl;
STR
M
LM
MN
LMN
KLM
MNO
KLMNO
7 rows selected.
SQL> exec :letter:='DE'
PL/SQL procedure successfully completed.
SQL> exec :occ:=3
PL/SQL procedure successfully completed.
SQL> /
STR
DE
CDE
DEF
SQL> exec :letter:='DE'
PL/SQL procedure successfully completed.
SQL> exec :occ:=4
PL/SQL procedure successfully completed.
SQL> /
STR
DE
CDE
DEF
CDEF
SQL>Nicolas.
adding a WHERE clauses to support occ=1 or occ=0
Edited by: N. Gasparotto on Dec 22, 2008 4:34 PM -
Hi Friends,
We are implementing DMS in our organization. Our file storing system is explained below.
1st level - Vendor name (like Nyro / Hydraulics / techno or code : A112 , A113, A114 etc...)
2nd level - Project name (like 1130 / 1131 / 1132 )
3rd level - Dept. (like Civil / electric/ admin)
4th levl - Incoming / Out going docs.
5th level - Type (like Drawings / docs / memos)
We want to give authorization to one group combination of levels like in 1st level - Nyro, 2nd level- A2, 3rd level -3rd level - admin, so on...our requirement is to store documents at various levels along with authorization.
our requirement is not to have individual doc. authorization, which we can do on each document on authorization tab assigning user / user group.
We need to send the work flow item to different set of persons on storage of document on each level on each status. Like if we store doc. for Nyro - 1130 - civil - incoming - Drawings (considering livels of above example) work flow should go to A1 goup other wise with to another group.
We can do this with classification (by creating characteristics / class and attaching to doc. type) but I can't have authorization at individual class or characteristic , i.e. I can control at doc. type only. Since we have three characters for doc. type code we need to make many doc. types considering above scenario.
If we use three characters of doc. type, lab office or authorization group can be used for other levels but we can't send work flow item.
By using Document structure we can make BOM by linking the two or more docs. with qty.
Is there any best way using SAP DMS ? Now we are implementing SAP R/3, not plans to invest in another software.
Regards,
Sai KrishnaHi Sai,
It's definate that the reuirement not get addressed in standard environment. Better way write a abap programe with workflow with user gropu or levels predefined and irrespective of status the group will be intimated or communicated.
Discuss with abap person who knows workflow very well.
I hope this will be helpful one.
Regards,
Ravindra -
Query required ......and have points..
Hi Experts..
I am working on "Earnig and Deduction Department wise Statemant "Report.
Department wise sum of all wage Earning (Basis Pay,LTA ect.) to be calculated. For example, in IT Department there are 10 employees so .Sum of all wages given for these 10 employees is to be added and displayed as a single value for all wage type.
wht i did..... take all deptarment and pernr in a internal table from PA0001. and than want to read the database for all wages with key PERNR and department code .
Plzz tell me the right abap query to achive the oputput...
Regards
LakhanHi Experts..
I am working on "Earnig and Deduction Department wise Statemant "Report.
Department wise sum of all wage Earning (Basis Pay,LTA ect.) to be calculated. For example, in IT Department there are 10 employees so .Sum of all wages given for these 10 employees is to be added and displayed as a single value for all wage type.
wht i did..... take all deptarment and pernr in a internal table from PA0001. and than want to read the database for all wages with key PERNR and department code .
Plzz tell me the right abap query to achive the oputput...
Regards
Lakhan -
Hi,
I have to get the Year-to-date amount on an ALV output for a GL account. Is there any FM to do it?... Currently Iam just getting the output for the period that I put in selection screen.
Thank you,
SB.Hi
You have to use the filed symbols for this purpose.
see the sample code
report zfgldr0010
line-size 122
line-count 60
no standard page heading
message-id zndc.
Database Tables
tables: bsis, " Accounting: Secondary Index for G/L Accounts
ska1, " GL Account Master
t001, " Company Codes
csks, " Cost Centers Master
setnode, " Cost Center Group Hierarchy
setleaf. " Cost Center Group Hierarchy
Declaration of Internal Tables
Internal Table to fetch the Opex Budget & Capex Actual Data
data: begin of it_bud_tab occurs 0,
lednr like cosp-lednr, " Ledger No
objnr like cosp-objnr, " Object No
gjahr like cosp-gjahr, " Fiscal Year
wrttp like cosp-wrttp, " Actuals
versn like cosp-versn, " Version
twaer like cosp-twaer, " Currency
perbl like cosp-perbl, " Period Block
kstar like cosp-kstar, " Cost Element/GL A/C No
wog001 like cosp-wog001, " Total Value
wog002 like cosp-wog002, " Total Value
wog003 like cosp-wog001, " Total Value
wog004 like cosp-wog002, " Total Value
wog005 like cosp-wog001, " Total Value
wog006 like cosp-wog002, " Total Value
wog007 like cosp-wog001, " Total Value
wog008 like cosp-wog002, " Total Value
wog009 like cosp-wog001, " Total Value
wog010 like cosp-wog002, " Total Value
wog011 like cosp-wog001, " Total Value
wog012 like cosp-wog002, " Total Value
end of it_bud_tab.
Internal Table to fetch the Settlement Costs(Opex-Actual)
data: begin of it_set_tab occurs 0,
kokrs like coep-kokrs, " Controlling Area
belnr like coep-belnr, " Acc Document
buzei like coep-buzei, " Line Item
perio like coep-perio, " Period Block
wkgbtr like coep-wkgbtr, " Value in CO Curr
lednr like coep-lednr, " Ledger No
objnr like coep-objnr, " Object No
gjahr like coep-gjahr, " Fiscal Year
wrttp like coep-wrttp, " Actuals
versn like coep-versn, " Version
kstar like coep-kstar, " Cost Element
beknz like coep-beknz, " Dr/Cr Indicator
parob1 like coep-parob1, " Partner Object
end of it_set_tab.
Internal Table to fetch the COBRB data(Settlement rules)
data: begin of cobrb_tab occurs 0,
objnr like cobrb-objnr, " Object No
rec_objnr1 like cobrb-rec_objnr1, " Ref Object No
bureg like cobrb-bureg, " Dostribution Rule
lfdnr like cobrb-lfdnr, " Sequence No
perbz like cobrb-perbz, " Settlement Rule
konty like cobrb-konty, " Acct Assign Category
bukrs like bsis-bukrs, " Company Code
kostl like bsis-kostl, " Cost Center
end of cobrb_tab.
Internal Table to Settlement Actual Costs for Cost center & GL
data: begin of set_act_tab occurs 0,
kostl like csks-kostl, " Cost Center
hkont like bsis-hkont, " GL Account No
amt_atd like bsis-dmbtr, " YTD Actual
end of set_act_tab.
Internal Table to Settlement Actual Costs for Cost center
data: begin of set1_act_tab occurs 0,
kostl like csks-kostl, " Cost Center
hkont like bsis-hkont, " GL Account No
amt_atd like bsis-dmbtr, " YTD Actual
end of set1_act_tab.
Internal Table to Capex Budget Figures
data: begin of cap_tab occurs 0,
belnr like coej-belnr, " Accounting Doc No
buzei like coej-buzei, " Line Item No
objnr like coej-objnr, " Object No
wrttp like bpej-wrttp, " Value Type
gjahr like coej-gjahr, " Fiscal Year
wtjhr like bpej-wtjhr, " budget Value
end of cap_tab.
Internal Table to Segragate the Budget Figures(Full Year and YTD)
data: begin of cap1_tab occurs 0,
gjahr like coej-gjahr, " Fiscal Year
kostl(10) type n, " Cost Center
hkont(10) type n, " GL Account No
amt_fy like coej-wkf001, " Full Year Amount
amt_ytd like coej-wkf001, " Ytd Amount
end of cap1_tab.
Internal Table to Sum up the Budget Figures(Full Year and YTD)
data: begin of cap2_tab occurs 0,
gjahr like coej-gjahr, " Fiscal Year
kostl(10) type n, " Cost Center
amt_fy like coej-wkf001, " Full Year Amount
amt_ytd like coej-wkf001, " Ytd Amount
end of cap2_tab.
Internal Table to Segragate the CAPEX YTD data(GL Wise)
data: begin of cap_ytd_tab occurs 0,
gjahr like coej-gjahr, " Fiscal Year
kostl(10) type n, " Cost Center
kstar like coej-kstar, " Cost Element
amt_ytd like coej-wkf001, " Ytd Amount
end of cap_ytd_tab.
Internal Table to Segragate the CAPEX YTD data(CC Wise)
data: begin of cap1_ytd_tab occurs 0,
gjahr like coej-gjahr, " Fiscal Year
kostl(10) type n, " Cost Center
amt_ytd like coej-wkf001, " Ytd Amount
end of cap1_ytd_tab.
Internal Table to Segragate the Budget Figures(Full Year and YTD)
data: begin of it_ytd_tab occurs 0,
gjahr like cosp-gjahr, " Fiscal Year
kostl like bsis-kostl, " Cost Center
kstar like cosp-kstar, " Cost Element
amt_fy like cosp-wkf001, " Full Year Amount
amt_ytd like coej-wkf001, " Ytd Amount
end of it_ytd_tab.
Internal Table to Segragate the Budget Figures(Full Year and YTD)
data: begin of it_ytd1_tab occurs 0,
gjahr like cosp-gjahr, " Fiscal Year
kostl like bsis-kostl, " Cost Center
amt_fy like cosp-wkf001, " Full Year Amount
amt_ytd like coej-wkf001, " Ytd Amount
end of it_ytd1_tab.
Internal Table to fetch the Actual YTD Figures
data: begin of it_act_tab occurs 0,
bukrs like bsis-bukrs, " Company Code
hkont like bsis-hkont, " GL Account No
gjahr like bsis-gjahr, " Fiscal Year
belnr like bsis-belnr, " Accounting Doc No
budat like bsis-budat, " Posting Date
waers like bsis-waers, " Currency
kostl like bsis-kostl, " Cost Center
shkzg like bsis-shkzg, " Dr/Cr Indicator
dmbtr like bsis-dmbtr, " Doc Amount
end of it_act_tab.
Internal Table to fetch the Actual YTD Figures( GL-SUM)
data: begin of act1_tab occurs 0,
bukrs like bsis-bukrs, " Company Code
kostl like bsis-kostl, " Cost Center
hkont like bsis-hkont, " GL Account No
gjahr like bsis-gjahr, " Fiscal Year
dmbtr like bsis-dmbtr, " Doc Amount
end of act1_tab.
Internal Table to fetch the Actual YTD Figures( CC-SUM)
data: begin of act2_tab occurs 0,
bukrs like bsis-bukrs, " Company Code
kostl like bsis-kostl, " Cost Center
gjahr like bsis-gjahr, " Fiscal Year
dmbtr like bsis-dmbtr, " Doc Amount
end of act2_tab.
Internal Table to fetch the WBS Data
data: begin of wbs_tab occurs 0,
pspnr like prps-pspnr, " WBS Element
posid like prps-posid, " WBS Structure Element
objnr like prps-objnr, " Object No
psphi like prps-psphi, " Project ID
pbukr like prps-pbukr, " Company Code
pkokr like prps-pkokr, " Controlling Area
fkstl like prps-fkstl, " Cost center
end of wbs_tab.
Internal Table to get Capex Actual from Networks
data: begin of net_tab occurs 0,
aufnr like afko-aufnr, " Order No
ftrmi like afko-ftrmi, " Release Date
pronr like afko-pronr, " Project No
aufpl like afvc-aufpl, " Routing No
aplzl like afvc-aplzl, " Counter No
objnr like afvc-objnr, " Object No
projn like afvc-projn, " WBS Element
end of net_tab.
Internal Table to get Capex Actual from Orders
data: begin of ord_tab occurs 0,
aufnr like aufk-aufnr, " Order No
aedat like aufk-aedat, " Order Date
kostl like aufk-kostl, " Cost center
objnr like aufk-objnr, " Object No
pspel like aufk-pspel, " WBS Element
end of ord_tab.
Internal Table to fetch the Capex Actual Data
data: it_cap_tab like kv02s occurs 0 with header line.
Internal Table to store the output of function-G_SET_TREE_IMPORT.
data : ccenter_group_tab like sethier occurs 0 with header line.
Internal Table to store the output of function-G_SET_TREE_IMPORT.
data : cost_center_tab like setvalues occurs 0 with header line.
Declaration of Variables
data: v_f_oper_amnt like bsis-wrbtr, " Operations F Year Budget
v_f_depr_amnt like bsis-wrbtr, " Depreciation F Year Budget
v_f_main_amnt like bsis-wrbtr, " Maintenance F Year Budget
v_f_capx_amnt like bsis-wrbtr, " Capex F Year Budget
v_b_oper_amnt like bsis-wrbtr, " Operations Budget YTD
v_b_depr_amnt like bsis-wrbtr, " Depreciation Budget YTD
v_b_main_amnt like bsis-wrbtr, " Maintenance Budget YTD
v_b_capx_amnt like bsis-wrbtr, " Capex Budget YTD
v_a_oper_amnt like bsis-wrbtr, " Operations Actual YTD
v_a_depr_amnt like bsis-wrbtr, " Depreciation Actual YTD
v_a_main_amnt like bsis-wrbtr, " Maintenance Actual YTD
v_a_capx_amnt like bsis-wrbtr, " Capex Actual YTD
v_v_oper_amnt type i, " Operations Variance
v_v_depr_amnt type i, " Depreciation Variance
v_v_main_amnt type i, " Maintenance Variance
v_v_capx_amnt type i, " Capex Variance
v_t_f_amnt type i, " Total F Year Budget
v_t_b_amnt type i, " Total Budget YTD
v_t_a_amnt type i, " Total Actual YTD
v_t_v_amnt type i, " Total Variance
v_gt_f_amnt type i, " GTotal F Year Budget
v_gt_b_amnt type i, " GTotal Budget YTD
v_gt_a_amnt type i, " GTotal Actual YTD
v_gt_v_amnt type i, " GTotal Variance
v_per_oper type i, " % YTD Operations
v_per_depr type i, " % YTD Depreciation
v_per_main type i, " % YTD Maintenance
v_per_capx type i, " % YTD Capex
v_per_tot type i, " % YTD Total
v_per_gtot type i, " % YTD G Total
v_kstar(4) type n, " Cost element
v_yr(2) type c, " Year
v_year(4) type c, " Year
v_lines type i, " Number
v_str(10) type c, " String
v_gl(4) type n, " GL element
v_gl1(10) type n, " GL Account Code
v_mon(2) type n, " Month
v_month(2) type n, " Month
v_day(2) type n, " Day
v_date like sy-datum, " Start Date in Year
v_setid like sethier-setid, " To store Identification of a set
v_subrc like sy-subrc, " Return code
v_settid like rgsbs-setnr. " Identification of a set
data: v_f_oper_amnt1 type i, " Operations F Year Budget
v_f_depr_amnt1 type i, " Depreciation F Year Budget
v_f_main_amnt1 type i, " Maintenance F Year Budget
v_f_capx_amnt1 type i, " Capex F Year Budget
v_b_oper_amnt1 type i, " Operations Budget YTD
v_b_depr_amnt1 type i, " Depreciation Budget YTD
v_b_main_amnt1 type i, " Maintenance Budget YTD
v_b_capx_amnt1 type i, " Capex Budget YTD
v_a_oper_amnt1 type i, " Operations Actual YTD
v_a_depr_amnt1 type i, " Depreciation Actual YTD
v_a_main_amnt1 type i, " Maintenance Actual YTD
v_a_capx_amnt1 type i. " Capex Actual YTD
Declaration of Constants
constants : c_i type c value 'I', " Sign
c_x type c value 'X', " Sign
c_d type c value 'D', " Type
c_h type c value 'H', " Credit Ind
c_s type c value 'S', " Type
c_o type c value 'O', " Type
c_a type c value 'A', " Type
c_01(2) type n value '01', " Month
c_opt1(2) type c value 'EQ', " Option
c_opt2(2) type c value 'BT', " Option
c_dot(3) type c value '...', " Dots
c_or(2) type c value 'OR', " Type
c_ks(2) type c value 'KS', " Type
c_mon(2) type n value '01', " Month
c_ndc like setnode-setname value 'NDC', " CC Group
c_glno like coej-versn value '000', " For GL No
c_versn1 like coej-versn value '100', " Value
c_kokrs like coej-kokrs value '1000', " Controlling Area
c_wrttp like coej-wrttp value '01', " Value Type
c_wrttp1 like coej-wrttp value '41', " Value Type
c_wrttp2 like coej-wrttp value '04', " Value Type
c_versn like coej-versn value '000', " Version
c_kbud like bpej-vorga value 'KBUD', " Activity
c_kbfr like bpej-vorga value 'KBFR', " Activity
c_kbn0 like bpej-vorga value 'KBN0', " Activity
c_it_bud_tab_wog0(15) value 'IT_BUD_TAB-WOG0',
c_prart like prps-prart value 'CA', " Project Type
c_psin like afvc-steus value 'PSIN', " Control Key
c_lednr like cosp-lednr value '00', " Ledger
c_lednr1 like bpej-lednr value '0002', " Ledger
c_class1 like setnode-setclass value '0101', " Class
c_class2 like setnode-subclass value '1000', " Subclass
c_thous type i value '1000', " Number
c_settab like rgsbs-table value 'CCSS', " Table for set
c_cctfld like t800s-feld value 'KOSTL'. " Field name
Declaration of Ranges
ranges: rn_kostl for csks-kostl. " Cost Centers
Selection Screen
selection-screen begin of block b1 with frame title text-001.
parameters : p_bukrs like t001-bukrs
default '1000'," Company Code
p_gjahr like bsis-gjahr
default sy-datum+0(4), " Fiscal Year
p_date like bsis-budat obligatory. " Date
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-021.
parameters : p_cgrup like setnode-setname. " Cost Center Group
select-options: s_kostl for csks-kostl. " Cost Center
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-029.
select-options :
s_opers for ska1-saknr obligatory, " Operns & Support GL A/C
s_deprc for ska1-saknr obligatory, " Depreciation GL A/C
s_mmain for ska1-saknr obligatory, " Major Maintenance GL A/C
s_capex for ska1-saknr obligatory. " Capital Expenditure GL A/C
selection-screen end of block b3.
Initialization
initialization.
At selection-screen
at selection-screen.
Validate the Selection Screen fields
perform validate_screen.
Value request for Cost Center Group.
at selection-screen on value-request for p_cgrup .
Get the F4 Help for Cost center Group
perform set_auswaehlen(sapfk00b) using c_settab c_cctfld
changing p_cgrup v_subrc
v_settid.
Start-of-Selection
start-of-selection.
Clear all the Variables in the Program
perform clear_var.
Get the Cost Centers from Cost Center Group.
perform get_cc_values.
Get the Budget data from database Table COSP
perform get_budget_data.
Get the Settlement Costs data from database Tables COBRB,COSP
perform get_cobrb_data.
Get the Actual YTD data from database Table BSIS
perform get_act_ytd_data.
Get the WBS Element Data
perform get_wbs_data.
Get the Networks and Activities for the WBS
perform get_net_ord_data.
Get the WBS Budget data from database Tables BPEJ
perform get_cap_budget_data.
Get the WBS Actual YTD data for WBS
perform get_cap_act_ytd_data.
Top-of-page
top-of-page.
Write the Report and Column Headings
perform top_of_page.
End-of-Selection
end-of-selection.
D-splay the Output Report.
perform display_report.
Form-Routines
*& Form validate_screen
Validation of selection Screen fields
form validate_screen.
Validation of Company Code
clear t001.
if not p_bukrs is initial.
select single bukrs
into t001-bukrs
from t001
where bukrs eq p_bukrs.
if sy-subrc <> 0.
message e999 with 'Incorrect Company Code'(033).
endif.
endif.
Validation of GL Account Code( P & L Operations )
clear ska1.
if not s_opers[] is initial.
select saknr up to 1 rows
into ska1-saknr
from ska1
where saknr in s_opers
and ktopl = c_kokrs
and xbilk = ' '.
endselect.
if sy-subrc <> 0.
message e999 with
'Incorrect GL Account for Operations and Support Cost'(034).
endif.
endif.
Validation of GL Account Code( P & L Depreciation)
clear ska1.
if not s_deprc[] is initial.
select saknr up to 1 rows
into ska1-saknr
from ska1
where saknr in s_deprc
and ktopl = c_kokrs
and xbilk = ' '.
endselect.
if sy-subrc <> 0.
message e999 with
'Incorrect GL Account for Depreciation'(035).
endif.
endif.
Validation of GL Account Code( P & L Maintenance)
clear ska1.
if not s_mmain[] is initial.
select saknr up to 1 rows
into ska1-saknr
from ska1
where saknr in s_mmain
and ktopl = c_kokrs
and xbilk = ' '.
endselect.
if sy-subrc <> 0.
message e999 with
'Incorrect GL Account for Major Maintenance'(036).
endif.
endif.
Validation of GL Account Code (Balance Sheet-Capex)
clear ska1.
if not s_capex[] is initial.
select saknr up to 1 rows
into ska1-saknr
from ska1
where saknr in s_capex
and ktopl = c_kokrs
and xbilk = c_x.
endselect.
if sy-subrc <> 0.
message e999 with
'Incorrect GL Account for Capital Expenditures'(037).
endif.
endif.
Validation of Cost Center Group
if not p_cgrup is initial .
clear setleaf-setname.
select setname up to 1 rows
from setleaf
into setleaf-setname
where setname eq p_cgrup and
setclass = c_class1 and
subclass = c_class2.
endselect.
if sy-subrc <> 0.
clear setnode-setname.
select setname up to 1 rows
from setnode
into setnode-setname
where setname eq p_cgrup and
setclass = c_class1 and
subclass = c_class2.
endselect.
if sy-subrc <> 0.
message e999 with
'Enter Correct Cost Center Group'(038).
endif.
endif.
endif.
Validation of Cost Center
clear csks.
if not s_kostl[] is initial.
select kostl up to 1 rows
into csks-kostl
from csks
where kostl in s_kostl
and kokrs = c_kokrs.
endselect.
if sy-subrc <> 0.
message e999 with
'Enter Correct Cost Center Code'(039).
endif.
endif.
Enter either Cost Center Group or Values
if not p_cgrup is initial and not s_kostl[] is initial.
message e999 with
'Enter either Cost Center Group or Values'(040).
endif.
Validation of Date
if p_date+0(4) ne p_gjahr.
message e999(zndc) with
'Please Enter the date in same Fiscal Year'(020).
endif.
To enter only last day of the month
clear: v_month, v_day, v_year.
v_month = p_date+4(2).
v_day = p_date+6(2).
v_year = p_date+0(4).
if ( v_month = '01' or v_month = '03' or v_month = '05' or
v_month = '07' or v_month = '08' or v_month = '10' or
v_month = '12' ).
if v_day ne '31'.
message e999(zndc) with
'Enter Last date of the Month'(022).
endif.
elseif ( v_month = '04' or v_month = '06' or v_month = '09' or
v_month = '11' ).
if v_day ne '30'.
message e999(zndc) with
'Enter Last date of the Month'(022).
endif.
elseif v_month = '02'.
if v_year eq '2004' or v_year eq '2008'.
if v_day ne '29'.
message e999(zndc) with
'Enter Last date of the Month'(022).
endif.
else.
if v_day ne '28'.
message e999(zndc) with
'Enter Last date of the Month'(022).
endif.
endif.
endif.
endform. " validate_screen
*& Form get_cc_values
Get the Cost Centers from Cost Center Group
form get_cc_values.
Populate the Cost Centers from Cost Center Group
if s_kostl[] is initial.
if p_cgrup is initial.
p_cgrup = c_ndc.
else.
p_cgrup = p_cgrup.
endif.
Concatenating Setnode table setclass,subclass fields and
Cost Center Group
concatenate c_class1 c_class2 p_cgrup
into v_setid.
Calling function module to get SET_HIERARCHY & SET_VALUES
perform frm_g_set_tree_import tables ccenter_group_tab[]
cost_center_tab[]
using v_setid.
loop at cost_center_tab.
rn_kostl-low = cost_center_tab-from.
rn_kostl-high = cost_center_tab-to.
rn_kostl-sign = c_i.
if rn_kostl-low = rn_kostl-high.
rn_kostl-option = c_opt1.
else.
rn_kostl-option = c_opt2.
endif.
append rn_kostl.
endloop.
clear v_setid.
endif.
else.
rn_kostl[] = s_kostl[].
endif.
endform. "get_cc_values
*& FORM FRM_G_SET_TREE_IMPORT
Subroutine to call the function G_SET_TREE_IMPORT.
form frm_g_set_tree_import
tables ccenter_group_tab structure sethier
cost_center_tab structure setvalues
using p_v_setid.
call function 'G_SET_TREE_IMPORT'
exporting
CLIENT = SY-MANDT
FIELDNAME = ' '
LANGU = SY-LANGU
NO_DESCRIPTIONS = ' '
NO_RW_INFO = ' '
setid = p_v_setid
TABNAME = ' '
NO_VARIABLE_REPLACEMENT = ' '
ROOT_HEADER_ONLY = ' '
NO_TABLE_BUFFERING = ' '
MAX_HIER_LEVEL = 99
DATE_FROM =
DATE_TO =
IMPORTING
SET_NOT_TRANSPARENT =
tables
set_hierarchy = ccenter_group_tab
set_values = cost_center_tab
EXCEPTIONS
SET_NOT_FOUND = 1
ILLEGAL_FIELD_REPLACEMENT = 2
ILLEGAL_TABLE_REPLACEMENT = 3
OTHERS = 4
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. "frm_g_set_tree_import
*& Form clear_var
Clear all the Variables in the program
form clear_var.
Clear/Initialize all the Variables
clear: v_f_oper_amnt1, v_f_depr_amnt1, v_f_main_amnt1,
v_f_capx_amnt1, v_b_oper_amnt1, v_b_depr_amnt1,
v_b_main_amnt1, v_b_capx_amnt1, v_a_oper_amnt1,
v_a_depr_amnt1, v_a_main_amnt1, v_a_capx_amnt1,
v_f_oper_amnt, v_f_depr_amnt, v_f_main_amnt,
v_f_capx_amnt, v_b_oper_amnt, v_b_depr_amnt,
v_b_main_amnt, v_b_capx_amnt, v_a_oper_amnt,
v_a_depr_amnt, v_a_main_amnt, v_a_capx_amnt,
v_v_oper_amnt, v_v_depr_amnt, v_v_main_amnt,
v_v_capx_amnt, v_t_f_amnt, v_t_b_amnt,
v_t_a_amnt, v_t_v_amnt, v_gt_f_amnt,
v_gt_b_amnt,v_gt_a_amnt,v_gt_v_amnt,
v_per_oper, v_per_depr, v_per_main,
v_per_capx, v_per_tot, v_per_gtot.
endform. "clear_var
*& Form get_budget_data
Get the Budget Data from Database Table COSP
form get_budget_data.
Form Local data
data: l_period(2) type n,
l_name(35) type c,
l_monat type i .
l_monat = p_date+4(2).
Field Symbols
field-symbols <fs>.
clear it_bud_tab.
refresh it_bud_tab.
select lednr " Ledger No
objnr " Object No
gjahr " Fiscal Year
wrttp " Actuals
versn " Version
twaer " Currency
perbl " Period Block
kstar " Cost Element/GL A/C No
wog001 " Total Value
wog002 " Total Value
wog003 " Total Value
wog004 " Total Value
wog005 " Total Value
wog006 " Total Value
wog007 " Total Value
wog008 " Total Value
wog009 " Total Value
wog010 " Total Value
wog011 " Total Value
wog012 " Total Value
into table it_bud_tab
from cosp
where lednr = c_lednr and
gjahr = p_gjahr and
wrttp = c_wrttp and
versn = c_versn and
beknz in (c_d,c_s).
if sy-subrc = 0.
Segragate the Budget Figures(Full Year and YTD)
loop at it_bud_tab.
if it_bud_tab-objnr+0(2) eq c_ks.
move-corresponding it_bud_tab to it_ytd_tab.
it_ytd_tab-kostl = it_bud_tab-objnr+6(10).
it_ytd_tab-amt_fy = it_bud_tab-wog001 + it_bud_tab-wog002 +
it_bud_tab-wog003 + it_bud_tab-wog004 +
it_bud_tab-wog005 + it_bud_tab-wog006 +
it_bud_tab-wog007 + it_bud_tab-wog008 +
it_bud_tab-wog009 + it_bud_tab-wog010 +
it_bud_tab-wog011 + it_bud_tab-wog012.
Get the YTD Budget using Field Symbols
do l_monat times.
l_period = sy-index.
concatenate c_it_bud_tab_wog0 l_period
into l_name.
assign (l_name) to <fs>.
it_ytd_tab-amt_ytd = it_ytd_tab-amt_ytd +
<fs>.
enddo.
collect it_ytd_tab.
clear it_ytd_tab.
endif.
endloop.
sort it_ytd_tab by gjahr kostl kstar.
Cost Center wise Sum Up of Costs
loop at it_ytd_tab.
at end of kostl.
sum.
move-corresponding it_ytd_tab to it_ytd1_tab.
append it_ytd1_tab.
endat.
clear it_ytd1_tab.
endloop.
sort it_ytd1_tab by gjahr kostl.
Segragate the Budget Figures into different Accounts/Cost elements
loop at it_ytd_tab.
if it_ytd_tab-kostl in rn_kostl.
Budget Full Year and YTD (Operations & Support Cost)
if not s_opers[] is initial.
if it_ytd_tab-kstar in s_opers.
v_f_oper_amnt = v_f_oper_amnt + it_ytd_tab-amt_fy.
v_b_oper_amnt = v_b_oper_amnt + it_ytd_tab-amt_ytd.
endif.
endif.
Budget Full Year and YTD (Depreciation)
if not s_deprc[] is initial.
if it_ytd_tab-kstar in s_deprc.
v_f_depr_amnt = v_f_depr_amnt + it_ytd_tab-amt_fy.
v_b_depr_amnt = v_b_depr_amnt + it_ytd_tab-amt_ytd.
endif.
endif.
Budget Full Year and YTD (Major Maintainance)
if not s_mmain[] is initial.
if it_ytd_tab-kstar in s_mmain.
v_f_main_amnt = v_f_main_amnt + it_ytd_tab-amt_fy.
v_b_main_amnt = v_b_main_amnt + it_ytd_tab-amt_ytd.
endif.
endif.
endif.
endloop.
Convert the Amount fields to nearest Thousand
v_f_oper_amnt1 = v_f_oper_amnt / c_thous .
v_f_depr_amnt1 = v_f_depr_amnt / c_thous .
v_f_main_amnt1 = v_f_main_amnt / c_thous .
v_b_oper_amnt1 = v_b_oper_amnt / c_thous .
v_b_depr_amnt1 = v_b_depr_amnt / c_thous .
v_b_main_amnt1 = v_b_main_amnt / c_thous .
endif.
endform. "get_budget_data
*& Form get_cobrb_data
Get the Settlement Data from Database Table COBRB
form get_cobrb_data.
clear cobrb_tab.
refresh cobrb_tab.
select objnr " Object No
rec_objnr1 " Ref Object No
bureg " Dostribution Rule
lfdnr " Sequence No
perbz " Settlement Rule
konty " Acct Assign Category
bukrs " Company Code
kostl " Cost Center
into table cobrb_tab
from cobrb
where kostl in rn_kostl.
sort cobrb_tab by objnr rec_objnr1.
delete adjacent duplicates from cobrb_tab comparing objnr.
Get the Settlement Costs from COEP Table
clear it_set_tab.
refresh it_set_tab.
if not cobrb_tab[] is initial.
select kokrs " Controlling Area
belnr " Acc Document
buzei " Line Item
perio " Period Block
wkgbtr " Value in CO Curr
lednr " Ledger No
objnr " Object No
gjahr " Fiscal Year
wrttp " Actuals
versn " Version
kstar " Cost Element
beknz " Dr/Cr Indicator
parob1 " Partner Object
into table it_set_tab
from coep
for all entries in cobrb_tab
where lednr = c_lednr and
wrttp = c_wrttp2 and
versn = c_versn and
gjahr = p_gjahr and
objnr = cobrb_tab-objnr and
parob1 = cobrb_tab-rec_objnr1 and
beknz in (c_o, c_a).
endif.
Settlement Actual Costs
loop at cobrb_tab.
if cobrb_tab-objnr+0(2) eq c_or.
loop at it_set_tab where objnr = cobrb_tab-objnr
and parob1 = cobrb_tab-rec_objnr1.
set_act_tab-kostl = cobrb_tab-kostl.
set_act_tab-hkont = it_set_tab-kstar.
Get the Actual Settlement Costs YTD Amount
if it_set_tab-perio between c_mon and v_month.
set_act_tab-amt_atd = set_act_tab-amt_atd +
abs( it_set_tab-wkgbtr ).
endif.
collect set_act_tab.
clear set_act_tab.
endloop.
endif.
endloop.
sort set_act_tab by kostl hkont.
Sum Up the Settlement Costs-CC wise
loop at set_act_tab.
at end of kostl.
read table set_act_tab index sy-tabix.
sum.
move-corresponding set_act_tab to set1_act_tab.
append set1_act_tab.
endat.
clear set1_act_tab.
endloop.
sort set1_act_tab by kostl.
delete set1_act_tab where amt_atd = 0.
endform. "get_cobrb_data
*& Form get_act_ytd_data
Get the Actual YTD Data from Database Table BSIS
form get_act_ytd_data.
clear it_act_tab.
refresh it_act_tab.
select
bukrs " Company Code
hkont " GL Account No
gjahr " Fiscal Year
belnr " Accounting Doc No
budat " Posting Date
waers " Currency
kostl " Cost Center
shkzg " Dr/Cr Indicator
dmbtr " Doc Amount
into table it_act_tab
from bsis
where bukrs eq p_bukrs and
gjahr eq p_gjahr and
budat le p_date and
kostl in rn_kostl.
if sy-subrc = 0.
sort it_act_tab by bukrs hkont.
loop at it_act_tab.
if it_act_tab-shkzg = c_h.
it_act_tab-dmbtr = it_act_tab-dmbtr * -1.
endif.
move-corresponding it_act_tab to act1_tab.
collect act1_tab.
clear act1_tab.
endloop.
sort act1_tab by bukrs kostl hkont.
endif.
Cost Center wise Sum Up of Costs
loop at act1_tab.
at end of kostl.
sum.
move-corresponding act1_tab to act2_tab.
append act2_tab.
endat.
clear act2_tab.
endloop.
sort act2_tab by gjahr kostl.
Seperate the different Actual YTD Expenditures
loop at act1_tab.
Actual YTD (Operations & Support Cost)
if not s_opers[] is initial.
if act1_tab-hkont in s_opers.
v_a_oper_amnt = v_a_oper_amnt + act1_tab-dmbtr.
endif.
endif.
Actual YTD (Depreciation)
if not s_deprc[] is initial.
if act1_tab-hkont in s_deprc.
v_a_depr_amnt = v_a_depr_amnt + act1_tab-dmbtr.
endif.
endif.
Actual YTD (Major Maintainance)
if not s_mmain[] is initial.
if act1_tab-hkont in s_mmain.
v_a_main_amnt = v_a_main_amnt + act1_tab-dmbtr.
endif.
endif.
endloop.
Opex Settlement Actual Costs
loop at set_act_tab.
Actual YTD (Operations & Support Cost)
if not s_opers[] is initial.
if set_act_tab-hkont in s_opers.
v_a_oper_amnt = v_a_oper_amnt + set_act_tab-amt_atd.
endif.
endif.
Actual YTD (Depreciation)
if not s_deprc[] is initial.
if set_act_tab-hkont in s_deprc.
v_a_depr_amnt = v_a_depr_amnt + set_act_tab-amt_atd.
endif.
endif.
Actual YTD (Major Maintainance)
if not s_mmain[] is initial.
if set_act_tab-hkont in s_mmain.
v_a_main_amnt = v_a_main_amnt + set_act_tab-amt_atd.
endif.
endif.
endloop.
Convert Amount Fields to nearest thousands
v_a_oper_amnt1 = v_a_oper_amnt / c_thous .
v_a_depr_amnt1 = v_a_depr_amnt / c_thous .
v_a_main_amnt1 = v_a_main_amnt / c_thous .
endform. " get_act_ytd_data
*& Form get_wbs_data
Get the WBS Element Data
form get_wbs_data.
clear wbs_tab.
refresh wbs_tab.
select pspnr " WBS Element
posid " WBS Structure Element
objnr " Object No
psphi " Project ID
pbukr " Company Code
pkokr " Controlling Area
fkstl " Cost Center
into table wbs_tab
from prps
where pbukr = p_bukrs and
pkokr = c_kokrs and
fkstl in rn_kostl and
prart = c_prart.
Consider only the Same Year WBS Elements Data
loop at wbs_tab.
v_yr = wbs_tab-posid+5(2).
if v_yr <> p_gjahr+2(2) .
delete wbs_tab index sy-tabix.
endif.
clear: v_yr, v_gl.
endloop.
sort wbs_tab by pspnr posid.
endform. "get_wbs_data
*& Form get_net_ord_data
Get the Network, Orders Data for the WBS
form get_net_ord_data.
Get the Network data
clear: net_tab, ord_tab.
refresh: net_tab, ord_tab.
if not wbs_tab[] is initial.
select a~aufnr " Order No
a~ftrmi " Release Date
a~pronr " Project No
b~aufpl " Routing No
b~aplzl " Counter No
b~objnr " Object No
b~projn " WBS Element
into table net_tab
from afko as a join afvc as b
on aaufpl eq baufpl
for all entries in wbs_tab
-
Problem in Fox Formula..
Hi,
Total field i require GL and PO Combination wise SUM(amount).
Variables
Provisions - Circle MU
Fiscal year/period 003.2010
Company code RIL
Controlling Area RIL
Header
Provisions - Circle MU
Fiscal year/period 003.2010
Company code RIL
Transactions
GL Acct PONumbr Costcenter Vendr SN SD Startdate enddate Amount Total
7145090 15958060 902604NM 284410 38 # 29.04.2010 31.05.2010 2000 3000
7145090 15958060 902605NM 284410 39 # 29.04.2010 31.05.2010 1000 3000
7145090 15958060 902607NM 284410 40 # 29.04.2010 31.05.2010 0000 3000
7145090 15963284 902601NM 518274 49 # 29.04.2010 31.05.2010 4500 9500
7145090 15963284 902601NM 345413 51 # 29.04.2010 31.05.2010 5000 9500
7145090 15964545 902603NM 345413 52 # 25.05.2010 31.05.2010 8000 9600
7145090 15964545 902603NM 345413 45 # 25.05.2010 31.05.2010 1600 9600
Fields to be changed
GL, PO , KF
Fox Code
DATA PO TYPE EBELN.
DATA GL TYPE 0GL_ACCOUNT.
DATA SUM TYPE F.
SUM = 0.
FOREACH GL,PO.
SUM = SUM + {0AMOUNT,GL,PO}.
endfor.
{TOTAL,GL,PO} = SUM.
IF I SEE IN DEBUG MODE ..LOOP IS ACCESSING GL Acct,PONumbr ,Costcenter,Vendr,SN,SD,Startdate,enddate WISE. AND IT IS NOT SUMMING UP BASED ON GL,PO........ EXPERTS PLZ PROVIDE UR SUGGETIONS.. Values should store in Cube...Not display mode.
Edited by: Madhu YL on Jun 23, 2010 10:52 AM
Edited by: Madhu YL on Jun 23, 2010 10:55 AMHi,
Can you try this fox code:
fields to be changed : keyfigure,Costcenter, Vendr, SN, SD, Startdate, enddate
foreach gl.
foreach po.
SUM = 0.
foreach Costcenter, Vendr, SN, SD, Startdate, enddate.
SUM = SUM + {0AMOUNT,Costcenter, Vendr, SN, SD, Startdate, enddate}.
endfor.
{TOTAL,Costcenter, Vendr, SN, SD, Startdate, enddate} = SUM.
" i dnt know on which particular record you want to store the total. Please check this part.
endfor.
endfor. -
Need a little help,a nd maybe some advice
I just finished making the beginning of a character planner for an rpg I play. I got the basic features done, and went about making a quick console interface for it so I could give it out and have people test it for me.
Here's the source: http://www.student.nvcc.edu/home/mappleman/trainer.zip
The main method looks like this:
public static void main(String[] args) {
TextInterface ui = new TextInterface();
ui.promptName();
ui.promptRace();
ui.promptProfession();
ui.promptStartStat();
ui.calcStats();
ui.printStats();
}promptName() works fine. It prompts for the name, and waits for the user to type something in. After that though it runs through the other methods not stopping for input where it should (at the lines with SavitchIn.readLine* ). It ends up croaking on a divide by zero error because it didn't take any input. Everything seems in perfect order to me. Any idea whats going on?
Thanks in advance! Also, some general input about my code style would be appreciated. This is the first non trivial program I've written so far, and by far my first potentialy USEFUL program!Hello again! After fixing the above problem, i found and fixed several other little problems, and now everything works wonderfully, except this. It gets to this part, and freezes up. The file is created, but the program doesn't exit. Trying to open the file with a text editor won't work, I end up having to kill the editor.
public void printStats(){
PrintWriter outputStream = null;
try{
outputStream = new PrintWriter(new FileOutputStream(character.getName() + ".txt"));
catch(FileNotFoundException e){
System.out.println("Error opening the file");
System.exit(0);
outputStream.println("Name: " + character.getName());
outputStream.println("Race: " + character.getRace());
outputStream.println("Profession: " + character.getProfession());
outputStream.println("Stats:");
int lvl = 0;
outputStream.print("CON:");
while (lvl < 101){
outputStream.print(" " + character.getStat(0, lvl));
lvl = 0;
outputStream.print("DEX:");
while (lvl < 101){
outputStream.print(" " + character.getStat(1, lvl));
lvl = 0;
outputStream.print("DIS:");
while (lvl < 101){
outputStream.print(" " + character.getStat(2, lvl));
lvl = 0;
outputStream.print("LOG:");
while (lvl < 101){
outputStream.print(" " + character.getStat(3, lvl));
lvl = 0;
outputStream.print("INT:");
while (lvl < 101){
outputStream.print(" " + character.getStat(4, lvl));
lvl = 0;
outputStream.print("STR:");
while (lvl < 101){
outputStream.print(" " + character.getStat(5, lvl));
lvl = 0;
outputStream.print("AGL:");
while (lvl < 101){
outputStream.print(" " + character.getStat(6, lvl));
lvl = 0;
outputStream.print("INF:");
while (lvl < 101){
outputStream.print(" " + character.getStat(7, lvl));
lvl = 0;
outputStream.print("WIS:");
while (lvl < 101){
outputStream.print(" " + character.getStat(8, lvl));
lvl = 0;
outputStream.print("AUR:");
while (lvl < 101){
outputStream.print(" " + character.getStat(9, lvl));
System.out.println("Stats written to " + character.getName() + ".txt");
outputStream.close();
}Thanks again! -
i want to calculate the sum of the average of the whole month having only days which contain entries(in a month).following query calculate the value by dividing the whole month.pls rectify the query and send.
SELECT MON, QTY, (QTY/(LAST_DAY(MON)-MON)) AVG_QTY
FROM
(SELECT TRUNC(ABC_DATE,'MONTH') MON,
SUM(NVL(ABC_MARKET_VALABC,0)+NVL(ABC_INT_ACCR,0)) QTY
FROM POS
GROUP BY TRUNC(ABC_DATE,'MONTH'))well,
1) I am just said that i have a table which has date wise sum
2) I pick the date wise sum and calculate the whole month
3) Now I want to calculate the average of the whole sum in such a way that If January Month has 21 record (means 21 days entries are there) I divide this (21) to the QTY (1st line 3rd col of the following query).
Following is the query for amendment.
SELECT MON, QTY, (QTY/(LAST_DAY(MON)-MON)) AVG_QTY
FROM
(SELECT TRUNC(POS_DATE,'MONTH') MON,
SUM(NVL(POS_MARKET_VAL_LCY,0)+NVL(POS_INT_ACCR_LCY,0)) QTY
FROM POS
GROUP BY TRUNC(POS_DATE,'MONTH'))
I think there is no problem to understand now.
Maybe you are looking for
-
How to find the BADI for the transaction CRM_IC in CRm 5.0
Hi all, I have a issue: in CRM 5.0, for the transaction CRM_IC (IC Web tcode), i need to do an enhancement for that tcode. In crm_ic, we can enter Business partner and product id data,whenever we provide the inputs for BP and Product id and if we pre
-
Ibook memory - where is it?!
Hi, I have a 60GB G4 ibook - and I seem to have used up alot of the memory after installing only a few things. I seem to remember checking the hard drive space shortly after getting it, but didnt bother questioning at the time the fact that there was
-
Serious problem with base station and/or computer internet connection
Hi, my powerbook does not detect my base station (another computer at home does, so the base station seems to be working) but it does detect other networks. I have allready tried to reset the basse station (many times) but it doesen't help. Have trie
-
Problem Downgrade from Win8 x64 to Win7Pro x64 - HP Sleekbook 14 b051TU
Dear all, I'm experiencing some problems while trying to downgrade this HP Sleekbook 14 b051TU machine from 32 bit to 64bit. It keeps showing me error message off unable to load the driver for the storage device. What I've done: 1. I have downloaded
-
Anyway to change how the track pad behaves on Yoga 13?
Hi I just bought a Yoga 13 and while I can change the speed the mouse moves is there anyway I can change: 1) the speed the track pad scrolls a page? 2) can I change the direction the page moves when I move my hand? ON the pad when I swipe downward th