SAP ABAP 顾问(开发工程师)能力模型_企业数字化建设者的博客-CSDN博客目标:基于对SAP abap 顾问能力模型的梳理,给一年左右经验的abaper 快速成长为三年经验提参考ALV/REPORT|SMARTFROM|SCREEN|OLE|BAPI|BDC|PI|IDOC|RFC|API|WEBSERVICE|Enhancement|UserExits|Badi|Debughttps://blog.csdn.net/java_zhong1990/article/details/132469977
目标: 掌握SAP MM模块,主要流程相关的BAPI 函数的使用,主要有如下模块:
询价 报价 货源清单 配额安排 采购信息记录 框架协议-合同 框架协议-计划协议 采购订单 采购收货 发票校验 发票过账
BAPI是SAP系统标准函数,比如:采购申请创建函数、采购订单创建函数等等。
采购信息记录修改 | SAP_ABAP_MM_BAPI清单案例教程——采购信息记录_企业数字化建设者的博客-CSDN博客 |
框架协议-合同创建 | SAP_ABAP_MM_BAPI清单案例教程——框架协议-合同_企业数字化建设者的博客-CSDN博客 |
框架协议-合同修改 | SAP_ABAP_MM_BAPI清单案例教程——框架协议-合同_企业数字化建设者的博客-CSDN博客 |
框架协议-计划协议创建 | SAP_ABAP_MM_BAPI清单案例教程——框架协议-计划协议_企业数字化建设者的博客-CSDN博客 |
采购申请创建 | SAP_ABAP_MM_BAPI清单案例教程——采购申请_企业数字化建设者的博客-CSDN博客 |
采购订单创建 | SAP_ABAP_MM_BAPI清单案例教程——采购订单_BAPI_PO_CREATE1_企业数字化建设者的博客-CSDN博客 |
采购订单收货创建 | SAP_ABAP_MM_BAPI清单案例教程——采购订单收货_企业数字化建设者的博客-CSDN博客 |
采购发票预制 | SAP_ABAP_MM_BAPI清单案例教程——采购发票校验_企业数字化建设者的博客-CSDN博客 |
采购发票过账 | SAP_ABAP_MM_BAPI清单案例教程——采购发票过账_企业数字化建设者的博客-CSDN博客 |
1.2.2 BAPI清单
ME_INFORECORD_MAINTAIN | 采购信息记录修改 |
BAPI_CONTRACT_CREATE | 框架协议-合同创建 |
BAPI_CONTRACT_CHANGE | 框架协议-合同修改 |
BAPI_SAG_CREATE | 框架协议-计划协议创建 |
BAPI_PR_CREATE | 采购申请创建 |
BAPI_PO_CREATE1 | 采购订单创建 |
BAPI_GOODSMVT_CREATE | 采购订单收货创建 |
BAPI_INCOMINGINVOICE_PARK | 采购发票预制 |
BAPI_INCOMINGINVOICE_POST | 采购发票过账 |
1.3.1 删除
采购信息记录删除函数,BAPI : ME_INFORECORD_MAINTAIN
程序逻辑:frm_call_bapi_delete
*&---------------------------------------------------------------------*
*& Report ZMMCP019
*&批量删除采购信息记录
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmmcp019.
INCLUDE zmmcp019_top .
INCLUDE zmmcp019_f01 .
INITIALIZATION.
START-OF-SELECTION.
PERFORM frm_get_data .
PERFORM frm_show_alv .
&---------------------------------------------------------------------*
*& 包含 ZMMCP019_TOP
*&---------------------------------------------------------------------*
TABLES: eina ,mara ,eine .
TYPE-POOLS: slis.
DATA: BEGIN OF gs_alv ,
* loekz TYPE eina-loekz, "完成
infnr TYPE eina-infnr, "信息记录
zwlcms TYPE mara-zwlcms, "物料长描述
matnr TYPE eina-matnr, "物料
matkl TYPE eina-matkl, "物料组
matklt(80) TYPE c, "物料组描述
lifnr TYPE eina-lifnr, "供应商
name1 TYPE lfa1-name1, "供应商名称
ekorg TYPE eine-ekorg, "采购组织
esokz TYPE eine-esokz, "信息类型
werks TYPE eine-werks, "工厂
ddtext TYPE dd07v-ddtext, "简短描述
loekz TYPE eina-loekz, "一般主数据删除标记
loekz2 TYPE eine-loekz, "采购数据删除标记
prdat TYPE eine-prdat , "有效至
sel(1) TYPE c , "选中
icon(4) TYPE c , "灯
infor(50) TYPE c , "报错信息
status(1) TYPE c , "状态
index TYPE syst_tabix , "序号
END OF gs_alv .
DATA:
gt_alv LIKE TABLE OF gs_alv,
gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
DATA: alv TYPE REF TO zcl_alv_print.
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE TEXT-001 .
SELECT-OPTIONS : s_infnr FOR eina-infnr , "信息记录
s_werks FOR eine-werks , "工厂
s_ekorg FOR eine-ekorg OBLIGATORY, "采购组织
s_lifnr FOR eina-lifnr , "供应商
s_matnr FOR eina-matnr , "物料
s_matkl FOR eina-matkl , "物料组
s_esokz FOR eine-esokz . "信息类型
SELECTION-SCREEN END OF BLOCK b01 .
&---------------------------------------------------------------------*
*& 包含 ZMMCP019_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data .
获取特定标识(采购)的描述
SELECT DISTINCT
domvalue_l ,
ddtext
INTO TABLE @DATA(lt_esokz)
FROM dd07v
WHERE domname = 'ESOKZ'
AND ddlanguage = '1' .
SELECT DISTINCT
a~infnr , "信息记录
b~zwlcms , "物料长描述
a~matnr , "物料
b~matkl , "物料组
( e~wgbez && e~wgbez60 ) AS matklt , "物料组描述
a~lifnr , "供应商
c~ekorg , "采购组织
c~esokz , "信息类型
c~werks , "工厂
d~name1 , "名称
a~loekz , "一般主数据删除标记
c~loekz AS loekz2 "采购数据删除标记
INTO CORRESPONDING FIELDS OF TABLE @gt_alv
FROM eina AS a
INNER JOIN mara AS b ON a~matnr = b~matnr
INNER JOIN eine AS c ON a~infnr = c~infnr
LEFT JOIN lfa1 AS d ON a~lifnr = d~lifnr
LEFT JOIN t023t AS e ON b~matkl = e~matkl AND e~spras = '1'
WHERE a~infnr IN @s_infnr
AND c~werks IN @s_werks
AND c~ekorg IN @s_ekorg
AND a~lifnr IN @s_lifnr
AND a~matnr IN @s_matnr
AND a~matkl IN @s_matkl
AND c~esokz IN @s_esokz
AND a~loekz <> 'X'
AND c~loekz <> 'X'
AND c~prdat < @sy-datum
.
匹配采购类型描述
SORT gt_alv BY infnr DESCENDING .
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL() .
-index = sy-tabix .
IF -esokz IS NOT INITIAL .
READ TABLE lt_esokz ASSIGNING FIELD-SYMBOL() WITH KEY domvalue_l = -esokz.
IF sy-subrc = 0 .
-ddtext = -ddtext .
ENDIF .
ENDIF .
ENDLOOP .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_show_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_show_alv .
PERFORM frm_set_fieldcat .
PERFORM frm_set_layout .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_SET_EVENT'
i_callback_user_command = 'FRM_USER_COMMAND'
it_fieldcat_lvc = gt_fieldcat
is_layout_lvc = gs_layout
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = gt_alv
EXCEPTIONS
OTHERS = 1.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_build_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*&---------------------------------------------------------------------*
FORM frm_build_fieldcat USING p_fieldname TYPE fieldname
p_qfieldname TYPE lvc_qfname
p_cfieldname TYPE lvc_cfname
p_ref_table TYPE lvc_rtname
p_ref_field TYPE lvc_rfname
p_convexit TYPE convexit
p_emphasize TYPE lvc_emphsz
p_scrtext_l TYPE scrtext_l
p_checkbox TYPE checkbox
p_edit TYPE lvc_edit.
gs_fieldcat-fieldname = p_fieldname.
gs_fieldcat-qfieldname = p_qfieldname.
gs_fieldcat-cfieldname = p_cfieldname.
gs_fieldcat-ref_table = p_ref_table.
gs_fieldcat-ref_field = p_ref_field.
gs_fieldcat-convexit = p_convexit.
gs_fieldcat-emphasize = p_emphasize.
gs_fieldcat-scrtext_l = p_scrtext_l.
gs_fieldcat-checkbox = p_checkbox.
gs_fieldcat-edit = p_edit.
gs_fieldcat-colddictxt = 'L'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR: gs_fieldcat.
ENDFORM. "BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form frm_set_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_fieldcat .
PERFORM frm_build_fieldcat USING 'SEL' '' '' '' '' '' '' '选中' 'X' 'X'.
PERFORM frm_build_fieldcat USING 'ICON' '' '' '' '' '' '' '状态灯' '' ''.
PERFORM frm_build_fieldcat USING 'INDEX' '' '' '' '' '' '' '序号' '' ''.
PERFORM frm_build_fieldcat USING 'WERKS' '' '' '' '' '' '' '工厂' '' ''.
PERFORM frm_build_fieldcat USING 'EKORG' '' '' '' '' '' '' '采购组织' '' ''.
PERFORM frm_build_fieldcat USING 'LIFNR' '' '' '' '' '' '' '供应商' '' ''.
PERFORM frm_build_fieldcat USING 'NAME1' '' '' '' '' '' '' '供应商名称' '' ''.
PERFORM frm_build_fieldcat USING 'MATNR' '' '' '' '' '' '' '物料' '' ''.
PERFORM frm_build_fieldcat USING 'ZWLCMS' '' '' '' '' '' '' '物料描述' '' ''.
PERFORM frm_build_fieldcat USING 'MATKL' '' '' '' '' '' '' '物料组' '' ''.
PERFORM frm_build_fieldcat USING 'MATKLT' '' '' '' '' '' '' '物料组描述' '' ''.
PERFORM frm_build_fieldcat USING 'INFNR' '' '' '' '' '' '' '采购信息记录' '' ''.
* PERFORM frm_build_fieldcat USING 'ESOKZ' '' '' '' '' '' '' '采购信息类型' '' ''.
PERFORM frm_build_fieldcat USING 'DDTEXT' '' '' '' '' '' '' '采购信息类型' '' ''.
PERFORM frm_build_fieldcat USING 'INFOR' '' '' '' '' '' '' '报错信息' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_layout .
gs_layout-cwidth_opt = 'X'.
gs_layout-zebra = 'X'.
ENDFORM.
FORM frm_set_event USING p_extab TYPE slis_t_extab.
SET PF-STATUS 'ZMMCP019'.
ENDFORM.
用户动作响应
FORM frm_user_command USING s_ucomm TYPE sy-ucomm re_selfield TYPE slis_selfield.
开始** 这段代码加上之后,才能对数据进行实时更新
DATA: lv_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lv_grid.
CALL METHOD lv_grid->check_changed_data.
re_selfield-refresh = 'X'.
re_selfield-col_stable = 'X'.
re_selfield-row_stable = 'X'.
CASE s_ucomm .
WHEN '&SEL_ALL'. "全选
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL() .
-sel = 'X' .
ENDLOOP .
WHEN '&CANCEL' ."取消全选
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL() .
-sel = '' .
ENDLOOP .
WHEN '&DELETE' ."删除
PERFORM frm_call_bapi_delete .
WHEN OTHERS .
ENDCASE .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_call_bapi_delete
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_call_bapi_delete .
DATA : lv_mara(18) TYPE c,
ls_eina TYPE mewieina,
* LT_EINA LIKE TABLE OF MEWIEINA ,
ls_einax TYPE mewieinax,
* LT_EINAX LIKE TABLE OF MEWIEINAX ,
ls_eine TYPE mewieine,
* LT_EINE LIKE TABLE OF MEWIEINE ,
ls_einex TYPE mewieinex,
* LT_EINEX LIKE TABLE OF MEWIEINEX .
lt_return TYPE mewi_t_return,
lw_return LIKE LINE OF lt_return.
调用bapi 执行删除动作
LOOP AT gt_alv INTO gs_alv WHERE sel = 'X' AND status <> '1' .
CLEAR : ls_eina ,ls_einax ,ls_eine ,ls_einex ,lw_return , lv_mara.
REFRESH :lt_return . "lt_eina,lt_einax ,lt_eine ,lt_einex.
判断:EINE-PRDAT与系统当前日期比较,EINE-PRDAT小于当前日期,红灯报错“采购信息记录在有效期内”
* IF gs_alv-prdat > sy-datum .
* gs_alv-icon = '@5C@'.
* gs_alv-infor = '信息记录删除失败:采购信息记录在有效期内' .
* MODIFY gt_alv FROM gs_alv.
* CLEAR gs_alv .
* CONTINUE .
* ENDIF .
*判断:状态EINA-LOEKZ=X,红灯报错“采购一般数据已删除”
*判断:状态EINE-LOEKZ=X,红灯报错“采购组织数据已删除”
* IF gs_alv-loekz = '' AND gs_alv-loekz2 = '' .
ls_eina-info_rec = gs_alv-infnr ."信息记录
lv_mara = |{ gs_alv-matnr ALPHA = IN }| ."物料
ls_eina-material = lv_mara .
ls_eina-mat_grp = gs_alv-ekorg ."物料组
ls_eina-vendor = |{ gs_alv-lifnr ALPHA = IN }| ."信息记录
ls_eina-delete_ind = 'X' ."采购信息:标记为删除的一般数据
* APPEND LS_EINA TO LT_EINA .
ls_einax-delete_ind = 'X' ."采购信息:标记为删除的一般数据
* APPEND LS_EINAX TO LT_EINAX .
ls_eine-info_rec = gs_alv-infnr ."信息记录
ls_eine-purch_org = gs_alv-ekorg ."采购组织
ls_eine-info_type = gs_alv-esokz ."采购信息记录分类
ls_eine-plant = gs_alv-werks ."工厂
ls_eine-delete_ind = 'X' ."采购信息:标记为删除的一般数据
* APPEND LS_EINE TO LT_EINE .
ls_einex-delete_ind = 'X' ."采购信息:标记为删除的一般数据
* APPEND LS_EINEX TO LT_EINEX .
CALL FUNCTION 'ME_INFORECORD_MAINTAIN'
EXPORTING
i_eina = ls_eina
i_einax = ls_einax
i_eine = ls_eine
i_einex = ls_einex
* IMPORTING
* e_eina = lw_e_eina
* e_eine = lw_e_eine
TABLES
return = lt_return.
READ TABLE lt_return INTO lw_return WITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
gs_alv-icon = '@5C@'.
gs_alv-infor = '信息记录删除失败:' && lw_return-message .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
gs_alv-icon = '@5B@'.
gs_alv-status = '1' .
gs_alv-infor = '已完成'.
ENDIF.
* ELSE .
* IF gs_alv-loekz = 'X' .
* gs_alv-icon = '@5C@'.
* gs_alv-infor = '信息记录删除失败:采购一般数据已删除' .
* ELSEIF gs_alv-loekz2 = 'X' .
* gs_alv-icon = '@5C@'.
* gs_alv-infor = '信息记录删除失败:采购组织数据已删除' .
* ENDIF .
* ENDIF .
MODIFY gt_alv FROM gs_alv.
CLEAR gs_alv .
ENDLOOP .
ENDFORM.
1.3.2 创建/修改
参考:https://may82jftve.feishu.cn/docx/IrFMdpxLcoHOE9xJQCmcMQSdnt9
1.3.3 创建/创建
FUNCTION zfm_po.
*"----------------------------------------------------------------------
*"*"本地接口:
*"----------------------------------------------------------------------
DATA:
"接口创建辅助参数
lw_prps TYPE prps,
l_bsart TYPE bsart,
l_knttp TYPE knttp,
lw_eban TYPE eban,
l_matnr TYPE matnr,
l_mtart TYPE mtart,
l_lifnr_o TYPE char10,
l_text TYPE char200,
l_status TYPE char1,
l_posid TYPE ps_posid,
"PO号
l_po TYPE bapimepoheader-po_number,
"增强
lw_exheader TYPE bapi_te_mepoheader,
lw_exheaderx TYPE bapi_te_mepoheaderx,
lw_extensionin TYPE bapiparex,
lt_extensionin TYPE STANDARD TABLE OF bapiparex,
"抬头文本
lw_textheader TYPE bapimepotextheader,
lt_textheader TYPE STANDARD TABLE OF bapimepotextheader,
"行项目文本
lw_textitem TYPE bapimepotext,
lt_textitem TYPE STANDARD TABLE OF bapimepotext,
"账户设置
lw_poaccount TYPE bapimepoaccount,
lt_poaccount TYPE STANDARD TABLE OF bapimepoaccount,
lw_poaccountx TYPE bapimepoaccountx,
lt_poaccountx TYPE STANDARD TABLE OF bapimepoaccountx,
"采购抬头
lw_poaddr TYPE bapimepoaddrvendor,
lw_poheader TYPE bapimepoheader,
lw_poheaderx TYPE bapimepoheaderx,
"采购行项目
lw_poitem TYPE bapimepoitem,
lt_poitem TYPE bapimepoitem OCCURS 0,
lw_poitemx TYPE bapimepoitemx,
lt_poitemx TYPE bapimepoitemx OCCURS 0,
"行项目定价条件确认
lw_condition TYPE bapimepocond,
lt_condition TYPE bapimepocond OCCURS 0,
lw_conditionx TYPE bapimepocondx,
lt_conditionx TYPE bapimepocondx OCCURS 0,
"计划行
lw_poschedule TYPE bapimeposchedule,
lt_poschedule TYPE bapimeposchedule OCCURS 0,
lw_poschedulex TYPE bapimeposchedulx,
lt_poschedulex TYPE bapimeposchedulx OCCURS 0,
"返回消息
lt_return TYPE bapiret2 OCCURS 0,
lw_return TYPE bapiret2.
DATA:l_ktokk LIKE lfa1-ktokk."供应商账户组
*-------------------------------------
* bapi字段处理
*-------------------------------------
***抬头***
CLEAR:lw_poheader.
lw_poheader-doc_type = 'NB' . "标准采购订单 订单类型
lw_poheader-vendor = '0000100280'."供应商帐户号
lw_poheader-purch_org = '2010'. "采购组织
lw_poheader-pur_group = '100'. "采购组
lw_poheader-comp_code = '2010'. "公司代码
lw_poheader-doc_date = sy-datum. "采购凭证日期
lw_poheader-pmnttrms = '0046'. "收付条件代码
lw_poheader-currency = 'CNY'. "货币
lw_poheaderx-doc_type = 'X'. "凭证类型
lw_poheaderx-vendor = 'X'. "供应商帐户号
lw_poheaderx-purch_org = 'X'. "采购组织
lw_poheaderx-pur_group = 'X'. "采购组
lw_poheaderx-comp_code = 'X'. "公司代码
lw_poheaderx-doc_date = 'X'. "采购凭证日期
lw_poheaderx-pmnttrms = 'X'. "收付条件代码
lw_poheaderx-currency = 'X'. "货币
lw_exheader-zuser = 'test'.
lw_extensionin-structure = 'BAPI_TE_MEPOHEADER'.
lw_extensionin-valuepart1 = lw_exheader..
APPEND lw_extensionin TO lt_extensionin.
lw_exheaderx-zuser = 'X'.
lw_extensionin-structure = 'BAPI_TE_MEPOHEADERX'.
lw_extensionin-valuepart1 = lw_exheaderx.
APPEND lw_extensionin TO lt_extensionin.
*————抬头文本———— 164个字符,132个字符每行
DATA:lv_text TYPE string.
lv_text = '抬头文本'.
* CLEAR lw_textheader.
* lw_textheader-text_id = 'F01'.
* lw_textheader-text_form = '/'.
* lw_textheader-text_line = lv_text+0(132).
* APPEND lw_textheader TO lt_textheader.
*
* CLEAR lw_textheader.
* lw_textheader-text_id = 'F01'.
* lw_textheader-text_form = '/'.
* lw_textheader-text_line = lv_text+132(132).
* APPEND lw_textheader TO lt_textheader.
***行项目**
lw_poitem-po_item = '000010'. "行项目编号
lw_poitem-material = '000003005003000052'. "物料编码
lw_poitem-matl_group = '3005004'. "物料组
* lw_poitem-short_text = '单据的设备名称'. "OA 单据的设备名称
lw_poitem-plant = '2012'. "工厂
lw_poitem-stge_loc = ''. "库存地点
lw_poitem-quantity = '000010'. "数量
lw_poitem-po_unit = 'KG'. "单位
* lw_poitem-preq_no = '0010001664'. "采购申请编号
* lw_poitem-preq_item = '00010'. "采购申请行项目
lw_poitem-tax_code = 'J2'. "税码
* lw_poitem-acctasscat = l_knttp. "科目分配类别
" K: 成本中心 F :订单 Q :项目 生成订单 P: 项目 A: 资产
* lw_poitem-item_cat = lw_eban-pstyp. "项目类别
* lw_poitem-costcenter = lw_item-kostl. "成本中心
* lw_poitem-over_dlv_tol = lw_item-uebto. "过量交货容差
* lw_poitem-under_dlv_tol = lw_item-untto. "交货不足容差
* lw_poitem-gr_non_val = lw_item-weunb. "收货,未评估
lw_poitem-gr_basediv = 'X'. "标识:基于收货的发票验证
APPEND lw_poitem TO lt_poitem.
lw_poitemx-po_item = '000010'. "行项目编号
lw_poitemx-material = 'X'. "物料编码
* lw_poitemx-short_text = 'X'.
lw_poitemx-plant = 'X'. "工厂
lw_poitemx-stge_loc = 'X'. "库存地点
lw_poitemx-quantity = 'X'. "数量
lw_poitemx-po_unit = 'X'. "单位
* lw_poitemx-preq_no = 'X'. "采购申请编号
* lw_poitemx-preq_item = 'X'. "采购申请行项目
lw_poitemx-tax_code = 'X'. "税码
* lw_poitemx-acctasscat = 'X'. "科目分配类别
* lw_poitemx-item_cat = 'X'. "项目类别
* lw_poitemx-costcenter = 'X'. "成本中心
* lw_poitemx-matl_group = 'X'.
* lw_poitemx-over_dlv_tol = 'X'.
* lw_poitemx-under_dlv_tol = 'X'.
* lw_poitemx-gr_non_val = 'X'.
lw_poitemx-gr_basediv = 'X'.
APPEND lw_poitemx TO lt_poitemx.
***账户设置*
* IF 1 <> 1.
* "生产订单号,wbs元素,资产编号,成本中心,
* CLEAR lw_poaccount.
* lw_poaccount-po_item = '000010'.
* lw_poaccount-orderid = lw_item-aufnr.
*
* lw_poaccount-wbs_element = lw_item-posid.
* lw_poaccount-asset_no = lw_item-anln1.
* lw_poaccount-sub_number = lw_item-anln2.
* lw_poaccount-costcenter = lw_item-kostl.
* APPEND lw_poaccount TO lt_poaccount .
*
* CLEAR lw_poaccountx.
* lw_poaccountx-po_item = '000010'.
* lw_poaccountx-orderid = 'X'.
* lw_poaccountx-wbs_element = 'X'.
* lw_poaccountx-asset_no = 'X'.
* lw_poaccountx-sub_number = 'X'.
* lw_poaccountx-costcenter = 'X'.
* APPEND lw_poaccountx TO lt_poaccountx.
* ENDIF.
***定价条件*
lw_condition-itm_number = '000010'."行项目号
lw_condition-cond_type = 'PBXX'. "条件类型
lw_condition-cond_value = '10'. "金额
lw_condition-cond_p_unt = 1. "价格单位
lw_condition-currency = 'CNY'. "货币
lw_condition-change_id = 'I'.
APPEND lw_condition TO lt_condition.
lw_conditionx-itm_number = '000010'. "行项目号
lw_conditionx-cond_type = 'X'. "条件类型
lw_conditionx-cond_value = 'X'. "金额
lw_conditionx-cond_p_unt = 'X'. "金额
lw_conditionx-currency = 'X'. "货币
lw_conditionx-change_id = 'X'.
APPEND lw_conditionx TO lt_conditionx.
*————行项目文本————
* CLEAR lw_textitem.
* lw_textitem-po_item = '000010'.
* lw_textitem-text_id = 'F01'.
* lw_textitem-text_form = '/'.
* lw_textitem-text_line = lv_text+0(132).
* APPEND lw_textitem TO lt_textitem.
* "IF lw_item-sgtxt+132(132) IS NOT INITIAL.
* CLEAR lw_textitem.
* lw_textitem-po_item = '000010'.
* lw_textitem-text_id = 'F01'.
* lw_textitem-text_form = '/'.
* lw_textitem-text_line = lv_text+132(132).
* APPEND lw_textitem TO lt_textitem.
* "ENDIF.
***计划行*
lw_poschedule-po_item = '000010'.
lw_poschedule-delivery_date = '20220101'."交货日期
APPEND lw_poschedule TO lt_poschedule.
lw_poschedulex-po_item = '000010'.
lw_poschedulex-po_itemx = 'X'.
lw_poschedulex-delivery_date = 'X'.
APPEND lw_poschedulex TO lt_poschedulex.
SET UPDATE TASK LOCAL .
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = lw_poheader
poheaderx = lw_poheaderx
poaddrvendor = lw_poaddr
* TESTRUN = 'X'
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* PARK_COMPLETE =
* PARK_UNCOMPLETE =
IMPORTING
exppurchaseorder = l_po
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = lt_return
poitem = lt_poitem
poitemx = lt_poitemx
* POADDRDELIVERY =
poschedule = lt_poschedule
poschedulex = lt_poschedulex
poaccount = lt_poaccount
* POACCOUNTPROFITSEGMENT =
poaccountx = lt_poaccountx
* POCONDHEADER =
* POCONDHEADERX =
pocond = lt_condition
pocondx = lt_conditionx
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
extensionin = lt_extensionin
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
potextheader = lt_textheader
potextitem = lt_textitem
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* SERIALNUMBER =
* SERIALNUMBERX =
* INVPLANHEADER =
* INVPLANHEADERX =
* INVPLANITEM =
* INVPLANITEMX =
.
* 结果处理
* 状态判定
CLEAR l_text.
LOOP AT lt_return INTO lw_return .
IF lw_return-type = 'E'
OR lw_return-type = 'A' .
l_status = 'E'.
ELSE.
CONTINUE.
ENDIF.
IF l_text IS INITIAL.
l_text = lw_return-message.
ELSE.
CONCATENATE l_text lw_return-message INTO l_text SEPARATED BY '//'.
ENDIF.
ENDLOOP.
* ADD 20230106 状态判断里面加入判断单号为空时
IF l_po IS INITIAL.
l_status = 'E'.
CONCATENATE '创建失败' l_text lw_return-message INTO l_text SEPARATED BY '//'.
ENDIF.
**
* 结果处理
IF l_status = 'E' .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
* 产生队列,后台进行自动审批
DATA l_qname TYPE trfcqout-qname.
l_qname = 'PO_SP_' && l_po.
CONDENSE l_qname NO-GAPS.
CALL FUNCTION 'TRFC_SET_QUEUE_NAME'
EXPORTING
qname = l_qname
nosend = ' '
trfc_if_sysfail = ' '
call_event = ' '
EXCEPTIONS
invalid_queue_name = 1
OTHERS = 2.
CALL FUNCTION 'ZMM_PO_APPROVAL_AUTO'
IN BACKGROUND TASK
AS SEPARATE UNIT
DESTINATION 'NONE'
EXPORTING
i_ebeln = l_po.
COMMIT WORK .
ENDFUNCTION.
SAP中的采购订单(Purchase Order,简称PO)是一项关键的采购管理工具,用于与供应商确认和管理采购需求、价格、交付和质量等细节。以下是与SAP采购订单相关的主要概念的说明:
采购组织(Purchasing Organization): 采购组织是企业内部的一个组织单元,负责管理和执行采购活动。每个采购订单都与特定的采购组织相关联。在SAP中,采购组织通常与企业的不同业务单元或部门相对应。
供应商(Vendor): 供应商是企业从其购买物料或服务的外部实体。在采购订单中,需要指定供应商的详细信息,包括供应商名称、地址和联系方式。
物料(Material): 物料是企业需要采购的具体物品或服务。采购订单中需要明确物料的描述、数量、单位、规格和质量要求等信息。
采购数量(Quantity): 采购订单规定了企业要采购的物料数量。这是采购需求的一部分,有助于规划供应链。
采购价格(Price): 采购订单包括了每个物料的价格,这是供应商为提供物料或服务而向企业收取的费用。价格通常以货币单位表示。
付款条件(Payment Terms): 采购订单中定义了付款条件,这是关于付款的具体规定,包括付款期限、折扣条件和付款方式等。
交付日期(Delivery Date): 采购订单规定了物料或服务的交付日期。这是指供应商应该将物料交付到企业的日期。
质量要求(Quality Requirements): 采购订单可能包括对物料或服务的质量要求,包括检验、测试和认证等方面的要求。
采购订单状态(Purchase Order Status): 采购订单可以具有不同的状态,如创建、已批准、已交付、已关闭等。这有助于跟踪订单的进展和管理。
采购订单审批(Purchase Order Approval): 在某些情况下,采购订单可能需要经过内部审批流程,以确保合规性和成本控制。审批可以包括多个层次和步骤,需要相关部门的批准。
供应商确认(Vendor Confirmation): 一旦采购订单生成,供应商通常需要确认其能够按照订单的要求履行交付。供应商确认有助于确保供应链的可靠性。
采购订单变更(Purchase Order Change): 如果采购需求或其他细节发生变化,可以创建采购订单变更以更新订单信息,例如数量、价格或交付日期。
4.1 基于Tcode的顺序排列
供应商主数据 | 物料主数据 | 货源清单 | 配额安排 | 采购信息记录 | 采购订单 | 框架协议 | 采购询价/报价 | 采购申请 | 订单收货 | 发票校验 | 物料需求计划 |
BP-供应商主数据 | MM01 - 物料主数据新增 | ME01 - 维护 | MEQ1 - 维护 | ME11 - 创建 | ME21N - 创建 | 框架协议-合同: | 询价: | ME51N - 创建采购申请 | MIGO - 货物移动 | MIRO - 发票校验 | MD01 - 联机 |
XK01 - 创建 | MM02 - 物料主数据修改 | ME03 - 显示 | MEQ3 - 显示 | ME12 - 修改 | ME22N - 更改 | ME31K - 创建 | ME41 - 创建 | ME52N - 更改采购申请 | MB03 - 显示物料凭证 | MD04 - 显示库存/需求状况 | |
XK02 - 更改 | MM03 - 物料主数据查询 | ME0M - 清单查询 | MEQ4 - 更改 | ME13 - 查询 | ME23N - 显示 | ME32K - 更改 | ME42 - 更改 | ME53N - 显示采购申请 | MB51 - 物料凭证清单 | ||
XK03 - 显示 | MM04 - 物料主数据冻结与解冻 | ME04 - 修改记录查询 | MEQM - 按物料 (清单显示) | ME14 - 修改记录查询 | ME29N - 审批 | ME33K - 显示 | ME43 - 显示 | ME54N - 批准采购请求 | MMBE - 库存总览 | ||
XK04 - 修改 | MM50 - 扩充物料视图 | ME15 - 删除 | ME34K - 维护补充 | ME44 - 维护补充 | ME5A - 清单查询 | MB52 - 现有仓库库存清单 | |||||
XK05 - 冻结 | MM06 - 删除物料标记 | ME1L - 清单查询 | ME35K - 审批 | ME45 - 审批 | |||||||
XK06 - 删除标记 | MM60 - 物料清单 | 框架协议-计划协议: | 报价: | ||||||||
XK07 - 科目组改变 | MM17 - 成批维护 | ME31L - 已知供应商 | ME47 - 维护 | ||||||||
ME37 - 库存传送计划协议 | ME48 - 显示 | ||||||||||
ME32L - 更改 | ME49 - 价格比较 | ||||||||||
ME33L - 显示 | |||||||||||
ME34L - 维护补充 | |||||||||||
ME35L - 审批 |
鸣谢:感谢查阅,请多多指教,有用请收藏、点赞哦 !