Anda di halaman 1dari 6

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

*& Report YBDC_ME11


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YBDC_ME11

no standard page heading line-size 255.


*start-of-selection.
type-pools: truxs .

types: begin of ty_return,


msgtype(2),
message(480),
end of ty_return .

data: begin of wa_data occurs 0 ,


LIFNR_001(010),
MATNR_002(018),
EKORG_003(004),
WERKS_004(004),
NORMB_005(001),
* INFNR_006(010),
IDNLF_006(035),
URZLA_007(003)," TYPE EINA-ULAND,
REGIO_008(003)," TYPE EINA-REGIO,
TELF1_009(016), "type eina-TELF0,

* MAHN2_008(004),
* LIFAB_009(010),
* LIFBI_010(010),
MEINS_010(003),
UMREZ_011(006),
UMREN_012(006),
APLFZ_013(003),
EKGRP_014(003),
NORBM_015(017),
BSTAE_016(004),
* MINBM_018(017),
WEBRE_017(001),
MWSKZ_018(002),
IPRKZ_019(001),
BWTAR_020(010)," type eine-BWTAR_D,
NETPR_021(014),
WAERS_022(005),
PEINH_023(006),
BPRME_024(003),
BPUMZ_025(006),
BPUMN_026(006),
* EKKOL_028(004),
MEPRF_027 type char10,"(001)," TYPE eine-MEPRF,
DATAB_028 type char10,"(008)," type RV13A-KODATAB,
DATBI_029(008)," type RV13A-KODATBI,
KSCHL2_030 TYPE CHAR4,"(004)," type konp-KSCHA,
KSCHL3_031 TYPE CHAR4," type konp-KSCHA,
KBETR2_032 TYPE CHAR7," type konp-KBETR_KOND,
KBETR3_033 TYPE CHAR7 ," type konp-KBETR_KOND,
end of wa_data.
data: it_data like standard table of wa_data with header line.
data: bdcdata like bdcdata occurs 0 with header line.
data: messtab like bdcmsgcoll occurs 0 with header line.
data: "it_data type standard table of ty_data,
it_return type standard table of ty_return,
it_pcec type standard table of pcec,
wa_pcec type pcec,
wa_return type ty_return.

data: it_raw type truxs_t_text_data,


l_mstring(480) ,
index type sy-index.

data: obj_alv type ref to cl_salv_table .

data : lv_mtart like mara-mtart,


lv_cnt(2) type c, " its a count
lv_dytxt(30) type c,
lv_kzsel(30) type c.

data : lt_btci type standard table of bdcdata with header line.

selection-screen: begin of block b1 with frame title text-001 .


parameters: p_file type localfile obligatory,
p_mode type ctu_params-dismode default 'A'.
selection-screen: end of block b1 .

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.
"perform open_group.

start-of-selection.
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = p_file
tables
i_tab_converted_data = it_data[]
exceptions
conversion_failed = 1
others = 2.
if sy-subrc <> 0.
* Implement suitable error handling here
" MESSAGE 'UNABLE TO CONVERT EXCEL FILE' TYPE 'E'.
endif.

start-of-selection.
if it_data is initial .
loop at it_data into wa_data .
perform bdc_dynpro using 'SAPMM06I' '0100'.
perform bdc_field using 'BDC_CURSOR'
'EINE-WERKS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EINA-LIFNR'
wa_data-LIFNR_001.
perform bdc_field using 'EINA-MATNR'
wa_data-MATNR_002.
perform bdc_field using 'EINE-EKORG'
wa_data-EKORG_003.
perform bdc_field using 'EINE-WERKS'
wa_data-WERKS_004.
perform bdc_field using 'RM06I-NORMB'
wa_data-NORMB_005.
*perform bdc_field using 'EINA-INFNR'
* wa_data-INFNR_006.
*perform bdc_dynpro using 'SAPMM06I' '0101'.
perform bdc_dynpro using 'SAPMM06I' '0101'.
perform bdc_field using 'BDC_CURSOR'
'EINA-IDNLF'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EINA-IDNLF'
wa_data-IDNLF_006.
perform bdc_field using 'EINA-URZLA'
wa_data-URZLA_007.
perform bdc_field using 'EINA-REGIO'
wa_data-REGIO_008.
perform bdc_field using 'EINA-TELF1'
wa_data-TELF1_009.
*perform bdc_field using 'EINA-MAHN2'
* wa_data-MAHN2_008.
*perform bdc_field using 'EINA-LIFAB'
* wa_data-LIFAB_009.
*perform bdc_field using 'EINA-LIFBI'
* wa_data-LIFBI_010.
perform bdc_field using 'EINA-MEINS'
wa_data-MEINS_010.
perform bdc_field using 'EINA-UMREZ'
wa_data-UMREZ_011.
perform bdc_field using 'EINA-UMREN'
wa_data-UMREN_012.

perform bdc_dynpro using 'SAPMM06I' '0102'.


perform bdc_field using 'BDC_CURSOR'
'EINE-NETPR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
*perform bdc_field using 'BDC_CURSOR'
* 'EINE-EKKOL'.
*perform bdc_field using 'BDC_OKCODE'
* '/00'.
perform bdc_field using 'EINE-APLFZ'
wa_data-APLFZ_013.
perform bdc_field using 'EINE-EKGRP'
wa_data-EKGRP_014.
perform bdc_field using 'EINE-NORBM'
wa_data-NORBM_015.
perform bdc_field using 'EINE-BSTAE'
wa_data-BSTAE_016.
*perform bdc_field using 'EINE-MINBM'
* wa_data-MINBM_018.
perform bdc_field using 'EINE-WEBRE'
wa_data-WEBRE_017.
perform bdc_field using 'EINE-MWSKZ'
wa_data-MWSKZ_018.
perform bdc_field using 'EINE-IPRKZ'
wa_data-IPRKZ_019.
perform bdc_field using 'EINE-BWTAR'
wa_data-BWTAR_020.
perform bdc_field using 'EINE-NETPR'
wa_data-NETPR_021.
perform bdc_field using 'EINE-WAERS'
wa_data-WAERS_022.
perform bdc_field using 'EINE-PEINH'
wa_data-PEINH_023.
perform bdc_field using 'EINE-BPRME'
wa_data-BPRME_024.
perform bdc_field using 'EINE-BPUMZ'
wa_data-BPUMZ_025.
perform bdc_field using 'EINE-BPUMN'
wa_data-BPUMN_026.
perform bdc_field using 'EINE-MEPRF'
wa_data-MEPRF_027.
*perform bdc_field using 'EINE-EKKOL'
* wa_data-EKKOL_028.
perform bdc_dynpro using 'SAPMM06I' '0105'.
perform bdc_field using 'BDC_CURSOR'
'EINE-ANGNR'.

perform bdc_field using 'BDC_OKCODE'


'/00'.
perform bdc_dynpro using 'SAPMM06I' '0103'.
perform bdc_field using 'BDC_CURSOR'
'RM06I-LTEX1(01)'.
perform bdc_field using 'BDC_OKCODE'
'=KO'.
perform bdc_dynpro using 'SAPMV13A' '0201'.
perform bdc_field using 'BDC_CURSOR'
'KONP-KBETR(03)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.

*perform bdc_field using 'BDC_OKCODE'


* '=BU'.
*
*perform bdc_dynpro using 'SAPMM06I' '0103'.
*perform bdc_field using 'BDC_CURSOR'
* 'RM06I-LTEX1(01)'.
*perform bdc_field using 'BDC_OKCODE'
* '=KO'.
*perform bdc_dynpro using 'SAPMV13A' '0201'.
*perform bdc_field using 'BDC_CURSOR'
* 'KONP-KBETR(03)'.
*perform bdc_field using 'BDC_OKCODE'
* '/00'.
perform bdc_field using 'RV13A-DATAB'
wa_data-DATAB_028.
perform bdc_field using 'RV13A-DATBI'
'31.12.9999'.
* wa_data-DATBI_029.
perform bdc_field using 'KONP-KSCHL(02)'
wa_data-KSCHL2_030.
perform bdc_field using 'KONP-KSCHL(03)'
wa_data-KSCHL3_031.
perform bdc_field using 'KONP-KBETR(02)'
wa_data-KBETR2_032.
perform bdc_field using 'KONP-KBETR(03)'
wa_data-KBETR3_033.
perform bdc_dynpro using 'SAPMV13A' '0201'.
perform bdc_field using 'BDC_CURSOR'
'KONP-KBETR(03)'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'RV13A-DATAB'
wa_data-DATAB_028.
perform bdc_field using 'RV13A-DATBI'
'31.12.9999'.

* wa_data-DATBI_029.

call transaction 'ME11' using bdcdata[] mode p_mode messages into messtab .
refresh bdcdata[] .

loop at messtab.

message id messtab-msgid
type messtab-msgtyp
number messtab-msgnr
into l_mstring
with messtab-msgv1
messtab-msgv2
messtab-msgv3
messtab-msgv4.

wa_return-msgtype = messtab-msgtyp .
wa_return-message = l_mstring .
append wa_return to it_return .
clear: wa_return, l_mstring .
endloop.

endloop .

if it_return is not initial.


perform error_display .
else.
message 'Data uploaded Sucessfully' type 'I' .
endif.

else .
message 'Excel file not converted' type 'I' .
endif .
"*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
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.

clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form ERROR_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form error_display .
TRY.
call method cl_salv_table=>factory
* exporting
* list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container =
* container_name =
importing
r_salv_table = obj_alv
changing
t_table = it_return.

call method obj_alv->display .


CATCH cx_salv_msg.
ENDTRY.

endform. " ERROR_DISPLAY