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

BAPI Program with Excel uploading

Former Member
0 Likes
5,863

Hi All,

     To start things off, here is the program requirements given to me.

* Create Custom table in database dictionary.

* Create a program that will upload 2 excel files into sap.

* Program must be able to convert files to sap.

* Program will create parked documents. Output should display parked documents.

* Non-SAP standard fields will be needed to be stored in a custom table.

* One time customer and one time vendor transactions should be possible

     Flow logic

Run program ------> *Select files from computer (client side) ------> Upload data into customised table.

I have done the first 2 parts. I have trouble optimizing my program, do you guys have any suggestions? Comments and instructions would be highly recommended.

     Thanks in advance!

Moderator Message:I recommend to read the useful Blog "Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers" to avoid the impression of "spec dumping and learn the principles of this before asking any more questions.

Message was edited by: Kesavadas Thekkillath

5 REPLIES 5
Read only

bishwajit_das
Active Contributor
0 Likes
3,399

Hi Alexandria,

You can try this program for excel upload,

where :-

The excel name is TEST.xls and C:\ is where the file is located.

And 'ZSCARR' is the database table where the data is upload from excel.

REPORT ZEXCEL_UPLOAD.

TYPE-POOLS truxs.

TABLES : zscarr.

* Selection screen

PARAMETER p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.xls'.

TYPES:

  BEGIN OF t_tab,

    carrid TYPE zscarr-carrid,

    seats  TYPE zscarr-total_seats,

  END OF t_tab.

DATA :

  t_upload  TYPE STANDARD TABLE OF t_tab,

  wa_upload TYPE t_tab,

  it_type   TYPE truxs_t_text_data.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'

  EXPORTING

*   PROGRAM_NAME  = SYST-CPROG

*   DYNPRO_NUMBER = SYST-DYNNR

    field_name    = 'P_FILE'

  IMPORTING

    file_name     = p_file.

START-OF-SELECTION.

* Uploading the data in the file into internal table

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

  EXPORTING

*   I_FIELD_SEPERATOR =

*   I_LINE_HEADER  = 'X'

    i_tab_raw_data = it_type

    i_filename     = p_file

  TABLES

    i_tab_converted_data = t_upload[]

  EXCEPTIONS

    conversion_failed = 1

    OTHERS            = 2.

  IF sy-subrc NE  0.

    MESSAGE ID sy-msgid

            TYPE sy-msgty

            NUMBER sy-msgno

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

  ENDIF.

END-OF-SELECTION.

* Uploading the data into the database table

  LOOP AT T_UPLOAD INTO WA_UPLOAD.

    ZSCARR-CARRID = WA_UPLOAD-CARRID.

    ZSCARR-TOTAL_SEATS = WA_UPLOAD-SEATS.

    MODIFY ZSCARR.

  ENDLOOP.

Try this out, but I dont know what your BAPI requirement is..so cant say about that.

Thanks ,

Bishwajit.

Read only

0 Likes
3,399

Hi Bishwajit,

     Firstly, thanks for the sample program. It has been helpful. I have trouble uploading excel files with table headers, so when I upload it messes up the entries. Anyway, here is the complete program requirements..

* PROGRAM REQUIREMENTS

  • Program Name: ZFI_P0010
  • Program Title: JV Upload 2
  • Transaction Code: Z_UPLOAD2
  • Program details:

Each upload file may be composed of several documents to be uploaded. Each document is separated based on column 1 since this is only filled-out once per document.

BAPI_ACC_DOCUMENT_POST may be used with the following additional requirements:

INPUT PARAMETER

  • File location from user workstation.  User should be able to search his/her workstation for the file.
  • There will be 2 Excel sheets:
    • Sheet 1: Accounting Document Header and Line item data
    • Sheet 2: Withholding Tax data
  • There should also be a tick button for “Test Run”

Thanks!

-Alex

Read only

0 Likes
3,399

Hi Alex,

I think I try to give you an idea how to upload an excel.But I think its not fair to expect SCN providing you with the complete solution.We are here to give solutions when you are stuck.

Thanks,

Bishwajit.

Read only

0 Likes
3,399

Ok, I understand. Anyway I managed to complete my program earlier. There are a lot of helpful topics in the community I just found about earlier. By the way, Thanks again for the sample program and sorry about asking for the complete solution. Lol,

Read only

0 Likes
3,399

Hi Alexandria,

I have similar requirement to develop a program which could do mass creation of GL Documents. Do you mind sharing the code which you have developed? So that I could use it as a reference.

Regards.

John