‎2007 Dec 24 9:16 AM
Friends I need the process to upload data from an EXCEL file located in the APPLICATION server to the internal table. I need your valuable inputs on this front.
Thanks in advance,
Ram.
‎2007 Dec 24 9:27 AM
hai,
use cg3y transaction to download file from app to local and convert XL in to txt file format with tab delimited and use gui_upload function module to down the file into your internal table to process .
plzz reward points if useful.
regards,
jai.m
‎2007 Dec 24 9:27 AM
hai,
use cg3y transaction to download file from app to local and convert XL in to txt file format with tab delimited and use gui_upload function module to down the file into your internal table to process .
plzz reward points if useful.
regards,
jai.m
‎2007 Dec 24 9:30 AM
Hi,
Just copy paste, this program activate and run this program.
Note: Before cheking this code prepare an excel sheet which has the same fields as t_data structure in this program.
This is to take the datas from Excel sheet which we have prepared and puts it into internal table and this internal table data is passed to MM01 transaction for saving that material.
&----
*& I N C L U D E S
&----
include zf_jaganmm01_bdc_top. "global declarations
include zf_jaganmm01_bdc_forms. "forms <--This includes all the perform forms.
&----
*& Include ZF_JAGANMM01_BDC_TOP
&----
*Structure for the internal table which is going to hold the data from excel sheet.
*TYPES: BEGIN OF t_data occurs 0,
types: begin of t_data,
*MARA
matnr(18), "Component
mbrsh(1), "Indstrl Sctr
mtart(4), "Type of Material
matkl(9), "Material group
spart(2), "Division
mtpos_mara(4), "General item category group
brgew(17), "Gross weight
gewei(3), "Weight Unit
ntgew(17), "Net weight
meins(3), "Base Unit of Measure
ferth(18), "Production/inspection memo
normt(18), "Industry Standard Description (such as ANSI or ISO)
tragr(4), "Transportation group
bstme(3), "Order unit
iprkz(1), "Period indicator for shelf life expiration date
*MAKT
matkx(4), "Material description
*MARC
werks(4), "Plant
atpkz(1), "Replacement part
mtvfp(2), "Checking Group for Availability Check
ladgr(4), "Loading group
ekgrp(3), "Purchasing group
mmsta(2), "Plant-Specific Material Status
disgr(4), "MRP Group
dismm(2), "MRP Type
dispo(3), "MRP controller
disls(2), "Lot size (materials planning)
beskz(1), "Procurement Type
lgpro(4), "Issue Storage Location
fabkz(1), "Indicator: Item relevant to JIT delivery schedules
eprio(4), "Stock determination group
plifz(3), "Planned delivery time in days
dzeit(3), "In-house production time
webaz(3), "Goods receipt processing time in days
fhori(3), "Scheduling Margin Key for Floats
*MARD
lgort(4), "Storage location
lgpbe(10), "Storage bin
end of t_data.
*Internal Table.
*DATA: it_data TYPE STANDARD TABLE OF t_data WITH HEADER LINE,
data: it_data type standard table of t_data with header line.
data: mess(140),
c type i,
t type i.
*Work area.
data: i_col type i,
i_row type i,
i_endcol type i,
i_endrow type i,
d_val(5).
types: begin of t_alsmex_tabline,
row type kcd_ex_row_n,
col type kcd_ex_col_n,
value type char50,
end of t_alsmex_tabline.
data: it_data1 like alsmex_tabline occurs 0 with header line.
field-symbols: <fs_data1> type data.
*Replacing INCLUDE BDCREX1.
data : bdcdata like bdcdata occurs 0 with header line,
bdcmsgcoll like bdcmsgcoll occurs 0 with header line,
it_bdcmsgcoll like bdcmsgcoll occurs 0 with header line,
d_total(5).
*S E L E C T I O N - S C R E E N.
selection-screen begin of line.
selection-screen comment 3(20) text-s01 for field group.
selection-screen position 25.
parameters group(12) default 'MM01'. "group name of session
selection-screen comment 48(20) text-s05 for field ctumode.
selection-screen position 70.
parameters ctumode like ctu_params-dismode default 'A'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
selection-screen end of line.
selection-screen skip.
selection-screen begin of line.
selection-screen comment 1(33) text-s10 for field nodata.
parameters: nodata default '/' lower case. "nodata
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(33) for field smalllog.
parameters: smalllog as checkbox. "' ' = log all transactions
"'X' = no transaction logging
selection-screen end of line.
*Initializing all the Internal table and its content.
initialization.
refresh: it_data1,
it_data.
&----
*& Form zf_upload
&----
text
----
--> p1 text
<-- p2 text
----
form zf_upload .
data: v_f4_filename type ibipparms-path.
data: v_alsm_filename type rlgrap-filename.
data: v_repid type sy-repid.
data: v_dynnr type sy-dynnr.
v_repid = sy-repid.
v_dynnr = sy-dynnr.
call function 'F4_FILENAME'
exporting
program_name = v_repid
dynpro_number = v_dynnr
FIELD_NAME =
importing
file_name = v_f4_filename.
.
v_alsm_filename = v_f4_filename.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = v_alsm_filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 36
i_end_row = 65536
tables
intern = it_data1
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.
refresh: it_data.
loop at it_data1.
assign component it_data1-col of structure it_data to <fs_data1>.
move: it_data1-value to <fs_data1>.
at end of row.
append it_data.
clear: it_data.
endat.
endloop.
endform. " zf_upload
&----
*& S T A R T - O F - S E L E C T I O N
&----
start-of-selection.
*THIS PERFORM IS USED TO FETCH ALL THE NECESSARY DATA.
perform zf_upload.
*STARTING BDC.
sort it_data by matnr.
if sy-subrc <> 0.
refresh: it_data.
endif.
loop at it_data.
refresh bdcdata.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MATNR'
it_data-matnr.
perform bdc_field using 'RMMG1-MBRSH'
it_data-mbrsh.
perform bdc_field using 'RMMG1-MTART'
it_data-mtart.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(13)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(02)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(04)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(06)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(09)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(12)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(13)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '0080'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-LGORT'.
perform bdc_field using 'BDC_OKCODE'
'=DEF_SAVE'.
perform bdc_field using 'RMMG1-WERKS'
it_data-werks.
perform bdc_field using 'RMMG1-LGORT'
it_data-lgort.
perform bdc_dynpro using 'SAPLMGMM' '0080'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-WERKS'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-WERKS'
it_data-werks.
perform bdc_field using 'RMMG1-LGORT'
it_data-lgort.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=PB26'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARA-MATKL'
it_data-matkl.
perform bdc_field using 'MARA-SPART'
it_data-spart.
perform bdc_field using 'MARA-MTPOS_MARA'
it_data-mtpos_mara.
perform bdc_field using 'BDC_CURSOR'
'MARA-NTGEW'.
perform bdc_field using 'MARA-BRGEW'
it_data-brgew.
perform bdc_field using 'MARA-GEWEI'
it_data-gewei.
perform bdc_field using 'MARA-NTGEW'
it_data-ntgew.
perform bdc_dynpro using 'SAPLMGMM' '4300'.
perform bdc_field using 'BDC_OKCODE'
'=MAIN'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=SP02'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARA-MATKL'
it_data-matkl.
perform bdc_field using 'MARA-SPART'
it_data-spart.
perform bdc_field using 'MARA-MTPOS_MARA'
it_data-mtpos_mara.
perform bdc_field using 'MARA-BRGEW'
it_data-brgew.
perform bdc_field using 'MARA-GEWEI'
it_data-gewei.
perform bdc_field using 'MARA-NTGEW'
it_data-ntgew.
perform bdc_field using 'DESC_LANGU_GDTXT'
'E'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=SP04'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'BDC_CURSOR'
'MARA-NORMT'.
perform bdc_field using 'MARA-FERTH'
it_data-ferth.
perform bdc_field using 'MARA-NORMT'
it_data-normt.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=SP06'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARA-SPART'
it_data-spart.
perform bdc_field using 'MARA-MATKL'
it_data-matkl.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=SP09'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'BDC_CURSOR'
'MARC-ATPKZ'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARC-ATPKZ'
it_data-atpkz.
perform bdc_field using 'MARA-BRGEW'
it_data-brgew.
perform bdc_field using 'MARA-GEWEI'
it_data-gewei.
perform bdc_field using 'MARA-NTGEW'
it_data-ntgew.
perform bdc_field using 'MARC-MTVFP'
it_data-mtvfp.
perform bdc_field using 'MARA-TRAGR'
it_data-tragr.
perform bdc_field using 'MARC-LADGR'
'0001'.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=SP12'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'BDC_CURSOR'
'MG03STEUMM-TAXIM'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARA-BSTME'
it_data-bstme.
perform bdc_field using 'MARC-EKGRP'
it_data-ekgrp.
perform bdc_field using 'MARA-MATKL'
it_data-matkl.
perform bdc_field using 'MARC-MMSTA'
it_data-mmsta.
perform bdc_field using 'MG03STEUMM-TAXIM'
''.
perform bdc_dynpro using 'SAPLMGMM' '0510'.
perform bdc_field using 'BDC_CURSOR'
'RMMZU-UMREZ'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMZU-UMREN'
'100'.
perform bdc_field using 'RMMZU-UMREZ'
'1'.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=SP12'.
perform bdc_field using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARA-BSTME'
it_data-bstme.
perform bdc_field using 'MARC-EKGRP'
it_data-ekgrp.
perform bdc_field using 'MARA-MATKL'
it_data-matkl.
perform bdc_field using 'MARC-MMSTA'
it_data-mmsta.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=SP13'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARC-DISGR'
it_data-disgr.
perform bdc_field using 'MARC-EKGRP'
it_data-ekgrp.
perform bdc_field using 'MARC-MMSTA'
it_data-mmsta.
perform bdc_field using 'MARC-DISMM'
it_data-dismm.
perform bdc_field using 'MARC-DISPO'
it_data-dispo.
perform bdc_field using 'BDC_CURSOR'
'MARC-DISLS'.
perform bdc_field using 'MARC-DISLS'
it_data-disls.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=SP19'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'MARC-BESKZ'
'X'.
perform bdc_field using 'MARC-LGPRO'
it_data-lgpro.
perform bdc_field using 'MARC-FABKZ'
it_data-fabkz.
perform bdc_field using 'MARC-EPRIO'
it_data-eprio.
perform bdc_field using 'BDC_CURSOR'
'MARC-PLIFZ'.
perform bdc_field using 'MARC-DZEIT'
it_data-dzeit.
perform bdc_field using 'MARC-PLIFZ'
it_data-plifz.
perform bdc_field using 'MARC-WEBAZ'
it_data-webaz.
perform bdc_field using 'MARC-FHORI'
it_data-fhori.
perform bdc_dynpro using 'SAPLMGMM' '4000'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
'Iron Rod'.
perform bdc_field using 'BDC_CURSOR'
'MARD-LGPBE'.
perform bdc_field using 'MARA-MEINS'
it_data-meins.
perform bdc_field using 'MARD-LGPBE'
it_data-lgpbe.
perform bdc_field using 'MARA-IPRKZ'
it_data-iprkz.
*perform bdc_transaction using 'MM01'.
call transaction 'MM01' using bdcdata
mode ctumode
UPDATE 'S'
messages into bdcmsgcoll.
*Getting the system message-id, message number, language keys through bdcmsgcoll.
refresh: it_bdcmsgcoll.
loop at bdcmsgcoll.
move: bdcmsgcoll-msgspra to it_bdcmsgcoll-msgspra,
bdcmsgcoll-msgid to it_bdcmsgcoll-msgid,
bdcmsgcoll-msgnr to it_bdcmsgcoll-msgnr.
append it_bdcmsgcoll.
endloop.
endloop.
*For printing Error messages.
loop at it_bdcmsgcoll.
call function 'FORMAT_MESSAGE'
exporting
id = it_bdcmsgcoll-msgid
lang = it_bdcmsgcoll-msgspra
no = it_bdcmsgcoll-msgnr
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
importing
msg = mess
exceptions
not_found = 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.
*Getting the system messages.
write:/5 it_data-matnr color 2,
30 mess color 3.
endloop.
endif.
*----
*
Start new screen
*
*----
*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform. "bdc_dynpro
*----
*
Insert field
*
*----
*
form bdc_field using fnam fval.
if fval <> nodata.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endif.