Sum in Internal Tables
Dear Friends,
I AM WRITING A REPORT TO SHOW THE ALL THE POs WHOSE GRs HAS BEEN DONE BUT NOT THE IRs.
LIKE :-
Serial_no Vendor_no vendor_name Po_no ItemNo GR_no Ref_Doc_num Amount
I GOT THE REPORT BUT NOW MY USER SAYS ....
HE WANTS one recod (Serial_no) if po_no and GR_no and ref_doc_num are same with Amount summed up.
so that serial number will be less and and he will get the total amount of the pending GR.
I am not getting the logic how shall I sum up the amounts comapring po, gr and Ref doc no.
Regards,
jeevan.
Thanks for your replies. but i am not getting that......
i have an internal table with POs ..item nos...grs..ref no..... anmount..
now i have to get it in another internal table where there will be only Serialno .. po.no.gr..and ref and amount summed up all the similar ref numbers.
here is code.. its not optimized...but see... i have included
*& Report ZMMR_TEST2
REPORT ZMMR_TEST2.
TABLES : EKKO, EKBE, LFA1.
TYPE-POOLS : SLIS.
DATA : begin of IT_ekbe4 OCCURS 1 ,
i_index type i,
lifnr TYPE ekko-lifnr,
name1 TYPE lfa1-name1,
no_name type string,
ebeln TYPE ekbe-ebeln,
ebelp TYPE ekbe-ebelp,
belnr TYPE ekbe-belnr,
xblnr TYPE ekbe-xblnr,
dmbtr TYPE ekbe-dmbtr,
bewtp TYPE ekbe-bewtp,
bwart TYPE ekbe-bwart,
menge type ekbe-menge,
end of IT_ekbe4.
DATA : it_ekbe like ekbe occurs 1 with header line,
it_ekbe2 like ekbe occurs 1 with header line,
it_ekbe3 like it_ekbe4 occurs 1 with header line.
DATA : V_TABIX LIKE SY-TABIX.
*DATA : it_ekbe4 type standard table of s_ekbe4 initial size 0,
wa_ekbe4 type s_ekbe4.
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*selection screen.
select-options : s_date for ekbe-budat.
PARAMETERS DOC_TYP LIKE EKKO-BSART.
*Start-of-selection.
select a~ebeln a~ebelp a~bewtp a~bwart a~xblnr a~dmbtr a~belnr
b~lifnr
c~name1
into (it_ekbe4-EBELN, it_ekbe4-ebelp, it_ekbe4-bewtp,
it_ekbe4-bwart, it_ekbe4-xblnr, it_ekbe4-dmbtr, it_ekbe4-belnr,
it_ekbe4-lifnr, it_ekbe4-name1)
from ekbe as a
inner join ekko as b
on a~ebeln = b~ebeln
inner join lfa1 as c
on b~lifnr = c~lifnr
where a~budat in s_date
and a~bewtp = 'E'
and a~bwart in ('101','102', '122')
and b~bstyp = 'F'
and b~bsart = DOC_TYP
and b~ekorg = '1000'
select ebeln ebelp bewtp bwart
from ekbe
into (it_ekbe2-EBELN , it_ekbe2-ebelp , it_ekbe2-bewtp ,
it_ekbe2-bwart)
where ebeln = IT_EKBE4-EBELN
and ebelp = it_ekbe4-ebelp
and bewtp = 'Q'.
APPEND IT_EKBE2.
ENDSELECT.
APPEND IT_EKBE4.
ENDSELECT.
LOOP AT IT_EKBE4.
V_TABIX = SY-TABIX.
READ TABLE IT_EKBE2 WITH KEY EBELN = IT_EKBE4-EBELN ebelp =
it_ekbe4-ebelp.
IF SY-SUBRC = 0.
DELETE IT_EKBE4 INDEX V_TABIX.
ENDIF.
ENDLOOP.
clear v_tabix.
LOOP AT IT_EKBE4.
if ( it_ekbe4-bwart = '102' or it_ekbe4-bwart = '122' ).
it_ekbe4-dmbtr = it_ekbe4-dmbtr * -1.
endif.
it_ekbe3-i_index = sy-tabix.
it_ekbe3-ebeln = it_ekbe4-ebeln.
it_ekbe3-ebelp = it_ekbe4-ebelp.
it_ekbe3-belnr = it_ekbe4-belnr.
it_ekbe3-xblnr = it_ekbe4-xblnr.
it_ekbe3-dmbtr = it_ekbe4-dmbtr.
it_ekbe3-lifnr = it_ekbe4-lifnr.
it_ekbe3-name1 = it_ekbe4-name1.
concatenate it_ekbe4-name1 '/' it_ekbe4-lifnr into it_ekbe3-no_name.
*separated by space.
append it_ekbe3. "YOU TOLD THIS TO BE COLLECT."
Collect it_ekbe3 into it_ekbe3.
ENDLOOp.
sub totals.
*loop at it_ekbe3.
*collect
*endloop.
loop at it_ekbe3.
write:/ it_ekbe3-ebeln , 'gr', it_ekbe3-belnr , 'ref', it_ekbe3-xblnr, 'amount', it_ekbe3-dmbtr.
endloop.
Similar Messages
-
plz give me a simple example for using SUM in internal table and do some calculations in the same internal table.
HI
CHECK WITH THIS
Syntax
SUM.
Effect
The statement SUM can only be specified within a loop starting with LOOP, and is only considered within a AT- ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables.
The statement SUM calculates the component total with the numeric data type (i, p, f) of all rows in the current control level and assigns these to the components of the work area wa. In the control levels FIRST, LAST, and outside of an AT-ENDAT control structure, the system calculates the sum of numeric components of all rows in the internal table.
Example
Control level processing for creating a list. At the end of line groups, the total of reserved places is calculated and issued.
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
sflight_wa LIKE LINE OF sflight_tab.
SELECT *
FROM sflight
INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
AT END OF carrid.
SUM.
ULINE.
WRITE: / 'Carrier Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
NEW-PAGE.
ENDAT.
AT LAST.
SUM.
WRITE: / 'Overall Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
ENDAT.
ENDLOOP.
Hope this solves ur problem....
<b>do reward if useful....</b>
regards
dinesh -
Dear Experts,
I have a Qty field which needs to be summed up when material no, po no and size are same in my internal table
Eg: PO no Mat no Size Qty
111 001 L 10
111 001 L 20
needs to be shown as
111 001 L 30
I have tried using the collect statement in several ways but unfortunately ddnt work out. Any suggestions?Although Farid's sugegestion of looping and over two tables and summing would work I don't there is any reason to desist with your original approach of using the collect statement. The collect statment is designed exactly for this purpose and would be more efficient than two nested loops. As described before the folloiwng code should work the correct data elements inserted instead of the descriptions
types: BEGIN OF tys_structure,
po_num type po_num,
mat_no type mat_no,
size type sizw,
qty type qty,
END OF tys_structure.
data: lt_table type standard table of tys_structure
with non-unique key matnr, po_no, size,
ls_workarea type type_structure.
collect ls_workarea into lt_table.
One additional note, It would probably be better to use a unique key of a sorted or hashed table if you only want the results to be aggreagted by material no, po no and size. I suggested a non-unique key of a standard table here because it is more flexible and i don't know what elese you might want to do with this table in your code. -
Summing the internal table values
Hi Experts,
I have requirement in report to add the values in the internal table based on document no.
for example
Document no date Amount Exchange Rate
190000012 05.04.2009 100 1
190000012 05.04.2009 200 1
190000012 05.04.2009 300 1
190000013 05.04.2009 100 1
190000013 05.04.2009 200 1
190000014 05.04.2009 100 1
If i use Collect or On change statements , the exchange rate is also adding
Document no date Amount Exchange Rate
190000012 05.04.2009 600 3
190000013 05.04.2009 300 2
190000014 05.04.2009 100 1
But i want to add only the amount field not the exchange rate .Please suggest me the best solutions.
I want to display as
Document no date Amount Exchange Rate
190000012 05.04.2009 600 1
190000013 05.04.2009 300 1
190000014 05.04.2009 100 1
Thanks in advance
satishhi,
check this
Sort itab by documentno.
Loop at itab1.
on change of itab1-dcno.
clear total.
move itab1-docno to itab2-docno.
itab2-total = itab-amont.
move itab1-total to itab2-total.
move itab1-date to itab2-date.
move itab1-rate to itab2-rate.
flag = ' '.
append itab2.
clear itab2.
else.
itab2-total = itab2-total + itab-amont.
endon
Endloop.
it will work for adjest append statement according to the out put .
~linganna -
To find sum in an internal table - Bit urgent
Hi SAP experts,
I have an internal table with the following fields and data :
Emp_number Section Days
1 A 10
1 B 20
3 A 20
3 B 10
2 A 20
2 B 10
Now I want to calculate the total days for each employee which is a sum of days of section A and days of section B.
I want the data as below into another internal table
Emp_number Total_days
1 30
2 30
3 30
Could any one tell the code for the same.
Useful answers wud be rewarded.
Vishnu.Hi Vishwanath,
In this case you have to use CONTROL BREAK STATEMENTS.
1.At first
2.At new
3.At end
4.At last
1.At first is going to trigger at the 1st loop of the internal table.From the 2nd loop it is not going to trigger.
It is mainly used for sub headings.
2.At new is going to trigger at the new value of the internal table.
3. At end is going to trigger at the end of the new value of a particular field.
It is mainly use for subtotals.
4.At last is going to trigger at the last loop of the internal table.
It is mainly use for grand totals.
So you gothrough the above 4 statements.
In your case you have to use the third statement i.e., At end.
At end
ur logic
endat. -
Summing fields in an Internal table
Hello,
I have an internal table in the following format:
Prod Order Material Req Qty Used Qty
A1 M1 2 2
A1 M2 1 0
A2 M3 3 3
A3 M1 4 0
I need to find out the material usage i.e. the no. of production orders the material was used in along with the sum of the required qty and used qty.
In the example above, the results will be
Material Req Qty Used Qty PO count
M1 6 2 2
M2 1 0 1
M3 3 3 1
I tried the following code:
SORT mat_comp_list_tmp BY matnr.
LOOP AT mat_comp_list_tmp INTO wa_comp_list_tmp.
Store the work area.
wa_comp_list_final = wa_comp_list_tmp.
AT END OF matnr.
SUM.
Move the quantity.
wa_comp_list_final-req_qty = wa_comp_list_tmp-req_qty.
wa_comp_list_final-used_qty = wa_comp_list_tmp-used_qty.
wa_comp_list_final-cnt_aufnr = sy-dbcnt.
MODIFY mat_comp_list_tmp FROM wa_comp_list_final.
ENDAT.
ENDLOOP.
But this gives me a PO count per material per Prod. Order. This is not desired.
Is there any other way to acheive this. Any help will be greatly appreciated.
Thanks,
RugmaniHi .. I try this.
DATA: l_cont TYPE i,
itab TYPE mat_comp_list_tmp OCCURS 0 WITH HEADER LINE.
SORT mat_comp_list_tmp BY matnr.
LOOP AT mat_comp_list_tmp INTO wa_comp_list_tmp.
AT NET matnr.
CLEAR: l_cont, itab.
ENDAT.
ADD 1 TO l_cont.
ADD wa_comp_list_tmp-req_qty TO itab-req_qty.
ADD wa_comp_list_tmp-used_qty TO itab-used_qty.
AT END OF matnr.
itab_cnt_aufnr = l_cont.
APPEND itab.
ENDAT.
ENDLOOP.
PD: itab must have matnr as first field
Thanks and Regards.
David Carballido -
ALV - need to sum values of internal table and display in ALV
I have data in internal table as:
Material date sum1 sum2
Mat_A 19990101 4 4
Mat_A 20080501 3 0
Mat_A 20080601 2 0
Mat_B 19990101 2 0
Mat_B 20080601 5 5
Required output is :
Material qty1 qty2 19990101 20080501 20080601
Mat_A 432 4 4 3 2
Mat_B 2+5 5 2 5
Thinking of using ALV to pass the internal table and display as classical report (and also to save as excel spreadsheet).
Counting your help on the following questions:
1) How to accomplish the sum in ALV report? Can ALV FM do that or one has to use ABAP to compute the sum from the given internal table?
2) Mat_A can have more date values. Here it got 3 distinct date values 19990101, 20080601, 20080501. If it has say 5 date values, how to create the ALV date columns (from 3 to 5 date columns) dynamically?
Thanks for the help.for the sum inalv we use generally..
it_fieldcat-do_sum = 1.
check this examples...
http://www.****************/Tutorials/ALV/Subtotals/text.htm
*& Report ZTEST_ALV_PERC_13317
REPORT ztest_alv_perc_13317.
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_events TYPE slis_t_event,
wa_events TYPE slis_alv_event,
it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
l_layout TYPE slis_layout_alv.
TYPES: BEGIN OF ty_itab,
field1(10),
qty1 TYPE i,
qty2 TYPE i,
qty3 TYPE i,
dummy TYPE c,
END OF ty_itab.
DATA: itab TYPE STANDARD TABLE OF ty_itab WITH HEADER LINE,
itab1 TYPE ty_itab.
START-OF-SELECTION.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
itab-field1 = 'FIRST'.
itab-qty1 = 2.
itab-qty2 = 1.
itab-qty3 = 5.
itab-dummy = 10.
APPEND itab.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'FIELD1'.
wa_fieldcat-tabname = 'ITAB'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'QTY1'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'QTY2'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'QTY3'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'DUMMY'.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-do_sum = 'X'.
wa_fieldcat-no_out = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = it_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF. -
Need clarification to sum the entries in a internal table
Hi Gurus ,
Below i have written the logic for have the count of number of records in the internal table along with it i need to find the Total dollar amount of all the records .
iam not sure how to have that total .
please provide me the solution .
you can see at the bottom the where i tryed to sum .
LOOP AT IT_BKPF.
*AP ENTRIES
IF ( ( IT_bkpf-yke_awsys <> ' ' ) AND
( It_bkpf-ldgrp = '0L' OR It_bkpf-ldgrp = ' ' ) AND
( IT_BKPF-BLART EQ 'N1' OR IT_BKPF-BLART EQ 'N2' OR IT_BKPF-BLART EQ 'LP' OR
IT_BKPF-BLART EQ 'TK' OR IT_BKPF-BLART EQ 'L5' OR IT_BKPF-BLART EQ 'L6' OR
IT_BKPF-BLART EQ '1A' OR IT_BKPF-BLART EQ '1B' OR IT_BKPF-BLART EQ '1C' OR
IT_BKPF-BLART EQ '1D' OR IT_BKPF-BLART EQ '1E' OR IT_BKPF-BLART EQ '1F' OR
IT_BKPF-BLART EQ '1G' OR IT_BKPF-BLART EQ '1H' OR IT_BKPF-BLART EQ '1I' OR
IT_BKPF-BLART EQ '1J' OR IT_BKPF-BLART EQ '1K' OR IT_BKPF-BLART EQ '1L' OR
IT_BKPF-BLART EQ '1M' OR IT_BKPF-BLART EQ '1N' ) ).
CLEAR : COUNT_AP_0L ,V_COUNT_AP_0L.
READ TABLE It_bseg WITH KEY BUKRS = IT_BKPF-BUKRS
BELNR = IT_BKPF-BELNR
GJAHR = IT_BKPF-GJAHR
BINARY SEARCH.
LOOP AT IT_BSEG FROM SY-TABIX.
IF IT_BSEG-BUKRS <> IT_BKPF-BUKRS.
OR IT_BSEG-BELNR <> IT_BKPF-BELNR
OR IT_BSEG-GJAHR <> IT_BKPF-GJAHR.
EXIT.
ENDIF.
IF SY-SUBRC IS INITIAL .
COUNT_AP_0L = COUNT_AP_0L + 1.
MOVE COUNT_AP_0L TO V_COUNT_AP_0L .
AT END OF DMBTR.
SUM.
ENDAT. ENDIF.
ENDLOOP.
Thanks ,
vinayHi,
Use the sum statment after AT LAST. statment.
regards,
Santosh Thorat. -
Problem in Summing the value in one internal table. Its very urgent.
Hi Experts,
I have 10 fields in one internal table and based on the 8th field changing, I have to sum the 3rd field.
I am unable to use AT END OF <FIELD8>, because any of the fields from 1 to 7 are changing, then this control break statement triggering.
Could any body tell me, how I have to do this.
Thanks,
bsv.Hi,
I think it could be as simple as below.
DATA: l_field8 TYPE bla bla.
READ TABLE itab
INTO wa_itab
INDEX 1.
l_field8 = wa_itab-field8.
LOOP AT itab INTO wa_itab.
IF l_field8 NE wa_itab-field8.
"Do the sum here
ENDIF.
ENDLOOP.
Regards,
Teddy
Edited by: Teddy Kurniawan on Jan 25, 2008 8:38 AM -
Sum function for internal table column
Dear Experts,
how can I sum a complete internal table column.
Regards
ertasHi,
Use SUM in AT END of event in the loop of an internal table.
Example
Loop at ITAB into wa_itab.
at end of wa_itab-field.
sum. " Here all numric fields will be summed and stored in that filed(wa_itab-field)
endat.
Endloop.
Regards
Krishna -
Hi All,
I have internal table like this.
Field1 Field2 Field3
a 1 5.000
b 1 5.000
b 1 3.000
b 1 10.000
b 1 10.000
b 2 15.000
c 1 10.000
c 2 10.000
Now i have to sum field3 based on field1 and field2 i.e My Output will be like this.
Field1 Field2 Field3
a 1 5.000
b 1 28.000
b 2 15.000
c 1 10.000
c 2 10.000.
Please suggest some solution as I guess this output is not possible thru At end of or at new.
We can get the desired output using on change of but the summation is not possible thru on change of.
Thanks and regards
Nazmul AzadHi,
Please refer the below program:
data : var(20) type c,
var1(20) type c,
var2(20) type c.
data : begin of itab occurs 0,
f1 type c,
f2 type i,
f3 type i,
end of itab.
itab-f1 = 'a'.
itab-f2 = '1'.
itab-f3 = '5'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '1'.
itab-f3 = '5'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '1'.
itab-f3 = '3'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '1'.
itab-f3 = '10'.
append itab.
clear itab.
itab-f1 = 'b'.
itab-f2 = '2'.
itab-f3 = '15'.
append itab.
clear itab.
itab-f1 = 'c'.
itab-f2 = '1'.
itab-f3 = '10'.
append itab.
clear itab.
itab-f1 = 'c'.
itab-f2 = '2'.
itab-f3 = '10'.
append itab.
clear itab.
//Sorted based on field1 and field2 and used At new
sort itab by f1 f2.
loop at itab.
at new f2.
sum.
endat.
endloop.
Best Regards,
Sumana -
Hi Gurus,
I want to print sum of a particular coloumn in dynamic internal table,
But in Field symbold use char type so i cant able to print sum.
help me to solve this problem.
Regards,
Bhuvana.Hi
Herwith i attach my code.
*& Report ZFR133_TELECAST_REVENUE *
REPORT zfr133_telecast_revenue .
MODULE xxxxxxxx. *
Objective :.......................................... *
Program : Updates Tables ( ) Downloads data ( ) *
Outputs List ( ) *
Technical Spec No ............... *
Date Created 17/09/2008 *
Author J.Bhuvaneswari *
Location SUN TV / Chennai *
LDB ..... *
External Dependencies *
Amendment History *
Who Change ID Reason *
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ *
XXXXXXXXX AADDMMYYYY Where XXXX = Developers Name................. *
AA- Developers Initial ................................ *
Includes *
*INCLUDE : *
Tables *
TABLES : t001, bkpf, csks, bseg, cskt.
Types Begin with TY_ *
TYPES : BEGIN OF ty_bkpf,
bukrs LIKE bkpf-bukrs,
belnr LIKE bkpf-belnr,
gjahr LIKE bkpf-gjahr,
monat LIKE bkpf-monat,
stblg LIKE bkpf-stblg,
END OF ty_bkpf,
BEGIN OF ty_bseg,
bukrs LIKE bseg-bukrs,
gjahr LIKE bseg-gjahr,
belnr LIKE bseg-belnr,
shkzg LIKE bseg-shkzg,
dmbtr LIKE bseg-dmbtr,
kostl LIKE bseg-kostl,
hkont LIKE bseg-hkont,
END OF ty_bseg,
BEGIN OF ty_cskt,
kostl LIKE cskt-kostl,
ltext LIKE cskt-ltext,
END OF ty_cskt,
BEGIN OF ty_temp,
belnr LIKE bseg-belnr,
monat LIKE bkpf-monat,
kostl LIKE cskt-kostl,
ltext LIKE cskt-ltext,
shkzg LIKE bseg-shkzg,
dmbtr LIKE bseg-dmbtr,
END OF ty_temp.
DATA: BEGIN OF ty_stru OCCURS 0,
kostl LIKE cskt-kostl,
monat LIKE bkpf-monat,
dmbtr LIKE bseg-dmbtr,
END OF ty_stru.
Constants Begin with C_ *
*CONSTANTS: *
Data Begin with W_ *
DATA : w_amt LIKE bseg-dmbtr,
w_var TYPE string,
w_text TYPE string,
w_value TYPE i,
w_cnt TYPE i VALUE 1,
w_mon TYPE month,
okcode TYPE sy-ucomm.
Infotypes ( HR Module Specific) *
*INFOTYPES : *
Internal tables Begin with IT_ *
DATA : it_bkpf TYPE TABLE OF ty_bkpf,
it_bseg TYPE TABLE OF ty_bseg,
it_cskt TYPE TABLE OF ty_cskt,
it_temp TYPE TABLE OF ty_temp,
it_tmp1 TYPE TABLE OF ty_temp,
it_tmp2 TYPE TABLE OF ty_temp,
it_ccen TYPE TABLE OF ty_temp,
it_monat TYPE TABLE OF ty_temp.
DATA : xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat,
ty_lay TYPE lvc_s_layo,
dy_table TYPE REF TO data,
dy_line TYPE REF TO data.
DATA : cl TYPE REF TO cl_gui_custom_container,
cl_alv TYPE REF TO cl_gui_alv_grid.
DATA : wa_bkpf TYPE ty_bkpf,
wa_bseg TYPE ty_bseg,
wa_cskt TYPE ty_cskt,
wa_temp TYPE ty_temp,
wa_tmp1 TYPE ty_temp,
wa_tmp2 TYPE ty_temp,
wa_ccen TYPE ty_temp,
wa_monat TYPE ty_temp,
wa_month TYPE t247.
Field Symbols Begin with FS_ *
*FIELD-SYMBOLS: *
FIELD-SYMBOLS: .
Insert *
*INSERT : *
Select Options Begin with SO_ *
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS : pr_bukrs LIKE t001-bukrs OBLIGATORY,
pr_gjahr LIKE bkpf-gjahr OBLIGATORY.
SELECT-OPTIONS : so_monat FOR bkpf-monat OBLIGATORY,
so_kostl FOR bseg-kostl OBLIGATORY,
so_hkont FOR bseg-hkont OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.
Parameters Begin with PR_ *
*PARAMETERS : *
Initialisation *
*INITIALIZATION.
At selection-screen *
*AT SELECTION-SCREEN.
S T A R T O F S E L E C T I O N *
START-OF-SELECTION.
******Select data from Header Table.
SELECT bukrs gjahr belnr monat stblg
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf
WHERE bukrs = pr_bukrs AND
gjahr = pr_gjahr AND
monat IN so_monat AND
stblg = ' '.
******Select data from Item Table
IF it_bkpf IS NOT INITIAL.
SELECT bukrs gjahr belnr shkzg dmbtr kostl hkont
FROM bseg INTO CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs = it_bkpf-bukrs AND
gjahr = it_bkpf-gjahr AND
belnr = it_bkpf-belnr AND
kostl IN so_kostl AND
hkont IN so_hkont.
ENDIF.
******Select Cost center text
SELECT kostl ltext
FROM cskt INTO CORRESPONDING FIELDS OF TABLE it_cskt
WHERE spras = 'EN' AND
kokrs = 'SUN1' AND
kostl IN so_kostl.
******Append data in temporary table.
LOOP AT it_bseg INTO wa_bseg.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY belnr = wa_bseg-belnr.
IF sy-subrc = 0.
wa_temp-belnr = wa_bkpf-belnr.
wa_temp-monat = wa_bkpf-monat.
wa_temp-kostl = wa_bseg-kostl.
READ TABLE it_cskt INTO wa_cskt WITH KEY kostl = wa_bseg-kostl.
IF sy-subrc = 0.
wa_temp-ltext = wa_cskt-ltext.
ENDIF.
IF wa_bseg-shkzg = 'H'.
wa_temp-dmbtr = wa_bseg-dmbtr * -1.
ELSE.
wa_temp-dmbtr = wa_bseg-dmbtr.
ENDIF.
APPEND wa_temp TO it_temp.
ENDIF.
ENDLOOP.
SORT it_temp BY kostl monat.
******Internal Table of cost center without duplications.
it_ccen = it_temp.
DELETE ADJACENT DUPLICATES FROM it_ccen COMPARING kostl.
******Internal Table of fiscal period without duplications.
it_monat = it_temp.
SORT it_monat BY monat.
DELETE ADJACENT DUPLICATES FROM it_monat COMPARING monat.
PERFORM dynamic_table.
PERFORM data_upload_dynamic_table.
SET SCREEN 3000.
IF cl IS INITIAL.
CREATE OBJECT cl EXPORTING container_name = 'TC'.
CREATE OBJECT cl_alv EXPORTING i_parent = cl.
ENDIF.
CALL METHOD cl_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'ZALIKP'
is_layout = ty_lay
CHANGING
it_outtab =
it_fieldcatalog = ifc.
*GET XX.
*END-OF-SELECTION.
E N D O F S E L E C T I O N *
At line selection *
*AT LINE-SELECTION.
User Command Processing *
*AT USER-COMMAND.
Top Of Page *
*TOP-OF-PAGE.
End Of Page *
*END-OF-PAGE.
*& Form DYNAMIC_TABLE
FORM dynamic_table .
PERFORM design_fieldcat USING 'KOSTL' 'BSEG' text-002 '10'.
PERFORM design_fieldcat USING 'LTEXT' 'CSKT' text-003 '30'.
LOOP AT it_monat INTO wa_monat.
CONCATENATE 'PE' wa_monat-monat INTO w_text.
w_mon = wa_monat-monat.
CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
EXPORTING
langu = sy-langu
month = w_mon
IMPORTING
t247 = wa_month.
w_var = wa_monat-monat.
w_text = wa_month-ltx.
PERFORM design_fieldcat USING w_var 'BKPF' w_text '10'.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO .
ENDFORM. " DYNAMIC_TABLE
*& Form DESIGN_FIELDCAT
FORM design_fieldcat USING value TYPE string
tab TYPE string
text TYPE string
length TYPE string.
xfc-fieldname = value.
xfc-tabname = tab.
xfc-reptext = text.
xfc-outputlen = length.
APPEND xfc TO ifc.
w_cnt = w_cnt + 1.
CLEAR xfc.
ENDFORM. " DESIGN_FIELDCAT
*& Form DATA_UPLOAD_DYNAMIC_TABLE
FORM data_upload_dynamic_table .
DATA : w_c(2) TYPE c,
w_c1(5) TYPE c,
w_c2(5) TYPE c.
CREATE DATA dy_line LIKE LINE OF .
CLEAR: wa_tmp2,w_amt.
ENDON.
ENDLOOP.
ENDLOOP.
ENDFORM. " DATA_UPLOAD_DYNAMIC_TABLE
*& Module STATUS_3000 OUTPUT
MODULE status_3000 OUTPUT.
SET PF-STATUS 'MENU'.
SET TITLEBAR 'TIT'.
ENDMODULE. " STATUS_3000 OUTPUT
*& Module USER_COMMAND_3000 INPUT
MODULE user_command_3000 INPUT.
CASE okcode.
WHEN 'BACK'." OR 'RW' OR '%EX'.
LEAVE PROGRAM.
CLEAR okcode.
ENDCASE.
ENDMODULE. " USER_COMMAND_3000 INPUT -
How to select and sum internal table records
Dear Friends
I kindly ask you if we have select statement
if s_mtart = 'z003'
select single pvprs from ckmlcr into ckmlcr-pvprs
where poper EQ s_poper and
kalnr = itab2-kalnr and
bdatj = itab2-bdatj and
curtp = itab2-curtp.
like this how can I calculate how many record it got and I want to get summation of this field(pvprs).And for all poper's must contain.
Please Let me remind you my itab is already open I didn't put any thing for this situationit seems to be you written this SELECT in a loop. if so,
instead of pushing the values into ckmlcr-pvprs ,create an internal table
data : begin of itab,
pvprs type ckmlcr-pvprs ,
end of itab.
then just after that SELECT SINGLE,
select single pvprs from ckmlcr <b>into ITAB-pvprs</b>
where poper EQ s_poper and
kalnr = itab2-kalnr and
bdatj = itab2-bdatj and
curtp = itab2-curtp.
IF SY-SUBRC = 0.
APPEND ITAB.
here either you can use APPEND OR COLLECT.
If you use COLLECT,all the values will get summed up and final sum will be in the table ITAB-pvprs.
ENDIF.
After all loops your itab will have the totals.
DESCRIBE TABLE ITAB LINES V_LINES.
V_LINES Will have total no of lines.
Regards
srikanth -
Sum of one column of an internal table
Hi All,
I have an internal table with two columns.
First column is having standard taxt "ZSSS" (for all rows).
The second column is having Amount value.
Internal table might have multiple lines with this structure.
Now i would like to sum the second column which is having Amount value.
How to code to get the sum in such scenario?
Your help will be appreciated.....
Regards
PavanHi
This is possible with COntrol Break Stamnts\Check below Code for example..
DATA: BEGIN OF line,
carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
fldate TYPE sbook-fldate,
custtype TYPE sbook-custtype,
class TYPE sbook-class,
bookid TYPE sbook-bookid,
END OF line.
DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY table_line.
SELECT carrid connid fldate custtype class bookid
FROM sbook INTO CORRESPONDING FIELDS OF TABLE itab.
LOOP AT itab INTO line.
AT FIRST.
WRITE / 'List of Bookings'.
ULINE.
ENDAT.
AT NEW carrid.
WRITE: / 'Carrid:', line-carrid.
ENDAT.
AT NEW connid.
WRITE: / 'Connid:', line-connid.
ENDAT.
AT NEW fldate.
WRITE: / 'Fldate:', line-fldate.
ENDAT.
AT NEW custtype.
WRITE: / 'Custtype:', line-custtype.
ENDAT.
WRITE: / line-bookid, line-class.
AT END OF class.
ULINE.
ENDAT.
ENDLOOP.
Hope it helps.
Praveen -
Hi All,
I have an internal table as follows.
Now if the KUNNR, PRCTR and VERNA field are similar, i have to sum up the QTY columns accordingly.
I mean to say, in this case, the rows 1, 2 and 3 have same kunnr, prctr and verna fields. Henc ei should sum up the corresponding columns (qty1, qty2, qty3 and SUM) and make it as one row.
kunnr | prctr | verna | qty1 | qty2 | qty3 | sum
11 | 100 | Raj | 10.0 | 5.0 | 0.0 | 15.0
11 | 100 | Raj | 8.0 | 1.0 | 2.0 | 11.0
11 | 100 | Raj | 0.0 | 0.0 | 6.5 | 6.5
12 | 200 | Ram | 2.0 | 0.0 | 0.0 | 2.0
How to carry out this calculation....???
Regards
PavanHi Friend,
Use the Control Break Statement for this, Go through the following steps
1. Sort the Internal Table
2. Loop the Internal Table
3. Use the Control Break Statement
4. Sum
5. Write Statement
6. Endloop.
Ex.
sort itab.
loop at itab.
at end of kunnr.
sum.
write: 'mara-kunnr'.
endat.
endloop.
Hope the answer of your question.
Regards,
Md Ziauddin.
Edited by: MD ZIAUDDIN on Dec 31, 2008 7:40 PM
Maybe you are looking for
-
Hi I want to utilize my digital out on my G5 for a set of audio monitors, and possibly other devices. How do I use the S/PDIF on the G5 with either an RCA-type S/PDIF jack or a pro XLR AES/EBU jack? I would imagine a simple cable, but can't seem to f
-
How i can set dropDown item to 6th item from java code ?
Hi Thank you for reading my post. how i can set dropDown item to 6th item from java code ? i have the value field of database and i can use it to set selected item of DropDown. so : can i use value field to set the selected item ? Thank u.
-
Hi is there a way to have the query sentence box closed when i run a query in SAP BO thank you
-
IPhone 3GS crashes with iTunes 9.0.2
Hello, I have a iPhone 3GS with latest 3.1.2 firmware and on my Macbook Pro I have iTunes 9.0.2 installed. Every time I connect my iPhone to my Macbook and load iTunes, iTunes just seems to hang with the spinning beachball and says in the dock applic
-
Ipod touch won't turn on after trying to charge after the battery ran out
I was about to charge my ipod because it was below 10% but before I could it ran out. Now, when I plug it in to the computer or my Ipod wall charger, it won't come up in itunes and my wall charger says it is charging (red light) but 30 minutes later,