01-SAP环境介绍以及abap基本语法

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1ABAPOVERVIEW&REPORT教材引用來源:SAPLibrary2SAP登錄新建一個SAP系統client3輸入正確用戶名密碼後登錄,如果該用戶已經登錄,則提示下面信息1.登錄並結束其他用戶2.登錄而不結束其他用戶3.退出登錄4567輸入欲編輯的程式名稱新增程式命名規則1.YXXX….2.ZXXX…群光的命名規則參考《SAP客製化命名原則》ABAPEditorT-code:SE388輸入程式名稱(Title)選擇開發之程式類型ABAPEditor9指定Package或使用LocalObject(不傳輸)練習程式請使用LocalObjectAssigningDevelopmentClass10RequestNumberDesc規則:UR單號+TCODE+NAME+DATE11根據所選之程式Type系統自動Generate新增之程式為Inactive狀態CreatingaProgram12ReportName,Module,DescriptionChangeHistory13儲存程式回前一段落離開編輯器向前或往後一段落切換顯示或修改模式語法檢查Active程式TestRun14Statement結束用‘.’將Cursor停在句法保留字上,並按[F1]鍵,可查詢Help1516執行結果報表預設Title17Exercise•1.複習SAP各項基本操作•2.新增一支練習程式18ReportBlockReportStartReportxxxGlobedefinitionTypes,TablesSelection-screenSelection-screenParametersSelect-optionsEventINITIALIZATION.ATSELECTION-SCREEN.START-OF-SELECTION.END-OF-SELECTION.TOP-OF-PAGE.END-OF-PAGE.19ReportStart•REPORTrep.1....NOSTANDARDPAGEHEADING2....LINE-SIZEcol3....LINE-COUNTn(m)4....MESSAGE-IDmid•ExampleREPORTZTEST06MESSAGE-IDZSD01LINE-SIZE80LINE-COUNT65(3)NOSTANDARDPAGEHEADING.20基本类型数据类型初始值说明示例CSPACE文本字符‘串’‘Name’N‘000..0’数字文本‘01234’T‘000000’时间‘150028’D‘00000000’日期‘20091231’I0整型345F0浮点数5E+04P0压缩数123,456,789.000X‘0’十六进制数‘3A’21變數宣告•SimpleFieldDefinitions-DATA:itypepdecimals0.•DefiningaStructuredDataObject-DATA:BEGINOFitab,...ENDOFitab.22TableWorkArea•TABLESdbtab.•EXAMPLESTABLES:MARA,MARC.23字串處理功能語法範例去除空白CONDENSECONDENSE(str)大小寫轉換TRANSLATETRANSLATEstrTOUPPERCASE.TRANSLATEstrTOLOWERCASE.結合字串CONCATENATECONCATENATEstr1str2INTOstr3.常量CONSTANTSCONSTANTSpi(8)VALUE'3.141593'.取得部分字元+initial(len)A=B+5(4).能夠使用的型態包含:C,D,N,T,X,STRING,XSTRING24Selection-screenSELECTION-SCREENBEGINOFBLOCKB1WITHFRAMETITLETEXT-001.PARAMETERS:P_WERKSTYPEMARC-WERKS.SELECT-OPTIONS:S_MATNRFORMARC-MATNR.SELECTION-SCREENENDOFBLOCKB1.25TextElement26TextElement27TextElement28TextElement29Selection-screen30Selection-screenSELECTION-SCREENBEGINOFLINE.PARAMETERS:P_MTARTTYPEMARA-MTART.SELECTION-SCREENENDOFLINE.31Selection-ScreenSELECTION-SCREENBEGINOFLINE.SELECTION-SCREENCOMMENT(10)FORFIELDP_MTART.PARAMETERS:P_MTARTTYPEMARA-MTART.SELECTION-SCREENENDOFLINE.32Selection-ScreenSELECTION-SCREENBEGINOFLINE.SELECTION-SCREENCOMMENT3(20)FORFIELDP_MTART.PARAMETERS:P_MTARTTYPEMARA-MTART.SELECTION-SCREENPOSITION40.SELECTION-SCREENCOMMENT(20)TEXT-AAA.SELECTION-SCREENENDOFLINE.33Selection-screenPARAMETERS:P_WERKSTYPEMARC-WERKSOBLIGATORY.PARAMETERS:P_MATNRTYPEMARC-MATNR.PARAMETERS:P_CHECKASCHECKBOXDEFAULT'X'.PARAMETERS:P_R1RADIOBUTTONGROUPR1.PARAMETERS:P_R2RADIOBUTTONGROUPR1.34Selection-screen•SELECT-OPTIONS–DEFAULTf–LOWERCASE–OBLIGATORY–NO-EXTENSION–NOINTERVALS35Selection-screenSELECT-OPTIONS:S_WERKSFORMARC-WERKSNOINTERVALS.SELECT-OPTIONS:S_MATNRFORMARC-MATNRNO-EXTENSION.36Event•INITIALIZATION.•ATSELECTION-SCREEN.•START-OF-SELECTION.•END-OF-SELECTION.•TOP-OF-PAGE.•END-OF-PAGE.37•Define•Initialization.程式一開始,最先執行段落.通常會用來作些初始值的設定,或是權限的確認.但部份公司會用來檢查工作執行的狀態.•Atselection-screen.這是針對User在選擇畫面中按下任何鍵後,立即所做的動作.通常用來判斷輸入的值是否正確,或是提供相當的協助.•Start-of-selection真正開始放你的程式,這部份通常是在放找尋資料的部份.•End-of-selection這段落通常是用來輸出資料的部份.•Top-of-page每當換頁時,這部份的程式碼.就會被執行到.通常是用來放表頭.•End-of-page每當換頁前,這部份的程式碼.就會被執行到.通常是用來放表尾.記著,這要配合Report的設定.ReportProgramStructure38ReadingData•讀取:SELECTselectclause[INTOclause]FROMfromclause[WHEREcond1][GROUPBYfields1][HAVINGcond2][ORDERBYfields2].–selectclause•Select[single|distinct]*•Select[single|distinct]field1field2…–INTOclause•INTOwa•INTOCORRESPONDINGFIELDSOFwa•INTO(f1,...,fn)•INTOTABLEitab•INTOCORRESPONDINGFIELDSOFTABLEitab•APPENDINGTABLEitab•APPENDINGCORRESPONDINGFIELDSOFTABLEitab39ReadingData–Fromclause•FROMdbtab•FROMtabref1[INNER]JOINtabref2ONcond•FROMtabref1LEFT[OUTER]JOINtabref2ONcond–Whereclause•WHEREcond•FORALLENTRIESINitabWHEREcond40ReadingData–ExamplesDATA:BEGINOFITAB2OCCURS0,MATNRTYPEMATNR,WERKSTYPEWERKS_D,ENDOFITAB2.SELECTMARA~MATNRMARC~WERKSINTOCORRESPONDINGFIELDSOFTABLEITAB2FROMMARAINNERJOINMARCONMARC~MATNR=MARA~MATNRWHEREMARA~MTART=‘FERT’ANDMARC~WERKS=‘TW01’.41InternalTable•新增APPEND•LOOPAT•修改MODIFY•刪除DELETE•清除REFRESH•筆數計算DESCRIBE•SORT42InternalTable•宣告DATA:BEGINOFITABOCCURS0,MATNRTYPEMATNR,DESCRTYPEMAKTX,ENDOFITAB.•新增–APENDitabITAB-MATNR=‘A’.ITAB-DESCR=‘MaterialA’.APPENDITAB.–APPENDwaTOitab.Data:WALIKEITAB.WA-MATNR=‘B’.WA-DESCR=‘MaterialB’.APPENDWATOITAB.AMaterialAAMaterialABMaterialB43InternalTable•LOOPATLOOPATITAB.WRITE:/ITAB-MATNR,ITAB-MAKTX.ENDLOOP.OUTPUT:AMaterialABMaterialB44InternalTable•修改–MODIFYitabfromwaindexIWA-MATNR=‘C’.MODIFYITABFROMWAINDEX2.–MODIFYitab=只在LOOPATitab有效LOOPATITAB.IFSY-TABIX=2.ITAB-MAKTX=‘CC’.ENDIF.MODIFYITAB.ENDLOOP.AMaterialACMaterialBAMaterialACCC45InternalTable•刪除–DELETEitabINDEXI.DELETEITABINDEX1.–DELETEitab=只在LOOPATitab有效LOOPATITAB.DELETEITAB.ENDLOOP.BMaterialB46InternalTable•清除REFRESH–REFRESHitab.•筆數計算DESCRIBEDATA:CNTTYPEI.DESCRIBETABLEITABLINESCNT.•SORTSORTITABBYMATNR.47WaysofstartingtheDebugger•1.在執行視窗的命令列輸入“/H”.•2.在程式碼中下Break-point.•3.在display模式開啟程式,找到要作中斷的點,直接設定“STOP”.48逐行執行執行一行整段回到上層向下執行,直到有新斷點495051end

1 / 51
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功