Skip to Content
-2
Mar 12, 2021 at 04:54 AM

BDC REQUIREMENT UPLOADING A EXCEL WITH 20 RECORDS

54 Views Last edit Mar 12, 2021 at 04:59 AM 2 rev

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

Attachments

mm01.txt (9.1 kB)