MINUS select in ABAP?
I have two tables both with the same key - table A and table B. Table A will always have either the same or more records than table B. I want to be able to SELECT those records that exist in table A, but not table B.
In Oracle SQL I would use a MINUS statement, but there doesn't appear to be an equivalient in SAP Open SQL.
The only solution I have is to do a "table A LEFT OUTER JOIN table b" and then look at the records returned and find those with null values returned from table B. See code below (yes I know, from a functional point of view this example doesn't make sense)
DATA: BEGIN OF ls_join,
bsid_bukrs TYPE bukrs,
bsid_belnr TYPE belnr_d,
bsid_gjahr TYPE gjahr,
bsid_buzei TYPE buzei,
bseg_bukrs TYPE bukrs,
END OF ls_join.
DATA: lt_join LIKE ls_join OCCURS 0.
SELECT bsid~bukrs
bsid~belnr
bsid~gjahr
bsid~buzei
zbseg~bukrs
INTO TABLE lt_join
FROM bsid left outer join zbseg
ON bsid~bukrs = zbseg~bukrs AND
bsid~belnr = zbseg~belnr AND
bsid~gjahr = zbseg~gjahr AND
bsid~buzei = zbseg~buzei
WHERE bsid~bukrs = '2000'.
DELETE FROM lt_join WHERE bseg_bukrs IS NOT INITIAL.
Surely there must be a better way than this?
> That looks like it would work in WAS 620 and above but, unfortunately, I am coding in SAP 4.6
> where that command is not available
I don#t think this is true, I have seen it many years ago, so it should be possible at least from release 4.0 onwards.
It is your only chance, if you want to solve your problem with OPEN SQL in not with internal tables.
Siegfried
Similar Messages
-
List of values minus select query
Hi
I have list of fixed values say (2,3,5,7,11,13, .. ...97). I want to minus this list withe some query. how can I do that in oracle 9i sql.
ex:
select (abovelist)
minus
select value from numbers;
I don't want to create the table with above list and minus it.
Regards,
Venkat
Edited by: user12152459 on Nov 2, 2009 10:08 PMHi,
Welcome to the forum!
So you want to treat those numbers as rows in a table, without actually putting them into a table.
Here's one way:
SELECT column_value
FROM TABLE (sys.odcinumberlist (2,3,5,7,11,13, .. ...97))
MINUS
SELECT value
FROM numbers
; -
Hi,
What is meant by dynamic selections in ABAP HR report using a LDB?hi,
use this.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE|TABLE <node>.
Also check this.
[https://forums.sdn.sap.com/click.jspa?searchID=20295165&messageID=5678733] -
Hi All
I am trying to set the value of a selection variable in an Ipak using ABAP using the following code
l_t_range-low = datetime.
l_t_range-sign = 'I'.
l_t_range-option = 'GT'.
I need to extract records with a timestamp greater than the value set in l_t_range-low.
However I get the error message
For sel. Field 'xxxxxxx', No selection with SIGN='I', OPTION 'GT' allowed.
I could use BETWEEN as a workaround but is there anything obviously wrong with the above code.
Thanx in advance
AsifHi,
Please check :
Ipak variable selection using ABAP
-Vikram -
Validate plants selected in Abap Query selection screen
Hi Everyone,
I have a requirement wherein i have to validate 'authority check' for the plants populated in the selection screen in an already created abap query.
I tried adding code in the code section. But i dont know how to use the select-option parameter. It already exists(VBAP-WERKS) in the table which is used for join, so i cannot add it in the additional fields. Am i correct ?
Also, i saw that the report program for this query uses this parameter sa SP$00008. I tried using it but it gives an error The IN operator with "SP$00008" is followed neither by an internal table nor by a value list.
Please help.
Also, please advice whether this requirement can be catered in this query alone? or should i go with writing a new report program for this? ( i personally feel that this would beat the purpose of using Abap Query. )
Regards,
TarunHi Tarun,
I am still not clear with the problem..I guess you require plant in your selection screen which you have.
i guess if you go to sq01tcode there is a option infoset query from where you can give your selection options and value.
have you selected all the fields in infoset and made a selection screen?
When you have done with your infoset you just need to diplay the fields and there is a automatic program generated.
Let me know...
Regards,
Nihkil. -
How to write select within select in ABAP
Hi Guys
I want to write a select statement in ABAP to select from 2 tables below is my code I want to write select within select statment in --->A and replace with ---> B
FORM sales_production_order USING p_vbeln TYPE vbeln_va
CHANGING p_aufnr TYPE aufnr
p_rtcod TYPE sysubrc.
CLEAR: p_rtcod,
p_aufnr.
A *******
SELECT aufnr FROM aufk INTO p_aufnr UP TO 1 ROWS
WHERE kdauf EQ p_vbeln .
B *******
SELECT kdauf from aufk into p_aufnr UP TO 1 ROWS
WHERE KDAUF IN ( SELECT VBELN FROM VBAP where vbeln EQ p_vbeln) .
ENDSELECT.
p_rtcod = sy-subrc.
ENDFORM. " sales
THi Eslam,
In select statements, ENDSELECT must be added when single line returned without the addition 'SINGLE'.
The innner query in your code, returns a single record but with the addition 'UP TO 1 ROWS'. The outer query also like this only. But the outer query ended with 'ENDSELECT', not for inner query.
Else you can add 'SINGLE' keyword.
SELECT aufnr FROM aufk INTO p_aufnr UP TO 1 ROWS
WHERE kdauf EQ '10' .
SELECT SINGLE kdauf from aufk into p_aufnr
WHERE KDAUF IN ( SELECT VBELN FROM VBAP where vbeln EQ p_vbeln) .
ENDSELECT.
SELECT aufnr FROM aufk INTO p_aufnr UP TO 1 ROWS
WHERE kdauf EQ '10' .
***** It assigns Nth record's KDAUF to p_aufnr provided N records satisfy the condition.
SELECT kdauf from aufk into p_aufnr UPTO 1 ROWS
WHERE KDAUF IN ( SELECT VBELN FROM VBAP where vbeln EQ 'p_vbeln) .
ENDSELECT.
ENDSELECT.
Regards,
R.Nagarajan. -
Designing a calculator using selection screen(abap)
hi i just now stepped into this technology. iam learning abap. i like to jknow how to design a calculator using selection screen.
could any one give your suggestions or any sites having such example programs .
thankyouHi
Welcome to SDN.
Use the sample peace of code for design Calculator.
Hi,
Create push buttons for the + , - , / , * , = in your dialog program.
Create an input field with the data type that can accept decimal places..
When the enter 12 then press the push button "+" button store the value 12 in a variable v1..Then clear the input field..
Then when the user enters another number..lets say "13"..
Then if the user presses the "=" button...Then sum the values from the variable v1 with the input field..
Hope this helps..
Check this sample code..
MODULE USER_COMMAND.
CASE SY-UCOMM.
WHEN 'ADDITION'.
ASSUMING THE INPUT FIELD NAME IS P_INPUT.
V_V1 = P_INPUT.
V_OPERATION = '+'.
CLEAR: P_INPUT.
WHEN 'EQUALTO'.
CASE V_OPERATION.
ADDITION
WHEN '+'.
SUM UP THE VALUES.
P_INPUT = P_INPUT + V_V1.
ENDCASE.
MULTIPLICATION
WHEN '*'.
MULTIPLY UP THE VALUES.
P_INPUT = P_INPUT * V_V1.
ENDCASE.
ENDCASE.
ENDMODULE.
Regards,
Sree -
Ipak variable selection using ABAP
Hi All
I am trying to set the value of a selection variable in an Ipak using ABAP using the following code
l_t_range-low = datetime.
l_t_range-sign = 'I'.
l_t_range-option = 'GT'.
I need to extract records with a timestamp greater than the value set in l_t_range-low.
However I get the error message
For sel. Field 'xxxxxxx', No selection with SIGN='I', OPTION 'GT' allowed.
I could use BETWEEN as a workaround but is there anything obviously wrong with the above code.
Thanx in advance
AsifHi Asif,
In our case we had a requirement to load the data for the transactions occuring in the last 15 days only, so we have write the routine on the last modified date feild in the infopackage.so as to select only records modified or created in the last 15 days..
attached is the sample code....
data: l_idx like sy-tabix.
read table l_t_range with key
fieldname = 'LAST_MODIFIED_DA'.
l_idx = sy-tabix.
data : w_cdate type d .
l_idx = sy-tabix.
w_cdate = sy-datum.
w_cdate = w_cdate - 15 .
L_t_RANGE-LOW = w_cdate .
L_t_RANGE-HIGH = sy-datum .
L_t_RANGE-SIGN = 'I'.
L_t_RANGE-OPTION = 'BT'.
append l_t_range.
modify l_t_range index l_idx.
p_subrc = 0.
Hope it helps...
-Vikram -
2 InfoPackages with selection via ABAP
Hello,
my problem is how to select data to be loaded in InfoPackage via ABAP?
One ODS is my Source-ODS containing lots of Data on customer.
Another ODS (calles selection-ODS) contains certain customer numbers.
In InfoPackage 1 I want to load from Source ODS to Goal-ODS 1 - Load contains all Customers (from Selection-ODS).
In InfoPackage 2 I want to load from Source ODS to Goal-ODS 2 - Load contains all Customers except those from Selection-ODS.
Since contents of Selection ODS changes - Selection in Infopackage 1 and 2 needs to be made via ABAP coding.
Can you please tell me how to do that?
Thank you very much,
AngelikaHi,
e.g.:
data: indx like sy-indx.
LOOP AT DATA_PACKAGE.
indx = sy-tabix-
select single * from selectods
where data_package-custno = selectods-custno.
if sy-subrc = 0. "found, okay
else. "not found, delete
DELETE DATA_PACKAGE index indx.
ENDIF.
ENDLOOP.
/manfred -
Date range selection in abap code in infopackage
Hi!
I have a field called "OPEN_DATE".
When the infopackage is runned, I need the abap code to fint the current date, and from that, make a date range from the first day of current month to the last day of current month
Ex:
Current date = 12.12.2008
Abap code should extract 01.12.2008 - 31.12.2008
Thanks!Hi helge,
Data: l_idx like sy-tabix.
Data: date_low like sy-datum,
date_high like sy-datum.
Date_low = sy-datum.
date_low+6(2) = '01'.
CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
EXPORTING
DAY_IN = Date_low
IMPORTING
LAST_DAY_OF_MONTH = date_high
read table l_t_range with key
fieldname = 'OPEN_DATE'.
l_idx = sy-tabix.
Pass Range values to L_T_Range Table.
Move date_low to L_T_Range -Low.
Move date_high to L_T_Range -High.
L_T_Range -Sign = u2018Iu2019. *****(Here: I u2013 Include, E u2013 Exclude)
L_T_Range -Option = u2018BTu2019.****( Here: BT u2013 Between )
modify l_t_range index l_idx.
p_subrc = 0.
Regards, -
Issue with Select options in select statement - ABAP Question
Hi
I am facing an issue with select options. Select statement is returning sy-subrc as 4.
I wrote the program as below:
SELECT-OPTIONS:
s_kunnr FOR bsad-kunnr,
s_lifnr FOR bsak-lifnr,
s_gjahr FOR bsad-gjahr,
s_bukrs FOR bsad-bukrs,
s_saknr FOR bsad-saknr,
s_budat FOR bsak-budat.
In start of selection I have written the select statement as
SELECT * FROM bsak INTO TABLE lt_bsak
WHERE bukrs IN s_bukrs AND lifnr = s_lifnr AND gjahr IN s_gjahr AND budat IN s_budat AND saknr IN s_saknr.
In selection screen I have not entered any values and executed the program. I am not getting any result. When I debug that, sy-subrc is 4 at above select statement. But table has records.
If am removing the "lifnr = s_lifnr " condition in select then select is returning values.
I am not getting where I made the mistake. Please suggest.
Thank you
HanuHi,
The problem here with where condition select option lifnr = s_lifnr.
Use below select query.
SELECT * FROM bsak INTO TABLE lt_bsak
WHERE bukrs IN s_bukrs
AND lifnr IN s_lifnr
AND gjahr IN s_gjahr
AND budat IN s_budat
AND saknr IN s_saknr.
s_lifnr is a select option and you are passing it as parameter lifnr = s_lifnr.
if you want to pass this s_lifnr as single vale then pass in below mentioned way.
lifnr = s_lifnr-low
BR,
Vijay -
Hi All,
I am using the following query, zzglvstid and zzglvrole are primary keys for the table zfi_glv_notf.
Data: w_test_name type tdname-zfi_glv_notf
SELECT tdname FROM zfi_glv_notf
INTO w_text_name
WHERE zzglvstid = w_group_status
AND zzglvrole = w_role.
ENDSELECT.
When I do and extended program check it says " SELECT TDNAME HAS AN EMPTY BODY", I don't why.
Can any one help me in getting it through ...(do not want to use "#EC *)
ThanksHi
First corrrect the DATA decleration...
it should be like <b>tablename - field name</b>
<b>Data: w_test_name type zfi_glv_notf-tdname</b>
SELECT tdname FROM zfi_glv_notf
INTO w_text_name
WHERE zzglvstid = w_group_status
AND zzglvrole = w_role.
ENDSELECT.
<b>Reward Points if it is helpful.</b>
Thanks & Regards
ilesh 24x7 -
Query on Select in ABAP ?
hi @,
In my scenario I have server proxy where the data is coming as multi row object in the input message.Now i need to select each record in the input message and perform some logic and then merge all the records into a structure to be passed as input to BAPI.
Now my doubt is can i used Select * on the input server proxy message or I have to define an internal table and then store the message there and after that call it one by one?
Regardshi prabhu,
how to move the input message to an internal table as the multi row in coming in different node in the message
Clould you provide some sample code or any help in this
regards -
Select query + ABAP logic
Dear SAPians,
I am trying to find best way of fetching some perculiar entries from a DB table. The scenario is explianed below:
1. If the values/entries in column C1 equal to value 'b' for a given key number in column T1, then it should be selected. (Duplicate keys are possible. )
2. If there is anyother entry/value in column C1 along with value 'b' for a given key number (T1) it should be discarded.
3. There are millions of entries in DB table, hence we want to cursor logic which fetches only 1000 at a time.
4. For a given Key number (in T1) there could be entries more than 1000.
(example:
Consider the following TABLE entries With T1 and C1 as two coloumns/fields
T1 C1
9866 b
9866 b
9877 a
9877 b
9877 c
9899 a
9899 b
9900 b
The problem is to retrieve the numbers whose C1 values are only b.In the above example 9877 and 9899
should not be retrieved as they have a C1 value other than b.[this step is done]
The database may contain million records.Due to performance reasons we cannot take more than 1000 entries at a time from the database.Now consider the following case
Case:
T1 C1
9866 b
9866 b
9877 a------3
9877 c
9877 b-------5
9877 b
9877 b
9877 b
9877 b------1000
9877 b-------1500
In the above case consider the number 9877 for which more than 1000 entries exits and from 5 th entry to 1500 entry the c1 value is 'b', in this case for the first 1000 entries 9877 will not satisfy the given condition hence will be retrieved, but during the second run 9877 is retrieved which is incorrect.There may be thousands of entries for a single T1 number and more possible C1 values and th table is not sorted.Sorry to give you the reply so late, never the less what you want is to use the the
DATA: packsize TYPE i VALUE 1000.
SELECT (tab_fields) FROM glpca
PACKAGE SIZE packsize
APPENDING CORRESPONDING FIELDS OF TABLE i_glpca_i
WHERE rldnr IN rldnr
AND rrcty IN rrcty
AND rvers IN rvers
AND kokrs IN kokrs
AND rbukrs IN rbukrs
AND ryear IN ryear
AND racct IN racct
AND rprctr IN prctr
AND sprctr IN pprctr.
ENDSELECT.
As you might notice the logig to pick up records 1000 at a time the PACKAGE SIZE addition is used. Because this kind of selection loops it allows for you to get records in chunks of 1000 if there are less than 1000 they are also taken up, this allows for you to manage the allocation memory and exit the selection once you have taken your desired number of records!
Regards
Tatenda Chaibva -
Hi all ,
In ECC 6.0 , i want to create a dynamic screen .
Requirement is as follows :
I will maintaining a Z table which will contain Program Name (Zreport1 , zreport2 , zreport3 , etc ) all with a common selection parameter PAYROLL AREA . Now , the selection screen of the new program needs to be such that if I maintain Zreport 1 and 2 in this Z table , then Report 1 and report2 description and the payroll area should come in sel screen
eg
THIS IS REPORT 1
Payroll Area : ____________
This is REPORT 2
PAYROLL AREA ...
Thus the sel screen of the new program should differ based on the Z table entires .
Pls lemme know suggestions on the sameHi Supriya,
You can check the below URL, it may help you.
http://wiki.sdn.sap.com/wiki/display/Snippets/ABAPProgramtogenerateselect-options+dynamically.
Seee that if you can try of LDB.
Thanks
Arbind
Maybe you are looking for
-
Need code for Generic Extraction using FM using multiple tables.
Hi Experts, We are doing a generic functional module extraction based on four tables - say, Table TT1 u2013 with fields AA, BB. Table TT2 u2013 with fields CC, DD. Table TT3 u2013 with fields EE, FF. Table TT4 u2013 with fields GG, HH. The value of t
-
Can OpenMQ use SMTP as transport in a distributed setup?
Hello all, I am researching the usability of OpenMQ to provide messaging services to a number of J2EE servers and clients distributed in a multi-segmented network (like central office and branch offices). Deployment in each network segment is complet
-
Add Jcombo in Task Bar.
Hi, Can anyone tell me how to add JComboBox or JTextField in Windows Taskbar for Desktop Search. Thanks Nicky
-
How to get USB ports work on Portege M400?
I am not able to get memory sticks, cameras and iPods recognized when plugged into the USB port of my M400. I have updated all the windows software and all the drivers that I can find. When a device is plugged in the found new hardware dialogue box c
-
I have a J2EE servlet I wrote for use in EP 7.0 using JCO.createClient methods. The code works but every now and then there seems to be a connection issue with the backend R/3 system. This issue also appears to be occuring randomly and no speific e