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: 

BDC to upload data for t code mm01

Former Member
0 Kudos

Hi all,

This is the first BDC program that i am writing. I need to upload 1050 records using tcode mm01.

Which method should i follow for this requirement. Can anyone help me in this regard.

Regards,

Sam.

18 REPLIES 18

arivazhagan_sivasamy
Active Contributor
0 Kudos

Hi Samuel,

Instead of using BDC, please use BAPI_MATERIAL_SAVEREPLICA.

Arivazhagan S

Clemenss
Active Contributor
0 Kudos

This message was moderated.

Former Member
0 Kudos

The data which you want to upload is in which format ? If there is lots of customization require in data during upload then go with BDC, else LSMW is good option.

Thnx,

Prakash

0 Kudos

Prakash,

Data is in xl format.

Rgds,

Sam.

0 Kudos

Hi Samuel,

You can use BAPI_MATERIAL_SAVEDATA instead of going for BDC.

Regards,

Manasa Veena P

chundru_ravindra
Participant
0 Kudos

Hi,

Upload Excel with GUI_UPLOAD and Convert with ALSM_EXCEL_TO_INTERNAL_TABLE.

Loop through this internal table create material by using FM BAPI_MATERIAL_SAVEDATA .

Ravindra

former_member187748
Active Contributor
0 Kudos

Hi Samuel,

please see these sample code and change your data according to your need

You will upload data through the format you required.

report ZFB01_POST_DOCUMENT

        no standard page heading line-size 255.

INCLUDE zbdcrec.

TYPE-POOLS : TRUXS.

TYPESBEGIN OF ty_input,

         bldat(10)   TYPE c"Document Date in Document

         blart(02)   TYPE c"Document Type

         bukrs(04)   TYPE c"Company Code

         budat(10)   TYPE c"Posting Date in the Document

         monat(2)    TYPE c"Period

         waers(5)    TYPE c"Currency key

         xblnr(16)   TYPE c"REFERENCE NUM

         newbs(02)   TYPE c"Posting Key for the Next Line Item

         newko(17)   TYPE c"Account or Matchcode for the Next Line Item

         wrbtr(18)   TYPE c"Amount

         gsber(04)   TYPE c"Business Area

         zterm(04)   TYPE c"Payment term

         zfbdt(10)   TYPE c"Baseline Date for Due Date Calculation

         zuonr       TYPE bseg-zuonr"Assignment

         sgtxt(35)   TYPE c"Text

         newbs1(02TYPE c"Posting Key for the Next Line Item

         newko1(17TYPE c"Account or Matchcode for the Next Line Item

         wrbtr1(18TYPE c"Amount

         mwskz(02)   TYPE c"Tax Code

         txjcd(15)   TYPE c,   "Tax Juridiction

         zuonr1(20)   TYPE c,   "Assignment

         sgtxt1(35)   TYPE c"Text

         newbs2(02TYPE c"Posting Key for the Next Line Item

         newko2(17TYPE c"Account or Matchcode for the Next Line Item

         gsber1(04)   TYPE c"Business Area

         kostl(10)   type c,   "cost center

         wrbtr2(18TYPE c"Amount

         mwskz1(02)   TYPE c,   "Tax Code

         txjcd1(15)   TYPE c"Tax Juridiction

         valut(10)   TYPE c"Value line Date

         zuonr2(20TYPE C"ASSIGNMENT

         sgtxt2(35)   TYPE c"Text

         gsber2(04)   TYPE c"Business Area

         kostl1(10)   type c,   "cost center

END OF ty_input.

DATA: it_input TYPE STANDARD TABLE OF ty_input WITH HEADER LINE ,

       wa_input TYPE ty_input.

DATA : BEGIN OF options.

         INCLUDE STRUCTURE ctu_params.

DATA : END OF options.

DATA: i_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,

       l_message LIKE bapiret2-message.

DATA: p_mode TYPE c.

DATA  BEGIN OF it_error OCCURS 1.

DATA : text(100TYPE c.

DATA  END   OF it_error.

DATA  BEGIN OF it_success OCCURS 1.

DATAtext(100) TYPE c.

DATA  END   OF it_success.

DATA: it_raw TYPE truxs_t_text_data.

*--------------------------------------------------------------------*

* sELECTION sCREEN

*--------------------------------------------------------------------*

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP 1.

*parameters: Customer radiobutton group G1,

*            Vendor  radiobutton group G1.

PARAMETERS : p_path LIKE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN : END   OF BLOCK b1.

SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

SELECTION-SCREEN SKIP 1.

PARAMETERS : mode_a      RADIOBUTTON    GROUP  r1,

              mode_n      RADIOBUTTON    GROUP  r1.

SELECTION-SCREEN : END   OF BLOCK b2.

*--------------------------------------------------------------------*

* AT SELECTION SCREEN

*--------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

   CALL FUNCTION 'F4_FILENAME'

     EXPORTING

       field_name = 'P_FILE '

     IMPORTING

       file_name  = p_path.

START-OF-SELECTION.

   CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

     EXPORTING

       i_line_header        = 'X'

       i_tab_raw_data       = it_raw       " WORK TABLE

       i_filename           = p_path

     TABLES

       i_tab_converted_data = it_input[]  "ACTUAL DATA

     EXCEPTIONS

       conversion_failed    = 1

       OTHERS               = 2.

   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_input.

   IF sy-tabix EQ 1 "for first  row

     CONTINUE.

   ENDIF.

ENDLOOP.

*--------------------------------------------------------------------*\

* start of selection

*--------------------------------------------------------------------*

START-OF-SELECTION.

  PERFORM upload_data.

*   Report for success

   PERFORM  success_text.

*   Report for Error

   PERFORM  error_text.

END-OF-SELECTION.

*

*  PERFORM bdc_transaction USING 'FB01'.

*

*  PERFORM close_group.

*&---------------------------------------------------------------------*

*&      Form  UPLOAD_DATA

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

form UPLOAD_DATA .

* PERFORM open_group.

    IF mode_a EQ 'X'.

     p_mode = 'A'.

   ELSEIF mode_n EQ 'X'.

     p_mode = 'N'.

   ENDIF.

   options-defsize = 'X'.

   options-updmode = ''.

   options-dismode = p_mode.

   LOOP AT it_input INTO wa_input.

perform bdc_dynpro      using 'SAPMF05A' '0100'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF05A-NEWKO'.

perform bdc_field       using 'BDC_OKCODE'

                               '/00'.

perform bdc_field       using 'BKPF-BLDAT'

                               wa_input-BLDAT.             "'29.05.2013'.

perform bdc_field       using 'BKPF-BLART'

                               wa_input-BLART.             "'R1'.

perform bdc_field       using 'BKPF-BUKRS'

                               wa_input-BUKRS.             "'1100'.

perform bdc_field       using 'BKPF-BUDAT'

                               wa_input-BUDAT.             "'29.05.2013'.

perform bdc_field       using 'BKPF-MONAT'

                               wa_input-MONAT.             "'2'.

perform bdc_field       using 'BKPF-WAERS'

                               wa_input-WAERS.             "'INR'.

perform bdc_field       using 'BKPF-XBLNR'

                               wa_input-XBLNR.             "'123'.

perform bdc_field       using 'FS006-DOCID'

                               '*'.

perform bdc_field       using 'RF05A-NEWBS'

                               wa_input-NEWBS.             "'01'.

perform bdc_field       using 'RF05A-NEWKO'

                               wa_input-NEWKO.             "'4000000612'.

perform bdc_dynpro      using 'SAPMF05A' '0301'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF05A-NEWKO'.

perform bdc_field       using 'BDC_OKCODE'

                               '=S+'.

perform bdc_field       using 'BSEG-WRBTR'

                               wa_input-WRBTR.             "'20000'.

perform bdc_field       using 'BSEG-GSBER'

                               wa_input-GSBER.             "'1105'.

perform bdc_field       using 'BSEG-ZTERM'

                               wa_input-ZTERM.             "'0001'.

perform bdc_field       using 'BSEG-ZFBDT'

                               wa_input-ZFBDT.             "'29.05.2013'.

perform bdc_field       using 'BSEG-ZUONR'

                               wa_input-ZUONR.             "'1234'.

perform bdc_field       using 'BSEG-SGTXT'

                               wa_input-SGTXT.             "'TEST1'.

perform bdc_field       using 'RF05A-NEWBS'

                               wa_input-NEWBS1.            "'50'.

perform bdc_field       using 'RF05A-NEWKO'

                               wa_input-NEWKO1.            "'3210025'.

perform bdc_dynpro      using 'SAPMF05A' '0300'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF05A-NEWKO'.

perform bdc_field       using 'BDC_OKCODE'

                               '=S+'.

perform bdc_field       using 'BSEG-WRBTR'

                               wa_input-WRBTR1.           "'15000'.

perform bdc_field       using 'BSEG-MWSKZ'

                               wa_input-MWSKZ.            "'A0'.

perform bdc_field       using 'BSEG-TXJCD'

                               wa_input-TXJCD.            "'9000'.

perform bdc_field       using 'BSEG-ZUONR'

                               wa_input-ZUONR1.           "'12345'.

perform bdc_field       using 'BSEG-SGTXT'

                               wa_input-SGTXT1.           "'TEST2'.

perform bdc_field       using 'RF05A-NEWBS'

                               wa_input-NEWBS2.           "'50'.

perform bdc_field       using 'RF05A-NEWKO'

                               wa_input-NEWKO2.           "'1215030'.

perform bdc_dynpro      using 'SAPLKACB' '0002'.

perform bdc_field       using 'BDC_CURSOR'

                               'COBL-KOSTL'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTE'.

perform bdc_field       using 'COBL-GSBER'

                               wa_input-GSBER1.           "'1105'.

perform bdc_field       using 'COBL-KOSTL'

                               wa_input-KOSTL.            "'11-R001'.

perform bdc_dynpro      using 'SAPMF05A' '0300'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF05A-NEWKO'.

perform bdc_field       using 'BDC_OKCODE'

                               '=BU'.

perform bdc_field       using 'BSEG-WRBTR'

                               wa_input-WRBTR2.            "'5000'.

perform bdc_field       using 'BSEG-MWSKZ'

                               wa_input-MWSKZ1.            "'A0'.

perform bdc_field       using 'BSEG-TXJCD'

                               wa_input-TXJCD1.            "'9000'.

perform bdc_field       using 'BSEG-VALUT'

                               wa_input-VALUT.             "'29.05.2013'.

perform bdc_field       using 'BSEG-ZUONR'

                               wa_input-ZUONR2.            "'123456'.

perform bdc_field       using 'BSEG-SGTXT'

                               wa_input-SGTXT2.            "'TEST3'.

perform bdc_field       using 'RF05A-NEWBS'

                               wa_input-NEWBS1.             "'50'.

perform bdc_field       using 'RF05A-NEWKO'

                               wa_input-NEWKO1.            "'3210025'.

perform bdc_field       using 'DKACB-FMORE'

                               'X'.

perform bdc_dynpro      using 'SAPLKACB' '0002'.

perform bdc_field       using 'BDC_CURSOR'

                               'COBL-KOSTL'.

perform bdc_field       using 'BDC_OKCODE'

                               '=ENTE'.

perform bdc_field       using 'COBL-GSBER'

                               wa_input-GSBER.           "'1105'.

perform bdc_field       using 'COBL-KOSTL'

                               wa_input-KOSTL.           "'11-R001'.

perform bdc_dynpro      using 'SAPMF05A' '0300'.

perform bdc_field       using 'BDC_OKCODE'

                               '/EPOS'.

perform bdc_field       using 'BDC_CURSOR'

                               'BSEG-WRBTR'.

perform bdc_dynpro      using 'SAPMF05A' '0700'.

perform bdc_field       using 'BDC_CURSOR'

                               'RF05A-NEWBS'.

perform bdc_field       using 'BDC_OKCODE'

                               '=BU'.

perform bdc_field       using 'BKPF-XBLNR'

                               wa_input-XBLNR.              "'123'.

*perform bdc_transaction using 'FB01'.

CALL TRANSACTION 'FB01' USING bdcdata

                             OPTIONS FROM options

                             MESSAGES INTO i_messtab.

     IF SY-SUBRC NE 0.

       CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'

         EXPORTING

           id         = sy-msgid

           number     = sy-msgno

           language   = sy-langu

           textformat = 'ASC'

           message_v1 = sy-msgv1

           message_v2 = sy-msgv2

           message_v3 = sy-msgv3

           message_v4 = sy-msgv4

         IMPORTING

           message    = l_message.

       .

       CONCATENATE l_message '-' wa_input-newko wa_input-wrbtr wa_input-budat INTO it_error-text

       SEPARATED BY ' '.

       APPEND it_error.

     ELSE.

       CONCATENATE 'DATA UPLOADED SUCCESSFULLY :' wa_input-newko  wa_input-wrbtr wa_input-budat

       INTO it_success-text SEPARATED BY ' '.

       APPEND it_success.

     ENDIF.

     REFRESH bdcdata.

     CLEAR: wa_input,l_message.

ENDLOOP.

***ENDLOOP.

endform.

                    " UPLOAD_DATA

FORM success_text .

   LOOP AT it_success.

     AT FIRST.

       WRITE :/10  'Following records successfully uploaded'.

       ULINE.

     ENDAT.

     WRITE :/10  it_success-text.

   ENDLOOP.

ENDFORM.

FORM error_text .

   LOOP AT it_error.

     AT FIRST.

       WRITE :/10  'Following records  are not uploaded'.

       ULINE.

     ENDAT.

     WRITE :/10  it_error-text.

   ENDLOOP.

ENDFORM.

Former Member
0 Kudos

Hi Samuel,

BDC is seldom preferred because of its pretty high dependency on screen sequence, ineffective error reporting and scrolling etc issues.

FM or BAPIs are always preffered.

Steps -

1) File Upload

a) Presentation/Desktop - Use GUI_UPLOAD or ALSM_EXCEL_TO_INTERNAL_TABLE

b) Application Server - Use Open, Read and Close datasets

2) Do prevalidations and data sanity checks like numeric field should not have char values, date/currency format checks, etc.

3) Call the FM to create/extend the materials -

a) Use BAPI_MATERIAL_SAVEDATA - It processes one material at a time.

b) Use BAPI_MATERIAL_SAVEREPLICA - It processes multiple materials at a  time.

4) Call BAPI_TRANSACTION_COMMIT to make the data persistent in Database upon successful call to BAPI of sytep 3.

5) Collect the messages returned from above BAPIs and show an audit log to user.

Ask in case of questions.

BR.

Former Member
0 Kudos

Hi Samule ,

madhu_vadlamani
Active Contributor
0 Kudos

Hi Samuel,

Please go with lsmw or bapi or idoc or batch input methods. Other option go with fm. it is not suggestible to go with recording screens.

Regards,

Madhu.

Former Member
0 Kudos

Hi,

I used lsmw to upload data and when i upload the data i get the following error

0 Kudos

Hi Samuel, May be your inputting file should be saved as Unicode format or others(If it is Text file). In your snapshot the material number is strange.

0 Kudos

Hi Feiyun Wu,

Iam uploading from an excel file.

0 Kudos

Hi Samuel,

have you used my previous BDC program, you have to change only your fields

It will do what you are searching for.

0 Kudos

Hi Sanjeev,

Since BDC had some issue i used lsmw. Ill check and get back.

Many thanks.

0 Kudos

What is the first record in file.

0 Kudos

Matnerial Number (Matnr)

0 Kudos

Hi,

1) In step 3 what is the first field

2) What is the field you mapped for MATNR to the structure BMM00.

3) lsmw which method you are using.

Regards,

Madhu.