通用導(dǎo)入導(dǎo)出程序(內(nèi)有完整代碼)_第1頁
通用導(dǎo)入導(dǎo)出程序(內(nèi)有完整代碼)_第2頁
通用導(dǎo)入導(dǎo)出程序(內(nèi)有完整代碼)_第3頁
通用導(dǎo)入導(dǎo)出程序(內(nèi)有完整代碼)_第4頁
通用導(dǎo)入導(dǎo)出程序(內(nèi)有完整代碼)_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、通用導(dǎo)入導(dǎo)出程序 (可以自動(dòng)生成模板)在SAP實(shí)施和運(yùn)維過程中經(jīng)常有需要批量將數(shù)量導(dǎo)入到透明表的場(chǎng)景。這時(shí)如何往往需要開發(fā)一些導(dǎo)入的程序。因?yàn)橥该鞅淼慕Y(jié)構(gòu)不同,所以這些導(dǎo)入程序往往只能對(duì)一個(gè)透明表進(jìn)行導(dǎo)入,并且由于這些程序相當(dāng)多,所以沒有完整的下載備份數(shù)據(jù)和生成模板的功能。為了省時(shí),作者開發(fā)這個(gè)通用導(dǎo)入導(dǎo)出程序,可以對(duì)所有的透明進(jìn)行導(dǎo)出導(dǎo)入并且自動(dòng)生成導(dǎo)入模板。另外提供跨CLIENT選項(xiàng),用戶可以選擇只處理當(dāng)前CLIENT的數(shù)據(jù)(這時(shí)模板中不會(huì)有MANDT字段)。-功能一:下載導(dǎo)入模板和下載數(shù)據(jù)(可選)選擇路徑和文件名生成的模板打開之后的樣子如果帶數(shù)據(jù)的話是這個(gè)樣子如果選擇跨CLIENT的話功

2、能二:上傳數(shù)據(jù)如果是導(dǎo)入系統(tǒng)透明表會(huì)有提示如果選擇確定導(dǎo)入-還是會(huì)打開文件選擇器選擇了本地的模板文件就可導(dǎo)入了(注意跨CLIENT選擇項(xiàng),選擇了跨CLIENT要使用帶MANDT字段的模板。希望能對(duì)整數(shù)據(jù)的XDJM們有所幫助-(以下是完整代碼,COPY到系統(tǒng)中激活即可)*&-*&ReportZRP_BC_GENERAL_IMPEXP*&*&-*&*&*&-*REPORTzrp_bc_general_impexp.TYPES:gtyt_fieldcatTYPElvc_t_fcat.*FIELD-SYMBOLS:*TYPEtable.CONSTANTS:gc_xTYPEchar1VALUEX,gc_

3、lpVALUE(,gc_rpVALUE),gc_isVALUE-.DATA:gr_exclTYPERANGEOFlvc_fnameWITHHEADERLINE.PARAMETERS:gp_tnTYPEtabnameMEMORYIDztctmOBLIGATORY.SELECTION-SCREENBEGINOFBLOCKgc1WITHFRAMETITLEg_gc1tx.PARAMETERSgp_dloadRADIOBUTTONGROUPrg1DEFAULTXUSER-COMMANDgc1.SELECTION-SCREENBEGINOFLINE.SELECTION-SCREENCOMMENT2(20

4、)g_icdatMODIFIDgc1.PARAMETERSgp_icdaASCHECKBOXMODIFIDgc1.SELECTION-SCREENENDOFLINE.PARAMETERSgp_uloadRADIOBUTTONGROUPrg1.SELECTION-SCREENENDOFBLOCKgc1.SELECTION-SCREENSKIP1.PARAMETERSgp_mandtASCHECKBOX.LOAD-OF-PROGRAM.PERFORMsub_init_screen.INITIALIZATION.ATSELECTION-SCREENOUTPUT.PERFORMsub_pbo_1000

5、.ATSELECTION-SCREEN.IFsy-ucomm=ONLI.PERFORMsub_check_screen.PERFORMsub_init_object.CASEgc_x.WHENgp_dload.PERFORMsub_download_1000CHANGINGsy-subrc.WHENgp_uload.PERFORMsub_upload_1000CHANGINGsy-subrc.ENDCASE.IFsy-subrc0.MESSAGE出現(xiàn)錯(cuò)誤!TYPEE.ELSE.CASEgc_x.WHENgp_dload.MESSAGE下載成功!TYPES.WHENgp_uload.MESSAG

6、E上傳成功!TYPES.ENDCASE.ENDIF.ENDIF.*START-OF-SELECTION.*&-*&Formsub_init_screen*&-*text*-*FORMsub_init_screen.g_gc1tx=你想干什么?.g_icdat=同時(shí)下載數(shù)據(jù)(僅限于表).ENDFORM.sub_init_screen*&-*&Formsub_pbo_1000*&-*text*-*FORMsub_pbo_1000.*break-point.LOOPATSCREEN.IFscreen-group1=GC1.IFgp_dload=gc_x.CLEARscreen-invisible.E

7、LSE.screen-invisible=1.ENDIF.MODIFYSCREEN.ENDIF.ENDLOOP.ENDFORM.sub_pbo_1000*&-*&Formsub_check_screen*&-*text*-*FORMsub_check_screen.TRANSLATEgp_tnTOUPPERCASE.IFgp_uload=gc_xAND(gp_tn(1)ZORgp_tn(1)Y).DATA:l_answer.CALLFUNCTIONPOPUP_TO_CONFIRMEXPORTINGtitlebar=sy-title*DIAGNOSE_OBJECT=text_question=你

8、導(dǎo)入的表是系統(tǒng)標(biāo)準(zhǔn)表,隨意修改有可以導(dǎo)致系統(tǒng)崩潰!text_button_1=確定導(dǎo)入!(001)icon_button_1=ICON_IMPORTtext_button_2=不導(dǎo)算了icon_button_2=ICON_CANCELdefault_button=2display_cancel_button=space*USERDEFINED_F1_HELP=*START_COLUMN=25*START_ROW=6*POPUP_TYPE=*IV_QUICKINFO_BUTTON_1=*IV_QUICKINFO_BUTTON_2=IMPORTINGanswer=l_answer*TABLES*P

9、ARAMETER=EXCEPTIONStext_not_found=1OTHERS=2.IFsy-subrc0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ELSE.IFl_answer=2.LEAVESCREEN.ELSE.MESSAGE導(dǎo)入系統(tǒng)標(biāo)準(zhǔn)表功能暫時(shí)取消,請(qǐng)等待項(xiàng)目組通知再開放使用!TYPEE.ENDIF.ENDIF.ENDIF.ENDFORM.sub_check_screen*&-*&Formsub_init_object*&-*text*-*FORMsub_ini

10、t_object.REFRESHgr_excl.gr_excl-sign=I.gr_excl-option=EQ.gr_excl-low=ZZZZZZZZ99999999.APPENDgr_excl.IFgp_mandtgc_x.gr_excl-sign=I.gr_excl-option=EQ.gr_excl-low=MANDT.APPENDgr_excl.ENDIF.ENDFORM.sub_init_object*&-*&Formsub_download_1000*&-*text*-*FORMsub_download_1000CHANGINGvalue(p_subrc)LIKEsy-subr

11、c.DATA:lt_fctTYPEgtyt_fieldcat,lt_fctsTYPEgtyt_fieldcat.DATA:lt_refTYPEREFTOdata,lt_ref2TYPEREFTOdata,l_pathLIKErlgrap-filename,l_lenTYPEcLENGTH6.FIELD-SYMBOLS:LIKELINEOFlt_fct,TYPEtable,TYPEANY,LIKELINEOFlt_fcts,TYPEtable,TYPEANY,.p_subrc=4.CALLFUNCTIONLVC_FIELDCATALOG_MERGEEXPORTINGi_structure_nam

12、e=gp_tnCHANGINGct_fieldcat=lt_fctEXCEPTIONSinconsistent_interface=1program_error=2OTHERS=3.IFsy-subrc0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ELSE.lt_fcts=lt_fct.DELETElt_fctsWHEREfieldnameINgr_excl.LOOPATlt_fctsASSIGNING.CLEAR:-domname,-decimals,-tech,-ref_t

13、able,-ref_field,-tabname.-datatype=CHAR.-inttype=C.IF-intlen30.-intlen=-outputlen=30.ENDIF.ENDLOOP.CALLMETHODcl_alv_table_create=create_dynamic_tableEXPORTINGit_fieldcatalog=lt_fctsIMPORTINGep_table=lt_refEXCEPTIONSgenerate_subpool_dir_full=1.IFsy-subrc0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWI

14、THsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ENDIF.ASSIGNlt_ref-*TO.APPENDINITIALLINETOASSIGNING.LOOPATlt_fctsASSIGNING.READTABLElt_fctASSIGNINGWITHKEYfieldname=-fieldname.ASSIGNCOMPONENT-fieldnameOFSTRUCTURETO.IFsy-subrc=0.*IF-fieldnameCPZDSE*.*=常量“/”.*ELSE.CLEARl_len.WRITE-intlenTOl_lenNO-ZERO.CONDENSEl_len

15、NO-GAPS.CONCATENATE-scrtext_mgc_lp-inttypel_lengc_rpINTO.*ENDIF.ENDIF.ENDLOOP.APPENDINITIALLINETOASSIGNING.LOOPATlt_fctsASSIGNING.ASSIGNCOMPONENT-fieldnameOFSTRUCTURETO.IFsy-subrc=0.PERFORMfrm_repeat_charUSING-intlengc_isCHANGING.ENDIF.ENDLOOP.IFgp_icda=gc_x.CALLMETHODcl_alv_table_create=create_dyna

16、mic_tableEXPORTINGit_fieldcatalog=lt_fctIMPORTINGep_table=lt_ref2EXCEPTIONSgenerate_subpool_dir_full=1.IFsy-subrc0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ENDIF.ASSIGNlt_ref2-*TO.IFgp_mandt=gc_x.SELECT*FROM(gp_tn)CLIENTSPECIFIEDAPPENDINGCORRESPONDINGFIELDSOFTA

17、BLE.ELSE.SELECT*FROM(gp_tn)APPENDINGCORRESPONDINGFIELDSOFTABLE.ENDIF.LOOPATASSIGNING.APPENDINITIALLINETOASSIGNING.MOVE-CORRESPONDINGTO.ENDLOOP.FREE:lt_ref2,.ENDIF.*BREAK-POINT.PERFORMget_localfilepathUSINGXLSSsy-titleCHANGINGl_path.IFsy-subrc0.IFsy-subrc=3.LEAVESCREEN.ELSE.MESSAGEIDsy-msgidTYPEsy-ms

18、gtyNUMBERsy-msgnoWITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ENDIF.ELSE.DATA:l_strTYPEstring.l_str=l_path.CALLFUNCTIONGUI_DOWNLOADEXPORTING*BIN_FILESIZE=filename=l_strfiletype=DAT*APPEND=*WRITE_FIELD_SEPARATOR=*HEADER=00*TRUNC_TRAILING_BLANKS=*WRITE_LF=X*COL_SELECT=*COL_SELECT_MASK=*DAT_MODE=*CONFIRM_OVERW

19、RITE=*NO_AUTH_CHECK=*CODEPAGE=*IGNORE_CERR=ABAP_TRUE*REPLACEMENT=#*WRITE_BOM=*TRUNC_TRAILING_BLANKS_EOL=X*WK1_N_FORMAT=*WK1_N_SIZE=*WK1_T_FORMAT=*WK1_T_SIZE=*WRITE_LF_AFTER_LAST_LINE=ABAP_TRUE*SHOW_TRANSFER_STATUS=ABAP_TRUE*IMPORTING*FILELENGTH=TABLESdata_tab=*FIELDNAMES=EXCEPTIONSfile_write_error=1

20、no_batch=2gui_refuse_filetransfer=3invalid_type=4no_authority=5unknown_error=6header_not_allowed=7separator_not_allowed=8filesize_not_allowed=9header_too_long=10dp_error_create=11dp_error_send=12dp_error_write=13unknown_dp_error=14access_denied=15dp_out_of_memory=16disk_full=17dp_timeout=18file_not_

21、found=19dataprovider_exception=20control_flush_error=21OTHERS=22.IFsy-subrc0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.ELSE.p_subrc=0.*DATA:*l_answer.*CALLFUNCTIONPOPUP_TO_CONFIRM*EXPORTING*titlebar=sy-title*DIAGNOSE_OBJECT=*text_question=是否馬上打開下載的模板進(jìn)行編輯?*text_b

22、utton_1=馬上打開*icon_button_1=ICON_XLS*text_button_2=以后再處理*icon_button_2=ICON_CANCEL*default_button=2*display_cancel_button=space*USERDEFINED_F1_HELP=*START_COLUMN=25*START_ROW=6*POPUP_TYPE=*IV_QUICKINFO_BUTTON_1=*IV_QUICKINFO_BUTTON_2=*IMPORTING*answer=l_answer*TABLES*PARAMETER=*EXCEPTIONS*text_not_fo

23、und=1*OTHERS=2.*IFsy-subrc0.*IFsy-subrc=3.*LEAVESCREEN.*ELSE.*MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgno*WITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.*ENDIF.*ELSE.*IFl_answer=1.*BREAK-POINT.*CALLFUNCTIONWS_EXECUTE*EXPORTING*DOCUMENT=*CD=*commandline=l_str*INFORM=*program=EXCEL*STAT=*WINID=*OSMAC_SCRIPT=*OS

24、MAC_CREATOR=*WIN16_EXT=*EXEC_RC=*IMPORTING*RBUFF=*EXCEPTIONS*frontend_error=1*no_batch=2*prog_not_found=3*illegal_option=4*gui_refuse_execute=5*OTHERS=6*.*IFsy-subrc0.*MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgno*WITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.*ENDIF.*data:l_returncodetypei.*CALLFUNCTIONGUI_EXE

25、C*EXPORTING*command=l_path*PARAMETER=*IMPORTING*RETURNCODE=l_returncode*.*CALLFUNCTIONITS_EXECUTE*EXPORTING*DOCUMENT=*CD=*commandline=l_str*INFORM=*program=EXCEL*STAT=*WINID=*OSMAC_SCRIPT=*OSMAC_CREATOR=*WIN16_EXT=*EXEC_RC=*IMPORTING*RBUFF=*EXCEPTIONS*frontend_error=1*prog_not_found=2*gui_refuse_exe

26、cute=3*OTHERS=4*.*IFsy-subrc0.*MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgno*WITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.*ENDIF.*callmethodCL_GUI_FRONTEND_SERVICES=EXECUTE*EXPORTING*DOCUMENT=l_str*APPLICATION=EXCEL*PARAMETER=l_str*EXCEPTIONS*CNTL_ERROR=1*ERROR_NO_GUI=2*BAD_PARAMETER=3*FILE_NOT_FOUND=4*PATH_NOT_FOUND=5*FILE_EXTENSION_UNKNOWN=6*ERROR_EXECUTE_FAILED=7*SYNCHRONOUS_FAILED=8*NOT_SUPPORTED_BY_GUI=9*others=10.*IFsy-subrc0.*MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgno*WITHsy-msgv1sy-msgv2sy-msgv3sy-msgv4.*ENDIF.*ENDIF.*ENDIF.ENDIF.ENDIF.ENDIF.FREE:lt_fcts,lt_fct.ENDFORM.sub_download_100

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論