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: 

Check if the value of a field in internal table exists in the database

Former Member
0 Kudos

Hello everyone,

I have a requirement where i need to check if the value of the field of a record in the internal table exist in the F4 help of the corresponding field in the database table.

For example : In transaction VA01 when we give the order quantity other than the ones specified in the f4 help an error message is raised as it is not present in the TVAK value table.Now if my internal table has an invalid entry then i need to move those entries to another internal table(itab1) and if the entries are valid i should move those entries into another internal table(itab2).

Please help me out in Validating all the fields of the internal field.Any suggestions in this regard would be very helpful for me

1 ACCEPTED SOLUTION

FabioPagoti
Active Contributor
0 Kudos

Hi Ashishreddy123,

For that, you can use function module "DDIF_DOMA_GET" to get all possible values for a specific domain. You can use it in case the domain was defined with single values or with a value table.

Regards,

5 REPLIES 5

FabioPagoti
Active Contributor
0 Kudos

Hi Ashishreddy123,

For that, you can use function module "DDIF_DOMA_GET" to get all possible values for a specific domain. You can use it in case the domain was defined with single values or with a value table.

Regards,

Former Member
0 Kudos

Hi Ashish,

Try this logic!!!!

If u need to check the field of your internal table exist in TVAK table, First applya select query on TVAK table bsed on for all entries of your internal table.

Now loop at your internal table into work area, inside loop read the table TVAK with work area-field name. After that just check if sy-subrc is not initial, than raise an error.

Hope this will help you to resolve the issue & close the thread.

BR,

Vinit

Clemenss
Active Contributor
0 Kudos

Hi Ashishreddy123,

you can use FM F4IF_FIELD_VALUE_REQUEST. Pass the DDIC reference for the field with Parameters TABNAME and FIELDNAME. Also pass parameter SUPPRESS_RECORDLIST = 'X'.

You will get the allowed values in table RETURN_TAB. Note that RETURN_TAB will also return the name of the determined search help (or check table) and if avalaible the texts from a related text table.

Check this code for a check if 'E' is a value in the search help for field SPRSL of table T100:

DATA:
  lv_fieldname   type fieldname value 'T100', 
  lv_tabname     type tabname value 'SPRSL', 
  lv_check_value type string value 'E',
  lv_tabfield    type ddshretval-RETFIELD,
  lt_RETURN_TAB  type table of ddshretval.
CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
  EXPORTING
    TABNAME    = lv_tabname
    FIELDNAME  = lv_fieldname
  TABLES
    RETURN_TAB = lt_RETURN_TAB
  EXCEPTIONS
    OTHERS     = 1.
IF SY-SUBRC = 0.
  concatenate lv_tabname lv_fieldname into lv_tabfield separated by '-'.
  LOOP AT lt_RETURN_TAB transporting no fields
    where RETFIELD = lv_tabfield
      and FIELDVAL = lv_check_value.
    exit.
  ENDLOOP.    
  IF SY-SUBRC <> 0.
    WRITE: lv_check_value, 'is not allowed for table field', lv_tabfield.
  ENDIF.
ENDIF.    
    

Regards,

Clemens

Former Member
0 Kudos

Hi ,

select <entries> from TVAK into table itab

for all entries in <internal table>

where quantity = <internal table>-quantity.

loop at <internal table> into wa.

read table itab with key quantity = wa-quantity.

if sy-subrc = 0.

move to itab1.

else.

move to itab2.

endif.

endloop.

hope this helps....

Former Member
0 Kudos

Thank you all for your valuable time and prompt replies... Some of your suggestions were very helpful to me... The solution given by Premalatha helped me the most... the process i followed for validation is :

i have written a select query on a value table to fetch all the values of a field(field 2) where field1 = wa-field1.

then read table with key field1 = wa-field1.

Getting into detail suppose i need to check if a particular VTWEG(Distribution Channel) exists for a specific VKORG(Sales Organisation) in VA01 transaction, Note : here all the values for comparison are taken from an internal table (it_flatfile) which is already filled from a flatfile.

 
loop at it_flatfile.
select vtweg from tvta into table it_vtweg where vkorg = it_flatfile-vkorg.
read table it_vtweg with key vtweg = it_flatfile-vtweg.
if sy-subrc = 0.
message  'Valid Entry' type 'I'.
endif.
endloop.

in the code above tvta is a value table which has the relationship between vtweg and vkorg.