Select statement having internal table in the wher clause...
Hi,
will all the entry from the internal i_crhd will be pased to the next select statement in the sample code below without looping? Thanks a lot!
REFRESH i_crhd.
SELECT objid vgwts
FROM crhd INTO CORRESPONDING FIELDS OF TABLE i_crhd
WHERE arbpl IN s_arbpl.
pulling the cost centre linked to the resource
IF sy-subrc EQ 0 AND i_crhd[] IS NOT INITIAL.
REFRESH i_crco.
SELECT kostl FROM crco
INTO CORRESPONDING FIELDS OF TABLE i_crco
FOR ALL ENTRIES IN i_crhd
WHERE objid = i_crhd-objid.
IF sy-subrc EQ 0.
do nothing.
ENDIF.
ENDIF.
Hi,
The code looks fine..u can very well go ahead with the code...
Wht all other ABAPers said about FOR ALL ENTRIES is absolutely rite.
But i have a small suggestion...
Why cant u use a INNNER JOIN for those 2 queries...
like...
SELECT cr~objid
cr~vgwts
co~kostl
FROM crhd AS cr INNER JOIN
crco AS co
ON crobjid = coobjid
INTO TABLE i_crco
WHERE cr~arbpl IN s_arbpl.
Now in i_crco 3 fields will be thr
objid, vgwts, kostl.....this one can change as u wish...
Why i suggest not to ue FOR ALL ENTRIES is sometimes it is a performanc killer....in this code i feel this will do fine...
Please let me know if u feel not ok with this code...
Reward if found useful...
Regards,
ABAPer 007.
Similar Messages
-
Can we apply select statement on internal table.
can we apply select statement on internal table.if yes thrn let me know how to do.
Dear Sachin,
You cannot use SELECT statement on internal table.
If you want to select some rows from internal table you can LOOP the table or you can READ the table.
<u>Please check the following links for your kind reference:</u>
<b>http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm
http://www.sap-img.com/ab009.htm
http://www.itsmarc.com/crs/Clas0302.htm
http://www.sapdevelopment.co.uk/tips/tips_itab.htm
http://searchsap.techtarget.com/search/1,293876,sid21,00.html?query=whatisinternaltable&bucket=ALL</b>
Cheers !
Moqeeth. -
How can i use the internal table as a WHERE clause ?
Dear Support ,
I have one internal table that save the material information ...
data : begin of itab ,
matnr like mara-matnr ,
end of itab .
And now i want to fetch the material desription text base on this internal table .
As i know that the "FOR ALL ENTRIES" statement is not allowed us to use "IN" this keyword ....
So , Has another solution for this case ? I don't want to use "LOOP AT ...." this way ...
Many thanks .
CarlosWhy can't you do
SELECT MATNR MAKTX INTO TABLE ITAB2 FROM MAKT FOR ALL ENTRIES IN ITAB WHERE MATNR = ITAB-MATNR. -
Select statement of severals tables with the same structure
Does anybody know - how to create a single select statement to count entries of several tables. These tables have the same structure and are connected by a foreign key to a - I would call master table. So in this master table - I have the names of all these others tables and what I want should look like this:
name__________ # entries
table_1_________100
table_2_________150
table_3__________80
Select table_name, count(table1.column1), count(table2.column1), count(table3.column1) from master, table1, table2, table3 Where master.id=table1.id OR master.id=table2.id OR master.id=table3.id Group By table_name
Thanks in advance
remoIf I understood your question correctly, this is what you (probably) need:
Select table_name, (select count(column1) from table1 Where master.id=table1.id), (select count(column1) from table2 Where master.id=table2.id), (select count(column1) from table3 Where master.id=table3.id)
from master -
UPDATE using a second table for the Where Clause
Hi There,
Hoep someone can help me!
I am attempting to update a field in Tbl.1 to a known value. However, i want to use another table to specify WHICH records to update.
in this case i want to use table early_provider to obtain the value 'HCR' then pass that to the UPDATE clause in order to SET early_provisions.type_name = 'HOMC'
I hope this makes sense.
UPDATE EARLY_PROVISIONS eps
SET TYPE_NAME = (SELECT *
FROM EARLY_PROVIDER ep
WHERE PROVIDER_TYPE = 'HCR'
WHERE EP.PROVIDER_ID = EPS.PROVIDER_ID);
I need to be able to include the field value 'HOMC in this statement but am not sure how, or if i am barking up the wrong tree.
Much appreciated in advance
PFGPFGMcAvoy wrote:
Karthick_Arp
Thanks. this seems to only update 15 rows of which already exist in the table early_provisions and filed type_name!
I should be selecting about 200 recordsd from early_provider that have the provider_type = 'HCR'
??I don't know your data. So i cant answer that. But for what you asked i think thats the correct UPDATE statement. So i think you have to investigate your data to find what is going on. -
UPDATE Statement executing for whole table even when WHERE Clause is presen
Hi Friends,
I have a problem in a stored procedure where i have written an update statement with a where clause. At a time only one row should get updated depending upon unique identifier in where clause.
But whats happening is that Update statement is getting executed for all the rows in the table neglecting the WHERE clause. I am not getting the clue as to why this is happening. Here is the stored Procedure And the update statement is in BOLD :-
CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
CntryMasterCode IN VARCHAR2,
CntryName IN VARCHAR2,
MDMUser IN VARCHAR2,
Exist IN INTEGER,
status IN VARCHAR2,
Inserted_By IN VARCHAR2 DEFAULT NULL,
Modified_By IN VARCHAR2 DEFAULT NULL,
Mdm_Code IN NUMBER DEFAULT 0,
Action IN VARCHAR2 DEFAULT 'add',
XGenAttNames IN VARCHAR2 DEFAULT NULL,
XGenAttValues IN VARCHAR2 DEFAULT NULL,
MirusAttNames IN VARCHAR2 DEFAULT NULL,
MirusAttValues IN VARCHAR2 DEFAULT NULL,
GenisysAttNames IN VARCHAR2 DEFAULT NULL,
GenisysAttValues IN VARCHAR2 DEFAULT NULL,
XGenModify IN VARCHAR2 DEFAULT NULL,
MirusModify IN VARCHAR2 DEFAULT NULL,
GenisysModify IN VARCHAR2 DEFAULT NULL
IS
strSQLXGen VARCHAR(1000);
strSQLMirus VARCHAR(1000);
strSQLGenisys VARCHAR(1000);
nMaxMDMCode INTEGER;
ifExist INTEGER;
NAME: proc_MDM_InsertCntryDetails
PURPOSE:
REVISIONS:
Ver Date Author Description
1.0 7/3/2009 1. Created this procedure.
NOTES:
Automatically available Auto Replace Keywords:
Object Name: proc_MDM_InsertCntryDetails
Sysdate: 7/3/2009
Date and Time: 7/3/2009, 7:11:20 PM, and 7/3/2009 7:11:20 PM
Username: (set in TOAD Options, Procedure Editor)
Table Name: (set in the "New PL/SQL Object" dialog)
BEGIN
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MASTER;
IF ifExist = 0 THEN
SELECT 1 INTO nMaxMDMCode FROM DUAL;
ELSE
SELECT MAX(MDM_CODE)+1 INTO nMaxMDMCode FROM MDM_COUNTRY_MASTER;
END IF;
IF Action='add' THEN
INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,Exist,status,Action,SYSDATE,Inserted_By);
strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || nMaxMDMCode || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen;
strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || nMaxMDMCode || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus;
strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || nMaxMDMCode || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Inserted_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys;
ELSE
UPDATE MDM_COUNTRY_MASTER
SET MDM_DESCRIPTION=CntryName,DAT_MODIFIED_BY=Modified_By,DAT_MODIFY_DATE=SYSDATE,
MDM_USER=MDMUser,MDM_ACTION=Action,MDM_STATUS=status,MDM_EXIST=Exist WHERE MDM_CODE=Mdm_Code;
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=1 AND MDM_CODE=Mdm_Code ;
IF ifExist = 0 THEN
strSQLXGen := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || XGenAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || Mdm_Code || ',' || '''' || 'XGen' || '''' || ',1,' || XGenAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen ;
ELSE
strSQLXGen := 'UPDATE MDM_COUNTRY_MAPPING SET ' || XGenModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=1' ;
EXECUTE IMMEDIATE strSQLXGen ;
END IF;
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=2 AND MDM_CODE=Mdm_Code ;
IF ifExist = 0 THEN
strSQLMirus := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || MirusAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || Mdm_Code || ',' || '''' || 'Mirus' || '''' || ',2,' || MirusAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus ;
ELSE
strSQLMirus := 'UPDATE MDM_COUNTRY_MAPPING SET ' || MirusModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=2' ;
EXECUTE IMMEDIATE strSQLMirus ;
END IF;
SELECT COUNT(*) INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE=3 AND MDM_CODE=Mdm_Code;
IF ifExist = 0 THEN
strSQLGenisys := 'INSERT INTO MDM_COUNTRY_MAPPING(MDM_CODE,SYSTEM_NAME,SYSTEM_CODE,' || GenisysAttNames || ',DAT_INSERTED_BY,DAT_INSERT_DATE) ' ||
'VALUES(' || Mdm_Code || ',' || '''' || 'Genisys' || '''' || ',3,' || GenisysAttValues || ',' || '''' || Modified_By || '''' || ',SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys ;
ELSE
strSQLGenisys := 'UPDATE MDM_COUNTRY_MAPPING SET ' || GenisysModify || ',DAT_MODIFY_DATE=SYSDATE,DAT_MODIFIED_BY=' || '''' || Modified_By || '''' || ' WHERE MDM_CODE=' || Mdm_Code || ' and SYSTEM_CODE=3' ;
EXECUTE IMMEDIATE strSQLGenisys ;
END IF;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END proc_MDM_InsertCntryDetails;
ThanksIt might be helpful to search this forum and google for PL/SQL (variables, stored procs, etc) naming standards. There are quite a few out there and you can choose one that works for you.
As an example, a lot of standards adopt naming prefixes, ie v_ for VARCHAR variable, n_ for NUMBER variable, pv_ for paramater VARCHAR, etc. -
How do I select a range of rows from an internal table in the debugger?
Hi,
I have a case where I wanted to delete a range of rows (several thousand) from an internal table using the debugger.
It seems that rows can only be selected one at a time by selecting (clicking) on the far left side of the row.
This is cumbersome, if not impossible when wishing to delete several thousand rows.
Other tools, such as Excel for example, allow for selecting a range of rows by selecting the first row and then holding the SHIFT key and selecting the last row and all rows in between will be selected.
I can't seem to find the combination of keys that will allow this in the table (or structure) tab of the debugger.
Is it possible to select a range of rows without having to select each row one at a time?
Thanks for your help,
AndyWhile it's a Table Control and should/could have a button to select all fields (or visible fields)...I don't think we can do it right now...I know it's a pain to select each row one at a time...but I don't we have any more options...
Greetings,
Blag. -
Using if logic in the where clause of a select statement
I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
Basically I am looking for a case statement like this
case
when all_off_trt = 'Y' and mail_para.code = 'Y' then false
else true
end
Message was edited by:
Tugnutt7Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
This is currently what I have, tested and working 100%.
cursor email_cur is
select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
from participant p, trialcom t, ethics s
where p.status='A'
and p.surname=t.surname
and p.initials=t.initials
and s.trial_cd = t.tricom
and s.centre = t.centre
and p.email is not null
and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable. -
How to display data from internal table in the SELECTION-SCREEN
Hello Experts,
My requirement is to display the data's from an internal table in the selection screen. I tried using selection-screen comment. But it is working only for a single record. Can anyone please tell me how to do this?Hi Ritika,
we cant use write statement inside selection-screen.
see my coding.
SELECTION-SCREEN BEGIN OF SCREEN 123 AS WINDOW TITLE TEXT-456.
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1
NO INTERVALS.
SELECT-OPTIONS SEL1 FOR SY-DATUM.
PARAMETERS PAR1(10).
<b>** I WANT ALL RECORDS FROM AN INTERNAL TABLE HERE ONLY</b>
SELECTION-SCREEN END OF BLOCK BL1.
SELECTION-SCREEN PUSHBUTTON 2(10) but1 USER-COMMAND cli1.
SELECTION-SCREEN PUSHBUTTON 20(10) but2 USER-COMMAND cli2.
SELECTION-SCREEN END OF SCREEN 123. -
Values from a Multi-Select in the where clause of a Select statement
I have a web page that solicits query parameters from the user.
The selections that the user makes will populate the WHERE clause of a Select statement.
One of the controls on the page is a multi-select control.
When this page posts, I would like to execute a Select statement wherein the selected values from this control appear in the .. Column IN ( <list here> ) portion of the WHERE clause.
This is an extremely common scenario, but I cannot seem to locate a how-to or message thread that addresses this specific case.
I have an idea that it may involve dynamic SQL or Execute Immediate, but cannot seem to pin down the answer.
Any help would be greatly appreciated!anonymous - As illustrated here: Re: Search on a typed in list of values
Scott -
Runtime error at select statement in RFC_READ TABLE FM
Dear All,
I have copied the standard FM RFC_READ_TABLE to incorporate the customer needs. Below is the select query which I have written in this FM.
SELECT (po_search_text-column_text) INTO <wa> FROM ekko
INNER JOIN ekpo ON ekko~ebeln = ekpo~ebeln
INNER JOIN eket ON ekpo~ebeln = eket~ebeln AND ekpo~ebelp = eket~ebelp
INNER JOIN lfa1 ON ekko~lifnr = lfa1~lifnr
INNER JOIN lfm1 ON ekko~lifnr = lfm1~lifnr AND ekko~ekorg = lfm1~ekorg
INNER JOIN lfb1 ON ekko~lifnr = lfb1~lifnr AND ekko~bukrs = lfb1~bukrs
INNER JOIN t024 ON ekko~ekgrp = t024~ekgrp
INNER JOIN zatscsng_status ON eket~ebeln = zatscsng_status~po_number
AND eket~ebelp = zatscsng_status~po_line
AND eket~etenr = zatscsng_status~po_sched_line
INNER JOIN adrc ON zatscsng_status~delivery_addr = adrc~addrnumber
WHERE (po_search_text-cond_text)
ORDER BY (po_search_text-sort_text).
Here, posearch_text-column_text_ will have the fields to be selected at runtime and posearch_text-cond_text_ is the where condition. It is running fine in this case.
But when I try to select Item Category ( EKPO-PSTYP), if data is present for this category, it is returning the values but if data is not there for the particular item category in the where clause, it is giving a RUNTIME ERROR at the select statement.
Here is the ERROR ANALYSIS:
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "ZATSCSNG_RFC_READ_TABLE" "(FUNCTION)", nor was it propagated by a
RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The current ABAP program has tried to execute an Open SQL statement
which contains a WHERE, ON or HAVING condition with a dynamic part.
The part of the WHERE, ON or HAVING condition specified at runtime in
a field or an internal table, contains the invalid value "<L_LINE>-PSTYP".
Edited by: Rob Burbank on Mar 17, 2010 5:09 PMNow that's what I call a join statement...
You probably have a bug in how you build po_search_text-cond_text, the content must be a syntactically correct where clause. It seems that in your example there is just "<L_LINE>-PSTYP" without a condition, so try omitting it altogether.
Debug the content of po_search_text-cond_text before it hits the select statement.
Thomas -
SELECT-OPTION to internal table
Hi,
I need to convert the select-option values into an internal table.
For example, if there is a select-option S_WERKS... i need all the values entered for S_WERKS into the internal table. The internal table structure contains only WERKS.
My actual requirement is, for the given plant values as select-option, i need to fetch all details of the plants. And I should not use any SELECT statements at any stage. Only through function module/ BAPI/BADI/Class methods.
I found one function module T001W_READ, but i need to pass the plant for that.
Please suggest.
Thanks in advance.
kishoreHi Kishore
Why can't you use any SELECTs? If it is so required why not writing your own FM to select them? You can pass your select-option via a generic parameter and assign it to a range at the beginning of your FM. Or you can assign it to a select-option-like table (you can find structure names of similar type from DDIC)
<i><b>e.g.</b></i>
TABLES t001w .
RANGES s_werks for t001w-werks .
DATA: BEGIN OF lt_werks ,
werks LIKE t001w-werks ,
END OF lt_werks .
s_werks[] = it_werks_so[] .
SELECT werks FROM t001w
INTO lt_werks
WHERE werks IN s_werks .
As another thing, let me introduce you the SDN Forums pointing system: You can assign points to posts which you find helpful while solving your problem. You can reward points by pressing the yellow star icon at header of each post. You can assign;
- one 10 points (solved)
- two 6 points (very helpful answer)
- many 2 points (helpful answer)
*--Serdar -
Internal table(Optimizing the codes)
Dear all,
Please help me in optimizing the following codes..
FORM fetch_item_data1 .
CLEAR itab_zsbhdr .
LOOP AT itab_zsbhdr .
IF itab_zsbhdr-bedae = 'SPI'.
SELECT * FROM zioel2 INTO i_zioel
WHERE ordr = itab_zsbhdr-vbeln
AND item = itab_zsbhdr-posnr
AND vdatu = itab_zsbhdr-vdatu .
APPEND i_zioel.
CLEAR i_zioel .
ENDSELECT .
ENDIF .
ENDLOOP .
ENDFORM. " FETCH_ITEM_DATA1
MY DOUBT:
For example if you all can see the select statement,,there we can also write as,
data : itab_zsbhdr_dummy like itab_zsbhdr occurs 0 with header line.
CLEAR itab_zsbhdr .
itab_zsbhdr_dummy[] = itab_zsbhdr[].
DELETE itab_zsbhdr_DUMMY[] WHERE bedat NE 'SPI'.
SELECT * FROM zioel2 appending table i_zioel
for all entries in itab_zsbhdr_DUMMY
WHERE ordr = itab_zsbhdr_dummy-vbeln
AND item = itab_zsbhdr_dummy-posnr
AND vdatu = itab_zsbhdr_dummy-vdatu .
So now we can see there is no append and modify.
So my question is ,,"Is it the right way to go?"
Again i am taking off the loop & instead deleting those date not equals to SPI.
So please help me by either confirming me with this particular optimization or give me some other optimized codes on this regard.
Thanx.hye..
i am inserting my comments
FORM fetch_item_data1 .
CLEAR itab_zsbhdr .
You have cleared the internal table, so the content is empty.. hence it will not enter into the loop.
LOOP AT itab_zsbhdr .
IF itab_zsbhdr-bedae = 'SPI'.
SELECT * FROM zioel2 INTO i_zioel
WHERE ordr = itab_zsbhdr-vbeln
AND item = itab_zsbhdr-posnr
AND vdatu = itab_zsbhdr-vdatu .
Never use a select in a loop, this means ur hitting the database n number of times which is not at all recommondable.
APPEND i_zioel.
CLEAR i_zioel .
ENDSELECT .
instead of using select and end select it can be directly writen into
select * from [dbtab] into table [itab] for all entreis in it_comparision
where [field] = it_comparision-field.
ENDIF .
ENDLOOP .
ENDFORM. " FETCH_ITEM_DATA1
Yeah ur second code is more recommmended with these modifications.
hope this is useful.
thnks.
imran. -
Count(*) function in select statement having group by condition
Hi
I would like to use count(*) in select statement having group by clause. say for example there is a state with a number of cities listed. I would like to get the count of cities for each state.
the sql stement is grouped by state and it is joined with 5 more tables.
Thanks
ps: ignore the previous postAssuming there is one record per city per state, then
SELECT state,count(*)
FROM state_tbl
GROUP BY stateWill get one record per state with the number of cities in each state. If you want to join that result set to other tables you need to either create a view with that statement or use an in-line view viz.
SELECT c.cust_name,c.state,s.num_cities
FROM customers c,
(SELECT state,count(*) num_cities
FROM state_tbl
GROUP BY state) s
WHERE c.state = s.stateTTFN
John -
Moving data in all the internal tables to the final table t_data
hi all,
how to data in all the internal tables to the final table t_data
*selecting fields from bkpf table
SELECT bukrs
belnr
gjahr
bldat
xblnr
usnam
FROM bkpf
INTO TABLE t_bkpf
WHERE bukrs EQ po_bukrs AND
belnr IN so_belnr AND
budat IN so_budat AND
blart IN so_blart.
IF t_bkpf[] IS INITIAL.
MESSAGE a999(zfi_ap_gl) WITH text-011.
STOP.
ELSE.
*selecting fields from bseg table.
SELECT bukrs
belnr
gjahr
koart
shkzg
dmbtr
zuonr
sgtxt
kostl
hkont
lifnr
prctr
FROM bseg
INTO TABLE t_bseg
FOR ALL ENTRIES IN t_bkpf
WHERE bukrs EQ t_bkpf-bukrs AND
belnr EQ t_bkpf-belnr AND
gjahr EQ t_bkpf-gjahr AND
lifnr IN so_lifnr.
ENDIF.
IF t_bseg[] IS INITIAL.
MESSAGE a999(zfi_ap_gl) WITH text-011.
STOP.
ELSE.
*selecting the companies address from adrc table
SELECT SINGLE addrnumber street str_suppl2 city1
region post_code1
FROM adrc
INTO wa_adrc
WHERE addrnumber EQ w_adrnr.
*selecting adrnr from the lfa1 table
SELECT lifnr adrnr name1 ort01 regio pstlz
FROM lfa1
INTO TABLE t_adrnr
FOR ALL ENTRIES IN t_bseg
WHERE lifnr EQ t_bseg-lifnr.
IF NOT t_adrnr[] IS INITIAL.
*populating the t_vaddress table.
SELECT addrnumber
street
str_suppl2
FROM adrc
INTO TABLE t_vaddress
FOR ALL ENTRIES IN t_adrnr
WHERE addrnumber EQ t_adrnr-adrnr.
*populating the t_vendor table with the vendor address
SELECT lifnr
adrnp_2
namev
name1
INTO TABLE t_vendor
FROM knvk
FOR ALL ENTRIES IN t_adrnr
WHERE lifnr EQ t_adrnr-lifnr AND
adrnp_2 EQ t_adrnr-adrnr.
ENDIF.
ENDIF.Loop the internal table which is having the maximum number of records,then use read table....for other internal tables....in that loop and then append them into final internal table.
Ex-LOOP AT IT_VBRP INTO WA_VBRP.
WA_FINAL-WERKS = WA_VBRP-WERKS_I.
WA_FINAL-KUNAG = WA_VBRP-KUNAG.
WA_FINAL-AEDAT = WA_VBRP-AEDAT.
READ TABLE IT_KONV INTO WA_KONV WITH KEY KNUMV = WA_VBRP-KNUMV
KPOSN = WA_VBRP-POSNR_I.
IF SY-SUBRC EQ 0.
WA_FINAL-KSCHL = WA_KONV-KSCHL.
CLEAR WA_KONV.
ENDIF.
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_VBRP-KUNAG.
IF SY-SUBRC EQ 0.
WA_FINAL-NAME1 = WA_KNA1-NAME1.
CLEAR WA_KNA1.
ENDIF.
ENDIF.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL,WA_KONV,wa_kna1.
ENDLOOP.
Maybe you are looking for
-
Issue in PA - Header Modifications for IT0105
Hi All, I have done header modifications for PA30 Screen, IT0000, IT0001 and IT 0105 (Communications) and for IT0021. I am able to get the details of PA, PSA, EG and ESG in the header details. But when an employee PA/PSA/EG/ESG has changed becoz of a
-
Messages won't send on certain networks
I get this message when trying to send my messages on certain wireless networks. The connection to the server "smtp.home.se" on port 25 timed out. You can try to send using a different server. All messages will use this server until you quit or chang
-
I want to convert string to 1-D array to input it to waveform graph?
thanks in advance
-
I try to activate my FaceTime on my ipad3 using my apple ID and password but every time shown this message ( FaceTime activation - could not sign in please check your network connection and try again ) , by the way many people used face time on my co
-
Hello! Just installed Arch64 on my computer, with the awesome wm. It's been a great learning experience(I've only used Ubuntu before, so it's not like I can say I've got much experience working with Linux) I've been trying to install Renoise, and I r