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 REQUIREMENT UPLOADING A EXCEL WITH 20 RECORDS

0 Kudos

mm01.txt

THIS AN EXCEL SUPPOSE CAN YOU PLEASE SUGGEST A BDC PROGRAM FOR REQUIREMENT

THIS PROGRAM ONIY FIRST RECORDED IS UPLOADED OTHER RECORD CAN'T BE UPLOAD .

WHETHER THIS IS THE PROGRAM CORRECT OR SUGGEST ANY PROGRAM:

report zmm01
no standard page heading line-size 255.

types : begin of rec_type,
matnr type rmmg1-matnr,
mbrsh type rmmg1-mbrsh,
mtart type rmmg1-mtart,
maktx type makt-maktx,
meins type mara-meins,
end of rec_type.

data : it_mat type table of rec_type with header line.

data it_excel type table of alsmex_tabline with header line.

data it_bdcdata type table of bdcdata with header line.

parameters p_file type ibipparms-path.

at selection-screen on value-request for p_file.


perform browse_file.
start-of-selection.
perform upload_excel_file.
perform convert_it_excel_to_it_mat.
perform validate_data.

*&---------------------------------------------------------------------*
*& Form BROWSE_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form browse_file .
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
importing
file_name = p_file
.

endform. " BROWSE_FILE
*&---------------------------------------------------------------------*
*& Form UPLOAD_EXCEL_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form upload_excel_file .

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_file
i_begin_col = 2
i_begin_row = 2
i_end_col = 9
i_end_row = 30
tables
intern = it_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
*
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " UPLOAD_EXCEL_FILE
*&---------------------------------------------------------------------*
*& Form CONVERT_IT_EXCEL_TO_IT_MAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form convert_it_excel_to_it_mat .
loop at it_excel.
case it_excel-col.

when 1.
it_mat-matnr = it_excel-value.

when 2.
it_mat-mbrsh = it_excel-value.

when 3.
it_mat-mtart = it_excel-value.

when 4.
it_mat-maktx = it_excel-value.

when 5.
it_mat-meins = it_excel-value.
append it_mat.
clear: it_mat,it_excel.
endcase.
endloop.


endform. " CONVERT_IT_EXCEL_TO_IT_MAT
*&---------------------------------------------------------------------*
*& Form VALIDATE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form validate_data .
loop at it_mat.
*REFRESH IT_BDCDATA.

perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
it_mat-matnr.
perform bdc_field using 'RMMG1-MBRSH'
it_mat-mbrsh.
perform bdc_field using 'RMMG1-MTART'
it_mat-mtart.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
it_mat-maktx.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
it_mat-meins.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.

call transaction 'MM01' using it_bdcdata mode 'A'.

*CLEAR :it_bdcdata.
* CLEAR : it_mat.
endloop.
if sy-subrc = 0.
message 'RECORDS ARE TRANSFERED SUCCESSFULLY' type 'S'.
endif.
endform. " VALIDATE_DATA
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0207 text
* -->P_0208 text
*----------------------------------------------------------------------*
form bdc_dynpro using prgm scrn.
it_bdcdata-program = prgm.
it_bdcdata-dynpro = scrn.
it_bdcdata-dynbegin = 'X'.
append it_bdcdata.
clear it_bdcdata.
endform. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0212 text
* -->P_0213 text
*----------------------------------------------------------------------*
form bdc_field using fname fvalue.
it_bdcdata-fnam = fname.
it_bdcdata-fval = fvalue.
append it_bdcdata.
clear it_bdcdata.
endform. " BDC_FIELD

4 REPLIES 4

former_member734615
Discoverer
0 Kudos

This program is a typical example of how we write BDC reports.
It should work if you have covered all the requirement.

0 Kudos

IT IS NOT WORKING ,ONLY FIRST RECORD VALUE STORED IN TABLE ,SECOND RECORD NOT STORING IN A TABLE,WHILE UPLOADING A EXCEL SHEET.

0 Kudos

call transaction 'MM01' using it_bdcdata mode 'A'.
Have you put a breakpoint on this statement and checked if all data is getting collected in internal table IT_BDCDATA?

KatiNonhebel
Advisor
Advisor

Welcome to SAP Community! I saw that you posted this question multiple times. To avoid duplicates, I will remove all duplicates, including this question. Here is the link to the same published question: (https://answers.sap.com/questions/13317408/bdc-record-not-uploading-directly-from-excel-while.html) Let’s give community members some time to be able to help you finding the correct answer to your question.

I am closing & locking this question as it is a duplication of this

Please do not ask the same question.

If you need further assistance feel free to reach out to moderators@sap.com