SELECT with calculations
good day
I am new to ABAP, How to I use calculation in SELECT statement, the following gives me errors
SELECT sf~carrid sf~connid sf~fldate sf~price sf~seatsocc ( sf~seatsmax - sf~seatsocc ) AS seatsavl
INTO CORRESPONDING FIELDS OF TABLE itab_flight
FROM ( sflight AS sf LEFT JOIN scarr AS sc ON sf~carrid = sc~carrid )
WHERE sf~carrid = carrier.
I want the value of
seatsaval
to be the difference of
seatsmax
and
seatsocc
thanx in advance
Can you check with ABAP Documentation , there you can find the possibilities that can be done on a table.
SELECT - aggregate
Syntax
... { MAX( [DISTINCT] col )
| MIN( [DISTINCT] col )
| AVG( [DISTINCT] col )
| SUM( [DISTINCT] col )
| COUNT( DISTINCT col )
| COUNT( * )
| count(*) } ... .
Effect
As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):
MAX( [DISTINCT] col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.
MIN( [DISTINCT] col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.
AVG( [DISTINCT] col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
SUM( [DISTINCT] col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.
COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.
If you are using aggregate expressions, all column labels that are not listed as an argument of an aggregate function are listed after the addition GROUP BY. The aggregate functions evaluate the content of the groups defined by GROUP BY in the database system and transfer the result to the combined rows of the resulting set.
The data type of aggregate expressions with the function MAX, MIN or SUM is the data type of the corresponding column in the ABAP Dictionary. Aggregate expressions with the function AVG have the data type FLTP, and those with COUNT have the data type INT4. The corresponding data object after INTO or APPENDING has to be selected accordingly.
Best Regards.
Similar Messages
-
Trouble with calculating fields. Can't select (check) fields. Also can't figure out what's wrong with a division field (percent) that I created. Keep getting the pop up that format of the field doesn't allow blah blah blah... Help!
1. Use the mouse to select the field and then press the space bar.
2. A null string is the same as zero. What is the result for division by zero? -
Using iPad2 to fill PDF forms with calculating cells
I currently have the PDF Expert app. installed. I have created a PDF form with calculating cells and cells with multiple selections using Adobe Acrobat X Pro. It works on my PC on 2 different PDF reader apps, however when I load it in PDF Expert on the iPad it does not calculate and the multiple selections aren't there. It also does not keep the formatting of the cell. I set the cells up as currency, however it does not show as currency once loaded in the PDF Expert app on the iPad. Is there an app out there for the iPad that will allow PDF form fill in and will also show the cell formatting and calculations? Or is this a limitation caused by iOS? I have also tried Adobe's reader app for the iPad and it doesn't show it on there as well. Any help would be greatly appreciated! Thanks!
I'd be amazed if you could. I wouldn't think it possible to even open a PDF, much less edit one.
-
Database selection with invalid cursor !
hi experts,
When execute SAP BW processchar, it occur some system error: (sm21)
Database selection with invalid cursor
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed).
this error occur when apply bw support package 19.
sap notes 1118584 Solution is: Import Support Package 17 . but my support package is 19.
how can i solve this error?
thanks,
xwu.I am only assuming things, but it might be worth to look closely if you were experiencing an ORA- error during the execution. This could have caused a rollback and thus closed the cursor. Please check the job log, the workprocess trace (dev_wX file) and the system log SM21 and ST22 as well.
Besides that check the oracle alertlog and the usertrace destination.
Best regards, Michael -
Database selection with invalid cursor with MaxDB database
Hi Experts,
I encountered the this error:
"Database selection with invalid cursor
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed)."
We are using bw support package 19 early this month. Previously is working fine but this problem occured from the last 2 days.
We are using MaxDB database.
Really appreciate any speedy responds.Hi,
We finally resolved the issue.
The solution:
We check the RFC connection test in SM59. There are connection error.
There is an error that related J2EE_ADMIN user.
SO we reset the J2EE_ADMIN id in SU01.
The problem goes away.
Many thanks -
Load data error: Database selection with invalid cursor (sm21)
hi experts,
when I execute processchar, it occur some system error:
"Database selection with invalid cursor ",
"Documentation for system log message BY 7 :
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed). "
the error msg occur when apply bw support package19.
data from DSO to CUBE, Transferred Recodes is not zero, but Added Recodes is zero.
Request status always yellow, process is running.
current sys info: BI7 and BW19, BASIS17,PI_BASIS17, the database is oracle10g R2.
thanks for your help.I have solved this issue, The Oracle checkpoint not complete.
thanks,
xwu. -
Processchar occur error: Database selection with invalid cursor (sm21)
hi,
when I execute processchar, it occur some system error:
"Database selection with invalid cursor ",
"Documentation for system log message BY 7 :
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed). "
the error msg occur when apply bw support package19.
data from DSO to CUBE, Transferred Recodes is not zero, but Added Recodes is zero.
Request status always yellow, process is running.
current sys info: BI7 and BW19, BASIS17,PI_BASIS17, the database is oracle10g R2.
thanks for your help.I have solved this issue , The Oracle checkpoint is not complete.
thanks,
xwu. -
Database selection with Invalid Cursor error in RSDRI_INFOPROV_READ
Hi Everyone.
I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
Logic of the code is as following
while <more data>
CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
Append lines of E_T_DATA to EO_T_DATA.
If total lines of data in EO_T_DATA > 200000
<save EO_T_DATA in a file using GUI_DOWNLOAD>
<clear EO_T_DATA>
EndIF
EndWhile.
As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
Error says "Database selection with invalid cursor".
I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
But it is imperative for me to save data in file at regular intervals as data volume is huge.
Any pointers in this direction will be helpful.Hi Everyone.
I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
Logic of the code is as following
while <more data>
CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
Append lines of E_T_DATA to EO_T_DATA.
If total lines of data in EO_T_DATA > 200000
<save EO_T_DATA in a file using GUI_DOWNLOAD>
<clear EO_T_DATA>
EndIF
EndWhile.
As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
Error says "Database selection with invalid cursor".
I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
But it is imperative for me to save data in file at regular intervals as data volume is huge.
Any pointers in this direction will be helpful. -
Hi
I want to create a app redirecting to my mebsite.This app permit to select a "area" selected on a UICollectionViewController, and an "event" selected with a UITableViewController.
I need to integer both informations on the FinalViewController (called in my app AnnoncesViewController) =>
The fisrst array is selected on CollectionViewController:@"http://carnet-du-jour.com/index.php/component/ohanah/?option=com_ohanah&view=e vents&Itemid=0&ohanah_venue_id=21"
The second array is selected onUITableViewController:@"&ohanah_category_id=1&textToSearch="
The final array must be:http://carnet-du-jour.com/index.php/component/ohanah/?option=com_ohanah&view=eve nts&Itemid=0&ohanah_venue_id=21&ohanah_category_id=1&textToSearch=
How can I integer these 2 NSArray to obtain this result to link to a UIWebView as FinalViewController?
Thank you for your help!!
My App is on Drobox:https://www.dropbox.com/s/43l1p2hj5bqamvn/Carnet%20du%20Jour.zip
Gracefully
RémySpehlerHi
I want to create a app redirecting to my mebsite.This app permit to select a "area" selected on a UICollectionViewController, and an "event" selected with a UITableViewController.
I need to integer both informations on the FinalViewController (called in my app AnnoncesViewController) =>
The fisrst array is selected on CollectionViewController:@"http://carnet-du-jour.com/index.php/component/ohanah/?option=com_ohanah&view=e vents&Itemid=0&ohanah_venue_id=21"
The second array is selected onUITableViewController:@"&ohanah_category_id=1&textToSearch="
The final array must be:http://carnet-du-jour.com/index.php/component/ohanah/?option=com_ohanah&view=eve nts&Itemid=0&ohanah_venue_id=21&ohanah_category_id=1&textToSearch=
How can I integer these 2 NSArray to obtain this result to link to a UIWebView as FinalViewController?
Thank you for your help!!
My App is on Drobox:https://www.dropbox.com/s/43l1p2hj5bqamvn/Carnet%20du%20Jour.zip
Gracefully
RémySpehler -
Delete statement that uses a sub-select with the statement in the cursor
Hi all,
How to write write a delete statement that uses a sub-select with the statement in the cursor?
CURSOR excluded_dates IS
SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
INTO my_current_date_time
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'DATE_TIME'
AND report_parameters.report_parameter_name = 'EXCLUDED_DATE';
OPEN excluded_dates;
LOOP
FETCH excluded_dates INTO my_excluded_date;
EXIT WHEN excluded_dates%NOTFOUND;
DELETE FROM edr_rpt_tmp_inclusion_table
WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
END LOOP;
CLOSE excluded_dates;ThanksHi,
In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
View created
SQL> select * from v_employees;
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
110 John Chen JCHEN 515.124.4269 28/09/1997 FI_ACCOUNT 8200,00 108 100
112 Jose Manuel Urman JMURMAN 515.124.4469 07/03/1998 FI_ACCOUNT 7800,00 108 100
125 Julia Nayer JNAYER 650.124.1214 16/07/1997 ST_CLERK 3200,00 120 50
127 James Landry JLANDRY 650.124.1334 14/01/1999 ST_CLERK 2400,00 120 50
131 James Marlow JAMRLOW 650.124.7234 16/02/1997 ST_CLERK 2500,00 121 50
133 Jason Mallin JMALLIN 650.127.1934 14/06/1996 ST_CLERK 3300,00 122 50
139 John Seo JSEO 650.121.2019 12/02/1998 ST_CLERK 2700,00 123 50
140 Joshua Patel JPATEL 650.121.1834 06/04/1998 ST_CLERK 2500,00 123 50
145 John Russell JRUSSEL 011.44.1344.429268 01/10/1996 SA_MAN 14000,00 0,40 100 80
156 Janette King JKING 011.44.1345.429268 30/01/1996 SA_REP 10000,00 0,35 146 80
176 Jonathon Taylor JTAYLOR 011.44.1644.429265 24/03/1998 SA_REP 8600,00 0,20 149 80
177 Jack Livingston JLIVINGS 011.44.1644.429264 23/04/1998 SA_REP 8400,00 0,20 149 80
181 Jean Fleaur JFLEAUR 650.507.9877 23/02/1998 SH_CLERK 3100,00 120 50
186 Julia Dellinger JDELLING 650.509.3876 24/06/1998 SH_CLERK 3400,00 121 50
189 Jennifer Dilly JDILLY 650.505.2876 13/08/1997 SH_CLERK 3600,00 122 50
200 Jennifer Whalen JWHALEN 515.123.4444 17/09/1987 AD_ASST 4400,00 101 10
16 rows selected
SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
2 rows deleted
SQL> regards, -
No selection with SIGN = 'I'; OPTION 'GE' allowed
Hello All,
I have added an ABAP routine in one of the InfoPackage to filter a field CREATDATE(char,8).
Whenever I am executing the InfoPackage I am getting the following error:-
For sel. field 'CREATDATE', no selection with SIGN = 'I'; OPTION 'GE' allowed
Message no. RSM1607
Through debugging I have noticed that after the EndForm of the InfoPackage filter the Program control goes to a System Program "RSS2_INTERPRET_SELOPTS_DS". All the Selection Options (EQ, BT, GE, GT, NE, LT, etc ) are defined in this program and the program control ignores the 'GE' option code specified in the program "RSS2_INTERPRET_SELOPTS_DS".
if not l_s_so-ge is initial.
clear l_s_selopts.
l_s_selopts-sign = 'I'.
l_s_selopts-option = 'GE'.
l_s_selopts-single = 'X'.
append l_s_selopts to e_t_selopts.
endif.
Can anyone help how to resolve this.
Thank You
Edited by: RACHANA_CG on Sep 27, 2010 2:28 PMHi,
I guess in Infopackage filter routine, you can only declare multiple single values or a range i.e technically I EQ & I BT.
Excluding or greater/less functions are disregarded. You can create a dynamic infopackage filter to have all the dates say for the next two years from the start date & run it.
--Akashdeep -
Select with no conditions taking long time, too many blocks, pctused?
select * from at_journal;is taking 15 seconds, which is absurd. I have similar situations with other log tables in this system.
(selecting with rownum < 5 and with first_rows hint still takes 15 seconds)
Suspicious parameters:
PCT_FREE 1
PCT_USED 99
(Some other log tables have PCT_FREE 5, PCTUSED 90)
The tables have frequent inserts, once every day all records older than 90 days get deleted.
After computing statistics:
Blocks: 42,304 (seems absurdly high)
Size: 663 Mb
NUM_ROWS: 505,966
After copying data without compression to new table:
Blocks: 3,785
Size: 60 Mb
NUM_ROWS: 505,966
The select on the new table is instantaneous.
On a side note, in general is compression for a table with frequent deletes OK? It seems OK to me.
Storage parameters of table creation script:
PCTUSED 99
PCTFREE 1
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
NOMONITORING;I imagine that most blocks for the table are empty. In my mind pctused of 99 means most of the block space should be full. I have read several explanations of PCTUSED/pctfree including oracle documentation and it seems pctused of 99 means the block should be 99% full.
Much thanks,
googoo wrote:
I imagine that most blocks for the table are empty. In my mind pctused of 99 means most of the block space should be full. I have read several explanations of PCTUSED/pctfree including oracle documentation and it seems pctused of 99 means the block should be 99% full.Hello, you don't give your database version, but if you were using Automatic Segment Space Management you would not need to worry about the PCTUSED setting, and it could be that you already are:
1 select tablespace_name, segment_space_management
2 from dba_TABLESPACES
TABLESPACE_NAME SEGMEN
SYSTEM MANUAL
SYSAUX AUTO
UNDOTBS1 MANUAL
TEMP MANUAL
USERS AUTO
EXAMPLE AUTOAnd if you are already using ASSM, then the PCTUSED is not an issue (PCTFREE still applies, but it's not an issue in your case).
goo wrote:
On a side note, in general is compression for a table with frequent deletes OK? It seems OK to me.Frequent DELETEs could be an issue because they will not reset the High Watermark, though there will not be a performance penalty because of the compression for DELETEs (the record only needs to be located for a DELETE, not decompressed). Your PCTUSED, however, is high enough so that any newly deleted record slots should be quickly reused, but... it depends on how those new records are being INSERTed. If, as Daniel says, the HWM is being effectively bypassed (Direct Path INSERTs, etc.), then the table will grow in size every day, but the volume of records effectively stays just about the same.
Have a look at how the new records are being added to that table, if it's a:
INSERT /*+ APPEND */ INTO tableA
SELECT...Then the HWM is being advanced, and the newly vacated slots from the DELETEd records are not being reused. So the table will continually grow, for roughly the same amount of data, and there'll be a proportionately longer data retrieval time. -
How to avoid select with in a loop.
Hi friends,
can any tell how to avoid the select with in a loop for the following code, since it badly effecting my performance. if possible with code
SELECT matnr werks
FROM marc
INTO TABLE it_marc
FOR ALL ENTRIES IN it_ausp_1
WHERE matnr = it_ausp_1-objek AND
werks = p_werks
AND mmsta LE 60.
SORT it_marc BY matnr.
CLEAR wa_ausp_1.
CLEAR wa_tabix.
LOOP AT it_ausp_1 INTO wa_ausp_1.
wa_tabix = sy-tabix.
READ TABLE it_marc INTO wa_marc WITH
KEY matnr = wa_ausp_1-objek
BINARY SEARCH.
IF sy-subrc EQ 0.
ELSE.
DELETE it_ausp_1 INDEX wa_tabix.
ENDIF.
ENDLOOP. " LOOP AT it_ausp_1 INTO wa_ausp_1.
APPEND LINES OF it_ausp_1 TO it_tal.
IF it_tal[] IS NOT INITIAL.
LOOP AT t_plan_order INTO fs_plan_order.
SELECT r~rsnum
r~rspos
r~matnr
r~nomng
r~meins
r~plnum
r~bdter
r~ewahr
r~alprf
r~posnr
r~baugr
m~dispo
INTO TABLE t_resb
FROM resb AS r
INNER JOIN marc AS m
ON rbaugr = mmatnr
AND rwerks = mwerks
FOR ALL ENTRIES IN it_tal
WHERE r~rsnum = fs_plan_order-rsnum
AND r~matnr = it_tal-objek
AND r~xloek = ' '
AND r~werks = p_werks.
APPEND LINES OF t_resb TO t_tacl.
ENDLOOP.SELECT r~rsnum r~rspos r~matnr r~nomng r~meins r~plnum r~bdter r~ewahr r~alprf r~posnr r~baugr m~dispo
INTO TABLE t_resb
FROM resb AS r
INNER JOIN marc AS m
ON r~baugr = m~matnr
AND r~werks = m~werks
FOR ALL ENTRIES IN it_tal
WHERE r~rsnum = fs_plan_order-rsnum
AND r~matnr = it_tal-objek
AND r~xloek = ' '
AND r~werks = p_werks.
The logic of this select is completely weird. Whcih order of the db-tables should be used, which indexes?
On RESB matnr, werks and xloek are in one index, but rsnum not.
Are the conditions in fs_plan_order and it_tal connected or independent?
It is probably much faster, to leave the fs_plan_order condition away and check it on the result.
SELECT r~rsnum r~rspos r~matnr r~nomng r~meins r~plnum r~bdter r~ewahr r~alprf r~posnr r~baugr m~dispo
INTO TABLE t_resb
FROM resb AS r
INNER JOIN marc AS m
ON m~matnr = r~baugr
AND m~werks = r~werks
FOR ALL ENTRIES IN it_tal
WHERE AND r~matnr = it_tal-objek
AND r~xloek = ' '
AND r~werks = p_werks.
sort fs_plan_order by rsnum.
loop at it_tal in wa.
read table fs_plan_order
with key rsnum = wa-rsnum
binary search.
if sy-subrc eq 0.
append ...
endif.
endloop.
Siegfried -
How to create VO with multiple dynamic where clauses on select with UNION?
I am trying to implement the View Object for the UNION query that looks like this:
select a,b,c...
from t1,t2,...
where dynamic_where_clause1
union all
select a,b,c,...
from t11,t12, ...
where dynamic_where_clause2
There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
I understand that recommended way with UNIONs is to wrap both queries into a parent select:
select * from (
select a,b,c...
from t1,t2,...
where ... -- table relationship joints
union all
select a,b,c,...
from t11,t12, ...
where ... -- table relationship joints
) QRSLT
where dynamic_where_clause
Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
Edited by: viksicom on Aug 2, 2012 8:48 AM -
I need a report in SAP which allows multiple Profit centers selection with
Hi,
Cany anybody help me with below issue -
I need a report in SAP which allowing multiple Profit centers selection with :
- Profit Center #
- Profit center Name
- Profit center long text
- Profit Center group
- the related PC node showing the BU and the product category group.
Let me know is there any report which can provide us with all this details.
With regards.Hi,
I recommend the PCA standard drill-down or interactive reports accessible via the follwoing menu path:
Accounting --> Enterprise Controlling --> PCA --> Infosystem --> Reports for PCA
There are several reports which allow entering profitcenter groups or profitcenters.
Long Text is not possible. Makes also no sense to report on Long Text.
Best regards,
Andreas
Maybe you are looking for
-
How to set to-mode to Fixed Value and give a date in RSDV transaction
Hi I am working in BI7.0 environment. I am deploying HR Reporting Project. I need to load data to HR Info Cube 0PAPA_C02, to do this I need to maintain validity slice (RSDV transaction) for the Info Cube. After first load I need to set "to-m
-
With an IMAP account, if "Store sent messages on the server" is checked (in Mailbox behaviors) does Mail only store sent mail on the server? So should it not be checked if you want Mail to store sent mail on the server and the computer? Thank you. iH
-
Query Migration from BW 3.5 to BW 7.0
Dear All, We are in the process of migrating from BW 3.5 to BW 7.0 and need to find answers to the following- Will the query variants created with BEx 3.5 and BW 3.5 be available with BEx 7.0/ BEx 3.5 in BW 7.0. What all settings need to be made to e
-
How to start weblogic server automattically (services.msc)
Hi Experts, I would like to monitor Hyperion services. ( I know only weblogic console option; please let me better option if any) I regularly login to Hyperion server and start admin server for weblogic then using url for console I check status of al
-
CJ20N NWA update funds management button
Hello In cj20n im trying to automate the NWA assignments in the funds management to the NWA. Is there a way to have this process automated. thanks MAtt