‎2009 Nov 11 6:23 AM
hi masters,
i have an issue where am calculating months per contract.
if i have one contract ex : 2001198 - the sum of months to this contract is - 36.
if i have another contract ex : 7866540 - the sum of months to this contract is - 46.
my requirment is i need to take the sum per contract and not total sum of 2 contracts how can i do this please can anyone tell please.
this is my code.
clear lzmonths.
LOOP AT svtab1 INTO st_tab1 where condtype = 'R0' . " months
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = st_tab1-condvalidto
i_datum_von = st_tab1-condvalidfrom
I_KZ_INCL_BIS = ' '
IMPORTING
e_monate = count.
st_tab1-zmonths = count + 1.
lzmonths = lzmonths + st_tab1-zmonths . " sum of months i get into lzmonths.
MODIFY svtab1 FROM st_tab1 TRANSPORTING zmonths.
ENDLOOP.
so how can i get per contract please advise.
thanks,
pasala.
‎2009 Nov 11 6:39 AM
Hi,
Use control break events.
AT NEW
REPORT ZSELECTION_SCREEN .
*************************************
DATA : BEGIN OF ITAB OCCURS 0,
F1(3) TYPE C,
F2 TYPE I,
F3 TYPE I ,
F3 TYPE P DECIMALS 2,
END OF ITAB.
DATA WA LIKE ITAB.
DATA : CNT TYPE N,
TOTAL TYPE STRING ,
SUM TYPE P DECIMALS 2.
DATA NO TYPE SY-LINNO.
****************************************
ITAB-F1 = 'A01'. ITAB-F2 = 25. ITAB-F3 = '1000.12'.
APPEND ITAB.
ITAB-F1 = 'A02'. ITAB-F2 = 20. ITAB-F3 = '900.23'.
APPEND ITAB.
ITAB-F1 = 'A01'. ITAB-F2 = 35. ITAB-F3 = '1200.65'.
APPEND ITAB.
ITAB-F1 = 'A03'. ITAB-F2 = 15. ITAB-F3 = '800'.
APPEND ITAB.
ITAB-F1 = 'A01'. ITAB-F2 = 15.ITAB-F3 = '1000'.
APPEND ITAB.
ITAB-F1 = 'A02'. ITAB-F2 = 45. ITAB-F3 = '2000'.
APPEND ITAB.
ITAB-F1 = 'A01'. ITAB-F2 = 55. ITAB-F3 = '1500'.
APPEND ITAB.
SORT ITAB BY F1.
*****************************************
LOOP AT ITAB .
AT NEW F1.
WRITE:/ 'TYPE :',ITAB-F1 ,20 'COUNT : CNT ' ,35 'TOTAL : TAT' .
NO = SY-LINNO.
WRITE:/20 'QUANTITY' ,40 'AMOUNT' .
ENDAT.
WRITE :/15 ITAB-F2,30 ITAB-F3 .
CNT = CNT + 1.
SUM = SUM + ITAB-F3.
AT END OF F1.
*SUM.
TOTAL = SUM.
READ LINE NO .
REPLACE 'CNT' WITH CNT INTO SY-LISEL.
REPLACE 'TAT' WITH TOTAL INTO SY-LISEL.
MODIFY CURRENT LINE.
CNT = 0.
SUM = 0.
SKIP.
ENDAT.
ENDLOOP.
Thansk,
Nelson
‎2009 Nov 11 6:39 AM
Hi,
Use control break events.
AT NEW
REPORT ZSELECTION_SCREEN .
*************************************
DATA : BEGIN OF ITAB OCCURS 0,
F1(3) TYPE C,
F2 TYPE I,
F3 TYPE I ,
F3 TYPE P DECIMALS 2,
END OF ITAB.
DATA WA LIKE ITAB.
DATA : CNT TYPE N,
TOTAL TYPE STRING ,
SUM TYPE P DECIMALS 2.
DATA NO TYPE SY-LINNO.
****************************************
ITAB-F1 = 'A01'. ITAB-F2 = 25. ITAB-F3 = '1000.12'.
APPEND ITAB.
ITAB-F1 = 'A02'. ITAB-F2 = 20. ITAB-F3 = '900.23'.
APPEND ITAB.
ITAB-F1 = 'A01'. ITAB-F2 = 35. ITAB-F3 = '1200.65'.
APPEND ITAB.
ITAB-F1 = 'A03'. ITAB-F2 = 15. ITAB-F3 = '800'.
APPEND ITAB.
ITAB-F1 = 'A01'. ITAB-F2 = 15.ITAB-F3 = '1000'.
APPEND ITAB.
ITAB-F1 = 'A02'. ITAB-F2 = 45. ITAB-F3 = '2000'.
APPEND ITAB.
ITAB-F1 = 'A01'. ITAB-F2 = 55. ITAB-F3 = '1500'.
APPEND ITAB.
SORT ITAB BY F1.
*****************************************
LOOP AT ITAB .
AT NEW F1.
WRITE:/ 'TYPE :',ITAB-F1 ,20 'COUNT : CNT ' ,35 'TOTAL : TAT' .
NO = SY-LINNO.
WRITE:/20 'QUANTITY' ,40 'AMOUNT' .
ENDAT.
WRITE :/15 ITAB-F2,30 ITAB-F3 .
CNT = CNT + 1.
SUM = SUM + ITAB-F3.
AT END OF F1.
*SUM.
TOTAL = SUM.
READ LINE NO .
REPLACE 'CNT' WITH CNT INTO SY-LISEL.
REPLACE 'TAT' WITH TOTAL INTO SY-LISEL.
MODIFY CURRENT LINE.
CNT = 0.
SUM = 0.
SKIP.
ENDAT.
ENDLOOP.
Thansk,
Nelson
‎2009 Nov 11 7:47 AM
thank you nelson.
am using my code in BADI.
So i have all the data in svtab1.
to get the number of months i am using a function module and i get the months per contract.
but how can i tell the system to look per contract and take the number of months by contract?
am confused here and i really need ur input please.
can you please tell me from my code instead of your code please if you dont mind.
LOOP AT svtab1 INTO st_tab1 where condtype = 'R0'
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = st_tab1-condvalidto
i_datum_von = st_tab1-condvalidfrom
I_KZ_INCL_BIS = ' '
IMPORTING
e_monate = count.
st_tab1-zmonths = count + 1.
lzmonths = lzmonths + st_tab1-zmonths . here i get total months but not per contract how can i say per contract?
MODIFY svtab1 FROM st_tab1 TRANSPORTING zmonths.
ENDLOOP.
‎2009 Nov 11 7:55 AM
I see some thing worng here
st_tab1-zmonths = count + 1.
try changing it to
st_tab1-zmonths = st_tab1-zmonths + count .
‎2009 Nov 11 8:03 AM
hi keshu,
i get the no of months into count and i add 1 to ger the current month as well.
total of all the months per contract i get into a variable called LZMONTH where i have the total of all the months.
since i said
lzmonths = lzmonths + st_tab1-zmonths .
it looks the total of all the months but not the total per contract.
so how can i say take the total months per contract.
thanks,
pasala.
‎2009 Nov 18 7:39 AM