{"id":1475,"date":"2016-02-11T17:13:12","date_gmt":"2016-02-11T16:13:12","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1475"},"modified":"2016-02-12T15:57:01","modified_gmt":"2016-02-12T14:57:01","slug":"abap-how-to-createmodify-source-lists","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1475","title":{"rendered":"ABAP &#8211; How to create\/modify Source lists"},"content":{"rendered":"<p>In this code snippet I&#8217;ll demonstrate how to create or modify a source list (TCode ME01).\u00a0I did&#8217;t find a suitable &#8220;standard way&#8221; how to do it, but after digging in the function module which processes inboud IDOC for source list (IDOC_INPUT_SRCLST) I managed to replicate the functionality in my own code.<\/p>\n<p><!--more--><\/p>\n<p>I tried\u00a0several ways how to do it:<\/p>\n<ul>\n<li><a href=\"#BATCH_INPUT\">Maintain source list via Batch Input<\/a><\/li>\n<li><a href=\"#IDOC\">Maintain source list via IDOC<\/a><\/li>\n<li><a href=\"#ME_DIRECT_INPUT_SOURCE_LIST\">Maintain source list via ABAP<\/a><\/li>\n<\/ul>\n<h1><a id=\"BATCH_INPUT\"><\/a>Source list via BDC &#8211; batch input<\/h1>\n<p>One possible solution is a batch input. But this one is not very practical when you need to modify source list&#8217;s line items (especially when there are more line items), because it&#8217;s quite difficult to adress line items apeearing on later pages of the list. So you can&#8217;t easily access them via index&#8230; but anyway, if anyone is interested, you can use the following code:<\/p>\n<pre lang=\"abap\">DATA:\r\n  gt_bdcdata TYPE TABLE OF bdcdata,\r\n  gt_return  TYPE TABLE OF bdcmsgcoll,\r\n  gv_message TYPE string.\r\n\r\nSTART-OF-SELECTION.\r\n  PERFORM bdc_dynpro USING 'SAPLMEOR'       '0200'.\r\n  PERFORM bdc_field  USING 'BDC_CURSOR'     'EORD-MATNR'.\r\n  PERFORM bdc_field  USING 'BDC_OKCODE'     '\/00'.\r\n  PERFORM bdc_field  USING 'EORD-MATNR'     '1000001974'.\r\n  PERFORM bdc_field  USING 'EORD-WERKS'     '0040'.\r\n\r\n* Modify validity dates of the 5th line of source list\r\n  PERFORM bdc_dynpro USING 'SAPLMEOR'       '0205'.\r\n  PERFORM bdc_field  USING 'BDC_CURSOR'     'EORD-BDATU(01)'.\r\n  PERFORM bdc_field  USING 'BDC_OKCODE'     '=NS'.\r\n  PERFORM bdc_field  USING 'EORD-VDATU(05)' '01.04.2016'.\r\n  PERFORM bdc_field  USING 'EORD-BDATU(05)' '02.04.2016'.\r\n\r\n* Add new line item in the source list\r\n  PERFORM bdc_dynpro USING 'SAPLMEOR'       '0205'.\r\n  PERFORM bdc_field  USING 'BDC_CURSOR'     'EORD-VDATU(02)'.\r\n  PERFORM bdc_field  USING 'BDC_OKCODE'     '=BU'.\r\n  PERFORM bdc_field  USING 'EORD-VDATU(02)' '10.04.2016'.\r\n  PERFORM bdc_field  USING 'EORD-BDATU(02)' '10.04.2016'.\r\n  PERFORM bdc_field  USING 'EORD-LIFNR(02)' '510769'.\r\n  PERFORM bdc_field  USING 'EORD-EKORG(02)' '0040'.\r\n  PERFORM bdc_field  USING 'EORD-MEINS(02)' 'PC'.\r\n  PERFORM bdc_field  USING 'EORD-EBELN(02)' '5500000667'.\r\n  PERFORM bdc_field  USING 'EORD-EBELP(02)' '0010'.\r\n  PERFORM bdc_field  USING 'EORD-AUTET(02)' '2'.\r\n\r\n\r\n  CALL TRANSACTION 'ME01' USING gt_bdcdata\r\n                          MODE  'N'\r\n                          UPDATE 'S'\r\n                          MESSAGES INTO gt_return.\r\n\r\n  LOOP AT gt_return ASSIGNING FIELD-SYMBOL(&lt;ls_return&gt;).\r\n    MESSAGE ID &lt;ls_return&gt;-msgid\r\n            TYPE &lt;ls_return&gt;-msgtyp\r\n            NUMBER &lt;ls_return&gt;-msgnr\r\n            WITH &lt;ls_return&gt;-msgv1\r\n                 &lt;ls_return&gt;-msgv2\r\n                 &lt;ls_return&gt;-msgv3\r\n                 &lt;ls_return&gt;-msgv4\r\n            INTO gv_message.\r\n    WRITE:\/ gv_message.\r\n  ENDLOOP.\r\n\r\nFORM bdc_field USING fnam fval.\r\n  DATA: ls_bdcdata TYPE bdcdata.\r\n\r\n  ls_bdcdata-fnam = fnam.\r\n  ls_bdcdata-fval  = fval.\r\n  APPEND ls_bdcdata TO gt_bdcdata.\r\nENDFORM.\r\n\r\nFORM bdc_dynpro USING prog scr.\r\n  DATA: ls_bdcdata TYPE bdcdata.\r\n\r\n  ls_bdcdata-program = prog.\r\n  ls_bdcdata-dynpro  = scr.\r\n  ls_bdcdata-dynbegin = 'X'.\r\n  APPEND ls_bdcdata TO gt_bdcdata.\r\nENDFORM.<\/pre>\n<h1><a id=\"IDOC\"><\/a>Source list via IDOC<\/h1>\n<p>I also tried\u00a0to use inbound IDOC method, because I don&#8217;t have to care about adressing the item row numbers and everything is done by SAP standard. The problem is that the IDOC <span style=\"color: #ff0000;\"><strong>completely IGNORES the MSGFN field.<\/strong><\/span> Therefore you are not able to neither modify nor delete line items of a source list. The only action you can do this way is to INSERT new items.<\/p>\n<pre lang=\"abap\">CLASS lcl_idoc DEFINITION.\r\n PUBLIC SECTION.\r\n   METHODS:\r\n     send_idoc.\r\n\r\n PRIVATE SECTION.\r\n   CONSTANTS:\r\n     co_idoc_header_segment TYPE edilsegtyp VALUE 'E1EORDH',\r\n     co_idoc_item_segment TYPE edilsegtyp VALUE 'E1EORDM',\r\n     co_idoc_message_type TYPE edi_mestyp VALUE 'SRCLST',\r\n     co_idoc_basic_type TYPE edi_idoctp VALUE 'SRCLST01'.\r\n\r\n   DATA:\r\n     ms_control_rec TYPE edidc,\r\n     mt_idoc_data TYPE TABLE OF edidd,\r\n     ms_process_data TYPE tede2.\r\n\r\n   METHODS:\r\n     create_control_record,\r\n     create_header_segment,\r\n     create_item_segments,\r\n     create_idoc_db,\r\n     post_idoc_inbound.\r\nENDCLASS.\r\n\r\nCLASS lcl_idoc IMPLEMENTATION.\r\n METHOD send_idoc.\r\n   ir_idoc-&gt;create_control_record( ).\r\n   ir_idoc-&gt;create_header_segment( ).\r\n   ir_idoc-&gt;create_item_segments( ).\r\n   ir_idoc-&gt;create_idoc_db( ).\r\n   ir_idoc-&gt;post_idoc_inbound( ).\r\n ENDMETHOD.\r\n\r\n\r\n METHOD create_control_record.\r\n   DATA:\r\n     lv_logsys type LOGSYS.\r\n\r\n   ms_control_rec-mestyp = co_idoc_message_type.\r\n   ms_control_rec-idoctp = co_idoc_basic_type.\r\n   ms_control_rec-direct = 2. \" 1 = outbound, 2 = inbound\r\n\r\n   CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'\r\n     IMPORTING\r\n       OWN_LOGICAL_SYSTEM = lv_logsys.\r\n\r\n   ms_control_rec-rcvprt = 'LS'.\r\n   ms_control_rec-rcvprn = lv_logsys.\r\n\r\n   ms_control_rec-sndprt = 'LS'.\r\n   ms_control_rec-sndprn = lv_logsys.\r\n   ms_control_rec-sndpor = 'DUMMY'.\r\n\r\n ENDMETHOD.\r\n\r\n\r\n METHOD create_header_segment.\r\n   DATA:\r\n     ls_header TYPE e1eordh.\r\n\r\n   CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'\r\n     IMPORTING\r\n       OWN_LOGICAL_SYSTEM = ls_header-logsy.\r\n\r\n   ls_header-msgfn = '005'. \"This is ignored!!!\r\n   ls_header-matnr = '1000001974'.\r\n   ls_header-werks = '0040'.\r\n\r\n   APPEND INITIAL LINE TO mt_idoc_data \r\n     ASSIGNING FIELD-SYMBOL(&lt;ls_header&gt;).\r\n\r\n   &lt;ls_header&gt;-segnam = co_idoc_header_segment.\r\n   &lt;ls_header&gt;-sdata  = ls_header.\r\n ENDMETHOD.\r\n\r\n\r\n METHOD create_item_segments.\r\n   DATA:\r\n     ls_item TYPE e1eordm,\r\n     lv_isocode type ISOCD_UNIT.\r\n\r\n*  IDOC accepts ISO codes ONLY!!! (e.g. 'PC' =&gt; 'PCE')\r\n   SELECT SINGLE isocode \r\n     FROM t006 INTO lv_isocode\r\n     WHERE msehi = 'PC'.\r\n\r\n*  INSERT new line item \r\n   ls_item-erdat = sy-datum. \r\n   ls_item-ernam = sy-uname. \r\n   ls_item-vdatu = '20160401'.\r\n   ls_item-bdatu = '20160401'.\r\n   ls_item-lifnr = '0000510769'.\r\n   ls_item-ebeln = '5500000667'.\r\n   ls_item-ebelp = '00010'.\r\n   ls_item-ekorg = '0040'.\r\n\r\n*  L = scheduling agreement\r\n   ls_item-vrtyp = 'L'. \" L = scheduling agreement\"\r\n\r\n*  '0' = Standard\r\n*  '2' = Consignment\r\n   ls_item-eortp = '0'. \" category of source list record \r\n\r\n*  ' ' = Source list record not relevant to MRP\r\n*  '1' = Record relevant to MRP\r\n*  '2' = Recored relevant to MRP, sch.lines generated automatically\r\n   ls_item-autet = '2'. \r\n\r\n   ls_item-meins = lv_isocode.\r\n\r\n   APPEND INITIAL LINE TO mt_idoc_data \r\n     ASSIGNING FIELD-SYMBOL(&lt;ls_item&gt;).\r\n\r\n   &lt;ls_item&gt;-segnam = 'E1EORDM'.\r\n   &lt;ls_item&gt;-sdata = ls_item.\r\n\r\n ENDMETHOD.\r\n\r\n\r\n METHOD create_idoc_db.\r\n\r\n   CALL FUNCTION 'IDOC_INBOUND_WRITE_TO_DB'\r\n     IMPORTING\r\n       pe_idoc_number = ms_control_rec-docnum\r\n       pe_inbound_process_data = ms_process_data\r\n     TABLES\r\n       t_data_records = mt_idoc_data\r\n     CHANGING\r\n       pc_control_record = ms_control_rec\r\n     EXCEPTIONS\r\n       idoc_not_saved = 1\r\n     OTHERS = 2.\r\n   IF sy-subrc &lt;&gt; 0.\r\n     MESSAGE ID sy-msgid \r\n             TYPE sy-msgty \r\n             NUMBER sy-msgno \r\n             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.\r\n   ELSE.\r\n     COMMIT WORK AND WAIT.\r\n   ENDIF.\r\n\r\n ENDMETHOD.\r\n\r\n METHOD post_idoc_inbound.\r\n   DATA:\r\n     lt_control_recs TYPE TABLE OF edidc.\r\n\r\n   APPEND ms_control_rec TO lt_control_recs.\r\n\r\n   CALL FUNCTION 'IDOC_START_INBOUND'\r\n     EXPORTING\r\n       pi_inbound_process_data = ms_process_data\r\n       pi_called_online = 'X'\r\n       succ_show_flag = 'X'\r\n     TABLES\r\n       t_control_records = lt_control_recs\r\n     EXCEPTIONS\r\n       invalid_document_number = 1\r\n       error_before_call_application = 2\r\n       inbound_process_not_possible = 3\r\n       old_wf_start_failed = 4\r\n       wf_task_error = 5\r\n       serious_inbound_error = 6\r\n       OTHERS = 7.\r\n\r\n   IF sy-subrc &lt;&gt; 0.\r\n     MESSAGE ID sy-msgid \r\n             TYPE sy-msgty \r\n             NUMBER sy-msgno \r\n             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.\r\n   ENDIF.\r\n\r\n ENDMETHOD.\r\nENDCLASS.\r\n\r\nSTART-OF-SELECTION.\r\n  CREATE OBJECT gr_idoc.\r\n  gr_idoc-&gt;send_idoc( ).<\/pre>\n<p>The reason why it&#8217;s not possible to modify or delete data is hidden in SAP standard FM &#8216;IDOC_INPUT_SRCLST&#8217;. If you dig in and check it&#8217;s form FILL_APPL_STRUCTURES_SRCLST you will find this:<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05.png\" rel=\"attachment wp-att-1478\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1478\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1478\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05.png\" data-orig-size=\"525,310\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Clear ZEORD\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05.png\" class=\"alignnone size-medium wp-image-1478\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05-300x177.png\" alt=\"Clear ZEORD\" width=\"300\" height=\"177\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05-300x177.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05-500x295.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_05.png 525w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ol>\n<li>In the called form\u00a0READ_SEG_E1EORDM you won&#8217;t find a row, where ZEORD is read.<\/li>\n<li>Even if the ZEAORD was read, on line #127 it is cleared.<\/li>\n<\/ol>\n<p>This means the even if you try to address line items from EORD by their positions (ZEORD), it will be cleared (by standard!!!) and everything will be treated as new line items.<\/p>\n<p>Next bad thing is hidden later in FM IDOC_INPUT_SRCLST, where it&#8217;s hardcoded, that all lines will be treated as NEW entries.<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06.png\" rel=\"attachment wp-att-1479\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1479\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1479\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06.png\" data-orig-size=\"566,178\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"IDOC problem\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06.png\" class=\"alignnone size-medium wp-image-1479\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06-300x94.png\" alt=\"IDOC problem\" width=\"300\" height=\"94\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06-300x94.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06-500x157.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_06.png 566w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Therefore you can&#8217;t use the IDOC method for updating or deleting entries unless you want to modify SAP standard.<\/p>\n<h1><a id=\"ME_DIRECT_INPUT_SOURCE_LIST\"><\/a>Source list via\u00a0ME_DIRECT_INPUT_SOURCE_LIST<\/h1>\n<p>Finally I&#8217;ve discovered a fully functional way how to<\/p>\n<ol>\n<li><strong>CREATE<\/strong><\/li>\n<li><strong>UPDATE<\/strong><\/li>\n<li><strong>DELETE<\/strong><\/li>\n<\/ol>\n<p>entries from the source list.<\/p>\n<p>I managed to do it by more or less replicating code from the IDOC_INPUT_SCRLST, where I re-used some function modules called there in the following order:<\/p>\n<ol>\n<li>ME_INITIALIZE_SOURCE_LIST<\/li>\n<li>ME_DIRECT_INPUT_SOURCE_LIST<\/li>\n<li><!--StartFragment -->ME_POST_SOURCE_LIST_NEW<\/li>\n<li>ME_WRITE_DISP_RECORD_SOS<\/li>\n<li>COMMIT WORK AND WAIT<\/li>\n<\/ol>\n<p>The following code takes two input parameters (validity of the new line in source list) on the selection screen, invalidates all existing lines in source list which validity time frame overlap with the new line&#8217;s validity and creates the new line with given validity dates.<\/p>\n<p>Here you can see source list status BEFORE the program execution<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07.png\" rel=\"attachment wp-att-1481\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1481\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1481\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07.png\" data-orig-size=\"635,253\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ME01 &amp;#8211; before execution\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07.png\" class=\"alignnone size-medium wp-image-1481\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07-300x120.png\" alt=\"ME01 - before execution\" width=\"300\" height=\"120\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07-300x120.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07-500x199.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_07.png 635w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>On the program&#8217;s selection screen I enter validity of the new line item in the source list<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_08.png\" rel=\"attachment wp-att-1482\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1482\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1482\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_08.png\" data-orig-size=\"345,98\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Selection screen\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_08.png\" class=\"alignnone size-medium wp-image-1482\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_08-300x85.png\" alt=\"Selection screen\" width=\"300\" height=\"85\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_08-300x85.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_08.png 345w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>And here is the status of the source list AFTER the program was executed<\/p>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09.png\" rel=\"attachment wp-att-1483\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1483\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1483\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09.png\" data-orig-size=\"628,226\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Updated source list\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09.png\" class=\"alignnone size-medium wp-image-1483\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09-300x108.png\" alt=\"Updated source list\" width=\"300\" height=\"108\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09-300x108.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09-500x180.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/ME01_09.png 628w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre lang=\"abap\">DATA:\r\n gv_new_sag   TYPE ebeln,\r\n gv_new_lifnr TYPE lifnr,\r\n gv_matnr     TYPE matnr,\r\n gv_werks     TYPE werks_d.\r\n\r\nSELECTION-SCREEN BEGIN OF BLOCK bl01.\r\n  PARAMETERS:\r\n    p_vdatu LIKE eord-vdatu,\r\n    p_bdatu LIKE eord-bdatu.\r\nSELECTION-SCREEN END OF BLOCK bl01.\r\n\r\n\r\nFORM update_source_list USING uv_new_sag TYPE ebeln\r\n                              uv_new_lifnr TYPE lifnr\r\n                              uv_matnr TYPE matnr\r\n                              uv_werks TYPE werks_d.\r\n  DATA:\r\n    lt_eordu TYPE TABLE OF eordu,\r\n    lt_eord TYPE TABLE OF eord,\r\n    lt_tupel TYPE TABLE OF metup,\r\n    lv_lifnr TYPE lifnr.\r\n\r\n* Get all existing source list's line items for given MATNR, WERKS, LIFNR\r\n  SELECT *\r\n    INTO CORRESPONDING FIELDS OF TABLE lt_eordu\r\n    FROM eord\r\n    WHERE matnr = uv_matnr\r\n      AND werks = uv_werks\r\n      AND (\r\n            ( vdatu &lt;= p_vdatu AND bdatu &gt;= p_vdatu )\r\n         OR ( vdatu &lt;= p_bdatu AND bdatu &gt;= p_bdatu )\r\n         OR ( vdatu &gt;= p_vdatu AND bdatu &lt;= p_bdatu )\r\n      ).\r\n\r\n* Make sure there's at least one source list's line item\r\n  CHECK lt_eordu IS NOT INITIAL.\r\n\r\n  SORT lt_eordu BY vdatu bdatu.\r\n  LOOP AT lt_eordu ASSIGNING FIELD-SYMBOL(&lt;ls_eordu&gt;).\r\n    APPEND INITIAL LINE TO lt_eord \r\n      ASSIGNING FIELD-SYMBOL(&lt;ls_eord&gt;).\r\n    MOVE-CORRESPONDING &lt;ls_eordu&gt; TO &lt;ls_eord&gt;.\r\n\r\n* Item which is valid at beginning of the new source list entry will be updated\r\n* It can be only one line\r\n    IF &lt;ls_eordu&gt;-vdatu &lt; p_vdatu AND \r\n       &lt;ls_eordu&gt;-bdatu &gt;= p_vdatu.\r\n\r\n* Update the item so it's validity ends before validity of the new entry\r\n      &lt;ls_eordu&gt;-bdatu = p_vdatu - 1.\r\n      &lt;ls_eordu&gt;-kz = 'U'.\r\n    ELSE.\r\n\r\n* Source list's items which are NOT valid at beginning of the new source list's entry will be deleted\r\n      &lt;ls_eordu&gt;-kz = 'D'.\r\n\r\n    ENDIF.\r\n\r\n  ENDLOOP.\r\n\r\n\r\n  READ TABLE lt_eordu ASSIGNING &lt;ls_eordu&gt; INDEX 1.\r\n* We use this line as a template for the new source list's entry\r\n  APPEND INITIAL LINE TO lt_eordu \r\n    ASSIGNING FIELD-SYMBOL(&lt;ls_eordu_new&gt;).\r\n  &lt;ls_eordu_new&gt; = &lt;ls_eordu&gt;.\r\n\r\n* Set correct data for the new source list's entry\r\n  CLEAR &lt;ls_eordu_new&gt;-zeord.\r\n  &lt;ls_eordu_new&gt;-kz = 'I'.\r\n  &lt;ls_eordu_new&gt;-vdatu = p_vdatu.\r\n  &lt;ls_eordu_new&gt;-bdatu = p_bdatu.\r\n\r\n  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'\r\n    EXPORTING\r\n      input = uv_new_lifnr\r\n    IMPORTING\r\n      output = &lt;ls_eordu_new&gt;-lifnr.\r\n\r\n  &lt;ls_eordu_new&gt;-ebeln = uv_new_sag.\r\n\r\n\r\n  CALL FUNCTION 'ME_INITIALIZE_SOURCE_LIST'.\r\n\r\n  CALL FUNCTION 'ME_DIRECT_INPUT_SOURCE_LIST'\r\n    EXPORTING\r\n      i_matnr = uv_matnr\r\n      i_werks = uv_werks\r\n      i_vorga = 'B'\r\n    TABLES\r\n      t_eord = lt_eordu\r\n    EXCEPTIONS\r\n      plant_missing = 1\r\n      material_missing = 2\r\n      OTHERS = 3.\r\n  IF sy-subrc = 0.\r\n    APPEND INITIAL LINE TO lt_tupel \r\n      ASSIGNING FIELD-SYMBOL(&lt;ls_tupel&gt;).\r\n    &lt;ls_tupel&gt;-matnr = uv_matnr.\r\n    &lt;ls_tupel&gt;-werks = uv_werks.\r\n\r\n    CALL FUNCTION 'ME_POST_SOURCE_LIST_NEW'.\r\n\r\n    CALL FUNCTION 'ME_WRITE_DISP_RECORD_SOS' IN UPDATE TASK\r\n      TABLES\r\n        eord_alt = lt_eord\r\n        eord_neu = lt_eordu\r\n        tupel = lt_tupel.\r\n\r\n    COMMIT WORK AND WAIT.\r\n  ENDIF.\r\n\r\nENDFORM.\r\n\r\nINITIALIZATION.\r\n  p_vdatu = sy-datum + 1.\r\n  p_bdatu = '99991231'.\r\n\r\n\r\nSTART-OF-SELECTION.\r\n  gv_new_sag = '5500000667'.\r\n  gv_new_lifnr = '510769'.\r\n\r\n  gv_matnr = '1000001974'.\r\n  gv_werks = '0040'.\r\n\r\n  PERFORM update_source_list USING gv_new_sag\r\n                                   gv_new_lifnr\r\n                                   gv_matnr\r\n                                   gv_werks.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this code snippet I&#8217;ll demonstrate how to create or modify a source list (TCode ME01).\u00a0I did&#8217;t find a suitable &#8220;standard way&#8221; how to do it, but after digging in the function module which processes inboud IDOC for source list &hellip; <a href=\"https:\/\/oprsteny.cz\/?p=1475\">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 - How to create\/modify Source lists","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,454,402],"tags":[460,461,457,459,458,211,455,456,462],"class_list":["post-1475","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","category-idoc","category-materials-management","tag-e1eordh","tag-e1eordm","tag-idoc","tag-idoc_inbound_write_to_db","tag-idoc_start_inbound","tag-me01","tag-me31l","tag-source-list","tag-srclst"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-nN","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1475","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=1475"}],"version-history":[{"count":3,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1475\/revisions"}],"predecessor-version":[{"id":1484,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1475\/revisions\/1484"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}