ABAP 销售订单BAPI创建批导程序
生活随笔
收集整理的這篇文章主要介紹了
ABAP 销售订单BAPI创建批导程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、效果圖
1.1篩選界面截圖
1.2模板數據上傳預覽圖
1.3導入效果圖
2、附贈源代碼
*&---------------------------------------------------------------------* *& Report ZVA01 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* report zva01. include: zotnp001."EXCEL封裝的對象,及相關的操作方法 tables: sscrfields."定義按鈕 type-pools: slis. *********************************************************************** * *數據類型定義邏輯塊 * ************************************************************************ data: gw_textfield like smp_dyntxt. data: bdcdata like bdcdata occurs 0 with header line. data: messtab like bdcmsgcoll occurs 0 with header line. *data: messtab2 like TABLE OF bdcmsgcoll . data: ctumode like ctu_params-dismode. data: g_dcount(5) type n value 0. "記錄數 data: ref_grid type ref to cl_gui_alv_grid. data:it_fieldcat type lvc_t_fcat,wa_fieldcat like line of it_fieldcat. data:l_kalks type knvv-kalks , "定價過程l_kschl type a904-kschl. "條件類型 "導入數據 data:begin of gt_tab occurs 0,txt type string,index type string, "銷售訂單auart type VBAK-auart, "銷售憑證類型vkorg type VBAK-vkorg, "銷售組織vtweg type VBAK-vtweg, "分銷渠道spart type VBAK-spart, "產品組vkbur type VBAK-vkbur, "銷售辦事處kunnr type string, "售達方kunag type string, "送達方bstnk type string, "客戶參考posnr type string, "行項目matnr type string, "物料kwmeng type string, "訂單數量werks type string, "工廠lgort type string, "庫存地點augru type string, "訂貨原因remarks type string, "抬頭備注lin type string, "行項目備注prsdt type string, "行項目定價日期end of gt_tab. data: begin of gt_out occurs 0, "顯示結果txt type string,index type string, "銷售訂單auart type VBAK-auart, "銷售憑證類型vkorg type VBAK-vkorg, "銷售組織vtweg type VBAK-vtweg, "分銷渠道spart type VBAK-spart, "產品組vkbur type VBAK-vkbur, "銷售辦事處kunnr type vbak-kunnr, "售達方kunag type likp-kunag, "送達方bstnk type string, "客戶參考posnr type vbap-posnr, "行項目matnr type vbap-matnr, "物料kwmeng2 type string, "訂單數量werks type string, "工廠lgort type string, "庫存地點augru type string, "訂貨原因remarks type string, "抬頭備注lin type string, "行項目備注prsdt type sy-datum, "行項目定價日期box(1),text type icons-text, "標識tabix type string, "文本kschl type konp-kschl, "條件類型kbetr type konp-kbetr, "條件金額konwa type konp-konwa, "條件貨幣kpein type konp-kpein, "條件單位kmein type konp-kmein, "計量單位kwmeng type vbap-kwmeng, "訂單數量end of gt_out. data:begin of gs_a904,kschl type konp-kschl, "條件類型kbetr type konp-kbetr, "條件金額konwa type konp-konwa, "條件貨幣kpein type konp-kpein, "條件單位kmein type konp-kmein, "計量單位end of gs_a904. define init_fieldcat.CLEAR WA_FIELDCAT.WA_FIELDCAT-FIELDNAME = &1.WA_FIELDCAT-COLTEXT = &2.APPEND WA_FIELDCAT TO IT_FIELDCAT. end-of-definition.************************************************************************ * *選擇界面程序邏輯塊 * ************************************************************************ selection-screen begin of block blk1 with frame title text-100. parameters : p_file like rlgrap-filename memory id file. selection-screen end of block blk1.selection-screen function key 1.initialization.gw_textfield-icon_id = '@EZ@'.gw_textfield-icon_text = text-001.sscrfields-functxt_01 = gw_textfield."點擊下載模板at selection-screen.case sscrfields-ucomm.when 'FC01'.perform frm_get_excel_templet.endcase."選擇文件路徑at selection-screen output.at selection-screen on value-request for p_file.perform get_tempath.start-of-selection.if p_file is initial.message '請選擇導入模板路徑' type 'S' display like 'E'.exit.endif.************************************************************************ * *數據處理邏輯塊 * ************************************************************************"獲取到上傳文檔的數據perform frm_upload_data."處理上傳文檔的數據perform frm_deal_data."AVL輸出perform frm_output.form frm_upload_data .data :lt_excel like alsmex_tabline occurs 0 with header line,l_col type i.field-symbols <fs>.field-symbols: <fs_tab> type standard table,<fs_line> type any.data: dref_table type ref to data,dref_line type ref to data.create data dref_table like table of gt_tab.assign dref_table->* to <fs_tab>.create data dref_line like gt_tab.assign dref_line->* to <fs_line>.call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'exportingfilename = p_filei_begin_col = 1i_begin_row = 2i_end_col = 50i_end_row = 20000tablesintern = lt_excelexceptionsinconsistent_parameters = 1upload_ole = 2others = 3. ************把 表 LT_TAB 的內容給到UPD_TAB1clear : gt_tab. refresh :gt_tab.delete lt_excel where row = '0001'.loop at lt_excel.l_col = lt_excel-col.assign component l_col of structure <fs_line> to <fs>.if <fs> is assigned.<fs> = lt_excel-value.endif.at end of row.append <fs_line> to <fs_tab>.clear <fs_line>.endat.endloop.append lines of <fs_tab> to gt_tab.g_dcount = lines( gt_tab ). "導入的記錄數unassign: <fs>,<fs_tab>,<fs_line>.clear: lt_excel[],lt_excel,l_col,dref_table,dref_line. endform. " FRM_UPLOAD_DATAform frm_va01_bapi.data:l_order_header_in like bapisdhd1, "銷售訂單抬頭l_order_header_inx like bapisdhd1x, "銷售訂單抬頭更新gt_return like table of bapiret2 with header line, "返回參數gt_order_items_in like table of bapisditm with header line, "銷售訂單項目gt_order_items_inx like table of bapisditmx with header line, "銷售訂單項目更新gt_order_partners like table of bapiparnr with header line, "銷售訂單合作伙伴l_sender like bapi_sender, "發送人邏輯系統l_salesdocumentin like bapivbeln-vbeln, "銷售訂單l_logic_switch like bapisdls, "邏輯切換的 SD 復選框l_order_conditions_in like table of bapicond with header line, "條件類型l_order_conditions_inx like table of bapicondx with header line, "條件類型更新l_salesdocument like bapivbeln-vbeln, "BAPI 銷售訂單gt_order_schedules_in like table of bapischdl with header line, "計劃行gt_order_schedules_inx like table of bapischdlx with header line, "計劃行更新。GT_ORDER_TEXT LIKE TABLE OF BAPISDTEXT WITH HEADER LINE."文本data:cp_eind type string,l_w type string,i_mes type char200."記錄銷售訂單抬頭,用作循環使用data:begin of gt_head occurs 0,index type string, "銷售訂單auart type string, "銷售憑證類型vkorg type string, "銷售組織vtweg type string, "分銷渠道spart type string, "產品組vkbur type string, "銷售辦事處bstnk type string, "客戶參考augru type string, "訂貨原因kunnr type string, "售達方kunag type string, "送達方Remarks TYPE STRING,end of gt_head."獲取到選中的訂單loop at gt_out where box = 'X'.gt_head-index = gt_out-index.gt_head-auart = gt_out-auart.gt_head-vkorg = gt_out-vkorg.gt_head-vtweg = gt_out-vtweg.gt_head-spart = gt_out-spart.gt_head-vkbur = gt_out-vkbur.gt_head-bstnk = gt_out-bstnk.gt_head-augru = gt_out-augru.gt_head-kunnr = gt_out-kunnr .gt_head-kunag = gt_out-kunag.GT_HEAD-Remarks = GT_OUT-Remarks.append gt_head.endloop."刪除重復項delete adjacent duplicates from gt_head comparing all fields.sort gt_head. * break k99997."進行數據處理loop at gt_head."銷售訂單clear l_salesdocumentin. * L_SALESDOCUMENTIN = GT_HEAD-INDEX.l_logic_switch-pricing = 'G'."銷售訂單抬頭clear l_order_header_in.l_order_header_in-doc_type = gt_head-auart."銷售訂單憑證類型l_order_header_in-sales_org = gt_head-vkorg."銷售組織l_order_header_in-distr_chan = gt_head-vtweg."分銷渠道l_order_header_in-division = gt_head-spart."產品組l_order_header_in-sales_off = gt_head-vkbur."銷售辦事處l_order_header_in-purch_no_c = gt_head-bstnk."客戶參考l_order_header_in-req_date_h = sy-datum."要求的交貨日期l_order_header_in-doc_date = sy-datum."憑證日期(接收/發送)if gt_head-auart = 'ZRE' or gt_head-auart = 'ZFR'.l_order_header_in-ord_reason = gt_head-augru."訂單原因endif."抬頭更新clear l_order_header_inx.l_order_header_inx-doc_type = 'X'.l_order_header_inx-sales_org = 'X'.l_order_header_inx-distr_chan = 'X'.l_order_header_inx-division = 'X'.l_order_header_inx-sales_off = 'X'.l_order_header_inx-purch_no_c = 'X'.l_order_header_inx-req_date_h = 'X'.l_order_header_inx-doc_date = 'X'.if gt_out-auart = 'ZRE'.l_order_header_inx-ord_reason = 'X'.endif."銷售合作伙伴gt_order_partners-partn_role = 'AG'."售達方gt_order_partners-partn_numb = gt_head-kunnr."售達方編號 * GT_ORDER_PARTNERS-ITM_NUMBER = GT_OUT-POSNR."銷售訂單項目append gt_order_partners.clear gt_order_partners.gt_order_partners-partn_role = 'WE'."送達方gt_order_partners-partn_numb = gt_head-kunag."送達方編號 * GT_ORDER_PARTNERS-ITM_NUMBER = GT_OUT-POSNR."銷售訂單項目append gt_order_partners.clear gt_order_partners."抬頭備注GT_ORDER_TEXT-TEXT_ID = 'Z003'."文本IDGT_ORDER_TEXT-LANGU = '1'."語言GT_ORDER_TEXT-TEXT_LINE = gt_head-Remarks."文本APPEND GT_ORDER_TEXT.CLEAR GT_ORDER_TEXT.loop at gt_out where box = 'X' and index = gt_head-index.call function 'CONVERSION_EXIT_CUNIT_INPUT'exportinginput = gt_out-kmeinimportingoutput = gt_out-kmein."銷售訂單項目gt_order_items_in-itm_number = gt_out-posnr."銷售訂單項目gt_order_items_in-material = gt_out-matnr."物料編碼gt_order_items_in-plant = gt_out-werks."工廠gt_order_items_in-store_loc = gt_out-lgort."庫存地點gt_order_items_in-target_qty = gt_out-kwmeng."目標數量gt_order_items_in-price_date = gt_out-prsdt."行項目定價日期append gt_order_items_in.clear gt_order_items_in."銷售訂單項目更新gt_order_items_inx-itm_number = gt_out-posnr.gt_order_items_inx-material = 'X'.gt_order_items_inx-plant = 'X'.gt_order_items_inx-store_loc = 'X'.gt_order_items_inx-target_qty = 'X'.gt_order_items_inx-price_date = 'X'.append gt_order_items_inx.clear gt_order_items_inx."計劃行gt_order_schedules_in-itm_number = gt_out-posnr."銷售憑證項目gt_order_schedules_in-req_qty = gt_out-kwmeng."各銷售單位訂單數量append gt_order_schedules_in.clear gt_order_schedules_in.gt_order_schedules_inx-itm_number = gt_out-posnr."銷售憑證項目gt_order_schedules_inx-req_qty = 'X'."各銷售單位訂單數量append gt_order_schedules_inx.clear gt_order_schedules_inx."條件類型l_order_conditions_in-itm_number = gt_out-posnr."銷售訂單項目l_order_conditions_in-cond_type = gt_out-kschl."條件類型l_order_conditions_in-cond_value = gt_out-kbetr."條件金額l_order_conditions_in-currency = gt_out-konwa."條件貨幣l_order_conditions_in-cond_unit = gt_out-kmein ."條件單位l_order_conditions_in-cond_p_unt = gt_out-kpein."條件定價單位l_order_conditions_in-curr_iso = gt_out-konwa."IOS代碼貨幣append l_order_conditions_in.clear l_order_conditions_in."條件類型更新l_order_conditions_inx-itm_number = gt_out-posnr."銷售訂單項目l_order_conditions_inx-cond_type = gt_out-kschl."條件類型l_order_conditions_inx-cond_value = 'X'."條件金額l_order_conditions_inx-currency = 'X'."條件貨幣l_order_conditions_inx-cond_unit = 'X' ."條件單位l_order_conditions_inx-cond_p_unt = 'X'."條件定價單位append l_order_conditions_inx.clear l_order_conditions_inx."項目備注GT_ORDER_TEXT-TEXT_ID = 'Z005'."文本 IDGT_ORDER_TEXT-ITM_NUMBER = gt_out-posnr."銷售訂單項目GT_ORDER_TEXT-LANGU = '1'."語言代碼GT_ORDER_TEXT-TEXT_LINE = gt_out-LIN."文本行APPEND GT_ORDER_TEXT.CLEAR GT_ORDER_TEXT.endloop."調用銷售訂單創建BAPIif gt_head-auart = 'ZRE'."由于BAPI:BAPI_SALESORDER_CREATEFROMDAT2把業務對象定義死了, 所以退貨訂單用此BAPI進行創建call function 'SD_SALESDOCUMENT_CREATE'exporting * salesdocument = salesdocumentinsales_header_in = l_order_header_insales_header_inx = l_order_header_inx * sender = sender * binary_relationshiptype = binary_relationshiptype * int_number_assignment = int_number_assignment * behave_when_error = behave_when_errorlogic_switch = l_logic_switch * business_object = 'BUS2032' * testrun = testrun * convert_parvw_auart = convertimportingsalesdocument_ex = l_salesdocumenttablesreturn = gt_return[]sales_items_in = gt_order_items_in[]sales_items_inx = gt_order_items_inx[]sales_partners = gt_order_partners[]sales_schedules_in = gt_order_schedules_in[]sales_schedules_inx = gt_order_schedules_inx[]sales_conditions_in = l_order_conditions_in[]sales_conditions_inx = l_order_conditions_inx[] * sales_cfgs_ref = order_cfgs_ref * sales_cfgs_inst = order_cfgs_inst * sales_cfgs_part_of = order_cfgs_part_of * sales_cfgs_value = order_cfgs_value * sales_cfgs_blob = order_cfgs_blob * sales_cfgs_vk = order_cfgs_vk * sales_cfgs_refinst = order_cfgs_refinst * sales_ccard = order_ccardsales_text = GT_ORDER_TEXT[] * sales_keys = order_keys * extensionin = extensionin * partneraddresses = partneraddresses * extensionex = extensionex.else.clear l_salesdocument.call function 'BAPI_SALESORDER_CREATEFROMDAT2'exporting * SALESDOCUMENTIN = L_SALESDOCUMENTINorder_header_in = l_order_header_inorder_header_inx = l_order_header_inx * SENDER = L_SENDER * BINARY_RELATIONSHIPTYPE = * INT_NUMBER_ASSIGNMENT = * BEHAVE_WHEN_ERROR =logic_switch = l_logic_switch * TESTRUN = * CONVERT = ' 'importingsalesdocument = l_salesdocumenttablesreturn = gt_return[]order_items_in = gt_order_items_in[]order_items_inx = gt_order_items_inx[]order_partners = gt_order_partners[]order_schedules_in = gt_order_schedules_in[]order_schedules_inx = gt_order_schedules_inx[]order_conditions_in = l_order_conditions_in[]order_conditions_inx = l_order_conditions_inx[] * ORDER_CFGS_REF = * ORDER_CFGS_INST = * ORDER_CFGS_PART_OF = * ORDER_CFGS_VALUE = * ORDER_CFGS_BLOB = * ORDER_CFGS_VK = * ORDER_CFGS_REFINST = * ORDER_CCARD =ORDER_TEXT = GT_ORDER_TEXT[] * ORDER_KEYS = * EXTENSIONIN = * PARTNERADDRESSES = * EXTENSIONEX = * NFMETALLITMS =.endif.* 處理錯誤消息:通過判斷消息的類型,來判斷BAPI是否成功clear i_mes.loop at gt_return.i_mes = i_mes && '*' && gt_return-type && gt_return-number && gt_return-message.if gt_return-type eq 'E' orgt_return-type = 'A' orgt_return = 'X'.cp_eind = 'X'. "失敗endif.if gt_return-type eq 'W'.l_w = 'X'.endif.endloop.if cp_eind ne 'X'.if l_w <> 'X'."存在警告信息loop at gt_out where index = gt_head-index and box = 'X'.gt_out-tabix = i_mes.gt_out-text = icon_green_light .gt_out-index = l_salesdocument.modify gt_out.endloop.else."成功生成訂單loop at gt_out where index = gt_head-index and box = 'X'.gt_out-tabix = i_mes.gt_out-text = icon_yellow_light .gt_out-index = l_salesdocument.modify gt_out.endloop.endif."提交事務call function 'BAPI_TRANSACTION_COMMIT'exportingwait = 'X'.commit work and wait.else."存在錯誤,創建失敗loop at gt_out where index = gt_head-index and box = 'X'.gt_out-tabix = i_mes.gt_out-text = icon_red_light .modify gt_out.endloop."回滾事務call function 'BAPI_TRANSACTION_ROLLBACK' .endif.clear l_order_header_in.clear l_order_header_inx.clear l_logic_switch.clear l_salesdocument.clear gt_return[].clear gt_order_items_in[].clear gt_order_items_inx[].clear gt_order_partners[].clear l_order_conditions_in[].clear l_order_conditions_inx[].clear gt_order_schedules_in[].clear gt_order_schedules_inx[].clear cp_eind.clear l_w.endloop.endform. form bdc_dynpro using program dynpro.clear bdcdata.bdcdata-program = program.bdcdata-dynpro = dynpro.bdcdata-dynbegin = 'X'.append bdcdata. endform. form bdc_field using fnam fval.clear bdcdata.bdcdata-fnam = fnam.bdcdata-fval = fval.append bdcdata. endform. *&---------------------------------------------------------------------* *& FORM FRM_GET_EXCEL_TEMPLET *&---------------------------------------------------------------------* * 下載EXCEL模版 *----------------------------------------------------------------------* * --> P1 TEXT * <-- P2 TEXT *----------------------------------------------------------------------* form frm_get_excel_templet .data: l_excel_control type ref to excel_control,l_objid type string value 'ZVA01', "模板對象名l_filename type string value '銷售訂單導入模板', "模板的EXCEL文件名l_br, "是否顯示路徑選擇l_dst type string value 'D:\'. " 路徑"創建對象create object l_excel_control."下載相關的EXCEL模板call method l_excel_control->get_excel_templetexportingi_objid = l_objidi_filename = l_filenameis_back_run = l_brchangingc_destination = l_dstexceptionstemplet_is_not_fount = 1can_not_save_file = 2templet_download_failure = 3others = 4.if sy-subrc ne 0.if sy-subrc eq 1.message '沒有找到相應的模板!' type 'S' display like 'E'.stop.elseif sy-subrc eq 2.stop.elseif sy-subrc eq 3.message '模板下載失敗!' type 'S' display like 'E'.stop.else.message '取得模板錯誤!' type 'S' display like 'E'.stop.endif.endif.clear: l_excel_control,l_objid, "模板對象名l_filename, "模板的EXCEL文件名l_br, "是否顯示路徑選擇l_dst. " 路徑 endform. " FRM_GET_EXCEL_TEMPLET *&---------------------------------------------------------------------* *& FORM GET_TEMPATH *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* * --> P1 TEXT * <-- P2 TEXT *----------------------------------------------------------------------* form get_tempath .call function 'WS_FILENAME_GET'exportingdef_filename = ' 'def_path = 'C:\'mask = 'EXCEL 文件 (*.XLS)|*.XLS;*.XLSX|'mode = '0'title = 'FIND THE TEXT FILE FOR UPLOAD'importingfilename = p_fileexceptionsinv_winsys = 1no_batch = 2selection_cancel = 3selection_error = 4others = 5.endform. " GET_TEMPATH *&---------------------------------------------------------------------* *& Form FRM_DEAL_DATA *&---------------------------------------------------------------------* *& 處理文檔數據 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* form frm_deal_data ."記錄銷售訂單抬頭,用作循環使用data:begin of gt_head occurs 0,index type string, "銷售訂單auart type string, "銷售憑證類型vkorg type string, "銷售組織vtweg type string, "分銷渠道spart type string, "產品組vkbur type string, "銷售辦事處bstnk type string, "客戶參考augru type string, "訂貨原因kunnr type string, "售達方kunag type string, "送達方remarks type string, "抬頭備注end of gt_head.data:l_index type i.data:matcher type ref to cl_abap_matcher.data:match type c length 1.DATA:L_QX TYPE CHAR1."記錄是否有權限"獲取到選中的訂單loop at gt_tab.gt_head-index = gt_tab-index.gt_head-auart = gt_tab-auart.gt_head-vkorg = gt_tab-vkorg.gt_head-vtweg = gt_tab-vtweg.gt_head-spart = gt_tab-spart.gt_head-vkbur = gt_tab-vkbur.gt_head-bstnk = gt_tab-bstnk.gt_head-augru = gt_tab-augru.gt_head-kunnr = gt_tab-kunnr .gt_head-kunag = gt_tab-kunag.gt_head-remarks = gt_tab-remarks .append gt_head.endloop."刪除重復項delete adjacent duplicates from gt_head comparing all fields.sort gt_head.loop at gt_tab.move-corresponding gt_tab to gt_out.clear l_kalks.call function 'CONVERSION_EXIT_ALPHA_INPUT'exportinginput = gt_out-kunnrimportingoutput = gt_out-kunnr.call function 'CONVERSION_EXIT_ALPHA_INPUT'exportinginput = gt_out-kunagimportingoutput = gt_out-kunag.call function 'CONVERSION_EXIT_ALPHA_INPUT'exportinginput = gt_out-posnrimportingoutput = gt_out-posnr.call function 'CONVERSION_EXIT_MATN1_INPUT'exportinginput = gt_out-matnrimportingoutput = gt_out-matnr."權限校驗CLEAR L_QX. * BREAK-POINT."銷售部門權限authority-check object 'ZVKBUR1'id 'ZVKBUR'field GT_OUT-VKBUR.if sy-subrc <> 0.gt_out-tabix = gt_out-tabix && '*沒有銷售部門' && GT_OUT-VKBUR && '的權限' .gt_out-text = icon_red_light.L_QX = 'X'.ENDIF."憑證類型權限authority-check object 'V_VBAK_AAT'id 'AUART'field GT_OUT-AUARTid 'ACTVT'FIELD '01'.if sy-subrc <> 0.gt_out-tabix = gt_out-tabix && '*沒有憑證類型' && GT_OUT-AUART && '創建的權限' .gt_out-text = icon_red_light.L_QX = 'X'.ENDIF. "銷售范圍權限authority-check object 'V_VBAK_VKO'id 'VKORG'field GT_OUT-VKORGid 'VTWEG'FIELD GT_OUT-VTWEGID 'SPART'FIELD GT_OUT-SPARTID 'ACTVT'FIELD '01'.if sy-subrc <> 0.gt_out-tabix = gt_out-tabix && '*沒有銷售范圍' && GT_OUT-VKORG && '創建的權限' .gt_out-text = icon_red_light.L_QX = 'X'.ENDIF.IF L_QX <> 'X'."有權限"檢查必填字段if gt_out-index is initial or gt_out-auart is initial or gt_out-vkorg is initial or gt_out-vtweg is initial orgt_out-spart is initial or gt_out-vkbur is initial or gt_out-kunnr is initial or gt_out-kunag is initial orgt_out-posnr is initial or gt_out-matnr is initial or gt_out-kwmeng is initial or gt_out-werks is initial orgt_out-lgort is initial.gt_out-tabix = gt_out-tabix && '*存在必填字段為空值,請檢查!' .gt_out-text = icon_red_light.endif.if gt_out-auart = 'ZOR' or gt_out-auart = 'ZYR'.if gt_out-bstnk is initial.gt_out-tabix = gt_out-tabix && '*客戶參考必填,請檢查!' .gt_out-text = icon_red_light.endif.elseif gt_out-auart = 'ZRE' or gt_out-auart = 'ZFR'.if gt_out-augru is initial.gt_out-tabix = gt_out-tabix && '*訂貨原因必填,請檢查!' .gt_out-text = icon_red_light.endif.endif."校驗抬頭數據一致性clear l_index.loop at gt_head where index = gt_tab-index.l_index = l_index + 1.endloop.if l_index > 1.gt_out-tabix = gt_out-tabix && '*該訂單抬頭數據不一致,請檢查!' .gt_out-text = icon_red_light.endif."校驗訂單類型是否正確if gt_out-auart = 'ZOR' or gt_out-auart = 'ZYR' or gt_out-auart = 'ZRE' or gt_out-auart = 'ZFR'.else.gt_out-tabix = gt_out-tabix && '*不能導入此' && gt_out-auart && '訂單類型,請檢查!' .gt_out-text = icon_red_light.endif."校驗銷售訂單、行項目是否為數字clear: matcher , match ."正則表達式matcher = cl_abap_matcher=>create( pattern = '\d+' text = gt_out-index ).match = matcher->match( ).if match <> 'X'.gt_out-tabix = gt_out-tabix && '*銷售訂單' && gt_out-index && '不是數字類型,請填寫數字!' .gt_out-text = icon_red_light.endif.clear: matcher , match ."正則表達式matcher = cl_abap_matcher=>create( pattern = '\d+' text = gt_out-posnr ).match = matcher->match( ).if match <> 'X'.gt_out-tabix = gt_out-tabix && '*行項目' && gt_out-posnr && '不是數字類型,請填寫數字!' .gt_out-text = icon_red_light.endif."校驗售達方和送達方select*from knvvinto table @data(gt_knvv)where kunnr = @gt_out-kunnrand vkorg = @gt_out-vkorgand vtweg = '00'and spart = '00'.if gt_knvv is initial.gt_out-tabix = gt_out-tabix && '*請BP維護售達方' && gt_out-kunnr && '的' && gt_out-vkorg && '銷售視圖!'.gt_out-text = icon_red_light.endif.clear gt_knvv.if gt_out-kunnr <> gt_out-kunag."售達方與送達方不一樣的時候,檢查送達方select*from knvvinto table gt_knvvwhere kunnr = gt_out-kunagand vkorg = gt_out-vkorgand vtweg = '00'and spart = '00'.if gt_knvv is initial.gt_out-tabix = gt_out-tabix && '*請BP維護送達方' && gt_out-kunag && '的' && gt_out-vkorg && '銷售視圖!'.gt_out-text = icon_red_light.endif.clear gt_knvv.endif."校驗行項目gt_tab-posnr = gt_tab-posnr mod 10.if gt_tab-posnr <> 0.gt_out-tabix = gt_out-tabix && '*行項目,請以10為單位遞增!'.gt_out-text = icon_red_light.endif."物料工廠校驗select*from marainto table @data(gt_mara)where matnr = @gt_out-matnr.if gt_mara is initial.gt_out-tabix = gt_out-tabix && '*該' && gt_out-matnr && '物料不存在'.gt_out-text = icon_red_light.else."物料存在"工廠檢驗select*from marcinto table @data(gt_marc)where matnr = @gt_out-matnrand werks = @gt_out-werks.if gt_marc is initial.gt_out-tabix = gt_out-tabix && '*該' && gt_out-matnr && '物料不存在' && gt_out-werks && '工廠視圖!'.gt_out-text = icon_red_light.else."工廠存在"庫存地點檢驗select*from mardinto table @data(gt_mard)where matnr = @gt_out-matnrand werks = @gt_out-werksand lgort = @gt_out-lgort.IF gt_mard is INITIAL.gt_out-tabix = gt_out-tabix && '*該' && gt_out-matnr && '物料不存在' && gt_out-werks && '工廠下的' && gt_out-lgort && '庫存地點!'.gt_out-text = icon_red_light.ENDIF.endif."銷售視圖校驗SELECT*FROM MVKEINTO TABLE @DATA(GT_MVKE)WHERE matnr = @gt_out-matnrAND VKORG = @GT_OUT-VKORGAND VTWEG = '00'.IF GT_MVKE IS INITIAL.gt_out-tabix = gt_out-tabix && '*該' && gt_out-matnr && '物料不存在' && GT_OUT-VKORG && '銷售視圖!' .gt_out-text = icon_red_light.ENDIF.endif.clear gt_mara.clear gt_marc.clear gt_mard.CLEAR GT_MVKE.IF GT_OUT-AUGRU is NOT INITIAL."訂貨原因檢查SELECT*FROM TVAUINTO TABLE @DATA(GT_TVAU)WHERE AUGRU = @GT_OUT-AUGRU.IF GT_TVAU IS INITIAL.gt_out-tabix = gt_out-tabix && '*該訂貨原因不存在,請填寫正確的訂貨原因編碼!' .gt_out-text = icon_red_light.ENDIF.ENDIF.CLEAR GT_TVAU."條件類型if gt_out-prsdt is initial.gt_out-prsdt = sy-datum.endif.if gt_out-auart <> 'ZFR'.selectkalksfrom knvvinto l_kalkswhere kunnr = gt_out-kunnrand vkorg = gt_out-vkorgand vtweg = '00'and spart = '00'.endselect.if l_kalks = 'Z1'."不含稅if gt_out-auart = 'ZYR'.gt_out-kschl = 'ZPR5'.else.gt_out-kschl = 'ZPR1'.endif.elseif l_kalks = 'Z2'."含稅if gt_out-auart = 'ZYR'.gt_out-kschl = 'ZPR4'.else.gt_out-kschl = 'ZPR0'.endif.endif.selecta904~kschlkbetrkonwakpeinkmeinfrom a904join konp on konp~knumh = a904~knumhinto gs_a904where a904~kschl = gt_out-kschland kbstat = '02'and a904~kfrst = ''and a904~vkorg = gt_out-vkorgand a904~kunnr = gt_out-kunnrand a904~vkbur = gt_out-vkburand a904~matnr = gt_out-matnrand a904~datbi >= gt_out-prsdtand a904~datab <= gt_out-prsdt.endselect.if gs_a904 is initial.gt_out-tabix = gt_out-tabix && '*不存在有效價格,請檢查!'.gt_out-text = icon_red_light.endif.gt_out-kschl = gs_a904-kschl.gt_out-kbetr = gs_a904-kbetr.gt_out-konwa = gs_a904-konwa.gt_out-kpein = gs_a904-kpein.gt_out-kmein = gs_a904-kmein.clear gs_a904.endif.call function 'CONVERSION_EXIT_CUNIT_OUTPUT'exportinginput = gt_out-kmeinimportingoutput = gt_out-kmein.ENDIF.gt_out-kwmeng = gt_tab-kwmeng .if gt_out-txt is initial.append gt_out.endif.clear gt_out.endloop.endform. *&---------------------------------------------------------------------* *& FORM FRM_OUTPUT *&---------------------------------------------------------------------* * TEXT *----------------------------------------------------------------------* * --> P1 TEXT * <-- P2 TEXT *----------------------------------------------------------------------* form frm_output .data: l_title type lvc_title,lt_layout type lvc_s_layo,l_colpos like sy-cucol value 1,lt_fieldcat type slis_t_fieldcat_alv.lt_layout-cwidth_opt = 'X'.lt_layout-box_fname = 'BOX'.refresh : lt_fieldcat."""" 憑證抬頭部份init_fieldcat 'INDEX' '銷售訂單' .init_fieldcat 'TEXT' '標識符' .init_fieldcat 'TABIX' '錯誤信息'.init_fieldcat 'AUART' '銷售憑證類型' .init_fieldcat 'VKORG' '銷售組織' .init_fieldcat 'VTWEG' '分銷渠道' .init_fieldcat 'SPART' '產品組' .init_fieldcat 'VKBUR' '銷售辦事處' .init_fieldcat 'KUNNR' '售達方' .init_fieldcat 'KUNAG' '送達方' .init_fieldcat 'BSTNK' '客戶參考' .init_fieldcat 'POSNR' '行項目' .init_fieldcat 'MATNR' '物料' .init_fieldcat 'KWMENG' '訂單數量' .init_fieldcat 'WERKS' '工廠' .init_fieldcat 'LGORT' '庫存地點' .init_fieldcat 'AUGRU' '訂貨原因' .init_fieldcat 'REMARKS' '抬頭備注' .init_fieldcat 'LIN' '行項目備注' .init_fieldcat 'PRSDT' '行項目定價日期' .init_fieldcat 'KSCHL' '條件類型' .init_fieldcat 'KBETR' '條件金額' .init_fieldcat 'KONWA' '條件貨幣' .init_fieldcat 'KPEIN' '定價單位' .init_fieldcat 'KMEIN' '計量單位' .call function 'REUSE_ALV_GRID_DISPLAY_LVC'exportingi_callback_program = sy-repidi_callback_pf_status_set = 'ALV_PF_STATUS'it_fieldcat_lvc = it_fieldcatis_layout_lvc = lt_layouti_callback_user_command = 'USER_COMMAND' * I_GRID_TITLE = L_TITLE * I_DEFAULT = 'X'i_save = 'A'tablest_outtab = gt_outexceptionsprogram_error = 1others = 2.if sy-subrc <> 0.message id sy-msgid type sy-msgty number sy-msgnowith sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.endif. endform. " FRM_OUTPUT **************設置狀態欄****************************** form alv_pf_status using rt_extab type slis_t_extab.data: begin of ex_tab occurs 0,fcode like sy-ucomm,end of ex_tab.set pf-status 'ZSD_VA01' excluding ex_tab. endform. "ADD BY KDL_D02 20190624 form user_command using r_ucomm like sy-ucommrs_selfield type slis_selfield.data: l_rsnum(10), "字符型預留號l_rspos(4), "字符型預留行號l_msg type string. "存放消息"聲明一個ALV實例"取得當前的ALV傳給聲明的實例,其目的就是取當ALV的對象。call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'importinge_grid = ref_grid."從ALV實例出來的數據更新ALV對應的內表call method ref_grid->check_changed_data.case r_ucomm.when 'INPUT'.data:l_x.loop at gt_out where box = 'X'.if gt_out-text = icon_red_light.l_x = 'X'.elseif gt_out-text = icon_yellow_light or gt_out-text = icon_green_light .l_x = 'S'.endif.endloop.if l_x = 'X'.message '存在錯誤數據,不能進行導入!' type 'E'.elseif l_x = 'S'.message '請勿重復導入數據!!!' type 'E'.else.data:answer type char2.call function 'POPUP_TO_CONFIRM_STEP'exportingdefaultoption = 'Y'textline1 = '警告:'textline2 = '是否需要進行導入!(PS:導入前請認真核查數據是否有誤,如未核查,可以點擊否或者取消來取消導入操作)'titel = '銷售訂單導入'start_column = 25start_row = 6cancel_display = 'X'importinganswer = answer.if answer = 'J'.perform frm_va01_bapi.elseif answer = 'N' or answer = 'A' .message '操作已取消!!!' type 'S'.endif.endif.clear l_x.perform frm_refresh_alv.when '&IC1'.read table gt_out index rs_selfield-tabindex into data(wa_sel_temp).if rs_selfield-value is not initial.IF wa_sel_temp-text = icon_yellow_light or wa_sel_temp-text = icon_green_light.if rs_selfield-fieldname = 'INDEX'."VA03跳轉set parameter id 'AUN' field rs_selfield-value.call transaction 'VA03' and skip first screen.endif.ENDIF.endif.when others.exit.endcase. endform. form frm_refresh_alv .data: gr_alvgrid type ref to cl_gui_alv_grid.call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'importinge_grid = gr_alvgrid.call method gr_alvgrid->refresh_table_displayexportingi_soft_refresh = 'X'exceptionsfinished = 1others = 2. endform.總結
以上是生活随笔為你收集整理的ABAP 销售订单BAPI创建批导程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jdbc获取clob图片_jdbc方式读
- 下一篇: centos6.4与win7双系统时间同