{"id":930,"date":"2014-02-11T09:18:04","date_gmt":"2014-02-11T08:18:04","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=930"},"modified":"2014-02-11T15:58:04","modified_gmt":"2014-02-11T14:58:04","slug":"abap-validation-of-manual-input","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=930","title":{"rendered":"ABAP &#8211; Validation of manual input"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"358\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=358\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" data-orig-size=\"44,50\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Picasa&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1365690880&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"SAP\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" class=\"alignleft size-full wp-image-358\" alt=\"SAP\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" width=\"44\" height=\"50\" \/>I faced a scenario where I had an ALV grid where all columns were made generic of type (let&#8217;s make it simple) CHAR255. Each column has its name in field catalog in format TABNAME-FIELDNAME (+ more human readable column header texts of course). What I needed to achieve was to make validation of data that user entered in the ALV cells. Since the cell validation is not available by default (because of type CHAR255) I had to make it dynamically.<br \/>\nIn this article I&#8217;d like to share my solution<!--more--><br \/>\nIf you know the Data Dictionary table name and field name you can get the search help name (if it exists) by calling a FM F4IF_DETERMINE_SEARCHHELP.<\/p>\n<p>If this module returns valid data you can use it to call second FM called F4IF_SELECT_VALUES which returns itab with values that are normally displayed when the search help is triggered.<\/p>\n<p>Generally the second FM can return enormous number of results so it&#8217;s wise to limit the search with a filter (filter the one and only value &#8211; which was entered by the user).<\/p>\n<p>If the second FM returns any result, it means the value is accepted as valid.<br \/>\nIf no result is returned, it means the value enetered by user is not valid for the given field.<\/p>\n<p>Now let&#8217;s take a look at how exactly this can be implemented:<\/p>\n<pre lang=\"abap\">DATA:\r\n* Table and field name you get during runtime\r\n  g_tabname TYPE dfies-tabname,\r\n  g_fieldname TYPE dfies-fieldname,\r\n\r\n* Search help helper variables\r\n  gs_shlp TYPE shlp_descr,\r\n  gt_allowed_values TYPE TABLE OF ddshretval.\r\n\r\n* Constants used for testing\r\nCONSTANTS:\r\n  gc_test_ok    TYPE werks_d VALUE '2021',\r\n  gc_test_error TYPE werks_d VALUE '6058'.\r\n\r\nFIELD-SYMBOLS:\r\n  &lt;fs_selopt&gt; TYPE ddshselopt.\r\n\r\n* We are testing against MARA table and its field MATNR\r\ng_tabname   = 'MARC'.\r\ng_fieldname = 'WERKS'.\r\n\r\n* Get the search help if it exists\/is defined\r\nCALL FUNCTION 'F4IF_DETERMINE_SEARCHHELP'\r\n  EXPORTING\r\n    tabname           = g_tabname\r\n    fieldname         = g_fieldname\r\n  IMPORTING\r\n    shlp              = gs_shlp\r\n  EXCEPTIONS\r\n    field_not_found   = 1\r\n    no_help_for_field = 2\r\n    inconsistent_help = 3\r\n    OTHERS            = 4.\r\nIF sy-subrc = 0.\r\n* Check if its a collective search help - in this case pick first one from list of included search helps\r\n  CALL FUNCTION 'DD_SHLP_EXPAND_HELPMETHOD'\r\n    EXPORTING\r\n      shlp_top = gs_shlp\r\n    IMPORTING\r\n      shlp_tab = gt_shlp_tab.\r\n\r\n  CLEAR gs_shlp.\r\n  CHECK gt_shlp_tab[] IS NOT INITIAL.\r\n\r\n  READ TABLE gt_shlp_tab INDEX 1 INTO gs_shlp.\r\n\r\n* Test with correct value\r\n  APPEND INITIAL LINE TO gs_shlp-selopt ASSIGNING &lt;fs_selopt&gt;.\r\n  &lt;fs_selopt&gt;-shlpname = gs_shlp-shlpname.\r\n  &lt;fs_selopt&gt;-shlpfield = g_fieldname.\r\n  &lt;fs_selopt&gt;-sign = 'I'.\r\n  &lt;fs_selopt&gt;-option = 'EQ'.\r\n  &lt;fs_selopt&gt;-low = gc_test_ok.\r\n\r\n  CLEAR gt_allowed_values[].\r\n* Collect values from search help filtered\r\n* by the plant user entered\r\n  CALL FUNCTION 'F4IF_SELECT_VALUES'\r\n    EXPORTING\r\n      shlp           = gs_shlp\r\n      call_shlp_exit = 'X'\r\n    TABLES\r\n      return_tab     = gt_allowed_values.\r\n  IF gt_allowed_values[] IS INITIAL.\r\n    WRITE:\/ ' Plant ', gc_test_ok, ' is not valid'.\r\n  ELSE.\r\n    WRITE:\/ ' Plant ', gc_test_ok, ' is OK'.\r\n  ENDIF.\r\n\r\n* Test with invalid plant\r\n  CLEAR gs_shlp-selopt[].\r\n  APPEND INITIAL LINE TO gs_shlp-selopt ASSIGNING &lt;fs_selopt&gt;.\r\n  &lt;fs_selopt&gt;-shlpname = gs_shlp-shlpname.\r\n  &lt;fs_selopt&gt;-shlpfield = g_fieldname.\r\n  &lt;fs_selopt&gt;-sign = 'I'.\r\n  &lt;fs_selopt&gt;-option = 'EQ'.\r\n  &lt;fs_selopt&gt;-low = gc_test_error.\r\n\r\n  CLEAR gt_allowed_values[].\r\n  CALL FUNCTION 'F4IF_SELECT_VALUES'\r\n    EXPORTING\r\n      shlp           = gs_shlp\r\n*     call_shlp_exit = 'X'\r\n    TABLES\r\n      return_tab     = gt_allowed_values.\r\n  IF gt_allowed_values[] IS INITIAL.\r\n    WRITE:\/ ' Plant ', gc_test_error, ' is not valid'.\r\n  ELSE.\r\n    WRITE:\/ ' Plant ', gc_test_error, ' is OK'.\r\n  ENDIF.\r\nENDIF.<\/pre>\n<p>The output (depending on data in your system) will be like on picture below:<a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/VALIDATION_USING_SEARCH_HELP.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"932\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=932\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/VALIDATION_USING_SEARCH_HELP.png\" data-orig-size=\"201,59\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Validation using search help\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/VALIDATION_USING_SEARCH_HELP.png\" class=\"alignleft size-full wp-image-932\" alt=\"Validation using search help\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/VALIDATION_USING_SEARCH_HELP.png\" width=\"201\" height=\"59\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I faced a scenario where I had an ALV grid where all columns were made generic of type (let&#8217;s make it simple) CHAR255. Each column has its name in field catalog in format TABNAME-FIELDNAME (+ more human readable column header &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=930\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"ABAP - Validation of manual input  http:\/\/wp.me\/p3nYbe-f0","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,86,9,1],"tags":[446,269,268,18,267],"class_list":["post-930","post","type-post","status-publish","format-standard","hentry","category-abap","category-alv","category-development","category-uncategorized","tag-abap","tag-f4if_determine_searchhelp","tag-f4if_select_values","tag-search-help","tag-validation"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-f0","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=930"}],"version-history":[{"count":5,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/930\/revisions"}],"predecessor-version":[{"id":936,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/930\/revisions\/936"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}