Sum in internal table issue
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.
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 -
SMART FORMS- data from internal table issue
Hi ,
I have a smart form in which I have to print three types of materials of Material Types say M1, M2 ,M3.
In the SMART FORM,Main Window, I have created 3 TABLES for 3 types of Materials ie,
TableM1,
TableM2,
TableM3.
The internal tables to populate these TABLES are
( passing from Print program ).
t_M1,
t_M2,
t_M3
The Number of FIELDS vary in all the tables ,thats why I have created 3 internal tables for Diff Material Types.
But only first TABLE is getting printed ie data inside TableM2, TableM3 are not getting printed.
Can any SMARTFORM Gurus please let me know how I can solve this issue.
Regards
AviHi,
Check whether you are mentioning any condition on the data. There are different possibilites of not getting printed. Like the way your displaying, data is in table.
Can you please clearly mention how did you populated the internal table and kept the logic to print the values in the table. So that it problem would be more clearly nown.
Br,
Laxmi -
Hi Experts,
Row
Column
Value
1
0001
Prem(First Name )
1
0002
Raj(Middle name )
1
0003
Kaushik(Last name
2
0001
Naresh
I have the above data in excel file and my internal table like as follows
Data : begin of it_itab occurs 0,
Row type c,
Column type string,
Value type string,
End of it_itab.
Now I want to upload the excel file to my internal table
filed wise i.e in my intenal table row
shold have row values from excel same as
for column and value also
Can anyone suggest me fix this issue?
Best Regards,
Ramjee MYou may use this function to put data in internal table.
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
filename = p_file *xcel file name
i_begin_col = p_scol *start column
i_begin_row = p_srow *start row
i_end_col = p_ecol *end col
i_end_row = p_erow *end row
TABLES
intern = it_tab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
Use this function to put data in internal table. -
Reading internal table issue?
SELECT PERNR WERKS ABKRS BUKRS KOSTL ENAME GSBER FROM PA0001
INTO TABLE GT_0001
FOR ALL ENTRIES IN GT_0709
WHERE PERNR = GT_0709-PERNR
AND ENDDA >= P_DATE
AND BEGDA <= P_DATE.
READ TABLE GT_0001 INTO LS_0001 WITH TABLE KEY PERNR = LS_0709-PERNE
IF SY-SUBRC = 0.
CALL FUNCTION 'PA03_PCR_READ'
EXPORTING
F_ABKRS = LS_0001-ABKRS
IMPORTING
F_CURRENT_BEGDA = GV_BEGINDATE
F_CURRENT_ENDDA = GV_ENDDATE.
ENDIF.
IN THIS CODE WHILE READING THE INTERNAL TABLE IT IS SHOWING ERROR?
PLEASE CORRECT THE CODE.
REGARDS
REDDYHi,
Please remove 'TABLE' keyword from your syntax.
Check the datatype of field PERNR & PERNE. It shoud be same.
Check the value which is in PERNE fied shoud be available in PERNR Field or not?
Hope by this things you will be able to resolve issue.
Regards,
Narendra -
Static internal table issue - Used in BI Extractor
Hi,
We are reading data from a table in to a static internal table and using this table for future lookups.
Once in a while we can't find data while doing a lookup from this static internal table , But most of the time it works.
Is it possible that data from this static internal table is removed due to memory issues during peak periods.
Thanks in advanceHere is the code and it is there in a function module.This function module is called from a different FM in a loop.
TABLES: OIU_CM_MAT_PRCD.
STATICS: i_mat_prcd LIKE OIU_CM_MAT_PRCD OCCURS 10 WITH HEADER LINE.
DATA: ws_lines like sy-toccu.
DESCRIBE TABLE i_mat_prcd LINES ws_lines.
IF ws_lines = 0.
SELECT * INTO TABLE i_mat_prcd
FROM OIU_CM_MAT_PRCD.
IF i_matnr > ' '.
SORT i_mat_prcd BY matnr.
ELSE.
SORT i_mat_prcd BY majpd_cd pd_cd.
ENDIF.
ENDIF.
IF i_matnr > ' '.
READ TABLE i_mat_prcd WITH KEY matnr = i_matnr
BINARY SEARCH.
IF SY-SUBRC = 0.
CHG_MAJOR = i_mat_prcd-MAJPD_CD.
CHG_MINOR = i_mat_prcd-PD_CD.
CONCATENATE i_mat_prcd-majpd_cd i_mat_prcd-pd_cd
INTO chg_prod.
ENDIF. " i_matnr > blank -
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. -
hi All,
I am having three itabs. itab1 and itab2 have common field prctr. And prctr can be same for many records in both itab1 and itab2. i want to check that if records for a particular prctr are not in itab1 but are in itab2 then those records be moved to itab3. can anyone give me some suggestion?
thanks and regards,
ReenaHi Reena,
If you want to append itab3 based on internal table is ITAB2.
Use this:
LOOP AT ITAB2.
READ TABLE ITAB1 WITH KEY PRCTR = ITAB2-PRCTR.
IF SY-SUBRC <> 0.
MOVE CORRESPONDING ITAB2 TO ITAB3.
APPEND ITAB3.
CLEAR ITAB2.
ENDIF.
ENDLOOP.
else If you want to append itab3 based on internal table is ITAB1
Use this:
LOOP AT ITAB1.
READ TABLE ITAB2 WITH KEY PRCTR = ITAB1-PRCTR.
IF SY-SUBRC <> 0.
MOVE CORRESPONDING ITAB1 TO ITAB3.
APPEND ITAB3.
CLEAR ITAB1.
ENDIF.
ENDLOOP.
Regards,
Vinod. -
Internal table Issue ( very urgent)
Hi,
There are two internal tables A and B.
Product is one of the fields of both A and B and is the key.
A has say say 10 products and B has 4 products.
I want to delete those products from A which are not there in B.
( It is somewhat like using 'FOR ALL ENTERIES IN ' with Select Statement)
Is this possible in internal tables without 'Loop at'. The actual table would have over 1 million records and and looping is a major concern.
I am new to abap and any help from you guys would be appreciated.....Advait,
I think you will need atleast one loop. This loop can be on the table B.
If product is the <b>left most field</b> of table B try this:
The last field for table A must be a flag for don't delete
SORT IT_B by product.
LOOP AT IT_B INTO WA_B.
AT NEW product.
WA_A-dont_delete = 'X'.
MODIFY IT_A FROM WA_A TRANSPORTING dont_delete WHERE product = wa_b-product.
ENDAT.
ENDLOOP.
DELETE IT_A WHERE dont_delete <> 'X'. -
Space removed from character data type when move to internal table issue...
Hi Friends,
I converted material code and other details into internal table which have corresponding data types.But in internal table,I can see material code as left justified ,but after that space was removed.For example if material code is 'ABC' then rest of the space(material char(18)) are removed.But I need remaining spaces.I tried to concatenate material code with spaces (caoncatenate matnr ` ` int etc .. )at right side and moved to another internal table.Its working.But the problem is material codes have different values like one material 'ABC' and another like '123893-h' etc.So I need to calculate the space(out of char 18) dynamiclly and need to put space based on material code value.
<< Moderator message - Everyone's problem is important >>
.Thank you all..
Regards,
Kumaran..
Edited by: Rob Burbank on Oct 26, 2010 11:18 AMHi Ramkumaran,
You have not told the purpose of having these spaces.
is it for transfering to a file?
If that is the case, use a table with fixed lenght lines instead of many fields.
i.e. try something like this
DATA : i_tab type standard table of BUSDATA,
wa_tab type BUSDATA.
wa_tab+0(10) = material number.
wa_tab+10(10) = material code.
wa_tab+20(4) = company code...
append wa_tab to i_tab.
Thanks
Vimal -
Logic required for a Internal table issue
Hi All,
I have 2 internal table. I need STLNR value to another internal table. Both having same field. But while reading from one internal table to another internal table using IDNRK key, One idnrk having 2 different stlnr value. But its taking only one. How to take both the values?
The internal table value like below.
it_stpo--> This is first table, Here one Idnrk having different stlnr value. I need the same in to next table. Here i read with idnrk field but its taking one stlnr value only into next table.
How to change the logic ?
Below is it_stpo table and next one is it_mbew_1
it_stpo
STLNR IDNRK MENGE
17224 00439RM1 2.3
17225 00439RM1 4.2
172333 00849RM2 5.6
172158 00432TM3 7.2
152164 00583RM4 8.4
176123 00583RM4 2.3
it_mbew_1
STLNR IDNRK STPRS
00439RM1 111.22
00439RM1 126.45
00849RM2 3.3364
00432TM3 15.5888
00583RM4 0
00583RM4 0.235
My logic like below,
SORT it_stpo BY idnrk.
SORT it_mbew_1 BY matnr.
LOOP AT it_mbew_1 INTO wa_mbew_1.
READ TABLE it_stpo INTO wa_stpo WITH KEY idnrk = wa_mbew_1-matnr BINARY SEARCH.
IF sy-subrc = 0.
wa_mbew_1-stlnr = wa_stpo-stlnr.
MODIFY it_mbew_1 FROM wa_mbew_1 TRANSPORTING stlnr WHERE matnr = wa_mbew_1-matnr.
ENDIF.
ENDLOOP.
Kindly help us.
MohanaTry below logic.
add one more field to it_stpo flag type char01.
update the field with value 'X'.
SORT it_stpo BY idnrk.
SORT it_mbew_1 BY matnr.
LOOP AT it_mbew_1 INTO wa_mbew_1.
CLEAR WA_STPO.
READ TABLE it_stpo INTO wa_stpo WITH KEY idnrk = wa_mbew_1-matnr
flag = 'X'.
if sy-subrc eq 0.
move ' ' to wa_stpo-flag.
modify it_stpo from wa_stpo index sy-tabix.
wa_mbew_1-stlnr = wa_stpo-stlnr.
MODIFY it_mbew_1 FROM wa_mbew_1 TRANSPORTING stlnr WHERE matnr = wa_mbew_1-matnr.
endif.
ENDLOOP.
Regards
Vinod -
How to structure the internal table issue I want to download to excel
Hi ,
I am trying to download the data from the internal table whose structure was
i HAVE ONE INTERNAL TABLE WHICH IS
123 ABC MIKE
123 ABC DALLAS
123 ABC BOMBAY
345 BCD MEENAL
345 BCD SHINDE
345 BCD UJWALA
I want the output the i WANT THE INTERNAL TABLE TO STRUCTURE IN THIS WAY
123 ABC MIKE
DALLAS
BOMBAY
345 BCD MEENAL
SHINDE
UJWALAU have to fill internal table as ..
Loop at ITAB. <-- contains all the values
at new field2.
itab1 = itab.
append itab1.
clear itab1.
continue.
endat.
clear : itab-field1 , itab-field2.
itab1 = itab.
append itab1.
clear itab1.
endloop.
Now download ITAB1. -
Xml to Internal table : Issue
Dear All,
I have written a program to bring the data from xml to internal table Below is the strucutre of my xml file .
- <Data>
- <MT Type="CR">
<MatType>FERT</MatType>
</MT>
- <OP Type="CR">
<MatNumber>9901040103-000115</MatNumber>
- <Activities Element="AT">
- <AT Type="CR">
<MaterialNumber>115</MaterialNumber>
<ActivityType>DEPR.</ActivityType>
</AT>
- <AT Type="CR">
<MaterialNumber>117</MaterialNumber>
<ActivityType>L.C.R</ActivityType>
</AT>
</Activities>
</OP>
</Data>
.However I am not able to handle the multiple entries which comes together . ie
- <AT Type="CR">
<MaterialNumber>115</MaterialNumber>
<ActivityType>DEPR.</ActivityType>
</AT>
- <AT Type="CR">
<MaterialNumber>117</MaterialNumber>
<ActivityType>L.C.R</ActivityType>
</AT>
Please let me know how to handle this . Thanks!
Regards,
SyedHi ,
To convert XML data into internal table u have to use FM "SMUM_XML_PARSE", this FM takes XString as input ,so first u have to
convert ur xml string into XString using FM "SCMS_STRING_TO_XSTRING".
Thanks
jitendra -
Working with internal table issue
Hi all
i have internal table with the follwing data
and i want to move the entries (FNAM ,FVAL ) that relate to one screen 0101
into new table and the entries for the new screen 7101 to diffrent table
program dynpro dynbegin fnam fval
SAPMF02D 0101 X
0000 BDC_CURSOR RF02D-D0110
0000 BDC_OKCODE /00
0000 RF02D-KUNNR 1000
0000 RF02D-D0110 X
SAPMF02D 7101 X
0000 BDC_OKCODE /EF12
0000 BDC_CURSOR RF02D-KUNNR
I want in table 1 for screen 0101
fnam fval
BDC_CURSOR RF02D-D0110
BDC_OKCODE /00
RF02D-KUNNR 1000
RF02D-D0110 X
and in table 2 screen 7101
BDC_OKCODE /EF12
BDC_CURSOR RF02D-KUNNR
what is the best way to do that assume the tables content can
be change i.e. have more screens.
Best regards
AlexHI Raymond
Thanks for replay
I try your code with little adjustment
TYPES: BEGIN OF dynpros,
program TYPE bdcdata-program,
dynpro TYPE bdcdata-dynpro,
bdcdata TYPE hrtb_bdcdata , <-- change it to table for the append statment APPEND <f1> TO <f2>-bdcdata.
END OF dynpros.
and what i get in e_data is :
E_DATA
SAPMF02D 0101 Standard Table[1x5(618)]
SAPMF02D 7101 Standard Table[1x5(618)]
this is not really what i need
i want to get all the FNAM and FVAL from the table like this
I want in table 1 for screen 0101
fnam fval
BDC_CURSOR RF02D-D0110
BDC_OKCODE /00
RF02D-KUNNR 1000
RF02D-D0110 X
and in table 2 screen 7101
BDC_OKCODE /EF12
BDC_CURSOR RF02D-KUNNR
Best Regards
Alex -
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
Maybe you are looking for
-
Cant purchase / check downloads in iTunes or cant perform software update
Have had huge issues with my internet over the last couple of days! i have a wireless router that was working fine yesterday! Now today if i try to log into iTunes I can no problem, but when i try to make a purchase or check downloads i get the error
-
How to include a button in report header like rowspan? &logfile generation?
I am really new to this form and I have some questions on the APEX HTML DB: The project I need to work on is like this: Based on some criteria, I need to do a database lookup. Then in the result, I need to be able to edit the individual record. So fa
-
I just updated my phone and it said connect to itunes, I plugged it in and opened itunes and nothing happened, what do I do?
-
Good Morning. may somebody help me please? I have a problem with the stock value method. I need to change the method from some items, from standard to weighted average. I followed all the step mentioned in "Help Sap". All warehouses are in zero, and
-
Lost messages in inbox when upgrade to Tiger
I just installed Tiger and lost all the messages in my inbox except the ones that were still on my mail server and could be reloaded into my mailbox. How do I get my lost messages back?