<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: BAPI for automatic Pr creation witth multiple files from excel sheet in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-for-automatic-pr-creation-witth-multiple-files-from-excel-sheet/m-p/7225326#M1524295</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can someone please give me sol........&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Aug 2010 05:56:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-08-06T05:56:01Z</dc:date>
    <item>
      <title>BAPI for automatic Pr creation witth multiple files from excel sheet</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-for-automatic-pr-creation-witth-multiple-files-from-excel-sheet/m-p/7225325#M1524294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have written a programm  for automatic PR creation  with the help of bapi , where its picks data from excel sheet and makes PR .It is picking excel files from one folder(Files) for PR creation and moving to another folder(Files sucess).&lt;/P&gt;&lt;P&gt;now the problem is if Folder (Files) contains one excel sheet ,PR is created fine , but if the Folder(Files) have multiple excel sheet ,its is creating 1st PR right, but next PR's contains all the line item of 1st PR , 2nd PR and so on .can anyone suggest me where is the problem in codes.&lt;/P&gt;&lt;P&gt;types : begin of x_file ,&lt;/P&gt;&lt;P&gt;        key1(10),&lt;/P&gt;&lt;P&gt;        pur_grp(4),&lt;/P&gt;&lt;P&gt;        maktx(40),&lt;/P&gt;&lt;P&gt;        plant(4) ,&lt;/P&gt;&lt;P&gt;        req(10),&lt;/P&gt;&lt;P&gt;        s_qty(13),&lt;/P&gt;&lt;P&gt;        wbs(24),&lt;/P&gt;&lt;P&gt;        gl(10),&lt;/P&gt;&lt;P&gt;        trackno(10),&lt;/P&gt;&lt;P&gt;        supl(4),&lt;/P&gt;&lt;P&gt;        deladd(255).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;types : end of x_file .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  data : str5 type char10.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  data : mm type char2.&lt;/P&gt;&lt;P&gt;  data : yyyy type char4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  data : dd type char2.&lt;/P&gt;&lt;P&gt;  data : str9 type char10.&lt;/P&gt;&lt;P&gt;  data : str6 type char10.&lt;/P&gt;&lt;P&gt;  data : month type char2.&lt;/P&gt;&lt;P&gt;  data : year type char4.&lt;/P&gt;&lt;P&gt;  year = sy-datum+0(4).&lt;/P&gt;&lt;P&gt;  month = sy-datum+4(2).&lt;/P&gt;&lt;P&gt;  dd = sy-datum+6(2).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  yyyy = sy-datum+0(4).&lt;/P&gt;&lt;P&gt;  mm = sy-datum+4(2).&lt;/P&gt;&lt;P&gt;  dd = sy-datum+6(2).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  clear str6 .&lt;/P&gt;&lt;P&gt;  clear str5.&lt;/P&gt;&lt;P&gt;  concatenate  dd'.' month '.' year into str5 .&lt;/P&gt;&lt;P&gt;  concatenate  yyyy mm dd into str6 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : file type rlgrap-filename .&lt;/P&gt;&lt;P&gt;data : it_file type table of x_file .&lt;/P&gt;&lt;P&gt;data : wa_file type x_file .&lt;/P&gt;&lt;P&gt;data : it_header type table of x_file .&lt;/P&gt;&lt;P&gt;data : wa_header type x_file .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;*&amp;amp;  Internal Table For Define Row and Coloum Postion&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;data: col_start type i value 1 ,&lt;/P&gt;&lt;P&gt;      row_start type i value 2,&lt;/P&gt;&lt;P&gt;      col_end type i value 256 ,&lt;/P&gt;&lt;P&gt;      row_end type i value 65000 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;*&amp;amp;  Internal Table For Retrieve  Data From Excel&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;*data: excel_bdcdata like kcde_cells occurs 0 with header line.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;*data: excel_bdcdata1 like kcde_cells occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data: excel_bdcdata like ALSMEX_TABLINE occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: excel_bdcdata1 like ALSMEX_TABLINE occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: it_index type i.&lt;/P&gt;&lt;P&gt;DATA : IT_INDEX1 TYPE I.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;*&amp;amp;  Define Field Symbol&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;field-symbols: &amp;lt;fs&amp;gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data :   bdcdata like bdcdata    occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data :   messtab like bdcmsgcoll occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : req_items type table of bapiebanc .&lt;/P&gt;&lt;P&gt;data : wa_req_items type bapiebanc .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : req_acc_asg type table of bapiebkn.&lt;/P&gt;&lt;P&gt;data : wa_req_acc_asg type bapiebkn.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : RETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE .&lt;/P&gt;&lt;P&gt;*data : return type table of	bapireturn.&lt;/P&gt;&lt;P&gt;*&lt;/P&gt;&lt;P&gt;*data : wa_return type bapireturn .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : number type ebeln .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*****************************&lt;STRONG&gt;MOVE FILES&lt;/STRONG&gt;******************************&lt;/P&gt;&lt;P&gt;data : xsource type string .&lt;/P&gt;&lt;P&gt;data : xdestin type string .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : destin1 type string .&lt;/P&gt;&lt;P&gt;data : destin2 type string .&lt;/P&gt;&lt;P&gt;DATA : DEST1 TYPE STRING.&lt;/P&gt;&lt;P&gt;DATA : DEST11 TYPE STRING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : DEST2 TYPE STRING.&lt;/P&gt;&lt;P&gt;DATA : DEST22 TYPE STRING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : sou_dir_name like SALFILE-LONGNAME.&lt;/P&gt;&lt;P&gt;data : tar_dir_name like SALFILE-LONGNAME.&lt;/P&gt;&lt;P&gt;data : tar_dir_name1 like SALFILE-LONGNAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : sou_filename like EDI_PATH-PTHNAM .&lt;/P&gt;&lt;P&gt;data : tar_filename like EDI_PATH-PTHNAM .&lt;/P&gt;&lt;P&gt;data : filename1  type string .&lt;/P&gt;&lt;P&gt;data : tar_filename1 like EDI_PATH-PTHNAM .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : file_itab like SALFLDIR occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data : wa_file_itab like SALFLDIR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : file_count type i .&lt;/P&gt;&lt;P&gt;data : dir_count type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : dir_table like sdokpath occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : file_table like SDOKPATH occurs 0 with header line.&lt;/P&gt;&lt;P&gt;data : wa_file_table like sdokpath.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : strr type string ,&lt;/P&gt;&lt;P&gt;       str1 type string ,&lt;/P&gt;&lt;P&gt;       str2 type string ,&lt;/P&gt;&lt;P&gt;       str3 type string .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : PA_VAL TYPE CHAR1.&lt;/P&gt;&lt;P&gt;sou_dir_name = 'D:\barcodes\files\'.&lt;/P&gt;&lt;P&gt;tar_dir_name = 'D:\barcodes\files-success\'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    "success folder.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'&lt;/P&gt;&lt;P&gt;  EXPORTING&lt;/P&gt;&lt;P&gt;    DIRECTORY  = sou_dir_name&lt;/P&gt;&lt;P&gt;    FILTER     = '&lt;STRONG&gt;.&lt;/STRONG&gt;'&lt;/P&gt;&lt;P&gt;  IMPORTING&lt;/P&gt;&lt;P&gt;    FILE_COUNT = file_count&lt;/P&gt;&lt;P&gt;    DIR_COUNT  = dir_count&lt;/P&gt;&lt;P&gt;  TABLES&lt;/P&gt;&lt;P&gt;    FILE_TABLE = file_table&lt;/P&gt;&lt;P&gt;    DIR_TABLE  = dir_table&lt;/P&gt;&lt;P&gt;  EXCEPTIONS&lt;/P&gt;&lt;P&gt;    CNTL_ERROR = 1&lt;/P&gt;&lt;P&gt;    OTHERS     = 2.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at file_table into wa_file_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear  :  strr , str1 , str2 , str3 .&lt;/P&gt;&lt;P&gt;  strr = wa_file_table-PATHNAME .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  concatenate sou_dir_name strr into str1 .&lt;/P&gt;&lt;P&gt;  concatenate tar_dir_name strr into str2 . " success&lt;/P&gt;&lt;P&gt;  concatenate tar_dir_name1 strr into str3 .         " failed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FILE = STR1 .&lt;/P&gt;&lt;P&gt;*start-of-selection.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;*&amp;amp;  Function For Retrieve Data From Excel&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*************************************************************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'&lt;/P&gt;&lt;P&gt;  EXPORTING&lt;/P&gt;&lt;P&gt;    filename                      = FILE&lt;/P&gt;&lt;P&gt;    i_begin_col                   = col_start&lt;/P&gt;&lt;P&gt;    i_begin_row                   = row_start&lt;/P&gt;&lt;P&gt;    i_end_col                     = col_end&lt;/P&gt;&lt;P&gt;    i_end_row                     = row_end&lt;/P&gt;&lt;P&gt;  tables&lt;/P&gt;&lt;P&gt;    intern                        = excel_bdcdata&lt;/P&gt;&lt;P&gt; EXCEPTIONS&lt;/P&gt;&lt;P&gt;   INCONSISTENT_PARAMETERS       = 1&lt;/P&gt;&lt;P&gt;   UPLOAD_OLE                    = 2&lt;/P&gt;&lt;P&gt;   OTHERS                        = 3.&lt;/P&gt;&lt;P&gt;  IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;WRITE : / 'File Error'.&lt;/P&gt;&lt;P&gt;EXIT.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;        .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  loop at excel_bdcdata.&lt;/P&gt;&lt;P&gt;    translate excel_bdcdata to upper case .&lt;/P&gt;&lt;P&gt;    move excel_bdcdata-col to it_index.&lt;/P&gt;&lt;P&gt;    assign component it_index of  structure  wa_file to &amp;lt;fs&amp;gt; .&lt;/P&gt;&lt;P&gt;    move excel_bdcdata-value to &amp;lt;fs&amp;gt;.&lt;/P&gt;&lt;P&gt;    at end of row.&lt;/P&gt;&lt;P&gt;      append wa_file to it_file .&lt;/P&gt;&lt;P&gt;        clear wa_file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;********************************************************************&lt;/P&gt;&lt;P&gt;sort it_file by key1. "pur_grp maktx plant  .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_header[] = it_file[].&lt;/P&gt;&lt;P&gt;delete adjacent duplicates from it_header comparing key1 pur_grp maktx&lt;/P&gt;&lt;P&gt;plant .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : h_item(5) type n .&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;data : h_pack(10) type n .&lt;/P&gt;&lt;P&gt;data : line_no(5) type n .&lt;/P&gt;&lt;P&gt;data : ln_no(5) type n .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_header into wa_header .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; ln_no = 1.&lt;/P&gt;&lt;P&gt;h_item = h_item + 10.&lt;/P&gt;&lt;P&gt;h_pack = h_pack + 1.&lt;/P&gt;&lt;P&gt;wa_req_items-preq_item = h_item .&lt;/P&gt;&lt;P&gt;wa_req_items-doc_type = 'BOM'.&lt;/P&gt;&lt;P&gt;wa_req_items-pur_group = wa_header-pur_grp .&lt;/P&gt;&lt;P&gt;wa_req_items-MATERIAL = wa_header-maktx .&lt;/P&gt;&lt;P&gt;wa_req_items-plant = wa_header-plant .&lt;/P&gt;&lt;P&gt;wa_req_items-pckg_no =  h_pack .&lt;/P&gt;&lt;P&gt;wa_req_items-deliv_date = str6 .&lt;/P&gt;&lt;P&gt;wa_req_items-item_cat = '0'.&lt;/P&gt;&lt;P&gt;wa_req_items-acctasscat = 'P'.&lt;/P&gt;&lt;P&gt;*wa_req_items-distrib = '2' .&lt;/P&gt;&lt;P&gt;**wa_req_items-gr_ind = 'X'.&lt;/P&gt;&lt;P&gt;wa_req_items-ir_ind = '2'.&lt;/P&gt;&lt;P&gt;wa_req_items-purch_org = 'TISL' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_req_items-QUANTITY =  wa_header-s_qty.&lt;/P&gt;&lt;P&gt;wa_req_items-PREQ_NAME =  wa_header-req.&lt;/P&gt;&lt;P&gt;wa_req_items-SUPPL_PLNT = wa_header-supl.&lt;/P&gt;&lt;P&gt;wa_req_items-trackingno = wa_header-trackno.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;append wa_req_items to req_items .&lt;/P&gt;&lt;P&gt;clear wa_req_items.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa_req_acc_asg-preq_item = h_item . &lt;/P&gt;&lt;P&gt;wa_req_acc_asg-g_l_acct = wa_file-gl .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WA_req_acc_asg-wbs_elem  = wa_header-wbs .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;append wa_req_acc_asg to req_acc_asg .&lt;/P&gt;&lt;P&gt;clear wa_req_acc_asg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;h_pack = h_pack + 1  .&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;clear ln_no .&lt;/P&gt;&lt;P&gt;***BREAK-POINT.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*********************************************************************&lt;/P&gt;&lt;P&gt;*&amp;amp; BAPI FUNCTION&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;*********************************************************************&lt;/P&gt;&lt;P&gt;call function 'BAPI_REQUISITION_CREATE'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; importing&lt;/P&gt;&lt;P&gt;   number                               = number&lt;/P&gt;&lt;P&gt;  tables&lt;/P&gt;&lt;P&gt;    requisition_items                   = req_items&lt;/P&gt;&lt;P&gt;   requisition_account_assignment       = req_acc_asg&lt;/P&gt;&lt;P&gt;   return                               = return .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 07:44:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-for-automatic-pr-creation-witth-multiple-files-from-excel-sheet/m-p/7225325#M1524294</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-08-04T07:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: BAPI for automatic Pr creation witth multiple files from excel sheet</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-for-automatic-pr-creation-witth-multiple-files-from-excel-sheet/m-p/7225326#M1524295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can someone please give me sol........&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Aug 2010 05:56:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-for-automatic-pr-creation-witth-multiple-files-from-excel-sheet/m-p/7225326#M1524295</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-08-06T05:56:01Z</dc:date>
    </item>
  </channel>
</rss>

