使用BAPI_CONTRACT_CREATE创建采购合同框架协议
生活随笔
收集整理的這篇文章主要介紹了
使用BAPI_CONTRACT_CREATE创建采购合同框架协议
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
*&---------------------------------------------------------------------*
*& Report ?ZMMF201 采購合同框架協(xié)議批導(dǎo)程序
*& T-code ?ZZME31K
*&---------------------------------------------------------------------*
*& Created by Xavery Hsueh on 2013-01-29 新開發(fā)程序
*&
*&---------------------------------------------------------------------*
REPORT ?zmmf201 NO STANDARD PAGE HEADING.
************************************************************************ ** ?聲明數(shù)據(jù)庫表 Declaration of database ?????????????????????????????** ************************************************************************ TABLES:ekko, ??????ekpo, ??????kna1. ???" ************************************************************************ ** ?定義結(jié)構(gòu)類型 Define the structure's type ?????????????????????????** ************************************************************************ * ????采購合同行項(xiàng)目及屬性 TYPES:BEGIN OF typ_ekpo, ???????ebelp ?TYPE ebelp, ????"采購合同項(xiàng)目號(hào) ???????pstyp ?TYPE pstyp, ????"項(xiàng)目類別 ???????knttp ?TYPE knttp, ????"科目分配類別 ???????matnr ?TYPE matnr, ????"物料號(hào) ???????matkl ?TYPE matkl, ????"物料組 ???????txz01 ?TYPE txz01, ????"短文本 ???????ktmng ?TYPE ktmng, ????"目標(biāo)數(shù)量 ???????meins ?TYPE meins, ????"單位 ???????netpr ?TYPE kbetr, ????"凈價(jià) ???????peinh ?TYPE epein, ????"價(jià)格單位 ???????bwtar ?TYPE bwtar_d, ??"評(píng)估類型 ???????mwskz ?TYPE mwskz, ????"稅碼 ???????werks ?TYPE werks_d, ?????"工廠 ???????webre ?TYPE webre, ????"基于GR的IV. ???????kostl ?TYPE kostl, ???????bednr ?TYPE bednr, ????"需求跟蹤號(hào) ???????kdatb ?TYPE ekko-kdatb, "條件記錄有效起始日期 ???????kdate ?TYPE ekko-kdate, "條件記錄有效截止日期 ???????atr01 ?TYPE char30, ?????END OF typ_ekpo. DATA: wa_ekpo TYPE typ_ekpo.
* ????采購合同抬頭數(shù)據(jù) TYPES:BEGIN OF typ_ekko, ???????ebeln ?TYPE ebeln, ???????"采購合同順序號(hào) ???????lifnr ?TYPE lifnr, ???????"供應(yīng)商賬號(hào) ???????evart ?TYPE bsart, ???????"協(xié)議類型 ???????ekorg ?TYPE ekko-ekorg, ??"采購組織 ???????ekgrp ?TYPE ekko-ekgrp, ??"采購組 ???????bukrs ?TYPE bukrs, ???????"公司代碼 ???????kdatb ?TYPE ekko-kdatb, ??"有效起始日期 ???????kdate ?TYPE ekko-kdate, ??"有效截止日期 ???????verkf ?TYPE everk, ???????"銷售員:外部合同號(hào) ???????waers ?TYPE waers, ???????"貨幣 ?????END OF typ_ekko. DATA: wa_ekko TYPE typ_ekko.
* ????采購合同數(shù)據(jù) DATA:BEGIN OF gt_po OCCURS 0, ???????ekko TYPE typ_ekko, ?????????"抬頭數(shù)據(jù) ???????ekpo TYPE TABLE OF typ_ekpo, "行項(xiàng)目數(shù)據(jù) ?????END OF gt_po. * ????結(jié)果內(nèi)表數(shù)據(jù) TYPES:BEGIN OF typ_result, ???????ekko ?TYPE typ_ekko, ???????"采購合同抬頭數(shù)據(jù) ???????ekpo ?TYPE typ_ekpo, ???????"采購合同行項(xiàng)目數(shù)據(jù) ???????box ??TYPE c, ??????????????"選擇標(biāo)記 ???????icon ?TYPE icon_d, ?????????"紅綠燈指示 ???????chrst TYPE char100, ????????"檢查結(jié)果 ?????END OF typ_result. ************************************************************************ ** ?定義變量與內(nèi)表 Define the variants and Internal tables ???????????** ************************************************************************ DATA:gt_result ?TYPE TABLE OF typ_result ?WITH HEADER LINE, ????gt_cell ?TYPE TABLE OF alsmex_tabline WITH HEADER LINE, ????gt_t149d TYPE TABLE OF t149d WITH HEADER LINE.
DATA:BEGIN OF gt_contract OCCURS 0, ??????ebeln TYPE ebeln, ??????contr TYPE ebeln, ??????icon ?TYPE icon_d, ??????chrst TYPE tdline, ????END OF gt_contract.
DATA:gt_text(4096) TYPE c OCCURS 0. DATA:g_file ?TYPE string. DATA:g_indic TYPE c, ??????????"數(shù)據(jù)錯(cuò)誤標(biāo)致 ????g_index TYPE i, ??????????"采購合同行項(xiàng)目的個(gè)數(shù) ????g_ebelp TYPE ebelp, ??????"行項(xiàng)目號(hào)計(jì)算 ????g_flag ?TYPE c. ??????????"判斷標(biāo)識(shí)
FIELD-SYMBOLS: TYPE typ_result. *@------------------ ALV 相關(guān)的變量 -----------------------------------* TYPE-POOLS:slis. DATA: g_grid TYPE REF TO ?cl_gui_alv_grid, ?????g_repid ????????????LIKE sy-repid, ?????g_structure_name ???TYPE tabname, ?????g_command ??????????TYPE ?slis_formname, ?????g_title ????????????TYPE lvc_title, ?????g_setting ??????????TYPE lvc_s_glay, ?????wa_print ???????????TYPE slis_print_alv, ?????gt_list_top_of_page TYPE slis_t_listheader, ?????gt_events ??????????TYPE slis_t_event WITH HEADER LINE, ?????gt_sort ????????????TYPE slis_t_sortinfo_alv, ?????wa_sort ????????????TYPE slis_sortinfo_alv, ?????wa_layout ??????????TYPE slis_layout_alv, ?????gt_fieldcat ????????TYPE slis_t_fieldcat_alv WITH HEADER LINE, ?????wa_fieldcat ????????LIKE LINE OF gt_fieldcat, ?????g_field ????????????TYPE char30, ?????g_save ?????????????TYPE c, ?????g_con_mark ?????????TYPE slis_fieldcat_alv-fieldname VALUE 'MARK', ?????g_length ???????????TYPE i, ?????g_pos ??????????????TYPE i.
FIELD-SYMBOLS:. *@---------------------------------------------------------------------* *@ ???創(chuàng)建采購合同 BAPI_CONTRACT_CREATE 用到的變量 *@---------------------------------------------------------------------* CONSTANTS:con_create TYPE char10 VALUE 'CREATE', ?????????con_change TYPE char10 VALUE 'CHANGE', ?????????con_yes ???TYPE c ?????VALUE 'X'.
DATA:g_action TYPE char10, ???????"執(zhí)行動(dòng)作說明 ????wa_header ???TYPE bapimeoutheader, ????wa_headerx ??TYPE bapimeoutheaderx, ????gt_h_cond_v ?TYPE TABLE OF bapimeoutheadvalidity WITH HEADER LINE, ????gt_h_cond_vx TYPE TABLE OF bapimeoutheadvalidityx WITH HEADER LINE, ????gt_item ?????TYPE bapimeout_t_item WITH HEADER LINE, ????gt_itemx ????TYPE bapimeout_t_itemx WITH HEADER LINE, ????gt_account ??TYPE TABLE OF bapimeoutaccount WITH HEADER LINE, ????gt_accountx ?TYPE TABLE OF bapimeoutaccountx WITH HEADER LINE, ????gt_item_cond_v TYPE TABLE OF bapimeoutvalidity WITH HEADER LINE, ????gt_item_cond_vx TYPE TABLE OF bapimeoutvalidityx WITH HEADER LINE, ????gt_item_cond ??TYPE TABLE OF bapimeoutcondition WITH HEADER LINE, ????gt_item_condx ?TYPE TABLE OF bapimeoutconditionx WITH HEADER LINE, ????gt_return TYPE bapiret2_t WITH HEADER LINE,
g_subrc TYPE sy-subrc.
DATA:g_ebeln TYPE bapimeoutheader-number, ??????????????????"#EC NEEDED ????gt_extensionin LIKE bapiparex OCCURS 0 WITH HEADER LINE, ????gt_extensionout TYPE bapiparex_t.
************************************************************************ ** ?宏定義 Define the macro ??????????????????????????????????????????** ************************************************************************ DEFINE mcr_range. ?clear &1. ?&1-sign = 'I'. ?&1-option = &2. ?&1-low = &3. ?&1-high = &4. ?append &1. END-OF-DEFINITION.
* 給FILEDCAT ALV內(nèi)表賦值 DEFINE mcr_field. ?clear wa_fieldcat. ?clear g_field. ?g_pos = g_pos + 1 . ?wa_fieldcat-col_pos ??????= ?g_pos. ?wa_fieldcat-fieldname = &1. ?wa_fieldcat-tabname = 'GT_RESULT'. * wa_fieldcat-no_out = 'X'. ?????"field no display, choose from layout ?wa_fieldcat-key = &2. ????????"SUBTOTAL KEY ?wa_fieldcat-seltext_l = &3. * 計(jì)算輸出字段的長(zhǎng)度 ?concatenate 'GT_RESULT-' &1 into g_field. ?assign (g_field) to . ?describe field output-length ?g_length. ?wa_fieldcat-outputlen = g_length. ?append wa_fieldcat to gt_fieldcat. END-OF-DEFINITION. ************************************************************************ ** ?選擇屏幕 Customize the selection-screen ??????????????????????????** ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK xavery WITH FRAME TITLE text-001. PARAMETERS: p_filenm TYPE rlgrap-filename. SELECTION-SCREEN END OF BLOCK xavery. ************************************************************************ ** ?執(zhí)行程序事件 Executing the program's events ??????????????????????** ************************************************************************ INITIALIZATION. ?PERFORM sub_init_cond.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filenm. ?PERFORM sub_get_directory.
START-OF-SELECTION. ?PERFORM sub_upload_data. ?????"上載數(shù)據(jù) ?PERFORM sub_process_data. ????"轉(zhuǎn)換數(shù)據(jù)類型與格式 ?PERFORM sub_check_header. ????"銷售訂單抬頭數(shù)據(jù)檢查 ?PERFORM sub_check_item. ??????"銷售訂單行項(xiàng)目數(shù)據(jù)檢查
END-OF-SELECTION. ?PERFORM sub_create_fieldcat. ?PERFORM sub_init_layout. ?PERFORM sub_display_as_alv.
*@---------------------------------------------------------------------* *@ ?????Form ?SUB_INIT_COND *@---------------------------------------------------------------------* * ??????初始化選擇條件 *----------------------------------------------------------------------* FORM sub_init_cond . ?p_filenm = '20130116-06-ME31K模版2.4.xlsx'. ENDFORM. ???????????????????" SUB_INIT_COND *&---------------------------------------------------------------------* *& ?????Form ?SUB_GET_DIRECTORY *&---------------------------------------------------------------------* * ??????給選擇條件字段添加文件目錄搜索幫助 *----------------------------------------------------------------------* FORM sub_get_directory. ?CALL FUNCTION 'WS_FILENAME_GET' ???EXPORTING ?????def_filename ????= p_filenm ?????mask ????????????= ',*.xls.' ?????mode ????????????= 'O' ?????title ???????????= 'File Name' ???IMPORTING ?????filename ????????= p_filenm ???EXCEPTIONS ?????inv_winsys ??????= 1 ?????no_batch ????????= 2 ?????selection_cancel = 3 ?????selection_error ?= 4 ?????OTHERS ??????????= 5. ?g_file = p_filenm. ENDFORM. ???????????????????" SUB_GET_DIRECTORY *&---------------------------------------------------------------------* *& ?????Form ?SUB_UPLOAD_DATA *&---------------------------------------------------------------------* * ??????將數(shù)據(jù)上載到內(nèi)表中 *----------------------------------------------------------------------* FORM sub_upload_data . * 上載電子表格數(shù)據(jù) ?CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' ???EXPORTING ?????filename ???????????????= p_filenm ?????i_begin_col ????????????= 1 ?????i_begin_row ????????????= 2 ?????i_end_col ??????????????= 139 ?????i_end_row ??????????????= 9999 ???TABLES ?????intern ?????????????????= gt_cell ???EXCEPTIONS ?????inconsistent_parameters = 1 ?????upload_ole ?????????????= 2 ?????OTHERS ?????????????????= 3. ENDFORM. ???????????????????" SUB_UPLOAD_DATA *&---------------------------------------------------------------------* *& ?????Form ?sub_process_data *&---------------------------------------------------------------------* * ??????將EXCEL上載上來的數(shù)據(jù)轉(zhuǎn)換到指定類型的內(nèi)表中 *----------------------------------------------------------------------* FORM sub_process_data . ?CLEAR:gt_result, ???????wa_ekko, ???????wa_ekpo, ???????g_index, ???????g_ebelp.
?g_flag = 'X'. ?g_index = 1. * 將上載的數(shù)據(jù)添加到結(jié)果內(nèi)表中 ?LOOP AT gt_cell. ???PERFORM sub_process_header. ??"處理采購合同抬頭數(shù)據(jù) ???PERFORM sub_process_item. ????"處理采購行項(xiàng)目數(shù)據(jù) * ??當(dāng)某行的指定字段值為‘#’號(hào),表示這是銷售訂單之間的分隔標(biāo)識(shí),本行 * ??不是有效數(shù)據(jù)。 ???AT END OF row. ?????IF g_flag = '#'. ????"銷售訂單結(jié)束行,不是有效的行項(xiàng)目數(shù)據(jù) ???????g_index = g_index + 1. ?"計(jì)算銷售訂單順序號(hào) ???????g_flag = 'X'. ???????CLEAR wa_ekko. ???????CLEAR g_ebelp. ?????ELSE. ???????CLEAR g_flag. ???????CLEAR gt_result. ???????g_ebelp = g_ebelp + 10. ?"計(jì)算銷售訂單行項(xiàng)目號(hào) ???????gt_result-ekko = wa_ekko. ???????gt_result-ekpo = wa_ekpo. ???????gt_result-ekko-ebeln = g_index. ???????gt_result-ekpo-ebelp = g_ebelp. ???????APPEND gt_result. ???????CLEAR wa_ekpo. ?????ENDIF. ???ENDAT. ?ENDLOOP. ENDFORM. ???????????????????" sub_process_data *&---------------------------------------------------------------------* *& ?????Form ?SUB_PROCESS_HEADER *&---------------------------------------------------------------------* * ??????處理上載文件中的采購合同抬頭數(shù)據(jù) *----------------------------------------------------------------------* FORM sub_process_header . ?CHECK g_flag = 'X'. ?CASE gt_cell-col. ???WHEN '0001'. ?????CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekko-lifnr. ????"供應(yīng)商賬號(hào) ???WHEN '0002'. ?????wa_ekko-evart = gt_cell-value. ?"協(xié)議類型 ???WHEN '0003'. ?????wa_ekko-ekorg = gt_cell-value. ?"采購組織 ???WHEN '0004'. ?????wa_ekko-ekgrp = gt_cell-value. ?"采購組 ???WHEN '0006'. ?????wa_ekko-bukrs = gt_cell-value. ?"公司代碼 ???WHEN '0007'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekko-kdatb. ?????"有效起始日期 ???WHEN '0008'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekko-kdate. ?????"有效截止日期 ???WHEN '0024'. ?????wa_ekko-verkf = gt_cell-value. ??"銷售員:外部合同號(hào) ???WHEN OTHERS. ?ENDCASE. ?wa_ekko-waers = 'RMB'. ENDFORM. ???????????????????" SUB_PROCESS_HEADER *&---------------------------------------------------------------------* *& ?????Form ?SUB_PROCESS_ITEM *&---------------------------------------------------------------------* * ??????處理上載文件中的銷售訂單行項(xiàng)目數(shù)據(jù) *----------------------------------------------------------------------* FORM sub_process_item . ?CASE gt_cell-col. ???WHEN '0001'. ?????IF gt_cell-value = '#'. ??"分隔標(biāo)記 ???????g_flag = '#'. ?????ENDIF. ???WHEN '0020'. ?????wa_ekpo-pstyp = gt_cell-value. ??????"項(xiàng)目類別 ???WHEN '0021'. ?????wa_ekpo-knttp = gt_cell-value. ??????"科目分配類別 ???WHEN '0009'. ?????wa_ekpo-matnr = gt_cell-value+0(18). "物料號(hào) ???WHEN '0005'. ?????wa_ekpo-werks = gt_cell-value. ??????"工廠 ???WHEN '0022'. ??????????????????????????"物料描述 ?????wa_ekpo-txz01 = gt_cell-value. ???WHEN '0023'. ?????wa_ekpo-matkl = gt_cell-value. ???WHEN '0010'. ?????wa_ekpo-ktmng = gt_cell-value. ??????"數(shù)量 ???WHEN '0011'. ?????wa_ekpo-meins = gt_cell-value. ??????"計(jì)量單位 ???WHEN '0012'. ?????wa_ekpo-netpr = gt_cell-value. ??????"凈價(jià) ???WHEN '0013'. ?????wa_ekpo-peinh = gt_cell-value. ??????"價(jià)格單位 ???WHEN '0014'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekpo-kdatb. ????????"有效截止日期 ???WHEN '0015'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekpo-kdate. ?????????"有效截止日期 ???WHEN '0016'. ?????wa_ekpo-bwtar = gt_cell-value. ??????"評(píng)估類型 ???WHEN '0017'. ?????wa_ekpo-mwskz = gt_cell-value. ??????"稅碼 ???WHEN '0018'. ?????wa_ekpo-webre = gt_cell-value. ??????"基于GR的IV. ???WHEN '0025'. ?????wa_ekpo-kostl ?= gt_cell-value. ???WHEN '0019'. ?????wa_ekpo-bednr ?= gt_cell-value. ???WHEN OTHERS. ?ENDCASE. ENDFORM. ???????????????????" SUB_PROCESS_ITEM *&---------------------------------------------------------------------* *& ?????Form ?SUB_CHECK_HEADER *&---------------------------------------------------------------------* * ??????檢查結(jié)果內(nèi)表的訂單抬頭數(shù)據(jù)并更新檢查狀態(tài) *----------------------------------------------------------------------* FORM sub_check_header .
ENDFORM. ???????????????????" SUB_CHECK_HEADER *&---------------------------------------------------------------------* *& ?????Form ?SUB_CHECK_ITEM *&---------------------------------------------------------------------* * ??????檢查結(jié)果內(nèi)表的訂單行項(xiàng)目數(shù)據(jù)并更新檢查狀態(tài) *----------------------------------------------------------------------* FORM sub_check_item . ?SELECT * FROM t149d INTO TABLE gt_t149d.
?SORT gt_t149d BY bwtar. ?LOOP AT gt_result ASSIGNING . * ??根據(jù)物料號(hào)來取物料組 ???IF -ekpo-matnr IS INITIAL. ???ELSE. ?????SELECT SINGLE ???????????matkl ???????????maktx ???????????meins ?????????INTO (-ekpo-matkl, ???????????????-ekpo-txz01, ???????????????-ekpo-meins) ?????????FROM mara INNER JOIN makt ON mara~matnr = makt~matnr ?????????WHERE mara~matnr = -ekpo-matnr AND ???????????????spras = 1. ???ENDIF. * ??檢查評(píng)估類型 ???CLEAR gt_t149d. ???READ TABLE gt_t149d WITH KEY bwtar = -ekpo-bwtar ????????????????????????????????BINARY SEARCH. ???IF sy-subrc = 0.
???ELSE. ?????IF -ekpo-bwtar IS NOT INITIAL. ???????-chrst = '輸入的評(píng)估類型不存在!'. ?????ENDIF. ???ENDIF. * ??數(shù)據(jù)正確賦綠燈,數(shù)據(jù)不正確賦紅燈 ???IF -chrst IS INITIAL. ?????-icon = '@08@'. ????????"綠燈 ???ELSE. ?????-icon = '@0A@'. ????????"紅燈 ???ENDIF. ?ENDLOOP. ENDFORM. ???????????????????" SUB_CHECK_ITEM *&---------------------------------------------------------------------* *& ?????Form ?SUB_CREATE_FIELDCAT *&---------------------------------------------------------------------* * ??????給輸出的結(jié)果內(nèi)表指定字段 *----------------------------------------------------------------------* FORM sub_create_fieldcat . ?CLEAR gt_fieldcat[]. ?mcr_field ?'ICON' ?????????'X' ???'指識(shí)標(biāo)識(shí)'. ?mcr_field ?'EKKO-EBELN' ???'X' ???'采購合同序號(hào)'. ?mcr_field ?'EKPO-EBELP' ???'X' ???'項(xiàng)目號(hào)'. ?mcr_field ?'EKKO-LIFNR' ???'' ????'供應(yīng)商賬號(hào)'. ?mcr_field ?'EKKO-EVART' ???'' ????'協(xié)議類型'. ?mcr_field ?'EKKO-EKORG' ???'' ????'采購組織'. ?mcr_field ?'EKKO-EKGRP' ???'' ????'采購組'. ?mcr_field ?'EKPO-WERKS' ???'' ????'工廠'. ?mcr_field ?'EKKO-BUKRS' ???'' ????'公司代碼'. ?mcr_field ?'EKKO-KDATB' ???'' ????'有效起始日期' . ?mcr_field ?'EKKO-KDATE' ???'' ????'有效截止日期' . ?mcr_field ?'EKKO-VERKF' ???'' ????'外部合同號(hào)'. ?mcr_field ?'EKPO-PSTYP' ???'' ????'項(xiàng)目類別'. ?mcr_field ?'EKPO-KNTTP' ???'' ????'科目分配類別'. ?mcr_field ?'EKPO-MATNR' ???'' ????'物料編號(hào)'. ?mcr_field ?'EKPO-TXZ01' ???'' ????'物料描述'. ?mcr_field ?'EKPO-MATKL' ???'' ????'物料組'. ?mcr_field ?'EKPO-KTMNG' ???'' ????'目標(biāo)數(shù)量'. ?mcr_field ?'EKPO-MEINS' ???'' ????'計(jì)量單位'. ?mcr_field ?'EKPO-KDATB' ???'' ????'條件記錄有效起始日期'. ?mcr_field ?'EKPO-KDATE' ???'' ????'條件記錄有效截止日期'. ?mcr_field ?'EKPO-NETPR' ???'' ????'凈價(jià)'. ?mcr_field ?'EKPO-PEINH' ???'' ????'價(jià)格單位'. ?mcr_field ?'EKPO-BWTAR' ???'' ????'評(píng)估類型'. ?mcr_field ?'EKPO-MWSKZ' ???'' ????'稅碼'. ?mcr_field ?'EKPO-WEBRE' ???'' ????'基于GR的IV'. ?mcr_field ?'EKPO-KOSTL' ???'' ????'成本中心'. ?mcr_field ?'EKPO-BEDNR' ???'' ????'需求跟蹤號(hào)'. ?mcr_field ?'CHRST' ????????'' ????'檢查結(jié)果'. ENDFORM. ???????????????????" SUB_CREATE_FIELDCAT *&---------------------------------------------------------------------* *& ?????Form ?SUB_INIT_LAYOUT *&---------------------------------------------------------------------* * ??????設(shè)置常用的輸出布局參數(shù) *----------------------------------------------------------------------* FORM sub_init_layout . ?wa_layout-zebra ????????????= 'X'. ?wa_layout-window_titlebar ??= '采購合同框架協(xié)議批導(dǎo)入程序'. ?wa_layout-colwidth_optimize = 'X'. ?wa_layout-box_fieldname ????= 'BOX'. ?wa_layout-header_text ??????= '選擇'. ENDFORM. ???????????????????" SUB_INIT_LAYOUT *&---------------------------------------------------------------------* *& ?????Form ?SUB_DISPLAY_AS_ALV *&---------------------------------------------------------------------* * ??????調(diào)用 ALV 的FUNCTION來輸出結(jié)果 *----------------------------------------------------------------------* FORM sub_display_as_alv . ?g_repid = sy-repid. ?g_setting-coll_top_p = 'X'. ??????"最小化 CALLBACK-TOP-OF-PAGE. * ABAP List Viewer ?CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' ???EXPORTING ?????i_callback_program ??????= g_repid ?????i_structure_name ????????= 'TYP_RESULT' ?????i_grid_title ????????????= g_title ?????i_grid_settings ?????????= g_setting ?????i_callback_user_command ?= 'SUB_USER_COMMAND' ?????i_callback_pf_status_set = 'SUB_SET_PF_STATUS' ?????i_save ??????????????????= g_save ?????is_layout ???????????????= wa_layout ?????it_fieldcat ?????????????= gt_fieldcat[] ???TABLES ?????t_outtab ????????????????= gt_result ???EXCEPTIONS ?????program_error ???????????= 1 ?????OTHERS ??????????????????= 2. ENDFORM. ???????????????????" SUB_DISPLAY_AS_ALV *@--------------------------------------------------------------------* *@ ?????Form ?sub_user_command *@--------------------------------------------------------------------* * ?????-->R_UCOMM ????事務(wù)功能碼 * ?????-->RS_SELFIELD ALV相關(guān)的數(shù)據(jù) *---------------------------------------------------------------------* FORM sub_user_command USING r_ucomm LIKE sy-ucomm ???????????????????????rs_selfield TYPE slis_selfield. ?DATA l_ebeln TYPE ebeln. ?CASE r_ucomm. ???WHEN '&IC1'. ????????????????"雙擊事件的功能碼 ?????CASE rs_selfield-fieldname. ???????WHEN 'EKKO-EBELN'. ?????????l_ebeln = rs_selfield-value. ?????????CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT' ???????????EXPORTING ?????????????i_ebeln ?????????????= l_ebeln ???????????EXCEPTIONS ?????????????not_found ???????????= 1 ?????????????no_authority ????????= 2 ?????????????invalid_call ????????= 3 ?????????????preview_not_possible = 4 ?????????????OTHERS ??????????????= 5. ?????????IF sy-subrc <> 0. ???????????MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno ???????????????????WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ?????????ENDIF.
???????WHEN OTHERS. ?????ENDCASE. ???WHEN 'CREATE'. ??????????????"創(chuàng)建銷售訂單 ?????PERFORM sub_ucomm_create. ?ENDCASE. * 刷新ALV報(bào)表 ?rs_selfield-refresh = 'X'. ENDFORM. ???????????????????"sub_user_command *@---------------------------------------------------------------------* *@ ??????FORM SUB_SET_PF_STATUS ???????????????????????????????????????* *@---------------------------------------------------------------------* * ?設(shè)置ALV菜單 * ?通過SE41,拷貝程序SAPLSLVC_FULLSCREEN的狀態(tài)STANDARD_FULLSCREEN過來 *@---------------------------------------------------------------------* FORM sub_set_pf_status USING rt_extab TYPE slis_t_extab. ?SET PF-STATUS 'STANDARD_FULLSCREEN'. ENDFORM. ???????????????????"sub_set_pf_status *&---------------------------------------------------------------------* *& ?????Form ?SUB_UCOMM_CREATE *&---------------------------------------------------------------------* * ??????創(chuàng)建銷售訂單 *----------------------------------------------------------------------* FORM sub_ucomm_create . ?PERFORM sub_check_data. ?"檢查數(shù)據(jù)是否正確 ?g_action = con_create. ?LOOP AT gt_result ASSIGNING WHERE icon = '@08@'. ???CLEAR:wa_ekko, ?????????wa_ekpo. * ??將抬頭數(shù)據(jù)信息賦值到BAPI函數(shù)的內(nèi)表 ???wa_ekko = -ekko. ???AT NEW ekko-ebeln. ?????REFRESH:gt_item, ?????????????gt_itemx, ?????????????gt_account, ?????????????gt_accountx, ?????????????gt_item_cond_v, ?????????????gt_item_cond_vx, ?????????????gt_item_cond, ?????????????gt_item_condx. ?????PERFORM sub_contract_header. ?????"處理銷售訂單抬頭數(shù)據(jù) ???ENDAT. * ??處理行項(xiàng)目的信息 ???wa_ekpo = -ekpo. ???PERFORM sub_contract_item. ???????"處理一般行項(xiàng)目信息 ???PERFORM sub_contract_account. ????"處理會(huì)計(jì)科目信息 ???PERFORM sub_contract_item_cond_v. "處理行項(xiàng)目的條件記錄有效日期 ???PERFORM sub_contract_item_cond. ??"處理行項(xiàng)目的條件記錄 * ??調(diào)用BAPI函數(shù)來創(chuàng)建銷售訂單 ???AT END OF ekko-ebeln. ?????PERFORM sub_contract_create. ???????"調(diào)用FUNCTION創(chuàng)建銷售訂單 ?????PERFORM sub_contract_commit. ???????"提交 ?????PERFORM sub_refresh_result. ????????"更新結(jié)果內(nèi)表 ???ENDAT. ?ENDLOOP. * 更新結(jié)果內(nèi)表 ?SORT gt_contract BY ebeln. ?LOOP AT gt_result ASSIGNING . ???CLEAR gt_contract. ???READ TABLE gt_contract WITH KEY ebeln = -ekko-ebeln ???????????????????????????????????BINARY SEARCH. ???IF sy-subrc = 0. ?????-icon ?= gt_contract-icon. ?????-ekko-ebeln = gt_contract-contr. ?????-chrst = gt_contract-chrst. ???ENDIF. ?ENDLOOP. ENDFORM. ???????????????????" SUB_UCOMM_CREATE *&---------------------------------------------------------------------* *& ?????Form ?SUB_CHECK_DATA *&---------------------------------------------------------------------* * ??????檢查導(dǎo)入的數(shù)據(jù)是否正確,如果不正確,則給出 Error Message,禁止 * ??????用戶繼續(xù)創(chuàng)建銷售訂單 *----------------------------------------------------------------------* FORM sub_check_data . ?LOOP AT gt_result WHERE icon = '@0A@'. ???MESSAGE '數(shù)據(jù)錯(cuò)誤,不能創(chuàng)建銷售訂單' TYPE 'E'. ?ENDLOOP. ENDFORM. ???????????????????" SUB_CHECK_DATA *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_HEADER *&---------------------------------------------------------------------* * ??????將采購合同抬頭數(shù)據(jù)添加到BAPI函數(shù)的內(nèi)表中 *----------------------------------------------------------------------* FORM sub_contract_header . ?wa_header-number ????= ''. "wa_ekko-ebeln. "合同號(hào) ?wa_header-vendor ????= wa_ekko-lifnr. "供應(yīng)商 ?wa_header-doc_type ??= wa_ekko-evart. "協(xié)議類型 ?wa_header-comp_code ?= wa_ekko-bukrs. "公司代碼 ?wa_header-doc_date ??= sy-datum. ?????"協(xié)議日期 ?wa_header-vper_start = wa_ekko-kdatb. "協(xié)議起始日期 ?wa_header-vper_end ??= wa_ekko-kdate. "協(xié)議截至日期 ?wa_header-purch_org ?= wa_ekko-ekorg. "采購組織 ?wa_header-pur_group ?= wa_ekko-ekgrp. "采購組 * ?wa_header-acum_value = wa_ekko-ktwrt. "目標(biāo)值 ?wa_header-currency ??= wa_ekko-waers. "貨幣 ?wa_header-langu ?????= sy-langu. ?wa_header-mast_cond ?= 'X'.
* ?wa_headerx-number ????= con_yes. "合同號(hào) ?wa_headerx-vendor ????= con_yes. "供應(yīng)商 ?wa_headerx-doc_type ??= con_yes. "協(xié)議類型 ?wa_headerx-comp_code ?= con_yes. "公司代碼 ?wa_headerx-doc_date ??= con_yes. "協(xié)議日期 ?wa_headerx-vper_start = con_yes. "協(xié)議起始日期 ?wa_headerx-vper_end ??= con_yes. "協(xié)議截至日期 ?wa_headerx-purch_org ?= con_yes. "采購組織 ?wa_headerx-pur_group ?= con_yes. "采購組 ?wa_headerx-acum_value = con_yes. "目標(biāo)值 ?wa_headerx-currency ??= con_yes. "貨幣 ?wa_headerx-langu ?????= con_yes. ?wa_headerx-mast_cond ?= con_yes.
?REFRESH: gt_h_cond_v, gt_h_cond_vx. ?gt_h_cond_v-serial_id ??= '1'. ?gt_h_cond_v-valid_from ?= wa_ekpo-kdatb. ?gt_h_cond_v-valid_to ???= wa_ekpo-kdate. ?APPEND gt_h_cond_v.
?gt_h_cond_vx-serial_id ??= '1'. ?gt_h_cond_vx-serial_idx ?= con_yes. ?gt_h_cond_vx-valid_from ?= con_yes. ?gt_h_cond_vx-valid_to ???= con_yes. ?APPEND gt_h_cond_vx. ENDFORM. ???????????????????" SUB_CONTRACT_HEADER *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ITEM *&---------------------------------------------------------------------* * ??????將采購合同行項(xiàng)目數(shù)據(jù)添加到BAPI函數(shù)的內(nèi)表中 *----------------------------------------------------------------------* FORM sub_contract_item . ?CLEAR: gt_item, gt_itemx. ?gt_item-item_no ???= wa_ekpo-ebelp. "行號(hào) ?gt_item-short_text = wa_ekpo-txz01. "短文本 ?gt_item-material ??= wa_ekpo-matnr. "物料編號(hào) ?gt_item-matl_group = wa_ekpo-matkl. "物料組 ?gt_item-plant ?????= wa_ekpo-werks. "工廠 ?gt_item-target_qty = wa_ekpo-ktmng. "目標(biāo)數(shù)量 ?gt_item-val_type ??= wa_ekpo-bwtar. "評(píng)估類型
?CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' ???EXPORTING ?????input ?????????= wa_ekpo-meins ?????language ??????= sy-langu ???IMPORTING ?????output ????????= wa_ekpo-meins ???EXCEPTIONS ?????unit_not_found = 1 ?????OTHERS ????????= 2.
?gt_item-po_unit ???= wa_ekpo-meins. ?gt_item-po_unit_iso = wa_ekpo-meins. ?gt_item-conv_num1 ??= '1'. ?gt_item-conv_den1 ??= '1'. ?gt_item-net_price ??= wa_ekpo-netpr. ???"凈價(jià) ?gt_item-price_unit ?= wa_ekpo-peinh. ???"價(jià)格單位 ?gt_item-orderpr_un ?= wa_ekpo-meins. ???"訂單價(jià)格單位(采購) ?gt_item-orderpr_un_iso = wa_ekpo-meins. "訂單價(jià)格單位(采購) ?gt_item-acctasscat ?= wa_ekpo-knttp. ???"科目分配類別 ?gt_item-item_cat ???= wa_ekpo-pstyp. ???"項(xiàng)目類別 ?gt_item-trackingno ?= wa_ekpo-bednr. ???"需求跟蹤號(hào) ?gt_item-tax_code ???= wa_ekpo-mwskz. ???"稅碼 * ?gt_item-pricedate ??= '4'. ?gt_item-price_date ?= wa_ekpo-kdatb. ?APPEND gt_item.
?gt_itemx-item_no ???= wa_ekpo-ebelp. "行號(hào) ?gt_itemx-item_nox ??= con_yes. ??????"行號(hào) ?gt_item-material ???= con_yes. ??????"物料號(hào) ?gt_itemx-short_text = con_yes. ??????"端文本 ?gt_itemx-matl_group = con_yes. ??????"物料組 ?gt_itemx-plant ?????= con_yes. ??????"工廠 ?gt_itemx-target_qty = con_yes. ??????"目標(biāo)數(shù)量 ?gt_itemx-po_unit ???= con_yes. ?gt_itemx-po_unit_iso = con_yes. ?gt_itemx-val_type ??= con_yes. ?gt_itemx-conv_num1 ?= con_yes. ?gt_itemx-conv_den1 ?= con_yes. ?gt_itemx-net_price ?= con_yes. ??????"凈價(jià) ?gt_itemx-price_unit = con_yes. ??????"價(jià)格單位 ?gt_itemx-orderpr_un = con_yes. ?gt_itemx-orderpr_un_iso = con_yes. ?gt_itemx-acctasscat = con_yes. ?????"科目分配類別 ?gt_itemx-item_cat ??= con_yes. ?????"項(xiàng)目類別 ?gt_itemx-trackingno = con_yes. ?????"需求跟蹤號(hào) ?gt_itemx-tax_code ??= con_yes. ?gt_itemx-pricedate ?= con_yes. ?????" ?gt_itemx-price_date = con_yes. ?APPEND gt_itemx. ENDFORM. ???????????????????" SUB_CONTRACT_ITEM *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ACCOUNT *&---------------------------------------------------------------------* * ??????text *----------------------------------------------------------------------* FORM sub_contract_account . ?CHECK wa_ekpo-kostl IS NOT INITIAL.
?CLEAR:gt_account, gt_accountx. ?gt_account-item_no = wa_ekpo-ebelp. ?"行號(hào) ?gt_account-serial_no = '01'. ?gt_account-co_area = 'SGJT'. * ?gt_account-profit_ctr = '0055000023'. ?CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' ???EXPORTING ?????input ?= wa_ekpo-kostl ???IMPORTING ?????output = gt_account-costcenter.
?APPEND gt_account.
?gt_accountx-item_no ???= wa_ekpo-ebelp. ?"行號(hào) ?gt_accountx-serial_no ?= '01'. ?gt_accountx-item_nox ??= con_yes. ?gt_accountx-serial_nox = con_yes. ?gt_accountx-costcenter = con_yes. ?gt_accountx-co_area ???= con_yes. * ?gt_account-profit_ctr ??= con_yes. ?APPEND gt_accountx. ENDFORM. ???????????????????" SUB_CONTRACT_ACCOUNT *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ITEM_COND_V *&---------------------------------------------------------------------* * ??????處理采購框架協(xié)議行項(xiàng)目上的條件記錄的有效日期 *----------------------------------------------------------------------* FORM sub_contract_item_cond_v . ?CHECK wa_ekpo-kdatb IS NOT INITIAL.
?CLEAR:gt_item_cond_v, gt_item_cond_vx. ?gt_item_cond_v-item_no ???= wa_ekpo-ebelp. ?gt_item_cond_v-serial_id ?= wa_ekpo-ebelp. ?gt_item_cond_v-valid_from = wa_ekpo-kdatb. ?gt_item_cond_v-valid_to ??= wa_ekpo-kdate. * ?gt_item_cond_v-plant ?????= wa_ekpo-werks. ?APPEND gt_item_cond_v.
?gt_item_cond_vx-item_no ???= wa_ekpo-ebelp. ?gt_item_cond_vx-serial_id ?= wa_ekpo-ebelp. ?gt_item_cond_vx-serial_idx = con_yes. ?gt_item_cond_vx-item_nox ??= con_yes. ?gt_item_cond_vx-valid_from = con_yes. * ?gt_item_cond_vx-plant ?????= con_yes. ?IF wa_ekpo-kdate IS INITIAL. ?ELSE. ???gt_item_cond_vx-valid_to ??= con_yes. ?ENDIF. ?APPEND gt_item_cond_vx. ENDFORM. ???????????????????" SUB_CONTRACT_ITEM_COND_V *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ITEM_COND *&---------------------------------------------------------------------* * ??????處理采購框架協(xié)議行項(xiàng)目上的條件記錄 *----------------------------------------------------------------------* FORM sub_contract_item_cond . ?CHECK wa_ekpo-kdatb IS NOT INITIAL.
?CLEAR:gt_item_cond, gt_item_condx. ?gt_item_cond-item_no ????= wa_ekpo-ebelp. ?gt_item_cond-serial_id ??= wa_ekpo-ebelp. ?gt_item_cond-cond_count ?= 1. ?gt_item_cond-cond_value ?= wa_ekpo-netpr. ?gt_item_cond-currency ???= wa_ekko-waers. ?gt_item_cond-cond_p_unt ?= wa_ekpo-peinh. ?gt_item_cond-cond_unit ??= wa_ekpo-meins. ?gt_item_cond-numerator ??= 1. ?gt_item_cond-denominator = 1. ?gt_item_cond-cond_type ??= 'PB00'. ?gt_item_cond-change_id ??= 'I'. ?APPEND gt_item_cond.
?gt_item_condx-item_no ????= wa_ekpo-ebelp. ?gt_item_condx-serial_id ??= wa_ekpo-ebelp. ?gt_item_condx-cond_count ?= 1. ?gt_item_condx-item_nox ???= con_yes. ?gt_item_condx-serial_idx ?= con_yes. ?gt_item_condx-cond_countx = con_yes. ?gt_item_condx-cond_value ?= con_yes. ?gt_item_condx-currency ???= con_yes. ?gt_item_condx-cond_p_unt ?= con_yes. ?gt_item_condx-cond_unit ??= con_yes. ?gt_item_condx-numerator ??= con_yes. ?gt_item_condx-denominator = con_yes. ?gt_item_condx-cond_type ??= con_yes. ?APPEND gt_item_condx. ENDFORM. ???????????????????" SUB_CONTRACT_ITEM_COND *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_CREATE *&---------------------------------------------------------------------* * ??????調(diào)用FUNCTION創(chuàng)建采購合同 *----------------------------------------------------------------------* FORM sub_contract_create . ?DATA l_ebeln TYPE ebeln. ?IF g_action = con_create. ??"無合同號(hào),新建 ???CALL FUNCTION 'BAPI_CONTRACT_CREATE' ??????EXPORTING ????????header ???????????????= wa_header ????????headerx ??????????????= wa_headerx * ?????testrun ??????????????= pa_test ??????IMPORTING ????????purchasingdocument ???= g_ebeln ??????TABLES ????????return ???????????????= gt_return ????????item ?????????????????= gt_item ????????itemx ????????????????= gt_itemx ????????account ??????????????= gt_account ????????accountx ?????????????= gt_accountx ????????item_cond_validity ???= gt_item_cond_v ????????item_cond_validityx ??= gt_item_cond_vx ????????item_condition ???????= gt_item_cond ????????item_conditionx ??????= gt_item_condx. * ????????head_cond_validity ???= gt_h_cond_v * ????????head_cond_validityx ??= gt_h_cond_vx ???. ?ELSE. ???" 有合同號(hào),修改 ???g_ebeln = wa_header-number. ???CALL FUNCTION 'BAPI_CONTRACT_CHANGE' ?????EXPORTING ???????purchasingdocument ???= l_ebeln ???????header ???????????????= wa_header ???????headerx ??????????????= wa_headerx * ?????testrun ??????????????= pa_test ?????IMPORTING ???????exp_header ???????????= wa_header ?????TABLES ???????return ???????????????= gt_return ???????item ?????????????????= gt_item ???????itemx ????????????????= gt_itemx ???????extensionin ??????????= gt_extensionin. ?ENDIF. ?LOOP AT ?gt_return WHERE type = 'E' OR type ?= 'A'. ???IF -chrst IS INITIAL. ?????-chrst = gt_return-message. ???ELSE. ?????CONCATENATE -chrst ' ' gt_return-message ???????????INTO ?-chrst. ???ENDIF. ???g_indic = 'X'. ?ENDLOOP. ?g_subrc = sy-subrc. ENDFORM. ???????????????????" SUB_CONTRACT_CREATE *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_COMMIT *&---------------------------------------------------------------------* * ??????如果所有的BAPI FUNCTION都沒有返回 ERROR MESSAGE,則更新到系統(tǒng) *----------------------------------------------------------------------* FORM sub_contract_commit . * 當(dāng)返回信息的LOOP循環(huán)有錯(cuò)誤的數(shù)據(jù)時(shí),SUBRC會(huì)變成0 這時(shí)不能更新數(shù)據(jù) ?IF g_subrc = 0. ???CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. * 當(dāng)返回信息的LOOP循環(huán)沒有錯(cuò)誤的數(shù)據(jù)時(shí),SUBRC會(huì)變成4,這時(shí)可以更新數(shù)據(jù) ?ELSE. ???CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' ?????EXPORTING ???????wait = 'X'. ?ENDIF. ENDFORM. ???????????????????" SUB_CONTRACT_COMMIT *&---------------------------------------------------------------------* *& ?????Form ?SUB_REFRESH_RESULT *&---------------------------------------------------------------------* * ??????創(chuàng)建完成后根據(jù)結(jié)果給出MESSAGE并刷新結(jié)果內(nèi)表 *----------------------------------------------------------------------* FORM sub_refresh_result . * 當(dāng)返回信息的LOOP循環(huán)有錯(cuò)誤的數(shù)據(jù)時(shí),SUBRC會(huì)變成0 這時(shí)創(chuàng)建失敗 ?IF g_subrc = 0. ???-icon = '@2O@'. ?ELSE. ???-icon = '@2K@'. * ???-ekko-ebeln = g_ebeln. ?ENDIF. * 最終狀態(tài) ?IF g_indic = 'X'. ???MESSAGE '程序執(zhí)行完成,存在錯(cuò)誤的數(shù)據(jù)!' TYPE 'S'. ?ELSE. ???MESSAGE '采購合同已創(chuàng)建!' TYPE 'S'. ?ENDIF.
?CLEAR gt_contract. ?gt_contract-ebeln = -ekko-ebeln. ?gt_contract-contr = g_ebeln. ?gt_contract-icon ?= -icon. ?gt_contract-chrst = -chrst. ?APPEND gt_contract. ENDFORM. ???????????????????" SUB_REFRESH_RESULT
************************************************************************ ** ?聲明數(shù)據(jù)庫表 Declaration of database ?????????????????????????????** ************************************************************************ TABLES:ekko, ??????ekpo, ??????kna1. ???" ************************************************************************ ** ?定義結(jié)構(gòu)類型 Define the structure's type ?????????????????????????** ************************************************************************ * ????采購合同行項(xiàng)目及屬性 TYPES:BEGIN OF typ_ekpo, ???????ebelp ?TYPE ebelp, ????"采購合同項(xiàng)目號(hào) ???????pstyp ?TYPE pstyp, ????"項(xiàng)目類別 ???????knttp ?TYPE knttp, ????"科目分配類別 ???????matnr ?TYPE matnr, ????"物料號(hào) ???????matkl ?TYPE matkl, ????"物料組 ???????txz01 ?TYPE txz01, ????"短文本 ???????ktmng ?TYPE ktmng, ????"目標(biāo)數(shù)量 ???????meins ?TYPE meins, ????"單位 ???????netpr ?TYPE kbetr, ????"凈價(jià) ???????peinh ?TYPE epein, ????"價(jià)格單位 ???????bwtar ?TYPE bwtar_d, ??"評(píng)估類型 ???????mwskz ?TYPE mwskz, ????"稅碼 ???????werks ?TYPE werks_d, ?????"工廠 ???????webre ?TYPE webre, ????"基于GR的IV. ???????kostl ?TYPE kostl, ???????bednr ?TYPE bednr, ????"需求跟蹤號(hào) ???????kdatb ?TYPE ekko-kdatb, "條件記錄有效起始日期 ???????kdate ?TYPE ekko-kdate, "條件記錄有效截止日期 ???????atr01 ?TYPE char30, ?????END OF typ_ekpo. DATA: wa_ekpo TYPE typ_ekpo.
* ????采購合同抬頭數(shù)據(jù) TYPES:BEGIN OF typ_ekko, ???????ebeln ?TYPE ebeln, ???????"采購合同順序號(hào) ???????lifnr ?TYPE lifnr, ???????"供應(yīng)商賬號(hào) ???????evart ?TYPE bsart, ???????"協(xié)議類型 ???????ekorg ?TYPE ekko-ekorg, ??"采購組織 ???????ekgrp ?TYPE ekko-ekgrp, ??"采購組 ???????bukrs ?TYPE bukrs, ???????"公司代碼 ???????kdatb ?TYPE ekko-kdatb, ??"有效起始日期 ???????kdate ?TYPE ekko-kdate, ??"有效截止日期 ???????verkf ?TYPE everk, ???????"銷售員:外部合同號(hào) ???????waers ?TYPE waers, ???????"貨幣 ?????END OF typ_ekko. DATA: wa_ekko TYPE typ_ekko.
* ????采購合同數(shù)據(jù) DATA:BEGIN OF gt_po OCCURS 0, ???????ekko TYPE typ_ekko, ?????????"抬頭數(shù)據(jù) ???????ekpo TYPE TABLE OF typ_ekpo, "行項(xiàng)目數(shù)據(jù) ?????END OF gt_po. * ????結(jié)果內(nèi)表數(shù)據(jù) TYPES:BEGIN OF typ_result, ???????ekko ?TYPE typ_ekko, ???????"采購合同抬頭數(shù)據(jù) ???????ekpo ?TYPE typ_ekpo, ???????"采購合同行項(xiàng)目數(shù)據(jù) ???????box ??TYPE c, ??????????????"選擇標(biāo)記 ???????icon ?TYPE icon_d, ?????????"紅綠燈指示 ???????chrst TYPE char100, ????????"檢查結(jié)果 ?????END OF typ_result. ************************************************************************ ** ?定義變量與內(nèi)表 Define the variants and Internal tables ???????????** ************************************************************************ DATA:gt_result ?TYPE TABLE OF typ_result ?WITH HEADER LINE, ????gt_cell ?TYPE TABLE OF alsmex_tabline WITH HEADER LINE, ????gt_t149d TYPE TABLE OF t149d WITH HEADER LINE.
DATA:BEGIN OF gt_contract OCCURS 0, ??????ebeln TYPE ebeln, ??????contr TYPE ebeln, ??????icon ?TYPE icon_d, ??????chrst TYPE tdline, ????END OF gt_contract.
DATA:gt_text(4096) TYPE c OCCURS 0. DATA:g_file ?TYPE string. DATA:g_indic TYPE c, ??????????"數(shù)據(jù)錯(cuò)誤標(biāo)致 ????g_index TYPE i, ??????????"采購合同行項(xiàng)目的個(gè)數(shù) ????g_ebelp TYPE ebelp, ??????"行項(xiàng)目號(hào)計(jì)算 ????g_flag ?TYPE c. ??????????"判斷標(biāo)識(shí)
FIELD-SYMBOLS: TYPE typ_result. *@------------------ ALV 相關(guān)的變量 -----------------------------------* TYPE-POOLS:slis. DATA: g_grid TYPE REF TO ?cl_gui_alv_grid, ?????g_repid ????????????LIKE sy-repid, ?????g_structure_name ???TYPE tabname, ?????g_command ??????????TYPE ?slis_formname, ?????g_title ????????????TYPE lvc_title, ?????g_setting ??????????TYPE lvc_s_glay, ?????wa_print ???????????TYPE slis_print_alv, ?????gt_list_top_of_page TYPE slis_t_listheader, ?????gt_events ??????????TYPE slis_t_event WITH HEADER LINE, ?????gt_sort ????????????TYPE slis_t_sortinfo_alv, ?????wa_sort ????????????TYPE slis_sortinfo_alv, ?????wa_layout ??????????TYPE slis_layout_alv, ?????gt_fieldcat ????????TYPE slis_t_fieldcat_alv WITH HEADER LINE, ?????wa_fieldcat ????????LIKE LINE OF gt_fieldcat, ?????g_field ????????????TYPE char30, ?????g_save ?????????????TYPE c, ?????g_con_mark ?????????TYPE slis_fieldcat_alv-fieldname VALUE 'MARK', ?????g_length ???????????TYPE i, ?????g_pos ??????????????TYPE i.
FIELD-SYMBOLS:. *@---------------------------------------------------------------------* *@ ???創(chuàng)建采購合同 BAPI_CONTRACT_CREATE 用到的變量 *@---------------------------------------------------------------------* CONSTANTS:con_create TYPE char10 VALUE 'CREATE', ?????????con_change TYPE char10 VALUE 'CHANGE', ?????????con_yes ???TYPE c ?????VALUE 'X'.
DATA:g_action TYPE char10, ???????"執(zhí)行動(dòng)作說明 ????wa_header ???TYPE bapimeoutheader, ????wa_headerx ??TYPE bapimeoutheaderx, ????gt_h_cond_v ?TYPE TABLE OF bapimeoutheadvalidity WITH HEADER LINE, ????gt_h_cond_vx TYPE TABLE OF bapimeoutheadvalidityx WITH HEADER LINE, ????gt_item ?????TYPE bapimeout_t_item WITH HEADER LINE, ????gt_itemx ????TYPE bapimeout_t_itemx WITH HEADER LINE, ????gt_account ??TYPE TABLE OF bapimeoutaccount WITH HEADER LINE, ????gt_accountx ?TYPE TABLE OF bapimeoutaccountx WITH HEADER LINE, ????gt_item_cond_v TYPE TABLE OF bapimeoutvalidity WITH HEADER LINE, ????gt_item_cond_vx TYPE TABLE OF bapimeoutvalidityx WITH HEADER LINE, ????gt_item_cond ??TYPE TABLE OF bapimeoutcondition WITH HEADER LINE, ????gt_item_condx ?TYPE TABLE OF bapimeoutconditionx WITH HEADER LINE, ????gt_return TYPE bapiret2_t WITH HEADER LINE,
g_subrc TYPE sy-subrc.
DATA:g_ebeln TYPE bapimeoutheader-number, ??????????????????"#EC NEEDED ????gt_extensionin LIKE bapiparex OCCURS 0 WITH HEADER LINE, ????gt_extensionout TYPE bapiparex_t.
************************************************************************ ** ?宏定義 Define the macro ??????????????????????????????????????????** ************************************************************************ DEFINE mcr_range. ?clear &1. ?&1-sign = 'I'. ?&1-option = &2. ?&1-low = &3. ?&1-high = &4. ?append &1. END-OF-DEFINITION.
* 給FILEDCAT ALV內(nèi)表賦值 DEFINE mcr_field. ?clear wa_fieldcat. ?clear g_field. ?g_pos = g_pos + 1 . ?wa_fieldcat-col_pos ??????= ?g_pos. ?wa_fieldcat-fieldname = &1. ?wa_fieldcat-tabname = 'GT_RESULT'. * wa_fieldcat-no_out = 'X'. ?????"field no display, choose from layout ?wa_fieldcat-key = &2. ????????"SUBTOTAL KEY ?wa_fieldcat-seltext_l = &3. * 計(jì)算輸出字段的長(zhǎng)度 ?concatenate 'GT_RESULT-' &1 into g_field. ?assign (g_field) to . ?describe field output-length ?g_length. ?wa_fieldcat-outputlen = g_length. ?append wa_fieldcat to gt_fieldcat. END-OF-DEFINITION. ************************************************************************ ** ?選擇屏幕 Customize the selection-screen ??????????????????????????** ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK xavery WITH FRAME TITLE text-001. PARAMETERS: p_filenm TYPE rlgrap-filename. SELECTION-SCREEN END OF BLOCK xavery. ************************************************************************ ** ?執(zhí)行程序事件 Executing the program's events ??????????????????????** ************************************************************************ INITIALIZATION. ?PERFORM sub_init_cond.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filenm. ?PERFORM sub_get_directory.
START-OF-SELECTION. ?PERFORM sub_upload_data. ?????"上載數(shù)據(jù) ?PERFORM sub_process_data. ????"轉(zhuǎn)換數(shù)據(jù)類型與格式 ?PERFORM sub_check_header. ????"銷售訂單抬頭數(shù)據(jù)檢查 ?PERFORM sub_check_item. ??????"銷售訂單行項(xiàng)目數(shù)據(jù)檢查
END-OF-SELECTION. ?PERFORM sub_create_fieldcat. ?PERFORM sub_init_layout. ?PERFORM sub_display_as_alv.
*@---------------------------------------------------------------------* *@ ?????Form ?SUB_INIT_COND *@---------------------------------------------------------------------* * ??????初始化選擇條件 *----------------------------------------------------------------------* FORM sub_init_cond . ?p_filenm = '20130116-06-ME31K模版2.4.xlsx'. ENDFORM. ???????????????????" SUB_INIT_COND *&---------------------------------------------------------------------* *& ?????Form ?SUB_GET_DIRECTORY *&---------------------------------------------------------------------* * ??????給選擇條件字段添加文件目錄搜索幫助 *----------------------------------------------------------------------* FORM sub_get_directory. ?CALL FUNCTION 'WS_FILENAME_GET' ???EXPORTING ?????def_filename ????= p_filenm ?????mask ????????????= ',*.xls.' ?????mode ????????????= 'O' ?????title ???????????= 'File Name' ???IMPORTING ?????filename ????????= p_filenm ???EXCEPTIONS ?????inv_winsys ??????= 1 ?????no_batch ????????= 2 ?????selection_cancel = 3 ?????selection_error ?= 4 ?????OTHERS ??????????= 5. ?g_file = p_filenm. ENDFORM. ???????????????????" SUB_GET_DIRECTORY *&---------------------------------------------------------------------* *& ?????Form ?SUB_UPLOAD_DATA *&---------------------------------------------------------------------* * ??????將數(shù)據(jù)上載到內(nèi)表中 *----------------------------------------------------------------------* FORM sub_upload_data . * 上載電子表格數(shù)據(jù) ?CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' ???EXPORTING ?????filename ???????????????= p_filenm ?????i_begin_col ????????????= 1 ?????i_begin_row ????????????= 2 ?????i_end_col ??????????????= 139 ?????i_end_row ??????????????= 9999 ???TABLES ?????intern ?????????????????= gt_cell ???EXCEPTIONS ?????inconsistent_parameters = 1 ?????upload_ole ?????????????= 2 ?????OTHERS ?????????????????= 3. ENDFORM. ???????????????????" SUB_UPLOAD_DATA *&---------------------------------------------------------------------* *& ?????Form ?sub_process_data *&---------------------------------------------------------------------* * ??????將EXCEL上載上來的數(shù)據(jù)轉(zhuǎn)換到指定類型的內(nèi)表中 *----------------------------------------------------------------------* FORM sub_process_data . ?CLEAR:gt_result, ???????wa_ekko, ???????wa_ekpo, ???????g_index, ???????g_ebelp.
?g_flag = 'X'. ?g_index = 1. * 將上載的數(shù)據(jù)添加到結(jié)果內(nèi)表中 ?LOOP AT gt_cell. ???PERFORM sub_process_header. ??"處理采購合同抬頭數(shù)據(jù) ???PERFORM sub_process_item. ????"處理采購行項(xiàng)目數(shù)據(jù) * ??當(dāng)某行的指定字段值為‘#’號(hào),表示這是銷售訂單之間的分隔標(biāo)識(shí),本行 * ??不是有效數(shù)據(jù)。 ???AT END OF row. ?????IF g_flag = '#'. ????"銷售訂單結(jié)束行,不是有效的行項(xiàng)目數(shù)據(jù) ???????g_index = g_index + 1. ?"計(jì)算銷售訂單順序號(hào) ???????g_flag = 'X'. ???????CLEAR wa_ekko. ???????CLEAR g_ebelp. ?????ELSE. ???????CLEAR g_flag. ???????CLEAR gt_result. ???????g_ebelp = g_ebelp + 10. ?"計(jì)算銷售訂單行項(xiàng)目號(hào) ???????gt_result-ekko = wa_ekko. ???????gt_result-ekpo = wa_ekpo. ???????gt_result-ekko-ebeln = g_index. ???????gt_result-ekpo-ebelp = g_ebelp. ???????APPEND gt_result. ???????CLEAR wa_ekpo. ?????ENDIF. ???ENDAT. ?ENDLOOP. ENDFORM. ???????????????????" sub_process_data *&---------------------------------------------------------------------* *& ?????Form ?SUB_PROCESS_HEADER *&---------------------------------------------------------------------* * ??????處理上載文件中的采購合同抬頭數(shù)據(jù) *----------------------------------------------------------------------* FORM sub_process_header . ?CHECK g_flag = 'X'. ?CASE gt_cell-col. ???WHEN '0001'. ?????CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekko-lifnr. ????"供應(yīng)商賬號(hào) ???WHEN '0002'. ?????wa_ekko-evart = gt_cell-value. ?"協(xié)議類型 ???WHEN '0003'. ?????wa_ekko-ekorg = gt_cell-value. ?"采購組織 ???WHEN '0004'. ?????wa_ekko-ekgrp = gt_cell-value. ?"采購組 ???WHEN '0006'. ?????wa_ekko-bukrs = gt_cell-value. ?"公司代碼 ???WHEN '0007'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekko-kdatb. ?????"有效起始日期 ???WHEN '0008'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekko-kdate. ?????"有效截止日期 ???WHEN '0024'. ?????wa_ekko-verkf = gt_cell-value. ??"銷售員:外部合同號(hào) ???WHEN OTHERS. ?ENDCASE. ?wa_ekko-waers = 'RMB'. ENDFORM. ???????????????????" SUB_PROCESS_HEADER *&---------------------------------------------------------------------* *& ?????Form ?SUB_PROCESS_ITEM *&---------------------------------------------------------------------* * ??????處理上載文件中的銷售訂單行項(xiàng)目數(shù)據(jù) *----------------------------------------------------------------------* FORM sub_process_item . ?CASE gt_cell-col. ???WHEN '0001'. ?????IF gt_cell-value = '#'. ??"分隔標(biāo)記 ???????g_flag = '#'. ?????ENDIF. ???WHEN '0020'. ?????wa_ekpo-pstyp = gt_cell-value. ??????"項(xiàng)目類別 ???WHEN '0021'. ?????wa_ekpo-knttp = gt_cell-value. ??????"科目分配類別 ???WHEN '0009'. ?????wa_ekpo-matnr = gt_cell-value+0(18). "物料號(hào) ???WHEN '0005'. ?????wa_ekpo-werks = gt_cell-value. ??????"工廠 ???WHEN '0022'. ??????????????????????????"物料描述 ?????wa_ekpo-txz01 = gt_cell-value. ???WHEN '0023'. ?????wa_ekpo-matkl = gt_cell-value. ???WHEN '0010'. ?????wa_ekpo-ktmng = gt_cell-value. ??????"數(shù)量 ???WHEN '0011'. ?????wa_ekpo-meins = gt_cell-value. ??????"計(jì)量單位 ???WHEN '0012'. ?????wa_ekpo-netpr = gt_cell-value. ??????"凈價(jià) ???WHEN '0013'. ?????wa_ekpo-peinh = gt_cell-value. ??????"價(jià)格單位 ???WHEN '0014'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekpo-kdatb. ????????"有效截止日期 ???WHEN '0015'. ?????CALL FUNCTION 'CONVERSION_EXIT_DATEX_INPUT' ???????EXPORTING ?????????input ?= gt_cell-value ???????IMPORTING ?????????output = wa_ekpo-kdate. ?????????"有效截止日期 ???WHEN '0016'. ?????wa_ekpo-bwtar = gt_cell-value. ??????"評(píng)估類型 ???WHEN '0017'. ?????wa_ekpo-mwskz = gt_cell-value. ??????"稅碼 ???WHEN '0018'. ?????wa_ekpo-webre = gt_cell-value. ??????"基于GR的IV. ???WHEN '0025'. ?????wa_ekpo-kostl ?= gt_cell-value. ???WHEN '0019'. ?????wa_ekpo-bednr ?= gt_cell-value. ???WHEN OTHERS. ?ENDCASE. ENDFORM. ???????????????????" SUB_PROCESS_ITEM *&---------------------------------------------------------------------* *& ?????Form ?SUB_CHECK_HEADER *&---------------------------------------------------------------------* * ??????檢查結(jié)果內(nèi)表的訂單抬頭數(shù)據(jù)并更新檢查狀態(tài) *----------------------------------------------------------------------* FORM sub_check_header .
ENDFORM. ???????????????????" SUB_CHECK_HEADER *&---------------------------------------------------------------------* *& ?????Form ?SUB_CHECK_ITEM *&---------------------------------------------------------------------* * ??????檢查結(jié)果內(nèi)表的訂單行項(xiàng)目數(shù)據(jù)并更新檢查狀態(tài) *----------------------------------------------------------------------* FORM sub_check_item . ?SELECT * FROM t149d INTO TABLE gt_t149d.
?SORT gt_t149d BY bwtar. ?LOOP AT gt_result ASSIGNING . * ??根據(jù)物料號(hào)來取物料組 ???IF -ekpo-matnr IS INITIAL. ???ELSE. ?????SELECT SINGLE ???????????matkl ???????????maktx ???????????meins ?????????INTO (-ekpo-matkl, ???????????????-ekpo-txz01, ???????????????-ekpo-meins) ?????????FROM mara INNER JOIN makt ON mara~matnr = makt~matnr ?????????WHERE mara~matnr = -ekpo-matnr AND ???????????????spras = 1. ???ENDIF. * ??檢查評(píng)估類型 ???CLEAR gt_t149d. ???READ TABLE gt_t149d WITH KEY bwtar = -ekpo-bwtar ????????????????????????????????BINARY SEARCH. ???IF sy-subrc = 0.
???ELSE. ?????IF -ekpo-bwtar IS NOT INITIAL. ???????-chrst = '輸入的評(píng)估類型不存在!'. ?????ENDIF. ???ENDIF. * ??數(shù)據(jù)正確賦綠燈,數(shù)據(jù)不正確賦紅燈 ???IF -chrst IS INITIAL. ?????-icon = '@08@'. ????????"綠燈 ???ELSE. ?????-icon = '@0A@'. ????????"紅燈 ???ENDIF. ?ENDLOOP. ENDFORM. ???????????????????" SUB_CHECK_ITEM *&---------------------------------------------------------------------* *& ?????Form ?SUB_CREATE_FIELDCAT *&---------------------------------------------------------------------* * ??????給輸出的結(jié)果內(nèi)表指定字段 *----------------------------------------------------------------------* FORM sub_create_fieldcat . ?CLEAR gt_fieldcat[]. ?mcr_field ?'ICON' ?????????'X' ???'指識(shí)標(biāo)識(shí)'. ?mcr_field ?'EKKO-EBELN' ???'X' ???'采購合同序號(hào)'. ?mcr_field ?'EKPO-EBELP' ???'X' ???'項(xiàng)目號(hào)'. ?mcr_field ?'EKKO-LIFNR' ???'' ????'供應(yīng)商賬號(hào)'. ?mcr_field ?'EKKO-EVART' ???'' ????'協(xié)議類型'. ?mcr_field ?'EKKO-EKORG' ???'' ????'采購組織'. ?mcr_field ?'EKKO-EKGRP' ???'' ????'采購組'. ?mcr_field ?'EKPO-WERKS' ???'' ????'工廠'. ?mcr_field ?'EKKO-BUKRS' ???'' ????'公司代碼'. ?mcr_field ?'EKKO-KDATB' ???'' ????'有效起始日期' . ?mcr_field ?'EKKO-KDATE' ???'' ????'有效截止日期' . ?mcr_field ?'EKKO-VERKF' ???'' ????'外部合同號(hào)'. ?mcr_field ?'EKPO-PSTYP' ???'' ????'項(xiàng)目類別'. ?mcr_field ?'EKPO-KNTTP' ???'' ????'科目分配類別'. ?mcr_field ?'EKPO-MATNR' ???'' ????'物料編號(hào)'. ?mcr_field ?'EKPO-TXZ01' ???'' ????'物料描述'. ?mcr_field ?'EKPO-MATKL' ???'' ????'物料組'. ?mcr_field ?'EKPO-KTMNG' ???'' ????'目標(biāo)數(shù)量'. ?mcr_field ?'EKPO-MEINS' ???'' ????'計(jì)量單位'. ?mcr_field ?'EKPO-KDATB' ???'' ????'條件記錄有效起始日期'. ?mcr_field ?'EKPO-KDATE' ???'' ????'條件記錄有效截止日期'. ?mcr_field ?'EKPO-NETPR' ???'' ????'凈價(jià)'. ?mcr_field ?'EKPO-PEINH' ???'' ????'價(jià)格單位'. ?mcr_field ?'EKPO-BWTAR' ???'' ????'評(píng)估類型'. ?mcr_field ?'EKPO-MWSKZ' ???'' ????'稅碼'. ?mcr_field ?'EKPO-WEBRE' ???'' ????'基于GR的IV'. ?mcr_field ?'EKPO-KOSTL' ???'' ????'成本中心'. ?mcr_field ?'EKPO-BEDNR' ???'' ????'需求跟蹤號(hào)'. ?mcr_field ?'CHRST' ????????'' ????'檢查結(jié)果'. ENDFORM. ???????????????????" SUB_CREATE_FIELDCAT *&---------------------------------------------------------------------* *& ?????Form ?SUB_INIT_LAYOUT *&---------------------------------------------------------------------* * ??????設(shè)置常用的輸出布局參數(shù) *----------------------------------------------------------------------* FORM sub_init_layout . ?wa_layout-zebra ????????????= 'X'. ?wa_layout-window_titlebar ??= '采購合同框架協(xié)議批導(dǎo)入程序'. ?wa_layout-colwidth_optimize = 'X'. ?wa_layout-box_fieldname ????= 'BOX'. ?wa_layout-header_text ??????= '選擇'. ENDFORM. ???????????????????" SUB_INIT_LAYOUT *&---------------------------------------------------------------------* *& ?????Form ?SUB_DISPLAY_AS_ALV *&---------------------------------------------------------------------* * ??????調(diào)用 ALV 的FUNCTION來輸出結(jié)果 *----------------------------------------------------------------------* FORM sub_display_as_alv . ?g_repid = sy-repid. ?g_setting-coll_top_p = 'X'. ??????"最小化 CALLBACK-TOP-OF-PAGE. * ABAP List Viewer ?CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' ???EXPORTING ?????i_callback_program ??????= g_repid ?????i_structure_name ????????= 'TYP_RESULT' ?????i_grid_title ????????????= g_title ?????i_grid_settings ?????????= g_setting ?????i_callback_user_command ?= 'SUB_USER_COMMAND' ?????i_callback_pf_status_set = 'SUB_SET_PF_STATUS' ?????i_save ??????????????????= g_save ?????is_layout ???????????????= wa_layout ?????it_fieldcat ?????????????= gt_fieldcat[] ???TABLES ?????t_outtab ????????????????= gt_result ???EXCEPTIONS ?????program_error ???????????= 1 ?????OTHERS ??????????????????= 2. ENDFORM. ???????????????????" SUB_DISPLAY_AS_ALV *@--------------------------------------------------------------------* *@ ?????Form ?sub_user_command *@--------------------------------------------------------------------* * ?????-->R_UCOMM ????事務(wù)功能碼 * ?????-->RS_SELFIELD ALV相關(guān)的數(shù)據(jù) *---------------------------------------------------------------------* FORM sub_user_command USING r_ucomm LIKE sy-ucomm ???????????????????????rs_selfield TYPE slis_selfield. ?DATA l_ebeln TYPE ebeln. ?CASE r_ucomm. ???WHEN '&IC1'. ????????????????"雙擊事件的功能碼 ?????CASE rs_selfield-fieldname. ???????WHEN 'EKKO-EBELN'. ?????????l_ebeln = rs_selfield-value. ?????????CALL FUNCTION 'ME_DISPLAY_PURCHASE_DOCUMENT' ???????????EXPORTING ?????????????i_ebeln ?????????????= l_ebeln ???????????EXCEPTIONS ?????????????not_found ???????????= 1 ?????????????no_authority ????????= 2 ?????????????invalid_call ????????= 3 ?????????????preview_not_possible = 4 ?????????????OTHERS ??????????????= 5. ?????????IF sy-subrc <> 0. ???????????MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno ???????????????????WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ?????????ENDIF.
???????WHEN OTHERS. ?????ENDCASE. ???WHEN 'CREATE'. ??????????????"創(chuàng)建銷售訂單 ?????PERFORM sub_ucomm_create. ?ENDCASE. * 刷新ALV報(bào)表 ?rs_selfield-refresh = 'X'. ENDFORM. ???????????????????"sub_user_command *@---------------------------------------------------------------------* *@ ??????FORM SUB_SET_PF_STATUS ???????????????????????????????????????* *@---------------------------------------------------------------------* * ?設(shè)置ALV菜單 * ?通過SE41,拷貝程序SAPLSLVC_FULLSCREEN的狀態(tài)STANDARD_FULLSCREEN過來 *@---------------------------------------------------------------------* FORM sub_set_pf_status USING rt_extab TYPE slis_t_extab. ?SET PF-STATUS 'STANDARD_FULLSCREEN'. ENDFORM. ???????????????????"sub_set_pf_status *&---------------------------------------------------------------------* *& ?????Form ?SUB_UCOMM_CREATE *&---------------------------------------------------------------------* * ??????創(chuàng)建銷售訂單 *----------------------------------------------------------------------* FORM sub_ucomm_create . ?PERFORM sub_check_data. ?"檢查數(shù)據(jù)是否正確 ?g_action = con_create. ?LOOP AT gt_result ASSIGNING WHERE icon = '@08@'. ???CLEAR:wa_ekko, ?????????wa_ekpo. * ??將抬頭數(shù)據(jù)信息賦值到BAPI函數(shù)的內(nèi)表 ???wa_ekko = -ekko. ???AT NEW ekko-ebeln. ?????REFRESH:gt_item, ?????????????gt_itemx, ?????????????gt_account, ?????????????gt_accountx, ?????????????gt_item_cond_v, ?????????????gt_item_cond_vx, ?????????????gt_item_cond, ?????????????gt_item_condx. ?????PERFORM sub_contract_header. ?????"處理銷售訂單抬頭數(shù)據(jù) ???ENDAT. * ??處理行項(xiàng)目的信息 ???wa_ekpo = -ekpo. ???PERFORM sub_contract_item. ???????"處理一般行項(xiàng)目信息 ???PERFORM sub_contract_account. ????"處理會(huì)計(jì)科目信息 ???PERFORM sub_contract_item_cond_v. "處理行項(xiàng)目的條件記錄有效日期 ???PERFORM sub_contract_item_cond. ??"處理行項(xiàng)目的條件記錄 * ??調(diào)用BAPI函數(shù)來創(chuàng)建銷售訂單 ???AT END OF ekko-ebeln. ?????PERFORM sub_contract_create. ???????"調(diào)用FUNCTION創(chuàng)建銷售訂單 ?????PERFORM sub_contract_commit. ???????"提交 ?????PERFORM sub_refresh_result. ????????"更新結(jié)果內(nèi)表 ???ENDAT. ?ENDLOOP. * 更新結(jié)果內(nèi)表 ?SORT gt_contract BY ebeln. ?LOOP AT gt_result ASSIGNING . ???CLEAR gt_contract. ???READ TABLE gt_contract WITH KEY ebeln = -ekko-ebeln ???????????????????????????????????BINARY SEARCH. ???IF sy-subrc = 0. ?????-icon ?= gt_contract-icon. ?????-ekko-ebeln = gt_contract-contr. ?????-chrst = gt_contract-chrst. ???ENDIF. ?ENDLOOP. ENDFORM. ???????????????????" SUB_UCOMM_CREATE *&---------------------------------------------------------------------* *& ?????Form ?SUB_CHECK_DATA *&---------------------------------------------------------------------* * ??????檢查導(dǎo)入的數(shù)據(jù)是否正確,如果不正確,則給出 Error Message,禁止 * ??????用戶繼續(xù)創(chuàng)建銷售訂單 *----------------------------------------------------------------------* FORM sub_check_data . ?LOOP AT gt_result WHERE icon = '@0A@'. ???MESSAGE '數(shù)據(jù)錯(cuò)誤,不能創(chuàng)建銷售訂單' TYPE 'E'. ?ENDLOOP. ENDFORM. ???????????????????" SUB_CHECK_DATA *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_HEADER *&---------------------------------------------------------------------* * ??????將采購合同抬頭數(shù)據(jù)添加到BAPI函數(shù)的內(nèi)表中 *----------------------------------------------------------------------* FORM sub_contract_header . ?wa_header-number ????= ''. "wa_ekko-ebeln. "合同號(hào) ?wa_header-vendor ????= wa_ekko-lifnr. "供應(yīng)商 ?wa_header-doc_type ??= wa_ekko-evart. "協(xié)議類型 ?wa_header-comp_code ?= wa_ekko-bukrs. "公司代碼 ?wa_header-doc_date ??= sy-datum. ?????"協(xié)議日期 ?wa_header-vper_start = wa_ekko-kdatb. "協(xié)議起始日期 ?wa_header-vper_end ??= wa_ekko-kdate. "協(xié)議截至日期 ?wa_header-purch_org ?= wa_ekko-ekorg. "采購組織 ?wa_header-pur_group ?= wa_ekko-ekgrp. "采購組 * ?wa_header-acum_value = wa_ekko-ktwrt. "目標(biāo)值 ?wa_header-currency ??= wa_ekko-waers. "貨幣 ?wa_header-langu ?????= sy-langu. ?wa_header-mast_cond ?= 'X'.
* ?wa_headerx-number ????= con_yes. "合同號(hào) ?wa_headerx-vendor ????= con_yes. "供應(yīng)商 ?wa_headerx-doc_type ??= con_yes. "協(xié)議類型 ?wa_headerx-comp_code ?= con_yes. "公司代碼 ?wa_headerx-doc_date ??= con_yes. "協(xié)議日期 ?wa_headerx-vper_start = con_yes. "協(xié)議起始日期 ?wa_headerx-vper_end ??= con_yes. "協(xié)議截至日期 ?wa_headerx-purch_org ?= con_yes. "采購組織 ?wa_headerx-pur_group ?= con_yes. "采購組 ?wa_headerx-acum_value = con_yes. "目標(biāo)值 ?wa_headerx-currency ??= con_yes. "貨幣 ?wa_headerx-langu ?????= con_yes. ?wa_headerx-mast_cond ?= con_yes.
?REFRESH: gt_h_cond_v, gt_h_cond_vx. ?gt_h_cond_v-serial_id ??= '1'. ?gt_h_cond_v-valid_from ?= wa_ekpo-kdatb. ?gt_h_cond_v-valid_to ???= wa_ekpo-kdate. ?APPEND gt_h_cond_v.
?gt_h_cond_vx-serial_id ??= '1'. ?gt_h_cond_vx-serial_idx ?= con_yes. ?gt_h_cond_vx-valid_from ?= con_yes. ?gt_h_cond_vx-valid_to ???= con_yes. ?APPEND gt_h_cond_vx. ENDFORM. ???????????????????" SUB_CONTRACT_HEADER *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ITEM *&---------------------------------------------------------------------* * ??????將采購合同行項(xiàng)目數(shù)據(jù)添加到BAPI函數(shù)的內(nèi)表中 *----------------------------------------------------------------------* FORM sub_contract_item . ?CLEAR: gt_item, gt_itemx. ?gt_item-item_no ???= wa_ekpo-ebelp. "行號(hào) ?gt_item-short_text = wa_ekpo-txz01. "短文本 ?gt_item-material ??= wa_ekpo-matnr. "物料編號(hào) ?gt_item-matl_group = wa_ekpo-matkl. "物料組 ?gt_item-plant ?????= wa_ekpo-werks. "工廠 ?gt_item-target_qty = wa_ekpo-ktmng. "目標(biāo)數(shù)量 ?gt_item-val_type ??= wa_ekpo-bwtar. "評(píng)估類型
?CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' ???EXPORTING ?????input ?????????= wa_ekpo-meins ?????language ??????= sy-langu ???IMPORTING ?????output ????????= wa_ekpo-meins ???EXCEPTIONS ?????unit_not_found = 1 ?????OTHERS ????????= 2.
?gt_item-po_unit ???= wa_ekpo-meins. ?gt_item-po_unit_iso = wa_ekpo-meins. ?gt_item-conv_num1 ??= '1'. ?gt_item-conv_den1 ??= '1'. ?gt_item-net_price ??= wa_ekpo-netpr. ???"凈價(jià) ?gt_item-price_unit ?= wa_ekpo-peinh. ???"價(jià)格單位 ?gt_item-orderpr_un ?= wa_ekpo-meins. ???"訂單價(jià)格單位(采購) ?gt_item-orderpr_un_iso = wa_ekpo-meins. "訂單價(jià)格單位(采購) ?gt_item-acctasscat ?= wa_ekpo-knttp. ???"科目分配類別 ?gt_item-item_cat ???= wa_ekpo-pstyp. ???"項(xiàng)目類別 ?gt_item-trackingno ?= wa_ekpo-bednr. ???"需求跟蹤號(hào) ?gt_item-tax_code ???= wa_ekpo-mwskz. ???"稅碼 * ?gt_item-pricedate ??= '4'. ?gt_item-price_date ?= wa_ekpo-kdatb. ?APPEND gt_item.
?gt_itemx-item_no ???= wa_ekpo-ebelp. "行號(hào) ?gt_itemx-item_nox ??= con_yes. ??????"行號(hào) ?gt_item-material ???= con_yes. ??????"物料號(hào) ?gt_itemx-short_text = con_yes. ??????"端文本 ?gt_itemx-matl_group = con_yes. ??????"物料組 ?gt_itemx-plant ?????= con_yes. ??????"工廠 ?gt_itemx-target_qty = con_yes. ??????"目標(biāo)數(shù)量 ?gt_itemx-po_unit ???= con_yes. ?gt_itemx-po_unit_iso = con_yes. ?gt_itemx-val_type ??= con_yes. ?gt_itemx-conv_num1 ?= con_yes. ?gt_itemx-conv_den1 ?= con_yes. ?gt_itemx-net_price ?= con_yes. ??????"凈價(jià) ?gt_itemx-price_unit = con_yes. ??????"價(jià)格單位 ?gt_itemx-orderpr_un = con_yes. ?gt_itemx-orderpr_un_iso = con_yes. ?gt_itemx-acctasscat = con_yes. ?????"科目分配類別 ?gt_itemx-item_cat ??= con_yes. ?????"項(xiàng)目類別 ?gt_itemx-trackingno = con_yes. ?????"需求跟蹤號(hào) ?gt_itemx-tax_code ??= con_yes. ?gt_itemx-pricedate ?= con_yes. ?????" ?gt_itemx-price_date = con_yes. ?APPEND gt_itemx. ENDFORM. ???????????????????" SUB_CONTRACT_ITEM *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ACCOUNT *&---------------------------------------------------------------------* * ??????text *----------------------------------------------------------------------* FORM sub_contract_account . ?CHECK wa_ekpo-kostl IS NOT INITIAL.
?CLEAR:gt_account, gt_accountx. ?gt_account-item_no = wa_ekpo-ebelp. ?"行號(hào) ?gt_account-serial_no = '01'. ?gt_account-co_area = 'SGJT'. * ?gt_account-profit_ctr = '0055000023'. ?CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' ???EXPORTING ?????input ?= wa_ekpo-kostl ???IMPORTING ?????output = gt_account-costcenter.
?APPEND gt_account.
?gt_accountx-item_no ???= wa_ekpo-ebelp. ?"行號(hào) ?gt_accountx-serial_no ?= '01'. ?gt_accountx-item_nox ??= con_yes. ?gt_accountx-serial_nox = con_yes. ?gt_accountx-costcenter = con_yes. ?gt_accountx-co_area ???= con_yes. * ?gt_account-profit_ctr ??= con_yes. ?APPEND gt_accountx. ENDFORM. ???????????????????" SUB_CONTRACT_ACCOUNT *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ITEM_COND_V *&---------------------------------------------------------------------* * ??????處理采購框架協(xié)議行項(xiàng)目上的條件記錄的有效日期 *----------------------------------------------------------------------* FORM sub_contract_item_cond_v . ?CHECK wa_ekpo-kdatb IS NOT INITIAL.
?CLEAR:gt_item_cond_v, gt_item_cond_vx. ?gt_item_cond_v-item_no ???= wa_ekpo-ebelp. ?gt_item_cond_v-serial_id ?= wa_ekpo-ebelp. ?gt_item_cond_v-valid_from = wa_ekpo-kdatb. ?gt_item_cond_v-valid_to ??= wa_ekpo-kdate. * ?gt_item_cond_v-plant ?????= wa_ekpo-werks. ?APPEND gt_item_cond_v.
?gt_item_cond_vx-item_no ???= wa_ekpo-ebelp. ?gt_item_cond_vx-serial_id ?= wa_ekpo-ebelp. ?gt_item_cond_vx-serial_idx = con_yes. ?gt_item_cond_vx-item_nox ??= con_yes. ?gt_item_cond_vx-valid_from = con_yes. * ?gt_item_cond_vx-plant ?????= con_yes. ?IF wa_ekpo-kdate IS INITIAL. ?ELSE. ???gt_item_cond_vx-valid_to ??= con_yes. ?ENDIF. ?APPEND gt_item_cond_vx. ENDFORM. ???????????????????" SUB_CONTRACT_ITEM_COND_V *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_ITEM_COND *&---------------------------------------------------------------------* * ??????處理采購框架協(xié)議行項(xiàng)目上的條件記錄 *----------------------------------------------------------------------* FORM sub_contract_item_cond . ?CHECK wa_ekpo-kdatb IS NOT INITIAL.
?CLEAR:gt_item_cond, gt_item_condx. ?gt_item_cond-item_no ????= wa_ekpo-ebelp. ?gt_item_cond-serial_id ??= wa_ekpo-ebelp. ?gt_item_cond-cond_count ?= 1. ?gt_item_cond-cond_value ?= wa_ekpo-netpr. ?gt_item_cond-currency ???= wa_ekko-waers. ?gt_item_cond-cond_p_unt ?= wa_ekpo-peinh. ?gt_item_cond-cond_unit ??= wa_ekpo-meins. ?gt_item_cond-numerator ??= 1. ?gt_item_cond-denominator = 1. ?gt_item_cond-cond_type ??= 'PB00'. ?gt_item_cond-change_id ??= 'I'. ?APPEND gt_item_cond.
?gt_item_condx-item_no ????= wa_ekpo-ebelp. ?gt_item_condx-serial_id ??= wa_ekpo-ebelp. ?gt_item_condx-cond_count ?= 1. ?gt_item_condx-item_nox ???= con_yes. ?gt_item_condx-serial_idx ?= con_yes. ?gt_item_condx-cond_countx = con_yes. ?gt_item_condx-cond_value ?= con_yes. ?gt_item_condx-currency ???= con_yes. ?gt_item_condx-cond_p_unt ?= con_yes. ?gt_item_condx-cond_unit ??= con_yes. ?gt_item_condx-numerator ??= con_yes. ?gt_item_condx-denominator = con_yes. ?gt_item_condx-cond_type ??= con_yes. ?APPEND gt_item_condx. ENDFORM. ???????????????????" SUB_CONTRACT_ITEM_COND *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_CREATE *&---------------------------------------------------------------------* * ??????調(diào)用FUNCTION創(chuàng)建采購合同 *----------------------------------------------------------------------* FORM sub_contract_create . ?DATA l_ebeln TYPE ebeln. ?IF g_action = con_create. ??"無合同號(hào),新建 ???CALL FUNCTION 'BAPI_CONTRACT_CREATE' ??????EXPORTING ????????header ???????????????= wa_header ????????headerx ??????????????= wa_headerx * ?????testrun ??????????????= pa_test ??????IMPORTING ????????purchasingdocument ???= g_ebeln ??????TABLES ????????return ???????????????= gt_return ????????item ?????????????????= gt_item ????????itemx ????????????????= gt_itemx ????????account ??????????????= gt_account ????????accountx ?????????????= gt_accountx ????????item_cond_validity ???= gt_item_cond_v ????????item_cond_validityx ??= gt_item_cond_vx ????????item_condition ???????= gt_item_cond ????????item_conditionx ??????= gt_item_condx. * ????????head_cond_validity ???= gt_h_cond_v * ????????head_cond_validityx ??= gt_h_cond_vx ???. ?ELSE. ???" 有合同號(hào),修改 ???g_ebeln = wa_header-number. ???CALL FUNCTION 'BAPI_CONTRACT_CHANGE' ?????EXPORTING ???????purchasingdocument ???= l_ebeln ???????header ???????????????= wa_header ???????headerx ??????????????= wa_headerx * ?????testrun ??????????????= pa_test ?????IMPORTING ???????exp_header ???????????= wa_header ?????TABLES ???????return ???????????????= gt_return ???????item ?????????????????= gt_item ???????itemx ????????????????= gt_itemx ???????extensionin ??????????= gt_extensionin. ?ENDIF. ?LOOP AT ?gt_return WHERE type = 'E' OR type ?= 'A'. ???IF -chrst IS INITIAL. ?????-chrst = gt_return-message. ???ELSE. ?????CONCATENATE -chrst ' ' gt_return-message ???????????INTO ?-chrst. ???ENDIF. ???g_indic = 'X'. ?ENDLOOP. ?g_subrc = sy-subrc. ENDFORM. ???????????????????" SUB_CONTRACT_CREATE *&---------------------------------------------------------------------* *& ?????Form ?SUB_CONTRACT_COMMIT *&---------------------------------------------------------------------* * ??????如果所有的BAPI FUNCTION都沒有返回 ERROR MESSAGE,則更新到系統(tǒng) *----------------------------------------------------------------------* FORM sub_contract_commit . * 當(dāng)返回信息的LOOP循環(huán)有錯(cuò)誤的數(shù)據(jù)時(shí),SUBRC會(huì)變成0 這時(shí)不能更新數(shù)據(jù) ?IF g_subrc = 0. ???CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. * 當(dāng)返回信息的LOOP循環(huán)沒有錯(cuò)誤的數(shù)據(jù)時(shí),SUBRC會(huì)變成4,這時(shí)可以更新數(shù)據(jù) ?ELSE. ???CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' ?????EXPORTING ???????wait = 'X'. ?ENDIF. ENDFORM. ???????????????????" SUB_CONTRACT_COMMIT *&---------------------------------------------------------------------* *& ?????Form ?SUB_REFRESH_RESULT *&---------------------------------------------------------------------* * ??????創(chuàng)建完成后根據(jù)結(jié)果給出MESSAGE并刷新結(jié)果內(nèi)表 *----------------------------------------------------------------------* FORM sub_refresh_result . * 當(dāng)返回信息的LOOP循環(huán)有錯(cuò)誤的數(shù)據(jù)時(shí),SUBRC會(huì)變成0 這時(shí)創(chuàng)建失敗 ?IF g_subrc = 0. ???-icon = '@2O@'. ?ELSE. ???-icon = '@2K@'. * ???-ekko-ebeln = g_ebeln. ?ENDIF. * 最終狀態(tài) ?IF g_indic = 'X'. ???MESSAGE '程序執(zhí)行完成,存在錯(cuò)誤的數(shù)據(jù)!' TYPE 'S'. ?ELSE. ???MESSAGE '采購合同已創(chuàng)建!' TYPE 'S'. ?ENDIF.
?CLEAR gt_contract. ?gt_contract-ebeln = -ekko-ebeln. ?gt_contract-contr = g_ebeln. ?gt_contract-icon ?= -icon. ?gt_contract-chrst = -chrst. ?APPEND gt_contract. ENDFORM. ???????????????????" SUB_REFRESH_RESULT
總結(jié)
以上是生活随笔為你收集整理的使用BAPI_CONTRACT_CREATE创建采购合同框架协议的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。