SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_ACC_GL_POSTING_POST



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> FI
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Sep 22, 2007 4:51 pm    Post subject: BAPI_ACC_GL_POSTING_POST Reply with quote

Code:

Author: pradeepchoudhari
REPORT zpradeep_gl_posting.

DATA:
* Structure for document header
g_docheader LIKE bapiache08,
* Table and header for G/L Account Line Items
gi_accountgl TYPE STANDARD TABLE OF bapiacgl08,
g_accountgl LIKE bapiacgl08,
* Table and header for Line Item Currency Fields
gi_amount TYPE STANDARD TABLE OF bapiaccr08,
g_amount LIKE bapiaccr08,
* Return
gi_return TYPE STANDARD TABLE OF bapiret2,
g_return LIKE bapiret2.

START-OF-SELECTION.
*---------------------------------------------------------
* HEADER DATA
*
* OBJ_TYPE Objekttypes can be found in table TTYP
* OBJ_KEY Seems that you can use any value
* OBJ_SYS Logical system. Logical ystems can be found in
* table TBDLS. If there is no logical system assigned
* to the client, assign it this way:
*
* Transaction: SPRO
* - Basis components
* - Application Link Enabling (ALE)

* - Sending and receiving systems
* - Logical systems
* - Define logical system
* - Assign client o logical system
*
*
*---------------------------------------------------------
g_docheader-obj_type = 'BKPFF'.
g_docheader-obj_key = '1'.
g_docheader-obj_sys = 'B3TCLNT800'.
g_docheader-username = sy-uname.
g_docheader-header_txt = 'BAPI test'.
g_docheader-comp_code = '1000'.

g_docheader-doc_date = sy-datum.

APPEND g_amount TO gi_amount.

*---------------------------------------------------------
* LINE ITEMS
*---------------------------------------------------------
* Item 1
g_accountgl-itemno_acc = '0000000001'.
g_accountgl-gl_account = '0000192600'.
g_accountgl-pstng_date = sy-datum.

APPEND g_accountgl TO gi_accountgl.


* Item 2
g_accountgl-itemno_acc = '0000000002'.
g_accountgl-gl_account = '0000192600'.

g_accountgl-pstng_date = sy-datum.

APPEND g_accountgl TO gi_accountgl.

*---------------------------------------------------------
* CURRENCY AND AMOUNT
*---------------------------------------------------------
* Item 1
g_amount-itemno_acc = '0000000001'.
g_amount-currency = 'EUR'.
g_amount-amt_doccur = 5000.

APPEND g_amount TO gi_amount.

* Item 2
g_amount-itemno_acc = '0000000002'.
g_amount-currency = 'EUR'.
g_amount-amt_doccur = -5000.

APPEND g_amount TO gi_amount.


END-OF-SELECTION.
* Call the BAPI function
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
EXPORTING
documentheader = g_docheader
* IMPORTING
* OBJ_TYPE =
* OBJ_KEY =
* OBJ_SYS =
TABLES
accountgl = gi_accountgl
currencyamount = gi_amount
return = gi_return
* EXTENSION1 =
.

LOOP AT gi_return INTO g_return.

WRITE: / g_return-message.
ENDLOOP.



Example 2
try implementing OSS 561175 which will get the system to calculate the next FI document number

Code:
REPORT yrb_test_doc_postng_via_bapi.

DATA: doc_header LIKE bapiache08,
      doc_item   LIKE bapiacgl08 OCCURS 0 WITH HEADER LINE,
      doc_values LIKE bapiaccr08 OCCURS 0 WITH HEADER LINE,
      return     LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
      extension1 like BAPIEXTC occurs 0 with header line,
      obj_type   LIKE bapiache08-obj_type,
      obj_key    LIKE bapiache02-obj_key,
      obj_sys    LIKE bapiache02-obj_sys,
      docnum     LIKE bkpf-belnr.

* Fill Document Header
doc_header-username = sy-uname.
doc_header-header_txt = 'TEST BOC BAPI POSTING'.
doc_header-comp_code = '1500'.
doc_header-doc_date = '20040901'.
doc_header-pstng_date = sy-datlo.
doc_header-doc_type = 'SA'.
* Fill Line 1 of Document Item
doc_item-itemno_acc = '1'.
doc_item-gl_account = '0000084600'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING DEBIT ITEM'.
doc_item-costcenter = '0000006300'.
doc_item-orderid = 'M5253'.
APPEND doc_item.
CLEAR doc_item.
* Fill Line 2 of Document Item
doc_item-itemno_acc = '2'.
doc_item-gl_account = '0000021960'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
APPEND doc_item.
CLEAR doc_item.
* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'GBP'.
doc_values-amt_doccur = '0.02-'.
APPEND doc_values.
CLEAR doc_values.
* Fill Line 2 of Document Value
doc_values-itemno_acc = '2'.
doc_values-currency_iso = 'GBP'.
doc_values-amt_doccur = '0.02'.
APPEND doc_values.
CLEAR doc_values.
* Add tax code in extension1 table.
extension1-field1 = 'BAPI CALL'.
APPEND EXTENSION1.
* All tables filled - now call BAPI.
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
  EXPORTING
    documentheader       = doc_header
  IMPORTING
    OBJ_TYPE             = doc_header-obj_type
    OBJ_KEY              = doc_header-obj_key
    OBJ_SYS              = doc_header-obj_sys
  TABLES
    accountgl            = doc_item
    currencyamount       = doc_values
    return               = return
    EXTENSION1           = EXTENSION1.
LOOP AT return WHERE type = 'E'.
  EXIT.
ENDLOOP.
IF sy-subrc EQ 0.
  WRITE: / 'BAPI call failed - debug and fix!'.
ELSE.
  CLEAR return.
  REFRESH return.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
   IMPORTING
     return        = return.
  WRITE: / 'BAPI call worked!!'.
  WRITE: / doc_header-obj_key, ' posted'.
ENDIF.


Example 3
Code:

REPORT  Z_FI_GL_POSTING.
 
 
include <icon>.
 
*/ =================================================================== *
CONSTANTS: on  VALUE 'X',
           off VALUE ' ',
           tabx TYPE X VALUE '09',
 
           c_e1bpache08 TYPE edilsegtyp VALUE 'E1BPACHE08',
           c_e1bpacgl08 TYPE edilsegtyp VALUE 'E1BPACGL08',
           c_e1bpaccr08 TYPE edilsegtyp VALUE 'E1BPACCR08'.
 
TYPES: BEGIN OF t_tab_index,
          from TYPE i,
          to   TYPE i,
       END   OF t_tab_index.
 
data :    tab type c.
 
DATA:
      e1bpache08 LIKE e1bpache08,
      e1bpacgl08 LIKE e1bpacgl08,
      e1bpaccr08 LIKE e1bpaccr08.
 
 
DATA:      g_subrc    TYPE subrc.
DATA:      g_file     TYPE string.
DATA:      g_segname  TYPE edilsegtyp.
DATA:      g_sdata    TYPE edi_sdata.
DATA:      g_first_doc.
DATA:      i_dataf     TYPE char2000   OCCURS 900 WITH HEADER LINE,
           i_dataf_doc TYPE char2000   OCCURS  50 WITH HEADER LINE.
 
DATA:      g_tab_index TYPE t_tab_index OCCURS 100 WITH HEADER LINE.
 
DATA:      i_accountgl TYPE bapiacgl08 OCCURS 100 WITH HEADER LINE,
           i_curramnt  TYPE bapiaccr08 OCCURS 100 WITH HEADER LINE,
           i_return    TYPE bapiret2   OCCURS  10 WITH HEADER LINE,
           g_docheader TYPE bapiache08.
 
*/ ======================== SELECTION ================================ *
 
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
PARAMETERS: excelf TYPE file_name LOWER CASE
            DEFAULT 'C:\my_excel_file.txt'.
SELECTION-SCREEN END   OF BLOCK b1.
 
*/ =========================== CORE ================================== *
START-OF-SELECTION.
 
*/ Call text File with GUI_UPLOAD
  g_file = excelf.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                      = g_file
*     FILETYPE                      = 'ASC'
*     HAS_FIELD_SEPARATOR           = ' '
*     HEADER_LENGTH                 = 0
*     READ_BY_LINE                  = 'X'
*   IMPORTING
*     FILELENGTH                    =
*     HEADER                        =
    TABLES
      data_tab                      = i_dataf
    EXCEPTIONS
      file_open_error               = 1
      file_read_error               = 2
      no_batch                      = 3
      gui_refuse_filetransfer       = 4
      invalid_type                  = 5
      no_authority                  = 6
      unknown_error                 = 7
      bad_data_format               = 8
      header_not_allowed            = 9
      separator_not_allowed         = 10
      header_too_long               = 11
      unknown_dp_error              = 12
      access_denied                 = 13
      dp_out_of_memory              = 14
      disk_full                     = 15
      dp_timeout                    = 16
      OTHERS                        = 17
            .
  IF sy-subrc <> 0.
    write: / Text-032.
    stop.
  ENDIF.
 
*/ Initialisation
  write tabx to tab.          " required as of ABAP 610 split cannot
*/                             have mixed char and byte types
  CLEAR   g_tab_index.
  REFRESH g_tab_index.
 
*/ how to process several doc : detecting docs in i_dataf
  g_first_doc = on.
  LOOP AT i_dataf.
    CLEAR: g_segname, g_sdata.
    SPLIT i_dataf AT tab INTO g_segname g_sdata.
    CHECK:  g_segname = c_e1bpache08,
            sy-tabix > 1.
*/ 1st document
    IF g_first_doc = on.
      g_tab_index-from = 1.
      g_tab_index-to   = sy-tabix - 1.
      APPEND g_tab_index.
*/ Next Documents
    ELSE.
      g_tab_index-from = g_tab_index-to + 1.
      g_tab_index-to   = sy-tabix - 1.
      APPEND g_tab_index.
    ENDIF.
    g_first_doc = off.
  ENDLOOP.
*/ Last doc.
  g_tab_index-from = g_tab_index-to + 1.
  g_tab_index-to   = sy-tfill.
  APPEND g_tab_index.
 
*/ Process documents.
  loop at g_tab_index.
     clear   i_dataf_doc.
     refresh i_dataf_doc.
     append lines of i_dataf from g_tab_index-from
                             to   g_tab_index-to
                             to   i_dataf_doc.
     perform process_document.
  endloop.
 
END-OF-SELECTION.
 
*/ =========================== ROUTINES ============================== *
 
*---------------------------------------------------------------------*
*       FORM process_document                                         *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM process_document.
*/ Clearing Memory
  CLEAR:   g_docheader, i_accountgl, i_curramnt, i_return, g_subrc.
  REFRESH:              i_accountgl, i_curramnt, i_return.
 
*/ Checking i_dataf_doc
*/ Mapping dataf => Bapi structures & internal tables
 
  CLEAR g_subrc.
  CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
    LOOP AT i_dataf_doc.
      CLEAR g_sdata.
      SPLIT i_dataf_doc AT tab INTO g_segname g_sdata.
 
      CASE g_segname.
*/ HEADER
        WHEN c_e1bpache08.
          PERFORM do_split_ache08.
          MOVE-CORRESPONDING e1bpache08 TO g_docheader.
 
          IF e1bpache08-doc_date IS INITIAL.
            CLEAR g_docheader-doc_date.
          ENDIF.
          IF e1bpache08-pstng_date IS INITIAL.
            CLEAR g_docheader-pstng_date.
          ENDIF.
          IF e1bpache08-trans_date IS INITIAL.
            CLEAR g_docheader-trans_date.
          ENDIF.
 
*/ Account GL
        WHEN c_e1bpacgl08.
          PERFORM do_split_acgl08.
          MOVE-CORRESPONDING e1bpacgl08 TO i_accountgl.
          IF e1bpacgl08-pstng_date IS INITIAL.
            CLEAR i_accountgl-pstng_date.
          ENDIF.
          APPEND i_accountgl.
 
*/ Account Currency & Amounts
        WHEN c_e1bpaccr08.
          PERFORM do_split_accr08.
          MOVE-CORRESPONDING e1bpaccr08 TO i_curramnt.
          APPEND i_curramnt.
 
*/ kick the line if segment name not filled
        WHEN space.
 
*/ Other names => Bad file structure !
        WHEN OTHERS.
          g_subrc = 2.
      ENDCASE.
 
    ENDLOOP. " i_dataf_doc
  ENDCATCH.
 
 
  IF sy-subrc = 1 OR
  NOT g_subrc IS INITIAL.
    perform message_output using on.
    exit.
  ENDIF.
 
 
*/ Calling the BAPI
  CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
    EXPORTING
      documentheader       = g_docheader
    TABLES
      accountgl            = i_accountgl
      currencyamount       = i_curramnt
      return               = i_return
*   EXTENSION1           =
            .
  LOOP AT i_return WHERE type CA 'AE'.
    g_subrc = 1.
    EXIT.
  ENDLOOP.
 
  IF NOT g_subrc IS INITIAL.
    perform message_output using on.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*        EXPORTING
*           WAIT          =
*        IMPORTING
*           RETURN        =
              .
      perform message_output using off.
  ENDIF.
 
ENDFORM.
 
 
 
*&---------------------------------------------------------------------*
*&      Form  do_split_ACHE08
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM do_split_ache08.
 
  CLEAR e1bpache08.
 
  SPLIT g_sdata AT tab INTO
 
  e1bpache08-obj_type
  e1bpache08-obj_key
  e1bpache08-obj_sys
  e1bpache08-username
  e1bpache08-header_txt
  e1bpache08-obj_key_r
  e1bpache08-comp_code
  e1bpache08-ac_doc_no
  e1bpache08-fisc_year
  e1bpache08-doc_date
  e1bpache08-pstng_date
  e1bpache08-trans_date
  e1bpache08-fis_period
  e1bpache08-doc_type
  e1bpache08-ref_doc_no
  e1bpache08-compo_acc
  e1bpache08-reason_rev
        .
ENDFORM.                    " do_split_ACHE08
*&---------------------------------------------------------------------*
*&      Form  do_split_ACGL08
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM do_split_acgl08.
  CLEAR e1bpacgl08.
  SPLIT  g_sdata AT tab INTO
                  e1bpacgl08-itemno_acc
                  e1bpacgl08-gl_account
                  e1bpacgl08-comp_code
                  e1bpacgl08-pstng_date
                  e1bpacgl08-doc_type
                  e1bpacgl08-ac_doc_no
                  e1bpacgl08-fisc_year
                  e1bpacgl08-fis_period
                  e1bpacgl08-stat_con
                  e1bpacgl08-ref_key_1
                  e1bpacgl08-ref_key_2
                  e1bpacgl08-ref_key_3
                  e1bpacgl08-customer
                  e1bpacgl08-vendor_no
                  e1bpacgl08-alloc_nmbr
                  e1bpacgl08-item_text
                  e1bpacgl08-bus_area
                  e1bpacgl08-costcenter
                  e1bpacgl08-acttype
                  e1bpacgl08-orderid
                  e1bpacgl08-orig_group
                  e1bpacgl08-cost_obj
                  e1bpacgl08-profit_ctr
                  e1bpacgl08-part_prctr
                  e1bpacgl08-wbs_element
                  e1bpacgl08-network
                  e1bpacgl08-routing_no
                  e1bpacgl08-order_itno
                  .
ENDFORM.                    " do_split_ACGL08
 
*&---------------------------------------------------------------------*
*&      Form  do_split_ACCR08
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM do_split_accr08.
  data: l_filler(100).
  CLEAR  e1bpaccr08.
  SPLIT  g_sdata AT tab INTO
            e1bpaccr08-itemno_acc
            e1bpaccr08-curr_type
            e1bpaccr08-currency
            e1bpaccr08-currency_iso
            e1bpaccr08-amt_doccur
            e1bpaccr08-exch_rate
            e1bpaccr08-exch_rate_v
            l_filler
            .
ENDFORM.                    " do_split_ACCR08
*&---------------------------------------------------------------------*
*&      Form  message_output
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_output using if_error.
 
  data: l_message(200),
        l_return type i.
 
   format color 1.
   skip.
   write: / text-020, g_tab_index-from,
            text-021, g_tab_index-to.
   skip.
 
   if if_error = on.
    write: / icon_red_light as icon, text-030 color 6.
   else.
    write: / icon_green_light as icon, text-031 color 5.
   endif.
   describe table i_return lines l_return.
   if l_return is initial.
     write: / text-032.
   endif.
   loop at i_return.
      CALL FUNCTION 'FORMAT_MESSAGE'
        EXPORTING
          ID              = i_return-id
          LANG            = sy-langu
          NO              = i_return-number
          V1              = i_return-MESSAGE_V1
          V2              = i_return-MESSAGE_V2
          V3              = i_return-MESSAGE_V3
          V4              = i_return-MESSAGE_V4
        IMPORTING
          MSG             = l_message
        EXCEPTIONS
          NOT_FOUND       = 1
          OTHERS          = 2
                .
      check sy-subrc = 0.
      write: / l_message.
   endloop.
ENDFORM.                    " message_output


Example 2

Code:
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 :                                                           *
*    -> General ledger account                                         *
*    -> Cost center                                                    *
*    -> WBS element                                                    *
*    -> Order number                                                   *
*    -> Amount                                                         *
*    -> 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&'  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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> FI All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.