Application Development and Automation 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: 
Read only

internal table validation

Former Member
0 Likes
2,258

how to find whether the fields of an internal table exists in a database table or not.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,279

hi sugautam

data itab1 type table of <table name> with header line." your internal table with data

data itab2 type table of matnr with header line." itab for the database table

select matnr from mara into iatb2.

data flag type i value 0.

loop at itab1.

loop at itab2 where matnr = itab1-matnr.

endloop.

if sy-subrc = 0.

write: / 'material' , itab1-material, 'exists'.

endloop.

9 REPLIES 9
Read only

Former Member
0 Likes
1,279

Hi,

Can you please give some more inputs on your query, so that i can able to give the answer

Regards

Ramakrishna Pathi

Read only

0 Likes
1,279

hi,

i have created a ztable which has a field Y_ITEM_NUM(Item Number).i have to find whether a item no. entered in this field exists in MARA-MATNR field?

Read only

0 Likes
1,279

Hi sugautam,

first of all get tall the records from Ztable to an internal table itab1.

then hit the table MARA using for all entries in the table itab1

and take the valid records into another internal table itab2.

select matnr

from mara

into table itab2

for all entries in itab1

where matnr EQ itab1-matnr.

if sy-subrc EQ 0.

you have all the matnrs existing in MARA in the new table itab2.

else.

not even 1 matnr is valid....

endif.

you can consider the matnrs in itab2 as valid matnrs....

I hope this will be helpful.

Let me know in case u require any furhter clarifications....

...Pavan.

Read only

0 Likes
1,279

just write the select query

select y_item_num from ztable into ztable where matnr = <field you passed in exit>

if sy-subrc = 0

then your entries is entered

else

no

endif.

cheers

s.janagar

Read only

Former Member
0 Likes
1,279

hi,

u can manually check internal table field inside the data base table . if this is not what u want pls explain ur question more specifically.

thanks,

Aditya

Read only

Former Member
0 Likes
1,279
Data:
  w_lines  type i,
  w_index type i value.

describe table itab lines w_lines.

while w_index le w_lines.

read table itab into wa index w_index.

Select single field from dbtable into w_field where field eq wa-field1. 
If sy-subrc ne 0.
  write: " field does not exit in db table
endif.
w_index = w_index + 1.
endwhile.

With luck,

Pritam.

Read only

Former Member
0 Likes
1,279

Hi Sugautam,

try this piece of code it might provide the full solution to your query supposing you want to check the availability of matnr value in the database table

data itab1 type table of <table name> with header line." your internal table

data itab2 type table of <table name> with header line." itab for the database table

select matnr from <table name> into iatb2.

data flag type i value 0.

loop at itab1.

loop at itab2.

if itab1-matnr = itab2-matnr.

flag = 1.

endif.

endloop.

if flag = 1.

write : / itab1-matnr,' exists'.

flag = 0.

endif.

endloop.

Edited by: raveeshgupta on Apr 23, 2009 10:53 AM

Read only

Former Member
0 Likes
1,279

Hi,

You can check whether a particular field of a table exists or not by firing a select on table DD03L.

Supply the Table name and the field name that you want to check to the table DD03L.

If sy-subrc is not zero, it is evident that , that field is not present in that particular table.

Thanks and Regards,

Sowmya Arni

Read only

Former Member
0 Likes
1,280

hi sugautam

data itab1 type table of <table name> with header line." your internal table with data

data itab2 type table of matnr with header line." itab for the database table

select matnr from mara into iatb2.

data flag type i value 0.

loop at itab1.

loop at itab2 where matnr = itab1-matnr.

endloop.

if sy-subrc = 0.

write: / 'material' , itab1-material, 'exists'.

endloop.