‎2008 Dec 19 10:20 AM
Hi,
I am trying to compare values in two different table fields, can someone advise me of the ABAP to do it.
I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)
Thanks,
Alec
‎2008 Dec 19 11:12 AM
Hi,
Do this way:-
I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)
select parnr from IHPA into it_IHPA.
sort it_IHPA by PARNR
if not it_IHPA[] is initial.
select ORGEH from T527X into table it_T527X
for all entries in it_IHPA
where ORGEH = it_IHPA- PARNR.
endif.
now it_T527X contains the req result
Thanks & Regards,
Krishna
‎2008 Dec 19 10:22 AM
Hi,
use command READ TABLE if you work with internal table.
If you work with database tables, use command SELECT.
‎2008 Dec 19 10:24 AM
HI.
1.fetch PARNR value from table IHPA.
2.Fetch ORGEH value from table T527X by using All entries
3.check sy-subrc <> 0.
Regards.
Jay
‎2008 Dec 19 10:24 AM
Hi Alec,
In ABAP, you can make use of LOOP and READ statements to compare the values.
As in this case,
I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)
Loop at ihpa into wa_ihpa.
Read table t527x into wa_t527x with key orgeh = wa_ihpa-parnr
binary search.
if sy-subrc eq 0.
" This means the value exists in table t527x. you can do the required modifications here.
endif.
Endloop.
Hope this is what you are looking for.
Best Regards,
Ram.
‎2008 Dec 19 10:29 AM
Hi,
Declare 1 internal table with one field PARNR,
Fill that internal table with all values of table IHPA,
Select the entries of table T527X into second internal table for all the values in first internal table, so the second internal table has all the vales only of the values in IHPA-PARNR.
Use SELECT statement with FOR ALL ENTRIES addition.
Regards
Bala Krishna
‎2008 Dec 19 10:31 AM
hi,
u can select data from IHPA by using slect
select PARNR from IHPA
into table it_tab.
and then select data from T527X
select ORGEH from t527X into i_tab2
for all entries in it_tab where parnr = it_tab-parnr.
then u can compare using loop at it_tab and read from table i_tab2.
thanks
‎2008 Dec 19 10:39 AM
Tried this as a test:
Loop at ihpa into wa_ihpa.
Read table t527x into wa_t527x with key orgeh = wa_ihpa-parnr
binary search.
if sy-subrc eq 0.
WRITE 'HELLO' TO ZORGUNIT.
endif.
Endloop.
I get a syntax error:
"VERSION ... ." expected after "IHPA".
what have I done wrong?
‎2008 Dec 19 10:42 AM
Hi Alec,
What is IHPA? I mean is that an internal table. How is it declared?
Ideally it should have been declared as
data: ihpa type standard table of ihpa,
wa_ihpa type ihpa.
Best Regards,
Ram.
‎2008 Dec 19 11:02 AM
Hi,
Don't read directly from the Table t527x, first get all the records into an internal table it_t527x and then use it.
Data : it_ihpa TYPE TABLE OF ihpa,
wa_ihpa TYEP ihpa,
it_t527x TYPE TABLE OF t527x,
wa_t527x TYPE t527x.
SELECT * FROM ihpa INTO TABLE it_ihpa.
SELECT * FROM t527x INTO TABLE it_t527x.
LOOP AT ihpa INTO wa_ihpa.
READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr
BINARY SEARCH.
IF sy-subrc EQ 0.
WRITE 'HELLO' TO ZORGUNIT.
ENDIF.
ENDLOOP.
Regards
Bala Krishna
‎2008 Dec 19 10:42 AM
declare 2 internal table read all your data into these table and in loop endloop statement compare all the value you want
loop
'your if condition for comparision
endloop
‎2008 Dec 19 10:43 AM
hi,
data :it_tab like standard table of ihpa with header line.
now u can loop at it_tab instead of ihpa.
thanks
‎2008 Dec 19 10:45 AM
Hi,
Pls check this:
loop at it_ihpa into wa_ihpa.
loop at it_t527x into wa_t527x.
if wa_ihpa-parnr eq wa_t527x-orgeh.
endif.
endloop.
endloop.
‎2008 Dec 19 11:00 AM
Hi,
First check the data type and length of parnr and orgeh fields. And make sure that values of these two fields have same length.
Check the following code:
data: it_ihpa like ihpa occurs 0 with header line,
wa_ihpa like it_ihpa,
it_t527x like t527x occurs 0 with header line,
wa_t527x like it_t527x.
select objnr parnr into corresponding fields of table it_ihpa from ihpa up to 100 rows.
sort it_ihpa by parnr.
select orgeh into corresponding fields of table it_t527x from t527x up to 100 rows.
sort it_t527x by orgeh.
loop at it_ihpa into wa_ihpa.
read table it_t527x into wa_t527x with key orgeh = wa_ihpa-parnr binary search.
if sy-subrc = 0.
write: 'successfully read'.
else.
write: 'read failed'.
endif.
endloop.
Regards,
Bhaskar
‎2008 Dec 19 11:12 AM
Hi,
Do this way:-
I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)
select parnr from IHPA into it_IHPA.
sort it_IHPA by PARNR
if not it_IHPA[] is initial.
select ORGEH from T527X into table it_T527X
for all entries in it_IHPA
where ORGEH = it_IHPA- PARNR.
endif.
now it_T527X contains the req result
Thanks & Regards,
Krishna
‎2008 Dec 19 11:33 AM
- Tried this
data: it_ihpa like ihpa occurs 0 with header line,
it_t527x like t527x occurs 0 with header line.
select parnr from IHPA into it_IHPA.
sort it_IHPA by PARNR
if not it_IHPA[] is initial.
select ORGTX from T527X into table it_T527X
for all entries in it_IHPA
where ORGEH = it_IHPA- PARNR.
endif.
write: it_T527X-ORGTX to ZORGUNITTEXT
- Got syntax error:
No component exists with the name "IF".
- What went wrong?
‎2008 Dec 19 12:01 PM
Hi,
Try the following code
TYPES : BEGIN OF ty_ihpa,
parnr TYPE ihpa-parnr,
END OF ty_ihpa.
DATA : it_tipha TYPE TABLE OF ty_ihpa,
wa_tipha TYPE ty_ihpa.
DATA : it_ihpa TYPE TABLE OF ihpa,
wa_ihpa TYPE ihpa,
it_t527x TYPE TABLE OF t527x,
wa_t527x TYPE t527x.
SELECT * FROM ihpa INTO TABLE it_ihpa.
SELECT * FROM t527x INTO TABLE it_t527x.
LOOP AT it_ihpa INTO wa_ihpa.
READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr
BINARY SEARCH.
IF sy-subrc EQ 0.
APPEND wa_ihpa-parnr TO it_tipha. "" Not able to understand what you are doing if Condition satisfied
ENDIF.
ENDLOOP.
Regards
Bala Krishna
‎2008 Dec 19 12:17 PM
Hi,
you forgott point after command "sort it_IHPA by PARNR"
PA: before your WRITE command, you need to use READ TABLE internal table it_T527X for move data to header line. If you don´t use that, ZORGUNITTEXT will be empty.
‎2008 Dec 19 12:23 PM
How can I get round the fact that T527X-ORGEH is type NUMC 8 characters and IHPA-PARNR is CHAR 12 characters.
I am currently trying the following but get a syntax error because the fields are not the same type / length
data: it_ihpa like ihpa occurs 0 with header line,
it_t527x like t527x occurs 0 with header line.
select * from IHPA into it_IHPA.
sort it_IHPA by PARNR.
if not it_IHPA is initial.
select ORGTX from T527X into table it_T527X
for all entries in it_IHPA
where ORGEH = it_IHPA-PARNR.
endif.
WRITE: it_t527x TO ZORGUNITEXT
‎2008 Dec 19 12:27 PM
Hi,
Thats why use the sample code i have given above, fetch data from both tables and once u got the correct values clear the internal tables data which u don't require further.
see above post of mine for sample code and use it.
Regards
Bala Krishna
‎2008 Dec 19 12:35 PM
‎2008 Dec 19 12:48 PM
Thanks Bala
When I have determined that there is a match between IHPA-PARNR and T527X-ORGEH I need to write T527X-ORGTX (org unit text) to field ZORGUNITEXT
Do you know how I should do that bit?
thanks again,
Alec
‎2008 Dec 19 1:23 PM
I am using the following ABAP but it is coming with SUBRC does not equal 0 any ideas what the problem is?
TYPES : BEGIN OF ty_ihpa,
parnr TYPE ihpa-parnr,
END OF ty_ihpa.
DATA : it_tipha TYPE TABLE OF ty_ihpa,
wa_tipha TYPE ty_ihpa.
DATA : it_ihpa TYPE TABLE OF ihpa with header line,
wa_ihpa TYPE ihpa,
it_t527x TYPE TABLE OF t527x with header line,
wa_t527x TYPE t527x.
SELECT * FROM ihpa INTO TABLE it_ihpa.
SELECT * FROM t527x INTO TABLE it_t527x.
LOOP AT it_ihpa INTO wa_ihpa.
READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr
BINARY SEARCH.
IF sy-subrc EQ 0.
WRITE: it_t527X-ORGTX TO ZORGUNITTEXT.
ELSE.
WRITE: 'Oh No!!!' TO ZORGUNITTEXT.
ENDIF.
ENDLOOP.
‎2008 Dec 19 1:26 PM
Hello Alec,
You have to SORT the table it_t527x before READ stmt.
SORT it_t527x BY orgeh.
READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr
BINARY SEARCH.
This will solve your problem.
BR,
Suhas
‎2008 Dec 19 1:32 PM
Hi,
In the below statement
WRITE: it_t527X-ORGTX TO ZORGUNITTEXT.
use as below
WRITE: wa_t527X-ORGTX TO ZORGUNITTEXT.
as the values of internal table it_t527x are read into work area wa_t527x.
put a break point at before statement and check the values in debugging mode.
what is the declared type of the ZORGUNITTEXT field?
Regards
Bala Krishna
‎2008 Dec 19 1:35 PM
something must be wrong. After I added that SORT command, I started it about 5mins ago, it's still running.
When I looked at table T527X it's already sorted by ORGEH.
Any Ideas?
‎2008 Dec 19 1:40 PM
Still not working
The declared type of ZORGUNITTEXT is C length 25 like T527X-ORGTX
Any ideas?
SUBRC is still coming with not = 0
Alec
‎2008 Dec 19 1:48 PM
OK now I'm confused:
I put a breakpoint as follows:
SELECT * FROM t527x INTO TABLE it_t527x.
LOOP AT it_ihpa INTO wa_ihpa.
READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr
BINARY SEARCH.
IF sy-subrc EQ 0.
BREAK-POINT.
WRITE: wa_t527X-ORGTX TO ZORGUNITTEXT.
ELSE.
WRITE: 'Damn it' TO ZORGUNITTEXT.
ENDIF.
ENDLOOP.
I have the correct values in the correct fields but still SUBRC does not = 0
WA_T527X-ORGTX Stockton - Front of House
ZORGUNITTEXT Damn it
WA_t527X-ORGEH 20008855
WA_IHPA-parnr 20008855
Whats Wrong?
Edited by: Alec Fletcher on Dec 19, 2008 1:50 PM
‎2008 Dec 19 1:51 PM
Hi,
It is in loop and that condition will be executed for all the records in the table, it will be 4 for one record and 0 if the condition is met. and again and again the ZORGUNITTEXT will be over written.
Just keep a break-point before IF statement and see the value for sy-subrc for few records.
Regards
Bala Krishna
‎2008 Dec 19 2:02 PM
Thanks Bala
It seems the value in field WA_t527X-ORGEH and WA_t527X-ORGTX do not change after each step through. SUBRC then changes to 4 and I see WA_t527X-ORGEH WA_IHPA-parnr changing each time.
any ideas Bala, thanks for all you help by the way
Alec
WA_T527X-ORGTX Stockton - Front of House
ZORGUNITTEXT Damn it
WA_t527X-ORGEH 20008855
WA_IHPA-parnr 20008855
‎2008 Dec 20 5:25 AM
Hi,
Try to out as a list and see, just modify your code as below in LOOP and ENDLOOP.
LOOP AT it_ihpa INTO wa_ihpa.
READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr
BINARY SEARCH.
IF sy-subrc EQ 0.
WRITE /: wa_t527X-ORGTX, sy-subrc
ENDIF.
ENDLOOP.
Regards
Bala Krishna