Application Development and Automation 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: 
Read only

Uploading excel file using Bapi f-02

Former Member
0 Likes
5,160

Hi guys

I have a very short memory on how to use BAPIs.I have been requested to develop a program for uploading an excel template using t-code f-02.So far i did my recording using BDC i developed my program.and on executing the batch cannot continue after posting to 30 line items,in my template am supposed to post up to 60 line items and i understand SAP can take up to 999 line items.A sample screen shot might elaborate.

Attached is my code snippet and template as well.I tried to do several checks and tests and am seeing i cant succeed.I came across someone on the net who was advising me to use a BAPI.Now my challenge is how to use a BAPI to upload this template.A sample code snippet might help.

I have also noticed that 'BAPI_ACC_DOCUMENT_POST' is also used to post to F-02,but i dont know how to get my way out with this BAPI.

Please help.

Regards

Rejoice

Hi guys

I have a very short memory on how to use BAPIs.I have been requested to develop a program for uploading an excel template using t-code f-02.So far i did my recording using BDC i developed my program.and on executing the batch cannot continue after posting to 30 line items,in my template am supposed to post up to 60 line items and i understand SAP can take up to 999 line items.A sample screen shot might elaborate.

Attached is my code snippet and template as well.I tried to do several checks and tests and am seeing i cant succeed.I came across someone on the net who was advising me to use a BAPI.Now my challenge is how to use a BAPI to upload this template.A sample code snippet might help.

I have also noticed that 'BAPI_ACC_DOCUMENT_POST' is also used to post to F-02,but i dont know how to get my way out with this BAPI.

Please help.

Regards

Rejoice

5 REPLIES 5
Read only

nandakumar_sasidharan
Participant
0 Likes
3,758

Hi Rejoice,

Please follow the below steps,

1. Upload the excel data from the PC to program using the function module 'GUI_DOWNLOAD' by passing  the filename.

2. You will get the content into the data_tab internal table.

3. Process the data and and pass the values to appropriate parameters of BAPI( is a function module used to post the data to SAP) which you have mentioned.

4. Get the information(Success/Fail) about the posting in the RETURN parameter of BAPI.

Hope this clears your doubt.

Regards,

Nandakumar/message/15135689/edit

Read only

VenkatRamesh_V
Active Contributor
0 Likes
3,758

Hi,

Goto SE 37 enter BAPI_ACC_DOCUMENT_POST Click Function module Documentation.

Regards,

Venkat

Read only

0 Likes
3,758

Hi guys.I tried the following code and i am stuck.

Report ZTRIAL

        no standard page heading line-size 255.

include zbdcrecx1.

TABLES: BSEG, BKPF.

TYPES: BEGIN OF it_lines, "Work table used for upload

line(1000) TYPE c,

  END OF it_lines.

DATA:      HEADER  LIKE  bapiache09,

       accountgl LIKE  bapiacgl09 OCCURS 0 WITH HEADER LINE,

       t_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

       CURRENCYAMOUNT LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,

       w_item_gl     TYPE bapiacgl09,

       t_item_gl   TYPE STANDARD TABLE OF bapiacgl09.

TYPES:BEGIN OF it_posting, "Work table used for upload

   company(4) TYPE N,

   doc_date(10) TYPE N,

   pstng_date(10) TYPE N,

   doc_type(2) Type N,

   fiscal_yr(10) TYPE N,

   ref_doc_no(15) TYPE N,

   pkey(2) type N,

   gl_account(018) TYPE N,

   busarea(4) TYPE N,

   pcenter(010) TYPE N,

   assignment(018) TYPE N,

   text(050) TYPE N,

   amount(016) TYPE N,

   tax(004) TYPE N,

END OF it_posting.

Data: it_posting TYPE STANDARD TABLE OF it_posting,

       w_postings type it_posting,

       t_curr TYPE STANDARD TABLE OF t001 ,

       w_curr type t001,

       w_item_curr   TYPE bapiaccr09,

       t_item_curr TYPE STANDARD TABLE OF bapiaccr09.

DATA : g_credit_total like bseg-dmbtr,

       g_debit_total  like bseg-dmbtr.

CONSTANTS: g_error_flag VALUE 'X'" Flag.

CONSTANTS : c_x    VALUE 'X'" Flag

data:

       g_obj_type like bapiache02-obj_type,

       g_obj_key like bapiache02-obj_key,

       g_obj_sys like bapiache02-obj_sys.

DATA: it_lines TYPE it_lines OCCURS 0 WITH HEADER LINE.

DATA: p_file1 TYPE string.

PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.

initialization.

user = sy-uname.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

   CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

     CHANGING

       file_name     = p_file

     EXCEPTIONS

       mask_too_long = 1

       OTHERS        = 2.

START-OF-SELECTION.

   p_file1 = p_file.

   CALL FUNCTION 'GUI_UPLOAD'

     EXPORTING

       filename = p_file1

       filetype = 'ASC'

     TABLES

       data_tab = it_lines .

   IF sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   ENDIF.

LOOP AT it_lines.

     SPLIT it_lines-line AT ',' INTO

w_postings-company

w_postings-doc_date

w_postings-pstng_date

w_postings-ref_doc_no

w_postings-pkey

w_postings-gl_account

w_postings-busarea

w_postings-pcenter

w_postings-assignment

w_postings-text

w_postings-amount

w_postings-tax

w_postings-amount .

APPEND w_postings TO it_posting.

*ENDIF.

ENDLOOP.

CLEAR:

  w_postings.

LOOP AT it_posting into w_postings.

   endloop.

   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'

   FORM populate_bapi USING rlv_counter TYPE posnr_acc.

**Populate line item details

   CONSTANTS : c_x    VALUE 'X'" Flag

   data g_cross_flag.

   IF w_postings-company NE Header-comp_code.

g_cross_flag = c_x.

   ENDIF.

*Fill Credit line item data

IF w_postings-pkey = 25.

w_item_gl-itemno_acc      = rlv_counter.

w_item_gl-comp_code       = w_postings-company.

w_item_gl-gl_account      = w_postings-gl_account.

w_item_gl-pstng_date      = header-pstng_date.

w_item_gl-BUS_AREA         = w_postings-busarea.

w_item_gl-profit_ctr      = w_postings-pcenter.

*w_item_gl-tax_code        = w_postings-tax_code.

w_item_gl-ALLOC_NMBR      = w_postings-assignment.

w_item_gl-ITEM_TEXT       = w_postings-text.

     APPEND w_item_gl TO t_item_gl.

* To fetch company code currency

       READ TABLE t_curr INTO w_curr

                         WITH KEY bukrs = w_postings-company

                         BINARY SEARCH.

w_item_curr-currency  = w_curr-waers.

w_item_curr-amt_doccur  = w_postings-amount * -1.

     APPEND w_item_curr TO t_item_curr.

CLEAR w_item_curr.

g_credit_total = g_credit_total + w_postings-amount.

* Clear variables

     CLEAR: w_postings,

w_item_curr,

w_curr,

w_item_gl.

*Fill Debit line item data

   ELSEIF w_postings-pkey =  50.

w_item_gl-itemno_acc      = rlv_counter.

w_item_gl-comp_code       = w_postings-company.

w_item_gl-gl_account      = w_postings-gl_account.

w_item_gl-pstng_date      = header-pstng_date.

w_item_gl-BUS_AREA         = w_postings-busarea.

w_item_gl-profit_ctr      = w_postings-pcenter.

w_item_gl-tax_code        = w_postings-tax.

w_item_gl-ALLOC_NMBR      = w_postings-assignment.

w_item_gl-ITEM_TEXT       = w_postings-text.

     APPEND w_item_gl TO t_item_gl.

        READ TABLE t_curr INTO w_curr

                         WITH KEY bukrs = w_postings-company

                         BINARY SEARCH.

w_item_curr-currency  = w_curr-waers.

w_item_curr-amt_doccur  = w_postings-amount * -1.

     APPEND w_item_curr TO t_item_curr.

CLEAR w_item_curr.

g_credit_total = g_credit_total + w_postings-amount.

* Clear variables

     CLEAR: w_postings,

w_item_curr,

w_curr,

w_item_gl.

endif.

endform.

FORM post_document.

   TYPES:BEGIN OF type_bkpf,

bukrs TYPE bkpf-bukrs,

belnr TYPE bkpf-belnr,

gjahr TYPE bkpf-gjahr,

         END OF  type_bkpf.

*Local variable declarations

   DATA: lv_belnr   TYPE belnr_d,

lv_bukrs   TYPE bukrs,

lv_gjahr   TYPE gjahr,

*lw_message TYPE type_message,

lv_msg     TYPE symsgv,

*lv_rdate   TYPE sy-datum,

lt_return  TYPE STANDARD TABLE OF bapiret2,

lw_return  TYPE bapiret2,                           "#EC NEEDED

lt_bkpf    TYPE STANDARD TABLE OF type_bkpf,

lw_bkpf    TYPE type_bkpf.

*lv_bvorg   TYPE bvor-bvorg.

*Clear local work area and variables

*lw_message,

   CLEAR:

lv_msg,

lw_return,

lw_bkpf.

   CLEAR: header-obj_type,

header-obj_key,

header-obj_sys.

   IF g_error_flag NE c_x.

     IF g_credit_total <> 0 AND g_debit_total <> 0.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'

     EXPORTING

documentheader =  header

     TABLES

accountgl      = t_item_gl

currencyamount = t_item_curr

       return         = t_return.

If t_return is not initial.

* Posting journal entries

   CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

     EXPORTING

documentheader = header

     IMPORTING

obj_type       = g_obj_type

obj_key        = g_obj_key

obj_sys        = g_obj_sys

     TABLES

accountgl      = t_item_gl

currencyamount = t_item_curr

       return   = t_return.

IF sy-subrc <> 0.

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

           EXPORTING

             wait = c_x.

       ENDIF.

Endif.

Endif.

ENDIF.

ENDFORM." POPULATE_BAPI

Read only

0 Likes
3,758

Hi, Rejoice

Before Appending to bapi itab,

use FM

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


for GL Account Number


Regards,

Venkat.

Read only

0 Likes
3,758

Rejoice, just a suggestion - you might want to post more specific questions since we're unable to read minds here on SCN (yet!). It's not quite reasonable to expect the SCN members to review your whole code and then guess what might not be working. What exactly does "stuck" mean?

Please read this blog and this one before posting further questions on SCN.

Thank you.