Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to retrieve a field value of an internal table?

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

7 REPLIES 7

Former Member
0 Kudos

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.

jayanthi_jayaraman
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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?

0 Kudos

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.

Former Member
0 Kudos

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