Read Table with condition
Hi,
can i write a Read table like for example,
read table itab into wa_itab with key matnr ne '4'.
as its giving me an error.
can suggest any other way to write the Read Table statement.
Thanks in advance.
Robert
Hi,
it is not possible.
try this way..
"delete the material which is not equal to 4 ..now itab contains values matnr ne4
delete table itab where matnr ne '4'.
or
loop at itab into wa_itab wher matnr ne '4'.
"move to another table
endloop.
or
loop at itab into wa_itab .
if wa_itab-matnr ne '4'.
continue
"move to another table
else.
delete itab index sy-tabix.
endif.
endloop.
prabhudas
Similar Messages
-
Replacemnt for read table with key binary search
as read table with
READ TABLE gt_INT_CURR_VALUE into gs_int_curr_value
WITH KEY gs_FS_EINA_KEY BINARY SEARCH.
the statement read tabel with key is absolute in ecc 6 so how to replace it .Hi subratt,
internal tables with header lines are obsolete and in oo context (CLASS / METHOD code) forbidden.
OK, you'd better use SORTED TABLE and FIELD-SYMBOLS to gt optimal code::
READ TABLE gt_INT_CURR_VALUE into gs_int_curr_value
WITH KEY gs_FS_EINA_KEY BINARY SEARCH.
may be replaced with
DATA:
gt_INT_CURR_VALUE_SORTED LIKE SORTED TABLE OF gs_int_curr_value
WITH [NON-]UNIQUE KEY <fields of gs_FS_EINA_KEY>.
FIELD-SYMBOLS:
<nt_curr_value> LIKE gs_int_curr_value.
gt_INT_CURR_VALUE_SORTED = gt_INT_CURR_VALUE.
READ TABLE gt_INT_CURR_VALUE_SORTED ASSIGNING <nt_curr_value>
WITH TABLE KEY <key1> = gs_FS_EINA_KEY-<key1> .. <keyn> = gs_FS_EINA_KEY-<keyn>.
Regards,
Clemens -
How to append records to final table with conditions
Hi
I am working on a report using tables vbrp vbrk glpca & konv to fetch the amount of billing document based on condition type (kschl)
Below is my query & records are fetching fine. But now I need to append my final display table.
Question 1.... which table I should loop into & which tables should be read ?
Question 2.... I want 4 coulumn in my alv to display amount from konv based on condition type (VPRS, ZK03,Z004, EK02)
EX: vbeln refdocnr fkdat ............ VPRS-KBETR ZK03-KBETR Z004-KBETR EK02-KBETR
000001 000001 1.1.14 ............ 14.00 -12.00 5.00 0.02
000002 000002 2.02.14 ......... 18.00 -10.00 0.00 0.00
It may be possible that for particular record there would be on ZK03 & VPRS VALUES BUT NO Z004 & EK02 so it will display 0 in that cell.
WITH ABOVE mentioned output how should I put my condition to read it_konv table based on condition types but append it in different colums for display ???
Is there a solution available or not please guide me through this.*declare output itab
DATA: BEGIN OF it_output,
vbeln type....
refdocnr...
fkdat...
vprs_kbetr...
zk03_kbetr..
z004_kbetr...
ek02_kbetr...
end of it_output.
LOOP AT it_join INTO wa_join.
MOVE vbeln fkdat from wa_join into wa_output.
LOOP AT it_konv INTO wa_konv
with key.....
CASE wa_konv-kschl.
WHEN 'VPRS'.
MOVE wa_konv-kbetr TO wa_output-vprs_kbetr.
etc....
ENDCASE.
READ TABLE it_glpca WITH KEY.... into wa_glpca.
IF sy-subrc = 0.
MOVE wa_glpca-refdocnr TO wa_output-refdocnr.
ENDIF.
APPEND wa_output TO it_output.
ENDLOOP.
ENDLOOP. -
Field symbols and READ TABLE with system code 4
Hi,
I have a hashed table and I am using field symbols to point to it to retrieve the field content. I then use it in the READ TABLE statement in the following way:
Loop at x_data assign <fs>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c1>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c2>.
READ TABLE ZZZZ assign <fs> with table key a1 = <c1>
a2 = <c2>.
If sy-subrc = 0.
endif.
I ran the debugger and I keep getting a 4. I am not able to get the value from a1 and a2 to see what it is and why it is causing a 4 sy-subrc. I know the value from the hashed table and the values c1 and c2 are the same, so the sy-subrc should be 0.
How would I read a hashed table using field symbols? I know that usig a standard table, I have to sort the table on the key fields() before I actually can do the READ TABLE using the binary search.
Please advise. Thanks
RTHai Rob
Go through the following Code
Field-Symbols are place holders for existing fields.
A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.
Field-Symbols are like Pointers in Programming language C .
Syntax check is not effective.
Syntax :
Data : v1(4) value abcd.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
Thanks & regards
Sreenivasulu P -
Get records number from internal table with condition.
Internal table itab got more than 1000 records,now i need to get the number of records with condition that itab-field1 = 'XXXX'.
actully, i got an inefficient logic to count the number in a loop statement. is there better way to implement it?hello,
Every time assigning data into temp table and delete may that may not be much efficient. You can check in loop logic how much time is taken. You can check the below code. here I am trying to check the numbers of plant for for one material.
In this logic material is the first field. So if there is option to make the required field in to the 1 st position then it will be nice.
TYPES: BEGIN OF x_count,
matnr TYPE matnr,
count TYPE i,
BEGIN OF x_count.
DATA: i_marc TYPE STANDARD TABLE OF marc,
i_count TYPE STANDARD TABLE OF x_count,
wa_count TYPE x_count.
FIELD-SYMBOLS: <wa_marc> TYPE marc.
SELECT * UP TO 1000 ROWS
FROM marc
INTO TABLE i_marc.
IF sy-subrc = 0.
SORT i_marc BY matnr.
LOOP AT i_marc ASSIGNING <wa_marc>.
wa_count-count = wa_count-count + 1.
AT END OF matnr.
wa_count-matnr = <wa_marc>-matnr.
APPEND wa_count TO i_count.
ENDAT.
ENDLOOP.
ENDIF.
Thanks
Subhanakr -
I would like to have this in my report in ABAP 7:
READ TABLE ti_prococolos WITH KEY
protocol = lc_protocol
status = 'abc'
status = 'ced'.
But I receive the following error, when verifying the syntax:
Key field "STATUS" has been used more than once. This is not allowed .
How can I solve this?
Thanks!The READ statement is used to read a specific row of the internal table, in this case it appears that you are saying that you want a record if the STATUS is either abc or def. You can't do that with the READ. You would need to use the LOOP.
Loop at ti_prococolos where protocol = lc_protocal
and ( status = 'abc' or status = 'ced' ).
* do what ever here, and EXIT after since you only want one row.
EXIT.
endloop.
Regards,
RIch Heilman -
Read Table with key field - question
Hi,
Can you use the same key field more than once?
For example:
READ TABLE I_TVKWZ INTO I_TVKWZ_2 WITH KEY WERKS = '1004'
Werks = '1002'.
I get an error when trying this.
Is there an alternative?
Thanks,
JohnHi John,
try this:
DATA: begin of itab occurs 0,
werks like mseg-werks,
i type i,
end of itab.
itab-werks = '1000'. itab-i = itab-i + 1. append itab.
itab-werks = '1000'. itab-i = itab-i + 1. append itab.
itab-werks = '2000'. itab-i = itab-i + 1. append itab.
itab-werks = '3000'. itab-i = itab-i + 1. append itab.
itab-werks = '5000'. itab-i = itab-i + 1. append itab.
itab-werks = '5000'. itab-i = itab-i + 1. append itab.
itab-werks = '7000'. itab-i = itab-i + 1. append itab.
itab-werks = '7000'. itab-i = itab-i + 1. append itab.
itab-werks = '9000'. itab-i = itab-i + 1. append itab.
itab-werks = '9000'. itab-i = itab-i + 1. append itab.
itab-werks = '9000'. itab-i = itab-i + 1. append itab.
loop at itab where werks = '1000' or werks = '9000'.
write: / itab-werks, itab-i.
endloop.
Regards, Dieter -
Read Table with Key in a Deep Structure
Hello,
I'd like to read a table while comparing a value in a deep structure. So in the following code the key ID is a deep structure within cs_purchase_order_message-purchase_order-item-value.
For some reason code check returns no errors with the following code, but I get a short dump with a syntax error on id-value when I execute the code.
read table cs_purchase_order_message-purchase_order-item assigning <fs_xml_item> with key id-value = <fs_item>-number_int.
How do I use "with key" when the value is in a deep structure?
Thanks,
MattRefer to example link below:
http://sap.ittoolbox.com/groups/technical-functional/sap-dev/read-deep-structure-736023.
Regards,
Venkat. -
Hi guys!
Please, what can i do when i use the
Read table xxxx WITH KEY tab_key = value ASSIGNING <fs>
statement and there is more than one entry with the specified selection criteria? How can i return the values to an internal table?
I need to get all the entries and i don't have the full table key.
thanks!Hi Fabio,
An efficient way to do this is to have your table sorted by a specific key. Let's say I have a table with the feild material number.
You can do this:
data: lv_index like sy-tabix.
sort itab by material_number.
ready table itab with key material_number = yournumber
binary search.
if sy-subrc eq 0.
move sy-tabix to lv_index. " this holds the index of your first material record
now we loop at the table start at that index
loop at itab index lv_index.
perform your processing
if we come accross a different material number - exit the loop.
if itab-material_number ne yournumber.
exit.
endif.
endloop.
endif.
This way you only processes the records you are looking for.
thanks.
JB -
How to use Read table with out key fields
Hi Experts,
I need to retrieve the 2 internal tables data into single table.
I have 3 common fields between the 2 tables but I don't have the Key fields. Then how to use the read table in this.
Thanks in Advance.
Edited by: satish4abap on Mar 10, 2010 9:39 AMHi Satish,
Key fields are nothing but the common fields with which you can pick the data from the second internal table.
If you can paste your Internal table fields then we will be able to assit you better.
However, in genral scenarios you can use it as below :
In this scenario, we are putting data from 3 internal table to another single internal table.
LOOP AT T_PRGEN INTO WA_PRGEN.
WA_FINAL-GUID_PR = WA_PRGEN-GUID_PR.
WA_FINAL-ATTR20A = WA_PRGEN-ATTR20A.
WA_FINAL-ATTR05A = WA_PRGEN-ATTR05A.
WA_FINAL-ATTR05B = WA_PRGEN-ATTR05B.
WA_FINAL-ATTR05C = WA_PRGEN-ATTR05C. " + DG1K902190
WA_FINAL-ATTR10A = WA_PRGEN-ATTR10A.
READ TABLE T_V_TCAV201 INTO WA_V_TCAV201 WITH KEY ATTRV20 = WA_PRGEN-ATTR20A BINARY SEARCH.
IF SY-SUBRC = 0.
WA_FINAL-TEXT1 = WA_V_TCAV201-TEXT1. "SUBID-TEXT1
ENDIF.
READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRGEN-GUID_PR BINARY SEARCH.
IF SY-SUBRC = 0.
WA_FINAL-PRVSY = WA_PNTPR-PRVSY. "PROD NO
WA_FINAL-GRVSY = WA_PNTPR-GRVSY. "LOGICAL SYS GROUP
ENDIF.
append wa_final to t_final.
endloop. -
Self join on a table with condition to extract records
Hello PL/SQL Gurus/experts,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
I have following table -
drop table t1;
create table t1(stud_NM,stud_id) as select
'Vikas',1 from dual union all select
'Andy',2 from dual union all select
'Chi',3 from dual union all select
'Derek',4 from dual union all select
'Kristien',5 from dual union all select
'Tom',6 from dual union all select
'Messi',7 from dual union all select
'Ketty',8 from dual;
drop table t2;
create table t2(stud_id,Class, CDate) as select
1,'BA','20120101' from dual union all select
1,'MA','20120101' from dual union all select
2,'BSc','20120531' from dual union all select
3,'MCA','20120606' from dual union all select
4,'MCA','20120701' from dual union all select
4,'Btech','20120715' from dual union all select
5,'MTech','20120730' from dual union all select
6,'MSc','20120801' from dual union all select
6,'MSc','20120802' from dual union all select
7,'MA','20120815' from dual union all select
8,'MA','20120815' from dual;
I have to get the output based on condition -
Extract Stud_Name, Count of records which has a condition as that of the one that if combination of Stud_Name & CDate is same then count this combination once only else if Stud_Name & CDate are different then count them as different records -
Currently i am using the following query to get the output -
select t1.stud_NM, count(distinct CASE WHEN orig.CDate<>ali.CDate then t1.stud_NM else
CASE WHEN orig.CDate=ali.CDate then '1' else null
end
end) Count
from t1,
t2 orig,
t2 ali
where t1.stud_id=orig.stud_id
and t1.stud_id=ali.stud_id
group by t1.stud_NM
order by t1.stud_NM
which is giving the following output, which looks fine as well -
STUD_NM COUNT
Andy 1
Chi 1
Derek 2
Ketty 1
Kristien 1
Messi 1
Tom 2
Vikas 1
8 rows selected.
So want to confirm if i am doing right or it is just because of the data it is giving me the right result ?
Kindly help me thanks in advance for your time and efforts.Hi,
You can simplify that, too. Since you're GROUPing BY stud_nm, concatenating COUNT (DISTINCT stud_nm || cdate) is just the same as COUNT (DISTINCT cdate), assuming cdate is not NULL.
Also, that assumes stud_nm is unique. (If it's not, the desired output doesn't make sense, but that's a different matter.) I'd do it this way:
SELECT t1.stud_nm
, t1.stud_id -- If wanted
, COUNT (DISTINCT t2.cdate) AS cnt
FROM t1
LEFT OUTER JOIN t2 ON t1.stud_id = t2.stud_id
GROUP BY t1.stud_nm, t1.stud_id
ORDER BY t1.stud_nm, t1.stud_id
OP: the query you posted will get the wrong results with other data. For example, if we add this to the sample data in t2:
7,'WX','20120816' from dual union all select
7,'YZ','20120817' from dual union all select
Karthick's solution (and my variant of it) correctly show a count of 3 for stud_id=7 (Messi), but your query has 2. -
Creation of SAP Query in SQ02 with Single Table With Condition
Hi All,
I want to Create SAP Query in SQ02 using single Table MCHA.
ii) I dont want all entries of MCHA Table I mean , I have to apply some Condition on this Table.
i.e Suppose I am having actual data in MCHA table is like this for Material M1.
Plant Material Batch BatchCreationdate
P1 M1 B1 20.06.2007
P2 M1 B1 04.05.2009
P3 M1 B1 04.05.2009
But I want the Output of SAP Query is like this:
Material Batch BatchCreationdate
M1 B1 20.06.2007
That is irrespective of Plant if Material & Batch are equal ---> 1st record with Lowest date shoud get at the output.
Please help me How write the code on single table in the SAP Query.
Thanks,
Kiran ManyamHi,
Your query should be like this:
Select MATNR CHARG HSDAT
from MCHA
into table t_mcha
where matnr = Materlal number from selection screen.
The structure of t_mcha should contain the fields that you select.
Then sort the table by date ascending
Sort t_mcha by HSDAT.
Hope this solves your problem.
Thanks,
Sowmya -
Data retrieval from keko table with conditions as for a group of same mat
hi Freinds,
the problem iam facing here is i have certain materials in table keko , among which i need to retrieve the material with date as the latest one for that particular material provided costing status is 'FR' and Release is "X'.
here is the example i gave where material 14ce2-1krs has 3 different dates , i need to retreive the latest one .... like this for 15ce2..
plz reply ... thanks...
Material Costing Date Costing Status Release 14CE2-1K-RS 02.25.2007 FR 14CE2-1K-RS 04.01.2007 FR X 14CE2-1K-RS 04.29.2007 FR X
15CE2 01.20.2007 FR X
15CE2 03.10.2007 FR X
15CE2 05.14.2007 FR X
15CE2 07.22.2007 FR XHi,
Sort ITAB by <Material> <Date> descnding.
Delete adjacent duplicates comparing Material.
Then table will contain material with latest date.
Hope this helps... -
Dynamic table with conditional formatting
Hi.
I haven't used Dreamweaver in a few years and now need to
knockup a simple page for a project and need some help.
I want to create a dynamic link to a spreadsheet (.xls or
.csv) and then apply conditional formatting so that if a cell in
the table equals '1' then an image is displayed in that cell on the
webpage. If the cell equals '2' a different image is displayed, and
so on.
This way I can give a simple spreadsheet to the users to
update and by only entering a '1' or a '2' into each cell in the
spreasheet, they are changing images in a table on a webpage..
Is that possible and if so, can someone point me in the right
direction to create such functionality?
Many thanks.You have convert that XLS file to CSV and then write your
PHP/PERL/ASP code to take the particular value and then that will
alter the image on condition. -
Help me to update table with condition's
this table is an alert table which will update when the sql server down , not pinging and drive space low.
Every 15 mins the monitoring system run. if the any issue came then it will update the information in this table. if the issue not solved by 15 mins the table will update again with the same details..
I would like update tickeraised = Y only on first time and if i got same issue less then 30 min the it should not change to Y.. based on server name , type and message.
min >10 and <20 min if any value is there then the table should not update with same value. can any one help me with tsql query...In future please post DDL and DML. For now I have created a scenario which will help you understand solution to your own requirement.
CREATE TABLE Tickets_Log(
Ticked_ID SMALLINT IDENTITY(1,1) PRIMARY KEY,
Ticket_Type VARCHAR(20) NOT NULL,
Log_Date DATETIME2 NOT NULL DEFAULT DATEADD(MINUTE,-15,GETDATE()),
Machine_Name VARCHAR(50) NOT NULL,
Message VARCHAR(100) NOT NULL,
Ticket_Status CHAR(2) NOT NULL DEFAULT 'N',
Update_Status SMALLINT DEFAULT 0)
INSERT Tickets_Log(Ticket_Type,Machine_Name,Message)
SELECT 'Pinging','HOD-400-651','Server Not Pinging' UNION
SELECT 'Low Drive Space','HOD-400-652','Drive Space Low' UNION
SELECT 'Connection','HOD-400-653','Unable to Connect to Server'
UPDATE TL
SET Log_Date=NewTickets.Log_Date,
Update_Status=1
FROM( SELECT 'Pinging' Ticket_Type,'HOD-400-651' Machine_Name,'Server Not Pinging' Message,GETDATE() Log_Date UNION
SELECT 'Pinging','HOD-400-653','Server Not Pinging',GETDATE() Log_Date) NewTickets
LEFT JOIN Tickets_Log TL ON NewTickets.Machine_Name=TL.Machine_Name AND NewTickets.Ticket_Type=TL.Ticket_Type
WHERE TL.Ticket_Type IS NOT NULL AND TL.Machine_Name IS NOT NULL AND DATEDIFF(MINUTE,TL.Log_Date,NewTickets.Log_Date)>=15 AND Update_Status=0
INSERT Tickets_Log(Ticket_Type,Machine_Name,Message,Log_Date)
SELECT NewTickets.*
FROM( SELECT 'Pinging' Ticket_Type,'HOD-400-651' Machine_Name,'Server Not Pinging' Message,GETDATE() Log_Date UNION
SELECT 'Pinging','HOD-400-653','Server Not Pinging',GETDATE() Log_Date) NewTickets
LEFT JOIN Tickets_Log TL ON NewTickets.Machine_Name=TL.Machine_Name AND NewTickets.Ticket_Type=TL.Ticket_Type
WHERE TL.Ticket_Type IS NULL AND TL.Machine_Name IS NULL
Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real.
The climb is all there is.
Maybe you are looking for
-
Need to transfer DOM over JMXMP
I need to transfer DOM object over JMXMP. Which is the best way to do encapsulating DOM in java object converting that into string and then send? i dont want to stream XMl file.
-
Performance log for ORACLE 10g
Hi everyone can anybody tell me where i can get the reporting from the performance logs in oracle 10g>? i need to generate reports for audit trail, no of hits in the portal , top ten url , and how often the user view a page or portlet? i thank you al
-
Getting subscription countdown message when signing into CC desktop, is that normal now?
Getting subscription countdown message when signing into CC desktop, is that normal now? Account is all paid up to date. It is since the regular payment was declined due to the card being cancelled and me uploading the new card details.
-
Time difference by date by time range - a better way?
Someone suggested this is a better place for my question: Hi I need to display the difference in time - every day for different time ranges, Example 1-2 pm, 4-5 pm, 7-8 pm. And I need the time difference in 2 dates in the past week for each of these
-
How do I reset the phone? Thanks.