<?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 BAPI_ACC_... Pb in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-acc-pb/m-p/927076#M60089</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried : BAPI_ACC_GL_POSTING_POST,&lt;/P&gt;&lt;P&gt;BAPI_ACC_DOCUMENT_POST and BAPI_ACC_EMPLOYEE_EXP_POST, in order to post (F-02) some expenses note.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In all cases, I don't really know how to fill the DOCUMENTHEADER-OBJ_TYPE : 'BBKPF' ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I ve always the same error message : "FI/CO interface: Line item entered several times&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone help me, please ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jun 2005 15:40:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-06-13T15:40:51Z</dc:date>
    <item>
      <title>BAPI_ACC_... Pb</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-acc-pb/m-p/927076#M60089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried : BAPI_ACC_GL_POSTING_POST,&lt;/P&gt;&lt;P&gt;BAPI_ACC_DOCUMENT_POST and BAPI_ACC_EMPLOYEE_EXP_POST, in order to post (F-02) some expenses note.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In all cases, I don't really know how to fill the DOCUMENTHEADER-OBJ_TYPE : 'BBKPF' ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I ve always the same error message : "FI/CO interface: Line item entered several times&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone help me, please ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2005 15:40:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-acc-pb/m-p/927076#M60089</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-06-13T15:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: BAPI_ACC_... Pb</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-acc-pb/m-p/927077#M60090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Erwan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't like this Bapi ...  I give you a code I have wrote .. maybe that will help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I use this BAPI for trans. FB50)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Frédéric&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*----------------------------------------------------------------------*
*   Programme Z_FI_BAPI_FB50.                                          *
*----------------------------------------------------------------------*
*   Program creation of G/L account document.                          *
*   This program make a simulation of the transaction code FB50.       *
*----------------------------------------------------------------------*
report z_fi_bapi_fb50
       no standard page heading
       line-size 80
       line-count 50.





*-------------------------------- DATA --------------------------------*
data : begin of itab_data occurs 500,
         hkont(10)  type c,                 " Compte
         kostl(10)  type c,                 " C.Coût
         posid(24)  type c,                 " Element d'OTP
         aufnr(12)  type c,                 " Ordre
         dmbtr(13)  type c,                 " Montant
         text(50)   type c,                 "texte
       end of itab_data.

data : struct_header type standard table of bapiache08
                     with header line ,
       itab_accountgl type standard table of bapiacgl08
                      with header line ,
       itab_return    type standard table of bapiret2
                      with header line ,
       itab_currency  type standard table of bapiaccr08
                      with header line ,
       itab_extension type standard table of bapiextc
                      with header line .

data : v_obj_type like bapiache02-obj_type,
       v_obj_key  like bapiache02-obj_key,
       v_obj_sys  like bapiache02-obj_sys,
       v_amount(13).

data:  object like nriv-object value 'RF_BELEG'.






*-------------------------- SELECTION SCREEN --------------------------*
selection-screen begin of block b2 with frame title text-002.
parameters : p_bukrs like bkpf-bukrs
                     default '1614',
             p_gjahr like bkpf-gjahr
                     default sy-datum(04),
             p_date  like sy-datum
                     default sy-datum,
             p_waers like bkpf-waers
                     default 'EUR',
             p_bktxt like bkpf-bktxt
                     obligatory ,
             p_file  like ibipparms-path
                     obligatory .
selection-screen end of block b2.

selection-screen begin of block b1 with frame title text-001.
parameters : p_blart1 radiobutton group 01,  "SB
             p_blart2 radiobutton group 01.  "OD
selection-screen end of block b1.





*------------------------------- EVENTS -------------------------------*
at selection-screen on value-request for p_file.
  call function 'F4_FILENAME'
       importing
            file_name = p_file.






*-------------------------------- MAIN --------------------------------*
start-of-selection.


* Read data from the Excel file.
  perform p_read_file.

* Append data for the BAPI.
  perform p_append_data.

* Create the line of account document.
  perform p_create.


end-of-selection.







*----------------------------------------------------------------------*
*   Form P_READ_FILE.                                                  *
*----------------------------------------------------------------------*
*   Reading the content of the file.                                   *
*   Structure of the file.                                             *
*   Column :                                                           *
*    -&amp;gt; General ledger account                                         *
*    -&amp;gt; Cost center                                                    *
*    -&amp;gt; WBS element                                                    *
*    -&amp;gt; Order number                                                   *
*    -&amp;gt; Amount                                                         *
*    -&amp;gt; Document header text                                           *
*----------------------------------------------------------------------*
form p_read_file.


  data : itab_file  like alsmex_tabline occurs 100 with header line ,
         v_flag_row type kcd_ex_row_n ,
         v_count(6) type n .


* Function to read the Microsoft Excel file.
  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       exporting
            filename                = p_file
            i_begin_col             = '1'
            i_begin_row             = '2'
            i_end_col               = '06'
            i_end_row               = '1000'
       tables
            intern                  = itab_file
       exceptions
            inconsistent_parameters = 1
            upload_ole              = 2
            others                  = 3.

  if sy-subrc ne space.
    stop.
  endif.


* Transfer data from ITAB_FILE to ITAB_DATA.
  loop at itab_file.

    if v_flag_row ne itab_file-row.
      append itab_data.
      clear  itab_data.
      move   itab_file-row to v_flag_row.
    endif.

    case itab_file-col.
      when '0001'.
        move itab_file-value to itab_data-hkont.
      when '0002'.
        move itab_file-value to itab_data-kostl.
      when '0003'.
        move itab_file-value to itab_data-posid.
      when '0004'.
        move itab_file-value to itab_data-aufnr.
      when '0005'.
        condense itab_file-value no-gaps.
        replace ',' with '.' into itab_file-value.
        move itab_file-value to itab_data-dmbtr.
      when '0006'.
        move itab_file-value to itab_data-text.
    endcase.

  endloop.


* Record the last row.
  append itab_data.
  clear  itab_data.


* Detele the empty row.
  delete itab_data where hkont eq space.


* Check there is something to do.
  describe table itab_data lines v_count.
  if v_count eq space.
    write : /1 ''.
    stop.
  endif.


endform.                     " P_READ_FILE.








*----------------------------------------------------------------------*
*   Form P_APPEND_DATA.                                                *
*----------------------------------------------------------------------*
*   Append data for the BAPI.                                          *
*----------------------------------------------------------------------*
form p_append_data.


  data : v_logsys  type logsys ,
         v_kostl   type kostl ,
         v_posid   type ps_posid ,
         v_aufnr   type aufnr ,
         v_blart   type blart ,
         v_count   type posnr_acc ,
         v_numkr   type nrnr ,
         v_nrlevel type nrlevel ,
         v_belnr   type belnr_d .



* Get the logical system number.
  select single logsys
         into v_logsys
         from t000
         where mandt eq sy-mandt.


* Get the document type.
  if p_blart1 ne space.
    move 'SB' to v_blart.
  else.
    move 'AB' to v_blart.
  endif.


* Find the next free number.
  select single numkr
         into v_numkr
         from t003
         where blart eq v_blart.
  select single nrlevel
         into v_nrlevel
         from nriv
         where object    eq object
         and   subobject eq p_bukrs
         and   nrrangenr eq v_numkr
         and   toyear    eq p_gjahr.
  v_nrlevel = v_nrlevel + 1.
  move v_nrlevel+10(10) to v_belnr.


* Append the header.
  move :
*         'BKPFF'  to struct_header-obj_type ,
*         v_logsys to struct_header-obj_sys ,
         sy-uname to struct_header-username ,
         p_bukrs  to struct_header-comp_code ,
         v_blart  to struct_header-doc_type ,
*         v_belnr  to struct_header-obj_key+00(10) ,
*         p_bukrs  to struct_header-obj_key+10(04) ,
*         p_gjahr  to struct_header-obj_key+14(04) ,
         p_date   to struct_header-doc_date ,
         p_date   to struct_header-pstng_date ,
         p_bktxt  to struct_header-header_txt .

* Append the post.
  loop at itab_data.

    v_count = v_count + 1.
    clear itab_accountgl.

    move : v_count         to itab_accountgl-itemno_acc ,
           itab_data-hkont to itab_accountgl-gl_account ,
           '00'            to v_kostl+00(02) ,
           itab_data-kostl to v_kostl+02(08) ,
           v_kostl         to itab_accountgl-costcenter ,
           itab_data-posid to v_posid ,
           v_posid         to itab_accountgl-wbs_element ,
           itab_data-aufnr to v_aufnr ,
           v_aufnr         to itab_accountgl-orderid ,
           itab_data-text  to itab_accountgl-item_text .
    if itab_accountgl-costcenter eq '00'.
      clear itab_accountgl-costcenter.
    endif.
    append itab_accountgl.

*   Montant du poste
    move : v_count         to itab_currency-itemno_acc,
           p_waers         to itab_currency-currency  ,
           itab_data-dmbtr to v_amount ,
           v_amount        to itab_currency-amt_doccur .
    append itab_currency.

  endloop.



endform.                     " P_APPEND_DATA.









*----------------------------------------------------------------------*
*  Form P_CREATE.                                                      *
*----------------------------------------------------------------------*
*   Create of G/L account document.                                    *
*----------------------------------------------------------------------*
form p_create.


  data : v_type    like itab_return-type ,
         v_nrlevel like nriv-nrlevel .


* Call the BAPI function
  call function 'BAPI_ACC_GL_POSTING_POST'
       exporting
            documentheader = struct_header
       importing
            obj_type       = v_obj_type
            obj_key        = v_obj_key
            obj_sys        = v_obj_sys
       tables
            accountgl      = itab_accountgl
            currencyamount = itab_currency
            return         = itab_return.

  if sy-subrc eq space.
    commit work and wait.
    if sy-subrc ne space.
      clear itab_return.
      move : 'E'   to itab_return-type,
             'S&amp;amp;'  to itab_return-id,
             '150' to itab_return-number ,
             'ERROR !!'
                   to itab_return-message.
      append itab_return.
      delete itab_return
             where number = '605'.
    endif.
  endif.


* Edit the result of the BAPI.
  loop at itab_return.
    perform p_message_return using itab_return.
    skip 1.
  endloop.

* It the document is create, edit the number.
  read table itab_return
       with key number = '605'.
  if sy-subrc eq space.
    skip 1.
    write : /1 text-003 ,
               ':' ,
               itab_return-message_v2+0(10).
    set parameter id 'BLN' field itab_return-message_v2+0(10).
  endif.


endform.                     " P_CREATE







*----------------------------------------------------------------------*
*   Form P_MESSAGE_RETURN.                                             *
*----------------------------------------------------------------------*
*   Edit the return message.                                           *
*----------------------------------------------------------------------*
form p_message_return
     using struct_return structure bapiret2.


* Color depends of the error type.
  case struct_return-type.
    when 'A'.
      format color 6.
      write : /1  'Termination !' ,
               20 'Classe de message :',
                  struct_return-id ,
               45 'Numéro :' ,
                  struct_return-number ,
              /1  '' ,
              /1  struct_return-message.
      format color off.
    when 'E'.
      format color 6.
      write : /1  'Error !      ' ,
               20 'Classe de message :',
                  struct_return-id ,
               45 'Numéro :' ,
                  struct_return-number ,
              /1  '' ,
              /1  struct_return-message.
      format color off.
    when 'I'.
      format color 5.
      write : /1  'Information. ' ,
               20 'Classe de message :',
                  struct_return-id ,
               45 'Numéro :' ,
                  struct_return-number ,
              /1  '' ,
              /1  struct_return-message.
      format color off.
    when 'S'.
      format color 4.
      write : /1  'Status.      ' ,
               20 'Classe de message :',
                  struct_return-id ,
               45 'Numéro :' ,
                  struct_return-number ,
              /1  '' ,
              /1  struct_return-message.
      format color off.
    when 'W'.
      format color 3.
      write : /1  'Warning !    ' ,
               20 'Classe de message :',
                  struct_return-id ,
               45 'Numéro :' ,
                  struct_return-number ,
              /1  '' ,
              /1  struct_return-message.
      format color off.
    when 'X'.
      format color 6.
      write : /1  'Short dump !!' ,
               20 'Classe de message :',
                  struct_return-id ,
               45 'Numéro :' ,
                  struct_return-number ,
              /1  '' ,
              /1  struct_return-message.
      format color off.
  endcase.


endform.                     " P_MESSAGE_RETURN
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2005 15:53:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-acc-pb/m-p/927077#M60090</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2005-06-13T15:53:05Z</dc:date>
    </item>
  </channel>
</rss>

