‎2010 Jun 30 6:38 AM
dear all,
i have a BW abap question for you.
this code is to select from a table and field /BIC/ZSFPPD96 is the key.
* cache mapping table once
IF g_t_sample IS INITIAL.
SELECT /BIC/ZSFPPD96 /BIC/ZSFPPD95 /BIC/ZSFPPD94
FROM /BIC/PZSFPPD96
INTO CORRESPONDING FIELDS OF TABLE g_t_project
WHERE objvers = 'A'.
ENDIF.
somewhere down there i have this code and this is where my problem is... the scenario is i would like to use both field ZSFPPD95 and ZSFPPD94 as key fields and how can i get this done? thanks
* look up Project code based on IO
READ TABLE g_t_project INTO g_s_project WITH TABLE KEY
/BIC/ZSFPPD95 = SOURCE_FIELDS-/BIC/ZSFPPD95 OR /BIC/ZSFPPD94 = SOURCE_FIELDS-/BIC/ZSFPPD94.
IF sy-subrc = 0.
RESULT = g_s_project-/bic/zattr1.
ELSE.
RESULT = ''.
ENDIF.
‎2010 Jun 30 6:46 AM
remove the OR condtion
READ TABLE g_t_project INTO g_s_project WITH TABLE KEY
/BIC/ZSFPPD95 = SOURCE_FIELDS-/BIC/ZSFPPD95 /BIC/ZSFPPD94 = SOURCE_FIELDS-/BIC/ZSFPPD94.
Press F1 or read and check the syntax
Thanks
Bala Duvvuri
‎2010 Jun 30 6:48 AM
hello bala,
by removing the OR, wont it give me an AND statement?
‎2010 Jun 30 6:54 AM
Yes you are right it gives AND statement,I am not sure how you can make it OR
Thanks
Bala Duvvuri
‎2010 Jun 30 6:51 AM
Hi ,
In the Read table Statement , we cannot use AND , OR Conditions . Remove the OR and try.
In this case , value combination of Fields /BIC/ZSFPPD95 and /BIC/ZSFPPD94 , READ TABLE STATEMENT RETRIEVE the record.
* look up Project code based on IO
READ TABLE g_t_project INTO g_s_project WITH TABLE KEY
/BIC/ZSFPPD95 = SOURCE_FIELDS-/BIC/ZSFPPD95 /BIC/ZSFPPD94 = SOURCE_FIELDS-/BIC/ZSFPPD94.
IF sy-subrc = 0.
RESULT = g_s_project-/bic/zattr1.
ELSE.
RESULT = ''.
ENDIF.
‎2010 Jun 30 6:55 AM
‎2010 Jun 30 7:00 AM
Hi ,
you need to break the READ TABLE statement as below , it will work. as per this , read table statement will try for /BIC/ZSFPPD95 ( Key 1 ) , if It fails , REad table will try to find the record with /BIC/ZSFPPD94 ( key 2 ) , even then it fails My result ( Target value ) will be blank.
* look up Project code based on IO
READ TABLE g_t_project INTO g_s_project WITH TABLE KEY
/BIC/ZSFPPD95 = SOURCE_FIELDS-/BIC/ZSFPPD95.
IF sy-subrc = 0.
RESULT = g_s_project-/bic/zattr1.
ELSE.
READ TABLE g_t_project INTO g_s_project WITH TABLE KEY /BIC/ZSFPPD94 = SOURCE_FIELDS-/BIC/ZSFPPD94.
IF sy-subrc = 0.
RESULT = g_s_project-/bic/zattr1.
ELSE.
RESULT = ''.
ENDIF.
ENDIF.
Edited by: Prasath Arivazhagan on Jun 30, 2010 8:00 AM
‎2010 Jun 30 10:30 AM
HI
first you need to check that your key field should be the primary key. so that you can avoid multiple records because read table will fetch only one record.
and rather using read table statement you can use llop at your internal table with condition
like loop at internal table itab where <field1> = 'some value' and <field2> = 'some values'.
in this case it will check both the conditions and will fethc the values only if both the conditions will meat.
but in this scenario if you have multiple values for the same combination you will have multiple records.
therefor you need to check that both the fields are primary fields of the table so that you can avoid the duplicacy of the record.
I hope this will clear your doubt.
<removed by moderator>
thanks
Lalit Gupta
Edited by: Thomas Zloch on Jun 30, 2010 12:30 PM - do not ask for points
‎2010 Jun 30 11:19 AM
As you have mentioned in the table /BIC/PZSFPPD96, the key field is /BIC/ZSFPPD96. So how do you expect to get a unique record for the non-key fields ?
‎2010 Jun 30 11:32 AM
I think the g_t_project is of sorted or hased type, so try this
loop at g_t_project INTO g_s_project where /BIC/ZSFPPD95 = SOURCE_FIELDS-/BIC/ZSFPPD95
or /BIC/ZSFPPD94 = SOURCE_FIELDS-/BIC/ZSFPPD94.
RESULT = g_s_project-/bic/zattr1.
exit.
endloop.
if sy-subrc ne 0.
clear result.
endif.
@Suhas - + 1 .... didnt notice that
Edited by: Keshav.T on Jun 30, 2010 4:03 PM