{"id":447,"date":"2013-04-17T15:03:07","date_gmt":"2013-04-17T14:03:07","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=447"},"modified":"2013-04-19T09:12:54","modified_gmt":"2013-04-19T08:12:54","slug":"automatic-assignment-of-incmd-groups-to-models-in-apo","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=447","title":{"rendered":"Automatic assignment of INCMD groups to models in APO"},"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\" style=\"color: #333333; font-size: 15.454545021057129px; font-style: normal; line-height: 21.81818199157715px;\" alt=\"SAP\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" width=\"44\" height=\"50\" \/><\/p>\n<p>It is possible to maintain interchangeability groups in APO manually with transaction \/INCMD\/UI but this is not practical in case we would like to automate some actions like assignment of INCMD groups to models.<\/p>\n<p><!--more--><\/p>\n<p>For this purpose I created a program that can be used:<\/p>\n<ol>\n<li>It reads all INCMD groups currently assigned to given range of source models and having status from given status range<\/li>\n<li>It assigns all selected INCMD groups to target models given also by range.<\/li>\n<li>In case the INCMD groups is already assigned to target model, this assignment is skipped<\/li>\n<li>Finally it notifies user about how many new assignments were created.<\/li>\n<\/ol>\n<pre lang=\"abap\">DATA:\r\n  l_model  TYPE \/incmd\/model,        \"used for selection screen only\r\n  l_status TYPE \/incmd\/istat.        \"used for selection screen only\r\n\r\nSELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-001.\r\nSELECT-OPTIONS: src_mod  FOR l_model,                 \" Source range of models\r\n                src_stat FOR l_status.                \" Source range of INCMD groups statuses\r\nPARAMETERS:     p_ungr AS CHECKBOX DEFAULT ' '.       \" Process also all unassigned groups\r\nSELECTION-SCREEN END OF BLOCK b01.\r\n\r\nSELECTION-SCREEN BEGIN OF BLOCK b02 WITH FRAME TITLE text-002.\r\nSELECT-OPTIONS: dst_mod  FOR l_model.                 \" Destination range of models\r\nSELECTION-SCREEN END OF BLOCK b02.\r\n\r\nDATA:\r\n  lt_header               TYPE TABLE OF \/incmd\/bapigrphdr02,\r\n  lt_return               TYPE TABLE OF bapiret2,\r\n  lt_scr_group_models     TYPE TABLE OF \/incmd\/bapigrpmodel02,\r\n  lt_add_models           TYPE TABLE OF \/sapapo\/model,\r\n  lt_existing_assignments TYPE \/sapapo\/modelinc_tab,\r\n  lt_newassignments       TYPE \/sapapo\/modelinc_tab,\r\n  lt_groups               TYPE \/sapapo\/inc_icno_sel_tab,\r\n  l_lines                 TYPE i.\r\n\r\nFIELD-SYMBOLS:\r\n  &lt;fs_status&gt;          LIKE src_stat,\r\n  &lt;fs_group&gt;           TYPE \/sapapo\/inc_icno_sel_str,\r\n  &lt;fs_scr_group_model&gt; type \/incmd\/bapigrpmodel02,\r\n  &lt;fs_return&gt;          TYPE bapiret2,\r\n  &lt;fs_newassignment&gt;   TYPE \/sapapo\/modelinc,\r\n  &lt;fs_add_model&gt;       TYPE \/sapapo\/model,\r\n  &lt;fs_header&gt;          TYPE \/incmd\/bapigrphdr02.\r\n\r\nSTART-OF-SELECTION.\r\n* Select all statuses in case no manual selection was made\r\n  IF src_stat IS INITIAL.\r\n    APPEND INITIAL LINE TO src_stat ASSIGNING &lt;fs_status&gt;.\r\n    &lt;fs_status&gt;-sign   = 'I'.\r\n    &lt;fs_status&gt;-option = 'BT'.\r\n    &lt;fs_status&gt;-low    = ' '.\r\n    &lt;fs_status&gt;-high   = '4'.\r\n  ENDIF.\r\n\r\n* Read all the INCMD groups together with models they are assigned to\r\n  CALL FUNCTION '\/INCMD\/BAPI_GROUP_GETLIST'\r\n    TABLES\r\n      group_status_selection = src_stat\r\n      model_selection        = src_mod\r\n      group_header_data      = lt_header\r\n      group_models_data      = lt_scr_group_models\r\n      return                 = lt_return.\r\n\r\n* Check for errors\r\n  READ TABLE lt_return ASSIGNING &lt;fs_return&gt; WITH KEY type = 'E' .\r\n  IF sy-subrc = 0.\r\n    MESSAGE ID &lt;fs_return&gt;-id\r\n      TYPE 'E'\r\n      NUMBER &lt;fs_return&gt;-number\r\n      WITH &lt;fs_return&gt;-message_v1\r\n           &lt;fs_return&gt;-message_v2\r\n           &lt;fs_return&gt;-message_v3\r\n           &lt;fs_return&gt;-message_v4.\r\n  ELSE.\r\n* Select target models the selected INCMD groups can be assigned to\r\n    SELECT model FROM \/sapapo\/model\r\n      INTO CORRESPONDING FIELDS OF TABLE lt_add_models\r\n      WHERE model IN dst_mod.\r\n\r\n    IF lt_add_models IS NOT INITIAL.\r\n* Get list of all INCMD groups to be assigned to destination range of models\r\n      IF p_ungr = 'X'.\r\n*       Process all available groups that matches selection conditions\r\n*       even if they are not currently assigned to any model\r\n        LOOP AT lt_header ASSIGNING &lt;fs_header&gt;.\r\n          APPEND INITIAL LINE TO lt_groups ASSIGNING &lt;fs_group&gt;.\r\n          &lt;fs_group&gt;-sign   = 'I'.\r\n          &lt;fs_group&gt;-option = 'EQ'.\r\n          &lt;fs_group&gt;-low    = &lt;fs_header&gt;-group_number.\r\n        ENDLOOP.\r\n      ELSE.\r\n        \"Process only groups assigned to some group from source selection model range\r\n        LOOP AT lt_scr_group_models ASSIGNING &lt;fs_scr_group_model&gt;.\r\n          APPEND INITIAL LINE TO lt_groups ASSIGNING  &lt;fs_group&gt;.\r\n          &lt;fs_group&gt;-sign   = 'I'.\r\n          &lt;fs_group&gt;-option = 'EQ'.\r\n          &lt;fs_group&gt;-low    = &lt;fs_scr_group_model&gt;-group_number.\r\n        ENDLOOP.\r\n\r\n        sort lt_groups.\r\n        delete ADJACENT DUPLICATES FROM lt_groups.\r\n      ENDIF.\r\n\r\n* Get all currently existing assignments for selected INCMD groups\r\n      CALL FUNCTION '\/SAPAPO\/INC_MODELS_GET'\r\n        EXPORTING\r\n          it_icno_sel = lt_groups\r\n        IMPORTING\r\n          et_modelinc = lt_existing_assignments.\r\n\r\n* Prepare i-table with new assignments\r\n      LOOP AT lt_groups ASSIGNING &lt;fs_group&gt;.\r\n        LOOP AT lt_add_models ASSIGNING &lt;fs_add_model&gt;.\r\n* Check if such assignment already exist in database\r\n          READ TABLE lt_existing_assignments\r\n            WITH KEY icno  = &lt;fs_group&gt;-low\r\n                     model = &lt;fs_add_model&gt;-model\r\n            TRANSPORTING NO FIELDS.\r\n* Skip if such assignment already exists\r\n          CHECK sy-subrc &lt;&gt; 0.\r\n\r\n* Create new assignment between INCMD group and model\r\n          APPEND INITIAL LINE TO lt_newassignments ASSIGNING &lt;fs_newassignment&gt;.\r\n          &lt;fs_newassignment&gt;-mandt = sy-mandt.\r\n          &lt;fs_newassignment&gt;-icno  = &lt;fs_group&gt;-low.\r\n          &lt;fs_newassignment&gt;-model = &lt;fs_add_model&gt;-model.\r\n        ENDLOOP.\r\n      ENDLOOP.\r\n\r\n* Write new assignments if any\r\n      IF lt_newassignments IS NOT INITIAL.\r\n        CALL FUNCTION '\/SAPAPO\/INC_MODELS_SET'\r\n          EXPORTING\r\n            it_modelinc = lt_newassignments.\r\n\r\n        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'\r\n          EXPORTING\r\n            wait = 'X'.\r\n      ENDIF.\r\n    ENDIF.\r\n\r\n* Write info message\r\n    DESCRIBE TABLE lt_newassignments LINES l_lines.\r\n    IF l_lines &gt; 0.\r\n      MESSAGE i114(zapo01) WITH 'Number of new INCMD Group-Model assignments: '\r\n                                l_lines.\r\n    ELSE.\r\n      MESSAGE i114(zapo01) WITH 'No new INCMD Group-Model assignment'.\r\n    ENDIF.\r\n  ENDIF.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to maintain interchangeability groups in APO manually with transaction \/INCMD\/UI but this is not practical in case we would like to automate some actions like assignment of INCMD groups to models.<\/p>\n","protected":false},"author":1,"featured_media":358,"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":"","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],"tags":[101,104,102,103,446,448,100,105,96,97,98,17],"class_list":["post-447","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-abap","category-development","tag-incmdbapi_group_getlist","tag-sapapoinc_models_delete","tag-sapapoinc_models_get","tag-sapapoinc_models_set","tag-abap","tag-apo","tag-bapi","tag-bapi_transaction_commit","tag-incmd-groups","tag-interchangeability","tag-model","tag-sap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-7d","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/447","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=447"}],"version-history":[{"count":7,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/447\/revisions"}],"predecessor-version":[{"id":464,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/447\/revisions\/464"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/media\/358"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}