‎2005 Dec 23 7:44 AM
I have a table which has following fields:
X1 TABLE (ZCONfig custom table)
LIFNR land1
123 br
234 br
456 br
567 Gr
and
X2 TABLE: (Internal table)
LIFNR:
234
567
123
Now I want to see if all the field values of LIFNR in internal table X2 (X2-LIFNR) are present in X1 or not.
Raise error if it is not.
How do I do this using SQL ? I guess I have to use read statement.
Please help. Points will be awarded.
Thanks.
Regards
‎2005 Dec 23 7:48 AM
‎2005 Dec 23 7:59 AM
select *
from ztable
into table it_ztable.
if sy-subrc = 0.
loop at it_x2table.
read table it_ztable with key lifnr = it_x2table-lifnr.
if sy-subrc <> 0.
raise error.....
endif.
endloop.
endif.
‎2005 Dec 23 7:52 AM
Hi Tushar,
1 Ya u are right , we need to use READ statement.
2. Populate X1 (all records)
in an internal table.
3. Then Loop at X2
and compare with X1.
( u can also keep an extra field in X2
of type c, so that if a record is found,
mark it as X )
4. try this code (just copy paste)
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
present TYPE c,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
*----
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = 'X000'.
APPEND itab.
SELECT * FROM t001 INTO TABLE t001.
*----
LOOP AT itab.
READ TABLE t001 with key bukrs = itab-bukrs.
IF sy-subrc = 0.
itab-present = 'X'.
MODIFY itab.
ENDIF.
ENDLOOP.
BREAK-POINT.
regards,
amit m.
Message was edited by: Amit Mittal
‎2005 Dec 23 7:53 AM
Hi Tushar,
Try this,
Loop at X2.
READ table X1 with key lifnr = X2-lifnr.
if sy-subrc <> 0.
error message.
endif.
endloop.
Thanks
Lakshman
‎2005 Dec 23 7:56 AM
Hi Tushar,
To begin with I am assuming that the Z config table that you had been referring to seems to be a lookup table where the internal table entries needs to be validated.
Here is a piece of code:
DATA: itab1 TYPE STANDARD TABLE OF lifnr,
itab2 LIKE itab1,
wa TYPE lifnr.
REFRESH itab1.
LOOP AT X2. "(your internal table).
CLEAR wa.
wa = x2-lifnr.
APPEND wa TO itab1.
ENDLOOP.
SELECT lifnr
FROM zconfigcustomtable
INTO itab2
FOR ALL ENTRIES IN itab1
WHERE lifnr EQ itab1-table_line.
LOOP AT X2.
READ TABLE itab2 TRANSPORTING NO FIELDS
WITH KEY table_line = x2-lifnr.
IF NOT sy-subrc IS INITIAL.
RAISE error.
ENDIF.
ENDLOOP.
Hope this helps....
Regards,
Srikanth
‎2005 Dec 23 8:02 AM
Tushar, do the other way round, it will be faster
data: ii type i.
loop at X2.
clear: ii.
select count(*) from x1 into ii.
if ii = 0 or sy-subrc <> 0.
*raise error
endif.
endloop.