{"id":1615,"date":"2017-03-28T13:57:18","date_gmt":"2017-03-28T12:57:18","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1615"},"modified":"2017-03-28T13:57:18","modified_gmt":"2017-03-28T12:57:18","slug":"abap-load-user-specific-selection-screen-variant-during-program-initialization","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1615","title":{"rendered":"ABAP &#8211; Load user-specific selection screen variant during program initialization"},"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\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" alt=\"\" width=\"44\" height=\"50\" \/>When user starts a program\/report in SAPGUI, he want&#8217;s to have some speicific fields to be pre-filled with fixed values. This is true especially on more complex selection screens. So he must either create a transaction which executes the report with selected variant, or he can start the program directly and choose the variant on the selection screen manually.<\/p>\n<p>But there&#8217;s also another option &#8211; load the variant dynamically by ABAP coding, during the INITIALIZATION event&#8230;<!--more-->The code initially tries to find user-specific variant.<\/p>\n<p>If it&#8217;s not successful, it tries to load STANDARD variant with default values preset for all users.<\/p>\n<pre lang=\"abap\">FORM load_selection_screen_variant.\r\n\r\n  DATA:\r\n    lv_subrc   TYPE sy-subrc,\r\n    lv_variant TYPE rsvar-variant.\r\n\r\n  lv_variant = |U_{ sy-uname }|.\r\n\r\n* Try to read user-specific variant\r\n  CALL FUNCTION 'RS_VARIANT_EXISTS'\r\n    EXPORTING\r\n      report  = sy-repid\r\n      variant = lv_variant\r\n    IMPORTING\r\n      r_c     = lv_subrc.\r\n\r\n* User specific variant does not exist - try to read default variant instead\r\n  IF lv_subrc IS NOT INITIAL.\r\n*          *****        System-Variante\r\n    lv_variant = 'STANDARD'.\r\n\r\n    CALL FUNCTION 'RS_VARIANT_EXISTS'\r\n      EXPORTING\r\n        report  = sy-repid\r\n        variant = lv_variant\r\n      IMPORTING\r\n        r_c     = lv_subrc.\r\n  ENDIF.\r\n\r\n* We have eiterh user-specific or default variant -&gt; load selection screen\r\n* with data from the selected variant\r\n  IF lv_subrc = 0.\r\n    CALL FUNCTION 'RS_SUPPORT_SELECTIONS'\r\n      EXPORTING\r\n        report               = sy-repid\r\n        variant              = lv_variant\r\n      EXCEPTIONS\r\n        variant_not_existent = 01\r\n        variant_obsolete     = 02.\r\n  ENDIF.\r\nENDFORM.<\/pre>\n<p>In the INITIALIZATION event, just call the above form to load the variant<\/p>\n<pre lang=\"abap\">INITIALIZATION.\r\n  IF sy-slset IS INITIAL.  \"Selektionsbilder-&gt; Variant name    \r\n    PERFORM selection_var_find.                               \r\n  ENDIF.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When user starts a program\/report in SAPGUI, he want&#8217;s to have some speicific fields to be pre-filled with fixed values. This is true especially on more complex selection screens. So he must either create a transaction which executes the report &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=1615\">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 - Load user-specific selection screen variant during program initialization","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,9,222,389],"tags":[446,355,358],"class_list":["post-1615","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","category-dynpro","category-sap","tag-abap","tag-selection-screen","tag-variant"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-q3","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1615","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=1615"}],"version-history":[{"count":1,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions"}],"predecessor-version":[{"id":1616,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions\/1616"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}