Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

HI ALL

Former Member
0 Kudos
104

hi all

i am having n number of line itms. i want to craete invoice for a set of 500 line items.ie if i am having 1100 items means i have to create 3 invoice. 500 + 500 + 100. for that i am havin bapi to post invoice, any suggestions plz

regards

karthik

1 ACCEPTED SOLUTION

Former Member
0 Kudos
77

Similar logic, I had implemented earlier. Check if it helps.

l_counter = 0.
  LOOP AT p_it_jour_item INTO l_wa_jour_item
               WHERE zjenum = p_wa_jour_header-zjenum.

    l_counter = l_counter + 1.


    l_wa_bapi_item-itemno_acc = l_counter.  "Item Number
    l_wa_bapi_item-gl_account = l_wa_jour_item-hkont. "GL Account
    l_wa_bapi_item-comp_code = l_wa_jour_item-bukrs. "Company code
*    l_wa_bapi_item-value_date =  l_last_day.        "Value Date
    l_wa_bapi_item-pstng_date = l_wa_jour_item-budat. "Psntg Date
    l_wa_bapi_item-costcenter = l_wa_jour_item-kostl. "Cost Center
    l_wa_bapi_item-orderid = l_wa_jour_item-aufnr.  "Order Number
    wa_bapi_header-header_txt = l_wa_jour_item-belnr. "Acc doc no.
    l_wa_bapi_item-alloc_nmbr = l_wa_jour_item-zuonr. "Alloc Number
    l_wa_bapi_item-profit_ctr = l_wa_jour_item-prctr. "Profit Center
*    l_wa_bapi_item-acct_key = l_wa_jour_item-bewar. "Account Key
    l_wa_bapi_item-cs_trans_t = l_wa_jour_item-bewar.

    APPEND l_wa_bapi_item TO p_it_bapi_item.

*Populate the amount structure
    l_wa_bapi_amnt-itemno_acc = l_counter.    "Item Number
*Check for debit / Credit
    IF l_wa_jour_item-shkzg = c_h.
*Credit
      l_wa_bapi_amnt-amt_doccur = l_wa_jour_item-pswbt.
    ELSE.
*debit
      l_wa_bapi_amnt-amt_doccur = -1 * l_wa_jour_item-pswbt.
    ENDIF.
* Sum for splitting
    l_current_sum = l_current_sum + l_wa_bapi_amnt-amt_doccur.
    l_wa_bapi_amnt-currency = p_wa_jour_header-waers.
    APPEND l_wa_bapi_amnt TO p_it_bapi_amnt.


    IF l_counter EQ 249.

      l_fl_file_split = c_x. "File has been split

      l_wa_bapi_item-itemno_acc = l_counter + 1.  "Item Number
      l_wa_bapi_item-gl_account = p_gl_account.
      l_wa_bapi_item-comp_code = l_wa_jour_item-bukrs. "Company code
*      l_wa_bapi_item-value_date =  l_last_day.        "Value Date
      l_wa_bapi_item-pstng_date = l_wa_jour_item-budat. "Psntg Date
      l_wa_bapi_item-costcenter = l_wa_jour_item-kostl. "Cost Center
      l_wa_bapi_item-orderid = l_wa_jour_item-aufnr.  "Order Number
      l_wa_bapi_item-ac_doc_no = l_wa_jour_item-belnr. "Acc doc no.
      l_wa_bapi_item-alloc_nmbr = l_wa_jour_item-zuonr. "Alloc Number
      l_wa_bapi_item-profit_ctr = l_wa_jour_item-prctr. "Profit Center
*      l_wa_bapi_item-acct_key = l_wa_jour_item-bewar. "Account Key
      l_wa_bapi_item-cs_trans_t = l_wa_jour_item-bewar.


      APPEND l_wa_bapi_item TO p_it_bapi_item.

*Populate the amount structure
      l_wa_bapi_amnt-itemno_acc = l_counter + 1.    "Item Number
      l_wa_bapi_amnt-amt_doccur = -1 * l_current_sum.
      CLEAR : l_current_sum , l_counter.
      l_wa_bapi_amnt-currency = p_wa_jour_header-waers.
      APPEND l_wa_bapi_amnt TO p_it_bapi_amnt.

* file is split
      CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
        EXPORTING
          documentheader = p_wa_bapi_header
        TABLES
          accountgl      = p_it_bapi_item
          currencyamount = p_it_bapi_amnt
          return         = l_it_bapi_ret.

      LOOP AT l_it_bapi_ret INTO l_wa_bapi_ret
                       WHERE type = 'E' OR type = 'A' .
        p_v_err_mess = wa_bapi_ret-message.
        APPEND p_v_err_mess TO i_mess.
        l_fl_file_err = c_x.
        EXIT.
      ENDLOOP.

      REFRESH: p_it_bapi_item, p_it_bapi_amnt, l_it_bapi_ret.
    ENDIF.

    IF l_fl_file_err = c_x.
      EXIT.
    ELSE.
      CONCATENATE p_wa_bapi_header-obj_key
                  p_wa_bapi_header-comp_code
                  p_wa_bapi_header-ref_doc_no
                  p_wa_bapi_header-pstng_date
      INTO p_v_err_mess SEPARATED BY c_tab.
      LOOP AT l_it_bapi_ret INTO l_wa_bapi_ret.
        CONCATENATE p_v_err_mess  l_wa_bapi_ret-message
        INTO p_v_err_mess SEPARATED BY c_tab.
        APPEND p_v_err_mess TO i_mess.
        CLEAR p_v_err_mess.
        EXIT.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

  IF l_fl_file_split = c_x.
    CLEAR l_fl_file_split.

    l_wa_bapi_item-itemno_acc = l_counter + 1.  "Item Number
    l_wa_bapi_item-gl_account = p_gl_account.
    l_wa_bapi_item-comp_code = l_wa_jour_item-bukrs. "Company code
*    l_wa_bapi_item-value_date =  l_last_day.        "Value Date
    l_wa_bapi_item-pstng_date = l_wa_jour_item-budat. "Psntg Date
    l_wa_bapi_item-costcenter = l_wa_jour_item-kostl. "Cost Center
    l_wa_bapi_item-orderid = l_wa_jour_item-aufnr.  "Order Number
    l_wa_bapi_item-ac_doc_no = l_wa_jour_item-belnr. "Acc doc no.
    l_wa_bapi_item-alloc_nmbr = l_wa_jour_item-zuonr. "Alloc Number
    l_wa_bapi_item-profit_ctr = l_wa_jour_item-prctr. "Profit Center
    l_wa_bapi_item-acct_key = l_wa_jour_item-bewar. "Account Key
    l_wa_bapi_item-cs_trans_t = l_wa_jour_item-bewar.

    APPEND l_wa_bapi_item TO p_it_bapi_item.

*Populate the amount structure
    l_wa_bapi_amnt-itemno_acc = l_counter + 1.    "Item Number
    l_wa_bapi_amnt-amt_doccur = -1 * l_current_sum.
    CLEAR : l_current_sum , l_counter.
    l_wa_bapi_amnt-currency = p_wa_jour_header-waers.
    APPEND l_wa_bapi_amnt TO p_it_bapi_amnt.

  ENDIF.
 
*  CALL BAPI AGAIN

  CLEAR l_current_sum.

1 REPLY 1

Former Member
0 Kudos
78

Similar logic, I had implemented earlier. Check if it helps.

l_counter = 0.
  LOOP AT p_it_jour_item INTO l_wa_jour_item
               WHERE zjenum = p_wa_jour_header-zjenum.

    l_counter = l_counter + 1.


    l_wa_bapi_item-itemno_acc = l_counter.  "Item Number
    l_wa_bapi_item-gl_account = l_wa_jour_item-hkont. "GL Account
    l_wa_bapi_item-comp_code = l_wa_jour_item-bukrs. "Company code
*    l_wa_bapi_item-value_date =  l_last_day.        "Value Date
    l_wa_bapi_item-pstng_date = l_wa_jour_item-budat. "Psntg Date
    l_wa_bapi_item-costcenter = l_wa_jour_item-kostl. "Cost Center
    l_wa_bapi_item-orderid = l_wa_jour_item-aufnr.  "Order Number
    wa_bapi_header-header_txt = l_wa_jour_item-belnr. "Acc doc no.
    l_wa_bapi_item-alloc_nmbr = l_wa_jour_item-zuonr. "Alloc Number
    l_wa_bapi_item-profit_ctr = l_wa_jour_item-prctr. "Profit Center
*    l_wa_bapi_item-acct_key = l_wa_jour_item-bewar. "Account Key
    l_wa_bapi_item-cs_trans_t = l_wa_jour_item-bewar.

    APPEND l_wa_bapi_item TO p_it_bapi_item.

*Populate the amount structure
    l_wa_bapi_amnt-itemno_acc = l_counter.    "Item Number
*Check for debit / Credit
    IF l_wa_jour_item-shkzg = c_h.
*Credit
      l_wa_bapi_amnt-amt_doccur = l_wa_jour_item-pswbt.
    ELSE.
*debit
      l_wa_bapi_amnt-amt_doccur = -1 * l_wa_jour_item-pswbt.
    ENDIF.
* Sum for splitting
    l_current_sum = l_current_sum + l_wa_bapi_amnt-amt_doccur.
    l_wa_bapi_amnt-currency = p_wa_jour_header-waers.
    APPEND l_wa_bapi_amnt TO p_it_bapi_amnt.


    IF l_counter EQ 249.

      l_fl_file_split = c_x. "File has been split

      l_wa_bapi_item-itemno_acc = l_counter + 1.  "Item Number
      l_wa_bapi_item-gl_account = p_gl_account.
      l_wa_bapi_item-comp_code = l_wa_jour_item-bukrs. "Company code
*      l_wa_bapi_item-value_date =  l_last_day.        "Value Date
      l_wa_bapi_item-pstng_date = l_wa_jour_item-budat. "Psntg Date
      l_wa_bapi_item-costcenter = l_wa_jour_item-kostl. "Cost Center
      l_wa_bapi_item-orderid = l_wa_jour_item-aufnr.  "Order Number
      l_wa_bapi_item-ac_doc_no = l_wa_jour_item-belnr. "Acc doc no.
      l_wa_bapi_item-alloc_nmbr = l_wa_jour_item-zuonr. "Alloc Number
      l_wa_bapi_item-profit_ctr = l_wa_jour_item-prctr. "Profit Center
*      l_wa_bapi_item-acct_key = l_wa_jour_item-bewar. "Account Key
      l_wa_bapi_item-cs_trans_t = l_wa_jour_item-bewar.


      APPEND l_wa_bapi_item TO p_it_bapi_item.

*Populate the amount structure
      l_wa_bapi_amnt-itemno_acc = l_counter + 1.    "Item Number
      l_wa_bapi_amnt-amt_doccur = -1 * l_current_sum.
      CLEAR : l_current_sum , l_counter.
      l_wa_bapi_amnt-currency = p_wa_jour_header-waers.
      APPEND l_wa_bapi_amnt TO p_it_bapi_amnt.

* file is split
      CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
        EXPORTING
          documentheader = p_wa_bapi_header
        TABLES
          accountgl      = p_it_bapi_item
          currencyamount = p_it_bapi_amnt
          return         = l_it_bapi_ret.

      LOOP AT l_it_bapi_ret INTO l_wa_bapi_ret
                       WHERE type = 'E' OR type = 'A' .
        p_v_err_mess = wa_bapi_ret-message.
        APPEND p_v_err_mess TO i_mess.
        l_fl_file_err = c_x.
        EXIT.
      ENDLOOP.

      REFRESH: p_it_bapi_item, p_it_bapi_amnt, l_it_bapi_ret.
    ENDIF.

    IF l_fl_file_err = c_x.
      EXIT.
    ELSE.
      CONCATENATE p_wa_bapi_header-obj_key
                  p_wa_bapi_header-comp_code
                  p_wa_bapi_header-ref_doc_no
                  p_wa_bapi_header-pstng_date
      INTO p_v_err_mess SEPARATED BY c_tab.
      LOOP AT l_it_bapi_ret INTO l_wa_bapi_ret.
        CONCATENATE p_v_err_mess  l_wa_bapi_ret-message
        INTO p_v_err_mess SEPARATED BY c_tab.
        APPEND p_v_err_mess TO i_mess.
        CLEAR p_v_err_mess.
        EXIT.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

  IF l_fl_file_split = c_x.
    CLEAR l_fl_file_split.

    l_wa_bapi_item-itemno_acc = l_counter + 1.  "Item Number
    l_wa_bapi_item-gl_account = p_gl_account.
    l_wa_bapi_item-comp_code = l_wa_jour_item-bukrs. "Company code
*    l_wa_bapi_item-value_date =  l_last_day.        "Value Date
    l_wa_bapi_item-pstng_date = l_wa_jour_item-budat. "Psntg Date
    l_wa_bapi_item-costcenter = l_wa_jour_item-kostl. "Cost Center
    l_wa_bapi_item-orderid = l_wa_jour_item-aufnr.  "Order Number
    l_wa_bapi_item-ac_doc_no = l_wa_jour_item-belnr. "Acc doc no.
    l_wa_bapi_item-alloc_nmbr = l_wa_jour_item-zuonr. "Alloc Number
    l_wa_bapi_item-profit_ctr = l_wa_jour_item-prctr. "Profit Center
    l_wa_bapi_item-acct_key = l_wa_jour_item-bewar. "Account Key
    l_wa_bapi_item-cs_trans_t = l_wa_jour_item-bewar.

    APPEND l_wa_bapi_item TO p_it_bapi_item.

*Populate the amount structure
    l_wa_bapi_amnt-itemno_acc = l_counter + 1.    "Item Number
    l_wa_bapi_amnt-amt_doccur = -1 * l_current_sum.
    CLEAR : l_current_sum , l_counter.
    l_wa_bapi_amnt-currency = p_wa_jour_header-waers.
    APPEND l_wa_bapi_amnt TO p_it_bapi_amnt.

  ENDIF.
 
*  CALL BAPI AGAIN

  CLEAR l_current_sum.