前两天吃中饭时同事说MR21修改价格用LSMW导入,每次只能导入一条商品价格,而每一个商品价格的修改都会产生一个凭证,问是否能批量导入。先去找了下BAPI,看了下BAPI_MATVAL_PRICE_CHANGE和BAPI_M_REVAL_CREATEPRICECHANGE两个BAPI,发现前一个每次只能修改一个商品价格,后一个根本就跑不起来,不知道咋回事,只能回头用SHDB解决问题。
REPORTzmr21
NOSTANDARDPAGEHEADINGLINE-SIZE255.
INCLUDEbdcrecx1.
PARAMETERS:dataset(132)LOWERCASE.
***DONOTCHANGE-thegenerateddatasection-DONOTCHANGE***
*
*Ifitisnessesarytochangethedatasectionusetherules:
*1.)Eachdefinitionofafieldexistsoftwolines
*2.)Thefirstlineshowsexactlythecomment
*'*dataelement:'followedwiththedataelement
*whichdescribesthefield.
*Ifyoudon'thaveadataelementusethe
*commentwithoutadataelementname
*3.)Thesecondlineshowsthefieldnameofthe
*structure,thefieldnamemustconsistof
*afieldnameandoptionalthecharacter'_'and
*threenumbersandthefieldlengthinbrackets
*4.)EachfieldmustbetypeC.
*
***Generateddatasectionwithspecificformatting-DONOTCHANGE***
DATA:BEGINOFrecordOCCURS0,
*dataelement:BUDAT
budat_001(010),
*dataelement:BUKRS
bukrs_002(004),
*dataelement:WERKS_D
werks_003(004),
*dataelement:SCREEN_VARIANT
screen_variant_004(030),
*dataelement:SCREEN_VARIANT
screen_variant_005(030),
*dataelement:MATNR
matnr_01_006(018),
*dataelement:VALPR
newvalpr_01_007(015),
ENDOFrecord.
***Endgenerateddatasection***
START-OF-SELECTION.
*PERFORMopen_datasetUSINGdataset.
PERFORMof_getexcel.
PERFORMopen_group.
PERFORMof_processdata.
PERFORMclose_group.
*PERFORMclose_datasetUSINGdataset.
FORMof_processdata.
DATA:li_curTYPEiVALUE0,
li_modTYPEi,
ls_fname(30)TYPEc,
ls_temp(2)TYPEc,
li_lenTYPEi,
li_inexTYPEiVALUE0.
li_mod=LINES(record).
breakypcheng.
LOOPATrecord.
li_cur=li_cur+1.
li_inex=li_inex+1.
IFli_inex=1.
PERFORMbdc_dynproUSING'SAPRCKM_MR21''0201'.
PERFORMbdc_fieldUSING'BDC_CURSOR''MR21HEAD-WERKS'.
PERFORMbdc_fieldUSING'MR21HEAD-BUDAT'record-budat_001.
PERFORMbdc_fieldUSING'MR21HEAD-BUKRS'record-bukrs_002.
PERFORMbdc_fieldUSING'MR21HEAD-WERKS'record-werks_003.
ENDIF.
MOVEli_curTOls_temp.
li_len=STRLEN(ls_temp).
IFli_len=1.
CONCATENATE'0'ls_tempINTOls_temp.
ENDIF.
PERFORMbdc_dynproUSING'SAPRCKM_MR21''0201'.
PERFORMbdc_fieldUSING'BDC_OKCODE''=ENTR'.
PERFORMbdc_fieldUSING'MR21HEAD-SCREEN_VARIANT''MR21_LAGERMATERIAL_0250'.
CONCATENATE'CKI_MR21_0250-MATNR('ls_temp')'INTOls_fname.
PERFORMbdc_fieldUSINGls_fnamerecord-matnr_01_006.
CONCATENATE'CKI_MR21_0250-NEWVALPR('ls_temp')'INTOls_fname.
PERFORMbdc_fieldUSINGls_fnamerecord-newvalpr_01_007.
li_mod=li_curMOD9.
IFli_mod=0.
CLEARli_cur.
PERFORMbdc_dynproUSING'SAPRCKM_MR21''0201'.
PERFORMbdc_fieldUSING'BDC_OKCODE''=DOWN'.
ENDIF.
ENDLOOP.
PERFORMbdc_dynproUSING'SAPRCKM_MR21''0201'.
PERFORMbdc_fieldUSING'BDC_OKCODE''=SAVE'.
PERFORMbdc_transactionUSING'MR21'.
ENDFORM."of_processdata
*&---------------------------------------------------------------------*
*&Formof_getexcel
*&---------------------------------------------------------------------*
*text
*----------------------------------------------------------------------*
FORMof_getexcel.
DATA:filenmTYPErlgrap-filenameVALUE'e:mr21.xls'.
FIELD-SYMBOLS:.
DATA:BEGINOFiexcelOCCURS0.
INCLUDESTRUCTUREalsmex_tabline.
DATA:ENDOFiexcel.
DATA:ls_colnameTYPEstring,
li_currowTYPEi.
CALLFUNCTION'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename=filenm
i_begin_col=1
i_begin_row=1
i_end_col=14
i_end_row=30000
TABLES
intern=iexcel
EXCEPTIONS
inconsistent_parameters=1
upload_ole=2
OTHERS=3.
IFsy-subrc