SELECT SUM( field1 field2 ) INTO C1
Is that possible with a select statement in ABAP or do I need to sum each row by itself then add them together afterwords?
Hi Craig,
this is not possible with a select statement in ABAP. You can use the routine mentioned by you:
DATA: C1 TYPE i,
C2 TYPE i,
total type i.
SELECT SUM( field1 ) SUM( fiedl2 ) into ( c1 c2 )from tablename.
total = c1 + c2.
Of course you can use the exec sql statement proposed by Andreas, but you have to select for the cllient explicitly. There are some disadvantages for native sql, too:
1. platform dependent
2. no syntax check for the native sql part
3. you bypass the SAP database buffer
For more details refer to the online help about EXEC SQL.
Cheers,
Morten
Similar Messages
-
How do sum(field1+field2) in opensql?
I want sum more than one field in opensql,But the follow sentences are wrong:
SELECT SINGLE sum( hsl12 ) + sum( hsl13 ) FROM faglflext INTO ....
SELECT SINGLE sum( hsl12 + hsl13 ) FROM faglflext INTO ....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.
Rewads if helpful -
"Select sum(field)" not summing
I have a PLSQL statement like:
select sum(field1) sum1,
sum (field2) sum2
into v_sum1,
v_sum2
where something = somethingElse;
How come my variable are being assigne a single row's (the first) field1 and field2 values rather than the actual sums?
If I do a SQLPLUS version of this (without the "into" part), I get the correct sums returned in a single row.
Thanks,I just tried your query and it should work if you only want a sum for a specific where clause. For example one employee's salary given the employee's id. If you want a list of salaries for every employee in a specific department, you need to put this into a cursor and loop through it.
This will look at all the rows based on the where statement and sum them all up. The reason it works in SQL*PLUS is that an implicit cursor is used (loops through automatically).
ex:
DECLARE
CURSOR C_SUM is
select ename,
sum(sal) sum1,
sum(comm)sum2
from emp
where deptno = 30;
BEGIN
FOR R_SUM IN C_SUM
LOOP
DBMS_OUTPUT.PUT_LINE(r_sum.ename ||' '||
r_sum.sum1 ||' '||
r_sum.sum2);
END LOOP;
END;
Make sure if you use DBMS_OUTPUT you have serveroutput on. Hope this helps. If it doesnt, post the actual code you are having problems with. -
Hi,
select sum( a~dmbtr )
into o_debit
from bsik as A inner join FAGLFLEXA as B
on abukrs = bRBUKRS
and agjahr = bRYEAR
and abelnr = bdocnr
where a~bukrs = x_bukrs
and a~lifnr = p_lifnr
and a~shkzg = 'S'
and a~budat in s_budat
and a~hkont gt '0000000000'
and a~hkont le '9999999999'
and b~prctr = p_prctr.
Above query is not giving result in o_debit though data is available in both the table. Please guide me, if I have written something wrong.Hi, Raj.
Test the following Sample It is working fine for me hope will work for you too, I did some little change.
TYPES: BEGIN OF ty_test,
dmbtr LIKE bsik-dmbtr,
END OF ty_test.
DATA: it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
SELECT SUM( a~dmbtr ) as dmbtr
INTO CORRESPONDING FIELDS OF TABLE it_test
FROM bsik AS a INNER JOIN faglflexa AS b ON ( a~bukrs = b~rbukrs AND a~gjahr = b~ryear AND a~belnr = b~docnr )
WHERE a~bukrs = x_bukrs
AND a~lifnr = p_lifnr
AND a~shkzg = 'S'
AND a~budat IN s_budat
AND a~hkont GT '0000000000'
AND a~hkont LE '9999999999'
AND b~prctr = p_prctr.
Please Reply if still any Issue,
Best Regards,
Faisal -
i want to add this substring value with 9
select sum(substr(8763,3,4)||'+'||9) from dual
means i need output 72FOR I IN C1 LOOP
IF V_COUNT=0 THEN
V_FILENAME:='AB'||P_DOCUMENT_NUM||'.txt';
ELSE
V_FILENAME:='AB'||SUBSTR(P_DOCUMENT_NUM,2,5)||+||V_COUNT||'.txt';
END IF;
L_FILE :=UTL_FILE.FOPEN('D:\oracle\visdb\9.2.0\plsql\temp',V_FILENAME,'W');
UTL_FILE.PUT_LINE(L_FILE ,'E2|' || TRUNC(I.RAC_BILL_TO_CUSTOMER_NUM,0) ||l_attr||
TRUNC(I.RAC_SHIP_TO_CUSTOMER_NUM,0) );
V_COUNT:=V_COUNT+1;
end loop;
Actuelly i have write the data into different files names(i have to increase the filename for tranction) for each record of cursor
but oracle is not allowing to add (V_FILENAME:='AB'||SUBSTR(P_DOCUMENT_NUM,2,5)||+||V_COUNT||'.txt';)
that sum -----SUBSTR(P_DOCUMENT_NUM,2,5)||+||V_COUNT can any one help; -
Performance Measure - Select SUM and Collect Statement.
Dear All,
I am using YNME_PROCESS_PO_CUST Badi in this i writing some validation Delivery Completion.
For that i need to calculate GR qty and Delivery quantity based on this i need some validation. But here i confussed which statement i need to use for bast performance.
Note: In Badi Item Level Data will be process one by one..like item level 10 then 20 then 30......Like that
Code will like that---
SELECT SUM( menge ) FROM ekes
INTO l_delqty
WHERE ebeln = ls_mepoitem-ebeln
AND ebelp = ls_mepoitem-ebelp.
SELECT SUM( dabmg ) FROM ekes
INTO l_grqty
WHERE ebeln = ls_mepoitem-ebeln
AND ebelp = ls_mepoitem-ebelp.
l_delqty1 = l_grqty - l_delqty.
IF l_delqty1 NE 0.
ls_mepoitem-elikz = ''.
CALL METHOD im_item->set_data( ls_mepoitem ).
ENDIF.
I check in SE38 response is better in this code.
Other code may be like that .. same data will be like upper/
SELECT * FROM ekes
INTO CORRESPONDING FIELDS OF TABLE it_ekes
WHERE ebeln = ls_mepoitem-ebeln
AND ebelp = ls_mepoitem-ebelp.
LOOP AT it_ekes.
MOVE-CORRESPONDING it_ekes TO it_ekes1.
COLLECT it_ekes1.
CLEAR it_ekes.
ENDLOOP.
READ TABLE it_ekes1 INDEX 1.
IF sy-subrc EQ 0.
l_delqty1 = it_ekes1-menge - it_ekes1-dabmg.
ENDIF.
IF l_delqty1 NE 0.
ls_mepoitem-elikz = ''.
CALL METHOD im_item->set_data( ls_mepoitem ).
ENDIF.
Can any send me document--
Regard
DKHi,
Single Select statement is certainly better.
But no need to do select * and using into corresponding fields. These will reduce the performance. Also the loop statment is not absolutely correct. Following could be a sample code.
TYPES: BEGIN OF gx_ekes, (maintaining same sequence of fields as in select statement, this way no need of into corresponding fields)
ebeln type ebeln,
ebelp type ebelp,
menge type bbmng,
dabmg type dabmg,
END OF gx_ekes.
DATA : lit_ekes TYPE TABLE OF gx_ekes,
git_ekes TYPE TABLE OF gx_ekes,
wa_ekes TYPE gx_ekes.
SELECT ebeln
ebelp
menge
dabmg
FROM ekes
INTO TABLE it_ekes
WHERE ebeln = ls_mepoitem-ebeln
AND ebelp = ls_mepoitem-ebelp.
LOOP AT lit_ekes INTO wa_ekes.
COLECT wa_ekes INTO git_ekes.
CLEAR: wa_ekes.
ENDLOOP.
CLEAR: lit_ekes.
Now the first record in git_ekes will have the sum as only one line item is being passed in the user exit.
Regards,
Pranav. -
How can I retrieve selected checkboxes by user into a JPA application?
Hello, I'm developing an app in JPA, still learning this, I'm displaying some checkboxes which I save into a List, then I separate the selections and put them into an Array, which I convert into String and that's what I store into MySQL table, this is what I have on the index.xhtml file:
<h:selectManyCheckbox value="#{employee.selectedItems}">
<f:selectItems var="checkList" value="#{employee.checkboxList()}" itemValue="#{checkList.idTechnology}" itemLabel="#{checkList.name}"></f:selectItems>
</h:selectManyCheckbox>
The method checkboxList is in charge of generating the checkboxes and assign a value and name, and the method "selectedItems" is the List<String> that stores the selected checkboxes values, so what I save into the table is something like this: "1,4,6,7" but I don't know how to retrieve the selections and check the checxkboxes according the what the user have on the table:
This is the method that I use to select all the records from the selected user, this fills all the textfields so I can edit the user, but not the checkboxes, and that's what I need to do:
public void seleccionarEmpleado(int id_empleado){
Query q = em.createNamedQuery("Employee.findByIdEmployee");
q.setParameter("IdEmployee", IdEmployee);
List<Empleado> listaEmple = q.getResultList();
for(IdEmployee emple1 : listaEmple){
emp.setIdEmployee(emple1 .getIdEmployeeo());
emp.setName(emple1 .getName());
emp.setLname(emple1 .getLname());
emp.setTel(emple1 .getTel());
emp.setAddress(emple1 .getDir());
emp.setTech(emple1 .getTecha());
Variable Tech is the one who gets the numbers like "2,3,4" etc, but how can I make the checkboxes to be checked according to these numbers? my english is not so good, thanks in advanced, have a nice day!Hello, I'm developing an app in JPA, still learning this, I'm displaying some checkboxes which I save into a List, then I separate the selections and put them into an Array, which I convert into String and that's what I store into MySQL table, this is what I have on the index.xhtml file:
<h:selectManyCheckbox value="#{employee.selectedItems}">
<f:selectItems var="checkList" value="#{employee.checkboxList()}" itemValue="#{checkList.idTechnology}" itemLabel="#{checkList.name}"></f:selectItems>
</h:selectManyCheckbox>
The method checkboxList is in charge of generating the checkboxes and assign a value and name, and the method "selectedItems" is the List<String> that stores the selected checkboxes values, so what I save into the table is something like this: "1,4,6,7" but I don't know how to retrieve the selections and check the checxkboxes according the what the user have on the table:
This is the method that I use to select all the records from the selected user, this fills all the textfields so I can edit the user, but not the checkboxes, and that's what I need to do:
public void seleccionarEmpleado(int id_empleado){
Query q = em.createNamedQuery("Employee.findByIdEmployee");
q.setParameter("IdEmployee", IdEmployee);
List<Empleado> listaEmple = q.getResultList();
for(IdEmployee emple1 : listaEmple){
emp.setIdEmployee(emple1 .getIdEmployeeo());
emp.setName(emple1 .getName());
emp.setLname(emple1 .getLname());
emp.setTel(emple1 .getTel());
emp.setAddress(emple1 .getDir());
emp.setTech(emple1 .getTecha());
Variable Tech is the one who gets the numbers like "2,3,4" etc, but how can I make the checkboxes to be checked according to these numbers? my english is not so good, thanks in advanced, have a nice day! -
Select XML with XMLFOREST into CLOB
Hi,
i am trying to select a XMLFOREST expression into a table with a clob column using oracle 10.2.0.4.0.
The query "select xmlforest(e.last_name) from employees e where e.employee_id = 100" returns <LAST_NAME>King</LAST_NAME>. The result is returned as a clob, but i get an error (ora-06550 inconsistent datatypes) if i try to select the query result into a clob.
So i wrote this code fragment to insert the result:
DECLARE
cl CLOB := NULL;
chCTX DBMS_XMLGEN.CTXHANDLE;
BEGIN
chCTX := dbms_xmlgen.newContext ('SELECT XMLFOREST(e.last_name) FROM employees e WHERE e.employee_id = 100');
dbms_xmlgen.getxml(chCTX,cl );
INSERT INTO TEMP_XML_CLOB(XML_CLOB)VALUES(cl);
COMMIT;
END;The plsql block is executed without an error but and inserts a row in the table, but the clob contains no data. So please give me advice how to store the result set in a clob in a proper way.
Thanks in advance
MatthiasDo you really need to store it as a CLOB? Oracle provides an XMLTYPE for storing XML which is far better.
Try using XMLTYPE and something like:
DECLARE
xml XMLTYPE;
BEGIN
SELECT XMLFOREST(e.last_name)
INTO xml
FROM employees e
WHERE e.employee_id = 100;
INSERT INTO TEMP_XML(XML) VALUES (xml);
COMMIT;
END;(untested)
Obviously you'll want to expand on the SELECT statement to ensure you get all the tags you want and your table will need changing too to cater for XMLTYPE.
I won't ask why you've got a table called "TEMP...", you must know that's just wrong in so many ways. -
How to do a SELECT from different tables into an internal table?
How to do a SELECT from different tables into an internal table?
I want to select data from MARA, MARC and ZPERSON and populate my ITAB_FINAL
REPORT zinternal_table.
TABLES:
mara,
marc,
zperson.
TYPES:
BEGIN OF str_table1,
v_name LIKE zperson-zname,
v_matnr LIKE marc-matnr,
v_emarc LIKE marc-emarc,
v_werks_d LIKE marc-werks_d,
v_dstat LIKE marc-dstat,
END OF str_table,
i_table1 TYPE STANDARD TABLE OF str_table1.
DATA:
BEGIN OF str_table2,
v_mandt LIKE mara-mandt,
v_ernam LIKE mara-ernam,
v_laeda LIKE mara-laeda,
END OF str_table2,
itab_final LIKE STANDARD TABLE OF str_table2.first find the link between mara , marc and zperson , if u have link to 3 tables then u can jus write a join and populate the table u want ( thats final table with all the fields).
u defenitely have alink between mara and marc so join them and retrieve all data into one internal table.
then for all the entries in that internal table retrieve data from zperson into another internal table.
then loop at one internal table
read another internal table where key equals in both the tables.
finally assign fileds if sy-subrc = 0.
gs_finaltable-matnr = gs_table-matnr
etc...
and finally append gs_finaltable to gt_finaltable.
there u go ur final table has all the data u want.
regards
Edited by: BrightSide on Apr 2, 2009 3:49 PM -
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(
"SELECT sum(COL_X) FROM TABLE_A");
int = rset.getInt("sum(NUM_CUSTOMER)");This is obviously wrong. Could someone please help me a little on the syntax? I just want to be able to get the sum of the numeric values in a column without having to loop through a ResultSet and manually adding up the total. My question is how can I access the results of this query by assigning the sum to a java variable?Hi,
Probably the easiest way is to use an alias for the sum column, i.e.:
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(
"SELECT SUM(COL_X) MY_SUM FROM TABLE_A"
int i = rset.getInt("MY_SUM");null -
Select sum(distinct column ) from ....
Hello All,
I have a table the contains ID and size.
An ID identifies a unique object, but it can be repeated. The following is valid:
ID Size
1 3
4 5
5 3
1 3
What I am trynig to do is get the sum of all sizes in the table. I tried this query:
select sum(distinct size) from table;
But it does give the right result since different objects could have the same size. I tried
select sum(size) group by ID;
But it prints to me huge number of IDs and sums the sizes of an ID together. What I want thuogh is to look at the unique rows (without duplicates) and then sum their sizes together and get the result.
Any help would be greatly appreciated.
Thank you
P.S.: Sorry, I am an absolute Oracle/SQl newbie.
Thanks for your help in advanceAn ID identifies a unique object, but it can be repeated.Fnord.
I think your data model could withstand some refactoring but what you need to do is:
SELECT sum(size) FROM
( SELECT distinct id, size FROM your_table)
/This of course assumes that your duplication is complete and you don't have duplicate IDs with different sizes.
You still ought to check out the concept of UNIQUE constraints though. A database ain't a database without relational integrity.
Cheers, APC -
Solaris 10 11/06 - grub Error 28: Selected item cannot fit into memory
I don't get install Solaris 10 11/06 in my IBM Thinkpad 600X laptop with 584 MB RAM memory.
When I try I get allways this message:
Error 28: Selected item cannot fit into memory.
I have seen similars topics in this forum but nobody has found a right solution.
Any idea to help me?
Thanks.I was testing my memory with memtest86 for three hours and I didn't find any problem.
I think my memory is working fine.
Thanks for your reply anyway -
The following query runs fine under 8.1.6 but returns bad result under 8.1.7.2 :
SELECT SUM(NBANOMALIE4), SUM(NBANOMALIE2)
FROM
(SELECT COUNT(*) "NBANOMALIE2" FROM CPN A, ANOCPN B WHERE A.CODENS= '128' AND B.CODANO='2' AND A.NUMFOR = B.NUMFOR ) ,
(SELECT COUNT(*) "NBANOMALIE4" FROM CPN A, ANOCPN B WHERE A.CODENS= '128' AND B.CODANO='4' AND A.NUMFOR = B.NUMFOR )
GROUP BY NBANOMALIE2, NBANOMALIE4;
Result given under 8.1.6 is
SUM(NBANOMALIE4) SUM(NBANOMALIE2)
1 0 (correct)
Result given under 8.1.7.2 is
0 0 (wrong)
if query is changed to "SELECT SUM(NBANOMALIE2), SUM(NBANOMALIE4) ..."
Result given under 8.1.7.2 is
1 1 (wrong too !)
actually the result given for ALL is the result of the last "SUM()" in the select ...
Is it a bug ? if so any patch ? Is there a workaround ?
Thanks for any help
Charlie [email protected]a solution was to use decode()
here is a workaround :
SELECT DECODE(B.CODANO,'2',1,0) NBANOMALIE2, DECODE(B.CODANO,'4',1,0) NBANOMALIE4
FROM CPN A, ANOCPN B
WHERE A.CODENS= '128' AND B.CODANO IN ('2','4') AND A.NUMFOR = B.NUMFOR;
I had it from http://www.orafaq.com/. ...
Charlie [email protected] -
How to import select photos from Iphoto into Adobe Elements
How to import select photos from Iphoto into Adobe Elements
If you wish to import in Elements Organizer here is the guide to help you out with all you need to use iPhoto and Organizer. http://helpx.adobe.com/elements-organizer/using/import-media-iphoto-library-mac.html
If you wish to set PSE Editor as your editor for iPhoto images then here is the help link to guide you for the same - http://helpx.adobe.com/photoshop-elements/kb/photoshop-elements-iphoto-mac-os.html
Hope it helps.
Thanks,
Garry -
Grub error 28: selected item cannot fit into memory
I installed arch, systemrescuecd, and trinity rescue kit on a usb stick. I used the mbr arch installed, grub 0.97, and edited the menu.lst to boot all os'es on the usb.
SystemRescueCD provides an os with all kinds of "rescue" tools, but also other tools like GAG(gag.sourceforge.net/index.html), Memtest86, FreeDos etc, which can be booted from the bootloader.
But, when I try to boot GAG, Memtest86, or FreeDos, grub gives me an error saying "error 28: selected item cannot fit into memory". According to grub, my lower memory is 630K, and my upper memory is about 3.4GiB. The GAG "kernel", is 24.7 kb, and the GAG initrd is 267.8 kb.
This is not really arch related, I know, but still, if you can help me, I'd be very thankful. Google doesn't seem to help me on this one.Hello again,
i tried with Solaris 10 5/08 on VMware ESX 3.5 and VMware Server 2, both failed. I tried several ISO images, mounted as ISO or DVD, altered BIOS parameters in VMware ESX, but nothing works for me.
VMs where created with 1024mb RAM and 8GB disk space, more than recommended.VMware seems to be more successful with installing Solaris10:
http://pubs.vmware.com/guestnotes/wwhelp/wwhimpl/common/html/wwhelp.htm?context=guestnotes&file=choose_install_guest_os.html#3888649
It seems to be a problem of GRUB in Solaris 10 5/08, but i don't know how to solve it. Every idea might be a great help for me.
Maybe you are looking for
-
About five days ago I bought a Toshiba A505-S6005 laptop at Best Buy. I am so sorry I did because this computer has been a pain in the **bleep** since day one. I have numerous problems or errors with the unit, but the system still works (to a point)
-
Problem installing iTunes + QuickTime
So, I uninstalled QuickTime (last week) and then installed QuickTime Alternative, because it's smaller in size and I don't use QuickTime at all. That's probably what's caused my problem, and here it is. So today I double clicked on the iTunes shortcu
-
Hi I have a an issue that I hoping to get help with. I've just done a foilo for ipad where I linked up multiple pdf files. Now my client want to have a folio for Android as well. Question Can I link to a pdf file that is in HTML Resources in a folio
-
Spry error in older version?
I get an error when I run in 6 and under using the "out of the box" spry accordion. the error line is line 334 from the .js file ******is the line with the error // XXX: IE doesn't allow the setting of tabindex dynamically. This means we can't //rely
-
I'm not sure if this is the appropriate category to place this question, but is there a way we can de-couple the open document plugin for abiword from the gnome libraries? It seems vastly inappropriate to require gnome for this plugin, considering th