2006 Feb 16 4:46 AM - last edited on 2024 Feb 04 2:07 AM by postmig_api_4
Hi all,
I got an internal table msgtab of type BDCMSGCOLL.
I want to retrieve the MSGV2 into a variable X from the table where MSGID = 'VL' and MSGNR = '311'.
I wrote like this but it fails:
data: X like BDCMSGCOLL-MSGV2.
READ TABLE msgtab WITH KEY
MSGID = 'VL' MSGNR = '311' into X.
What's wrong? Thanks
2006 Feb 16 4:50 AM
Hi,
Try this
Data w_msgtab type bdcmsgcoll.
data x type bdcmsgcoll-msgv2.
read table msgtab into w_msgtab with key msgid = 'VL' masgnr = '311'.
if sy-subrc eq 0.
x = w_msgtab-msgv2.
endif.
2006 Feb 16 4:49 AM
data: X like BDCMSGCOLL-MSGV2.
SORT msgtab BY msgid msgnr.
READ TABLE msgtab WITH KEY
MSGID = 'VL' MSGNR = '311' BINARY SEARCH.
X = msgtab-MSGV2.
Ps: Reward points if helpful.
2006 Feb 16 4:50 AM
Hi,
Try this
Data w_msgtab type bdcmsgcoll.
data x type bdcmsgcoll-msgv2.
read table msgtab into w_msgtab with key msgid = 'VL' masgnr = '311'.
if sy-subrc eq 0.
x = w_msgtab-msgv2.
endif.
2006 Feb 16 4:53 AM
hi Macy,
use..
<b>data: wa like BDCMSGCOLL.</b>
READ TABLE msgtab WITH KEY
MSGID = 'VL' MSGNR = '311' into wa.
now wa-msgv2 is the reqiired field..
regards
satesh
2006 Feb 16 4:57 AM
Hi macy,
Don't hard code the values.
try to use variables with the correct data type.
For ex :
data t_MSGID like BDCMSGCOLL-MSGID value 'VL'.
Read table msgtab with key MSGID = T_MSGID MSGNR = T_MSGNR X.
Try it out and let me know if you are able to resolve the issue.
Thank you.
Regards,
Karun M
2006 Feb 16 5:03 AM
Hi Karun,
Why do u think that we should not hard code the values?
Why is it better to hardcode in the data declaration part?
2006 Feb 16 5:07 AM
To make your code more flexible and reusable you must avoid hardcoding the values as said..
Since you can change the values at run time as per your wish.
Ps: Reward points if helpful.
2006 Feb 16 5:19 AM
Hi Macy Lo,
Check the <b>Data types</b> of BDCMSGCOLL-MSGID &
BDCMSGCOLL-MSGNR.
It fails because the datatypes doesn't matches.
You can check this with <i>sy-subrc</i> statement after the read statement.
Hope it helps.
Regards,
Maheswaran.B