1、HEADERLINE.PARAMETERSFILELOCALFILEOBLIGATORY.程序:ATSELECTION-SCREENONVALUE-REQUESTFORFILE.PERFORMPRM_FILE. 选择文件路径START-OF-SELECTION.FRM_EXCEL. 点击执行,赋值CALLSCREEN100. 跳转主屏幕*-*FORMPRM_FILE.METHODCL_GUI_FRONTEND_SERVICES=FILE_OPEN_DIALOGEXPORTINGWINDOW_TITLE=选择文件FILE_FILTERXLS模板文件|*.XLSXINITIAL_DIRECTORY
2、D:CHANGINGFILE_TABLE把导入的excel表赋给FILE_TABLERCEXCEPTIONSCNTL_ERROR1FILE_OPEN_DIALOG_FAILED2ERROR_NO_GUI3.CL_GUI_CFW=FLUSHCNTL_SYSTEM_ERROR2.READINTOINDEX1.IFSY-SUBRCEQLW_TABLE-FILENAME.ENDIF.ENDFORM.FRM_EXCEL. FUNCTIONALSM_EXCEL_TO_INTERNAL_TABLEFILENAMEFILEI_BEGIN_COL1 开始和结束的行列 I_BEGIN_ROWI_END_COL7
3、I_END_ROW100 TABLESINTERNIEXCELINCONSISTENT_PARAMETERSUPLOAD_OLEOTHERSWRITE:/读入文件错误!,FILE.ELSE.一般下面是才是我们关心的问题,循环excel,excel有3列,下面是IEXCEL-COL一列一列的读取,AT END OF ROW当读取一行(3列)后,赋给内表一行LOOPCASEIEXCEL-COL.WHENIT_USERS-USERNAMEIEXCEL-VALUE(20).IT_USERS-PASSWORDIT_USERS-LASTNAMEENDCASE.ROW. AT END OF也就是一行结束后赋
4、值APPENDIT_USERS. 当读取一行(3列)后,赋给内表一行ENDAT.ENDLOOP.ENDFORM.*&-点击按钮执行事件-*MODULEUSER_COMMAND_0100INPUT.SY-UCOMM.BAPIZ_BAPI.BDCZ_BDC.BACKLEAVEPROGRAM.EXITPRINTZ_SMARTFORMS.ENDMODULE. B A P I*BAPI变量l_bapipwdbapipwd.密码l_addressbapiaddr3.lastname姓氏l_usernameBAPIBNAME.用户名l_logondatabapilogond.日期此处的return在下面调到
5、他的自带MESSAGE,(提示信息)l_returnBAPIRET20*l_return1L_RETURN. 如果用系统表里的结构就可以用这句,而不用下面自己声明结构,不过一般必要的自己写结构WA_MSSAGE,USERNAMEBAPIBNAME-BAPIBNAME, UTYPEMESSAGE-MSGTY,消息类型MSGTXMESSAGE-MSGTX,消息文本FLAGSCLENGTH10, 消息灯颜色WA_MSSAGE.IT_MSSAGEWA_MSSAGEZ_BAPIWHERETAGX把前面读取excel的数据赋给这3个字段IT_USERS-USERNAME.IT_USERS-PASSWORD
6、.l_address-LASTNAMEIT_USERS-LASTNAME.address是一个系统结构,而我只需要LASTNAME字段,所以-lastnameBAPI_USER_CREATEusernamel_usernamepasswordl_bapipwdaddressl_addressLOGONDATAl_logondatareturnl_return.L_RETURN.IT_MSSAGE-USERNAMEl_username.IT_MSSAGE-UTYPEL_RETURN-TYPE.l-return是一张消息表IT_MSSAGE-MSGTXL_RETURN-MESSAGE.IT_MSS
7、AGE.如果是弹出消息提示,就是下面这串代码,因为我们要用lv来显示消息信息,所以这段代码此处无用L_RETURNTO*如果成功则调用i005(ZBAPI),否则调用自带的消息文本.MESSAGEi005(ZBAPI)l_return-MESSAGE.*定义窗口定制控制,定义ALV对象WA_CONTAINERSCRFNAMEVALUELV,LV是屏幕上画出来的LV的名字ALV_GRIDREFCL_GUI_ALV_GRID,WA_CUSTOM_CONTAINERCL_GUI_CUSTOM_CONTAINER.GS_FIELDCATLVC_S_FCAT,GT_FIELDCATLVC_T_FCAT.
8、*- PBO屏幕输出前执行-*STATUS_0100OUTPUT.*如果窗口还没有创建ALV对象则创建它ISINITIAL.CREATEOBJECTWA_CUSTOM_CONTAINERCONTAINER_NAMEWA_CONTAINER.屏幕上LV名字,在声明中已给初始值ALV_GRIDI_PARENTWA_CUSTOM_CONTAINER.FRM_FIELDCAT.调用自定义LV显示列表ALV_GRID-SET_TABLE_FOR_FIRST_DISPLAYIT_OUTTABIT_MSSAGEIT_FIELDCATALOGGT_FIELDCAT.CLEARIT_MSSAGE.ENDMODU
9、LE.*-自定义LV显示-*FRM_FIELDCATGS_FIELDCAT-COL_POSGS_FIELDCAT-FIELDNAMEUSERNAMEGS_FIELDCAT-OUTPUTLEN24.GS_FIELDCAT-COLTEXT用户GT_FIELDCAT.UTYPE20.消息类型MSGTX80.消息4.FLAGS10.备注 B D C*BDC批量Z_BDCIT_USERS.IT_USERS-TAGCLEAR:IT_BDCDATA,IT_BDCDATA.performbdc_dynprousingSAPLSUU50050bdc_fieldBDC_CURSORUSR02-BNAMEBDC_O
10、KCODE=CREA0100=UPDADDR3_DATA-NAME_LASTIT_USERS-LASTNAME.ADDR3_DATA-LANGU_Precord-LANGU_P_003.ADDR3_DATA-DEFLT_COMMzhG_PASSWORD2USLOGOND-USTYPG_PASSWORD1bdc_transactionSU01FRM_MESSAGE.放IF里,代表只有选中才会赋值*-Startnewscreen -BDC_DYNPROUSINGPROGRAMDYNPRO.IT_BDCDATA.IT_BDCDATA-PROGRAMPROGRAM.BDC模块库IT_BDCDATA-D
11、YNPRODYNPRO.BDC屏幕号码IT_BDCDATA-DYNBEGIN*-InsertfieldBDC_FIELDFNAMFVAL.NODATA.FVALIT_BDCDATA.IT_IT_BDCDATA系统结构IT_BDCDATA-FNAMFNAM.FNAM字段名IT_BDCDATA-FVALFVAL.字段值BDC_TRANSACTIONtcode.REFRESHmesstab.TRANSACTIONtcodeIT_BDCDATAMODEN如果是,则代表点击按钮时直接保存,不然会跳su01界面去UPDATESMESSAGES-FormFRM_MESSAGE-FRM_MESSAGEL_MSTRING(248).LIST.导入灯包TABLEST100.SELECTSINGLEFROMT100SPRSLmesstab-MSGSPRAANDARBGBmesstab-MSGIDMSGNRmesstab-MSGNR.L_MSTRINGT100-TEXT.CS&1REPLACEmesstab-MSGV1L_MSTRING.2messtab-MSGV23messtab-MSGV34messtab-MSGV4messta
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1