DEMO系列
作者:互联网
DEMO:BAPI_SALESORDER_CREATEFROMDAT2 创建订单
PARAMETERS p_kunnr TYPE kunnr DEFAULT '1004615'. PARAMETERS p_vkorg TYPE vkorg DEFAULT 'S600'. PARAMETERS p_vtweg TYPE vtweg DEFAULT '10'. PARAMETERS p_spart TYPE spart DEFAULT '00'. PARAMETERS p_werks TYPE werks_d DEFAULT 'S600'. PARAMETERS p_lgort TYPE lgort_d DEFAULT '6001'. PARAMETERS p_vstel TYPE vstel DEFAULT 'S600'. PARAMETERS p_matnr TYPE matnr DEFAULT 'TEST99'. DATA:ls_order_header_in LIKE bapisdhd1. DATA:ls_order_header_inx LIKE bapisdhd1x. DATA:lt_order_items_in LIKE TABLE OF bapisditm. DATA:lt_order_items_inx LIKE TABLE OF bapisditmx. DATA:ls_order_items_in LIKE bapisditm. DATA:ls_order_items_inx LIKE bapisditmx. DATA:lt_order_partners LIKE TABLE OF bapiparnr. DATA:ls_order_partners LIKE LINE OF lt_order_partners. DATA:lt_schedules_in LIKE TABLE OF bapischdl . DATA:lt_schedules_inx LIKE TABLE OF bapischdlx . DATA:ls_schedules_in LIKE bapischdl . DATA:ls_schedules_inx LIKE bapischdlx . DATA:lt_order_conditions_in LIKE TABLE OF bapicond . DATA:lt_order_conditions_inx LIKE TABLE OF bapicondx . DATA:ls_order_conditions_in LIKE bapicond . DATA:ls_order_conditions_inx LIKE bapicondx . DATA: lt_return LIKE TABLE OF bapiret2. DATA: ls_return LIKE bapiret2. DATA:lv_salesdocument LIKE bapivbeln-vbeln. CLEAR ls_order_header_in. ls_order_header_in-doc_type = 'ZDJX'."订单类型 ls_order_header_in-sales_org = p_vkorg. ls_order_header_in-distr_chan = p_vtweg."分销渠道 ls_order_header_in-division = p_spart."产品组 * ls_order_header_in-sales_off = . "销售部门 ls_order_header_in-purch_no_c = 'test'. CLEAR ls_order_header_inx. ls_order_header_inx-doc_type = 'X'. ls_order_header_inx-sales_org = 'X'. ls_order_header_inx-distr_chan = 'X'. ls_order_header_inx-division = 'X'. *ls_order_header_inx-sales_off = 'X'. ls_order_header_inx-ass_number = 'X'. ls_order_header_inx-updateflag = '1'. ls_order_header_inx-purch_no_c = 'X'. CLEAR ls_order_items_in. CLEAR lt_order_items_in[]. ls_order_items_in-itm_number = '10'."只有一个行项目 ls_order_items_in-material = p_matnr. ls_order_items_in-plant = p_werks. ls_order_items_in-store_loc = p_lgort. ls_order_items_in-target_qty = 1. ls_order_items_in-ship_point = p_vstel."装运点 ls_order_items_in-target_qu = 'EA'. ls_order_items_in-sales_unit = 'EA'. APPEND ls_order_items_in TO lt_order_items_in. CLEAR lt_schedules_in[]. CLEAR ls_schedules_in. ls_schedules_in-itm_number = '10'."只有一个行项目 ls_schedules_in-req_qty = 1. APPEND ls_schedules_in TO lt_schedules_in. CLEAR ls_schedules_inx. CLEAR lt_schedules_inx[]. ls_schedules_inx-updateflag = 'X'. ls_schedules_inx-itm_number = 'X'. ls_schedules_inx-req_qty = 'X'. APPEND ls_schedules_inx TO lt_schedules_inx. "售达方默认 CLEAR ls_order_partners. ls_order_partners-partn_role = 'AG'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. *&--------------------------------------------------------------------------------------- "如果送达方 使用一次性客户 CLEAR ls_order_partners. *ls_order_partners-partn_role = 'WE'. *ls_order_partners-partn_numb = '1'. * *CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' * EXPORTING * input = ls_order_partners-partn_numb * IMPORTING * output = ls_order_partners-partn_numb. * *ls_order_partners-name = '一次性客户测试'. *ls_order_partners-country = 'CN'. *APPEND ls_order_partners TO lt_order_partners. "送达方 CLEAR ls_order_partners. ls_order_partners-partn_role = 'WE'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. *&--------------------------------------------------------------- "付款方 CLEAR ls_order_partners. ls_order_partners-partn_role = 'RE'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. "收票方 CLEAR ls_order_partners. ls_order_partners-partn_role = 'RG'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. "价格条件 CLEAR lt_order_conditions_in[]. CLEAR lt_order_conditions_inx[]. CLEAR ls_order_conditions_in. ls_order_conditions_in-itm_number = '10'. ls_order_conditions_in-cond_st_no = ''. ls_order_conditions_in-cond_count = ''. ls_order_conditions_in-cond_type = 'ZPR0'. "定价条件 ls_order_conditions_in-cond_value = 1000. ls_order_conditions_in-currency = 'RMB'. "币别 APPEND ls_order_conditions_in TO lt_order_conditions_in. CLEAR ls_order_conditions_inx. ls_order_conditions_inx-itm_number = '10'. ls_order_conditions_inx-cond_st_no = ''. ls_order_conditions_inx-cond_count = ''. ls_order_conditions_inx-updateflag = 'X'. ls_order_conditions_inx-cond_type = 'ZPR0'. "定价条件 ls_order_conditions_inx-cond_value = 'X'. "价格 IF ls_order_conditions_in-currency IS NOT INITIAL. ls_order_conditions_inx-currency = 'X'. "币别 ENDIF. APPEND ls_order_conditions_inx TO lt_order_conditions_inx. CLEAR lv_salesdocument. CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING order_header_in = ls_order_header_in order_header_inx = ls_order_header_inx IMPORTING salesdocument = lv_salesdocument TABLES return = lt_return order_items_in = lt_order_items_in order_items_inx = lt_order_items_inx order_partners = lt_order_partners order_schedules_in = lt_schedules_in order_schedules_inx = lt_schedules_inx order_conditions_in = lt_order_conditions_in order_conditions_inx = lt_order_conditions_inx. IF lv_salesdocument IS NOT INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. WRITE lv_salesdocument. WRITE lv_salesdocument.
DEMO:BAPI_CUSTOMERRETURN_CREATE创建退货单
PARAMETERS p_kunnr TYPE kunnr DEFAULT '1004615'. PARAMETERS p_vkorg TYPE vkorg DEFAULT 'S600'. PARAMETERS p_vtweg TYPE vtweg DEFAULT '10'. PARAMETERS p_spart TYPE spart DEFAULT '00'. PARAMETERS p_werks TYPE werks_d DEFAULT 'S600'. PARAMETERS p_lgort TYPE lgort_d DEFAULT '6001'. PARAMETERS p_vstel TYPE vstel DEFAULT 'S600'. PARAMETERS p_matnr TYPE matnr DEFAULT 'TEST99'. DATA:ls_order_header_in LIKE bapisdhd1. DATA:ls_order_header_inx LIKE bapisdhd1x. DATA:lt_order_items_in LIKE TABLE OF bapisditm. DATA:lt_order_items_inx LIKE TABLE OF bapisditmx. DATA:ls_order_items_in LIKE bapisditm. DATA:ls_order_items_inx LIKE bapisditmx. DATA:lt_order_partners LIKE TABLE OF bapiparnr. DATA:ls_order_partners LIKE LINE OF lt_order_partners. DATA:lt_schedules_in LIKE TABLE OF bapischdl . DATA:lt_schedules_inx LIKE TABLE OF bapischdlx . DATA:ls_schedules_in LIKE bapischdl . DATA:ls_schedules_inx LIKE bapischdlx . DATA:lt_order_conditions_in LIKE TABLE OF bapicond . DATA:lt_order_conditions_inx LIKE TABLE OF bapicondx . DATA:ls_order_conditions_in LIKE bapicond . DATA:ls_order_conditions_inx LIKE bapicondx . DATA: lt_return LIKE TABLE OF bapiret2. DATA: ls_return LIKE bapiret2. DATA:lv_salesdocument LIKE bapivbeln-vbeln. CLEAR ls_order_header_in. ls_order_header_in-doc_type = 'ZDRE'."订单类型 ls_order_header_in-sales_org = p_vkorg. ls_order_header_in-distr_chan = p_vtweg."分销渠道 ls_order_header_in-division = p_spart."产品组 * ls_order_header_in-sales_off = . "销售部门 ls_order_header_in-purch_no_c = 'test'. CLEAR ls_order_header_inx. ls_order_header_inx-doc_type = 'X'. ls_order_header_inx-sales_org = 'X'. ls_order_header_inx-distr_chan = 'X'. ls_order_header_inx-division = 'X'. *ls_order_header_inx-sales_off = 'X'. ls_order_header_inx-ass_number = 'X'. ls_order_header_inx-updateflag = '1'. ls_order_header_inx-purch_no_c = 'X'. CLEAR ls_order_items_in. CLEAR lt_order_items_in[]. ls_order_items_in-itm_number = '10'."只有一个行项目 ls_order_items_in-material = p_matnr. ls_order_items_in-plant = p_werks. ls_order_items_in-store_loc = p_lgort. ls_order_items_in-target_qty = 1. ls_order_items_in-ship_point = p_vstel."装运点 ls_order_items_in-target_qu = 'EA'. ls_order_items_in-sales_unit = 'EA'. APPEND ls_order_items_in TO lt_order_items_in. CLEAR lt_schedules_in[]. CLEAR ls_schedules_in. ls_schedules_in-itm_number = '10'."只有一个行项目 ls_schedules_in-req_qty = 1. APPEND ls_schedules_in TO lt_schedules_in. CLEAR ls_schedules_inx. CLEAR lt_schedules_inx[]. ls_schedules_inx-updateflag = 'X'. ls_schedules_inx-itm_number = 'X'. ls_schedules_inx-req_qty = 'X'. APPEND ls_schedules_inx TO lt_schedules_inx. "售达方默认 CLEAR ls_order_partners. ls_order_partners-partn_role = 'AG'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. *&------------------------------------------------------------------- "送达方 如果使用一次性客户 CLEAR ls_order_partners. *ls_order_partners-partn_role = 'WE'. *ls_order_partners-partn_numb = '1'. * *CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' * EXPORTING * input = ls_order_partners-partn_numb * IMPORTING * output = ls_order_partners-partn_numb. * *ls_order_partners-name = '一次性客户测试'. *ls_order_partners-country = 'CN'. *APPEND ls_order_partners TO lt_order_partners. "送达方 CLEAR ls_order_partners. ls_order_partners-partn_role = 'WE'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. *&--------------------------------------------------------------- "付款方 CLEAR ls_order_partners. ls_order_partners-partn_role = 'RE'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. "收票方 CLEAR ls_order_partners. ls_order_partners-partn_role = 'RG'. ls_order_partners-partn_numb = p_kunnr. APPEND ls_order_partners TO lt_order_partners. "价格条件 CLEAR lt_order_conditions_in[]. CLEAR lt_order_conditions_inx[]. CLEAR ls_order_conditions_in. ls_order_conditions_in-itm_number = '10'. ls_order_conditions_in-cond_st_no = ''. ls_order_conditions_in-cond_count = ''. ls_order_conditions_in-cond_type = 'ZPR0'. "定价条件 ls_order_conditions_in-cond_value = 1000. ls_order_conditions_in-currency = 'RMB'. "币别 APPEND ls_order_conditions_in TO lt_order_conditions_in. CLEAR ls_order_conditions_inx. ls_order_conditions_inx-itm_number = '10'. ls_order_conditions_inx-cond_st_no = ''. ls_order_conditions_inx-cond_count = ''. ls_order_conditions_inx-updateflag = 'X'. ls_order_conditions_inx-cond_type = 'ZPR0'. "定价条件 ls_order_conditions_inx-cond_value = 'X'. "价格 IF ls_order_conditions_in-currency IS NOT INITIAL. ls_order_conditions_inx-currency = 'X'. "币别 ENDIF. APPEND ls_order_conditions_inx TO lt_order_conditions_inx. CLEAR lv_salesdocument. CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE' EXPORTING return_header_in = ls_order_header_in return_header_inx = ls_order_header_inx IMPORTING salesdocument = lv_salesdocument TABLES return = lt_return return_items_in = lt_order_items_in return_items_inx = lt_order_items_inx return_partners = lt_order_partners return_schedules_in = lt_schedules_in return_schedules_inx = lt_schedules_inx return_conditions_in = lt_order_conditions_in. * return_conditions_inx = lt_order_conditions_inx. IF lv_salesdocument IS NOT INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. WRITE lv_salesdocument.
DEMO:创建外向交货单BAPI_OUTB_DELIVERY_CREATE_SLS
parameters p_vbeln type vbeln_va. parameters p_sernr type objk-sernr. parameters p_vstel type vstel. data:ls_vbak type vbak. data:lt_vbap type table of vbap. data:ls_vbap type vbap. data:lv_delivery type bapishpdelivnumb-deliv_numb, lv_num_deliveries type bapidlvcreateheader-num_deliveries, lt_sales_order_items like table of bapidlvreftosalesorder , lt_return like table of bapiret2 . data:ls_sales_order_items like line of lt_sales_order_items. data:ls_return like line of lt_return. data:lt_serial_numbers like table of bapidlvserialnumber. data:ls_serial_numbers like line of lt_serial_numbers. data: lv_ship_point type bapidlvcreateheader-ship_point. data:lv_due_date type bapidlvcreateheader-due_date. start-of-selection. select single * from vbak into ls_vbak where vbeln = p_vbeln. select single * from vbap into ls_vbap where vbeln = p_vbeln. check sy-subrc = 0. clear: lv_delivery,lv_num_deliveries, lt_sales_order_items[], lt_serial_numbers[], lt_return[]. ls_sales_order_items-ref_doc = ls_vbak-vbeln. "参考订单号 ls_sales_order_items-ref_item = '000010'. "行项目号 单个航项目 "可以使用默认 ls_sales_order_items-dlv_qty = 1 . "数量 ls_sales_order_items-sales_unit = 'EA'. "单位 append ls_sales_order_items to lt_sales_order_items. ls_serial_numbers-ref_doc = ls_vbak-vbeln. ls_serial_numbers-ref_item = 10. ls_serial_numbers-serialno = p_sernr. call function 'CONVERSION_EXIT_GERNR_INPUT' exporting input = ls_serial_numbers-serialno importing output = ls_serial_numbers-serialno. append ls_serial_numbers to lt_serial_numbers. lv_ship_point = p_vstel. clear lv_delivery. lv_due_date = sy-datum + 365. call function 'BAPI_OUTB_DELIVERY_CREATE_SLS' exporting ship_point = lv_ship_point due_date = lv_due_date importing delivery = lv_delivery num_deliveries = lv_num_deliveries tables sales_order_items = lt_sales_order_items serial_numbers = lt_serial_numbers return = lt_return. call function 'BAPI_TRANSACTION_COMMIT' exporting wait = 'X'. write lv_delivery.
DEMO:修改外向交货单BAPI_OUTB_DELIVERY_CHANGE
简单demo,交货单数量+1,然后维护上序列号(有的公司没有启用序列号就不需要了) REPORT zdemo_vl02n. TABLES:likp,lips. PARAMETERS:p_vbeln TYPE vbeln_vl. PARAMETER:p_sernr TYPE objk-sernr. DATA:ls_header_data LIKE bapiobdlvhdrchg, ls_header_control LIKE bapiobdlvhdrctrlchg, lv_delivery LIKE bapiobdlvhdrchg-deliv_numb. DATA:lt_item_data LIKE TABLE OF bapiobdlvitemchg, lt_item_control LIKE TABLE OF bapiobdlvitemctrlchg , lt_item_serial_no LIKE TABLE OF bapidlvitmserno . DATA:ls_item_data LIKE bapiobdlvitemchg, ls_item_control LIKE bapiobdlvitemctrlchg , ls_item_serial_no LIKE bapidlvitmserno . DATA:lt_return TYPE TABLE OF bapiret2. DATA:lt_lips TYPE TABLE OF lips. DATA:ls_lips TYPE lips. DATA:lt_ser01 TYPE TABLE OF ser01. DATA:ls_ser01 TYPE ser01. DATA:lt_objk TYPE TABLE OF objk. DATA:ls_objk TYPE objk. "交货单信息 SELECT * FROM lips INTO TABLE lt_lips WHERE vbeln = p_vbeln. "交货单系列号的凭证抬头 SELECT * FROM ser01 INTO TABLE lt_ser01 WHERE lief_nr = p_vbeln. "交货单对应的物料+序列号 IF lt_ser01[] IS NOT INITIAL. SELECT * FROM objk INTO TABLE lt_objk FOR ALL ENTRIES IN lt_ser01 WHERE obknr = lt_ser01-obknr. ENDIF. CLEAR lt_item_serial_no[]. "填写物料+序列号 LOOP AT lt_lips INTO ls_lips. READ TABLE lt_ser01 INTO ls_ser01 WITH KEY lief_nr = ls_lips-vbeln posnr = ls_lips-posnr. CHECK sy-subrc = 0. LOOP AT lt_objk INTO ls_objk WHERE obknr = ls_ser01-obknr. CLEAR ls_item_serial_no. ls_item_serial_no-deliv_numb = ls_lips-vbeln. ls_item_serial_no-itm_number = ls_lips-posnr. ls_item_serial_no-serialno = ls_objk-sernr. APPEND ls_item_serial_no TO lt_item_serial_no[]. ENDLOOP. ENDLOOP. *&最后一个行项目上 数量加一,加一个物料 和序列号 ls_item_serial_no-deliv_numb = ls_lips-vbeln. ls_item_serial_no-itm_number = ls_lips-posnr. ls_item_serial_no-serialno = p_sernr. APPEND ls_item_serial_no TO lt_item_serial_no[]. "修改交货单数量 CLEAR ls_item_data. CLEAR lt_item_data[]. ls_lips-lfimg = ls_lips-lfimg + 1. ls_item_data-deliv_numb = ls_lips-vbeln. ls_item_data-deliv_item = ls_lips-posnr . ls_item_data-material = ls_lips-matnr . ls_item_data-dlv_qty = ls_lips-lfimg . ls_item_data-dlv_qty_imunit = ls_lips-lfimg. ls_item_data-fact_unit_denom = 1. ls_item_data-fact_unit_nom = 1. ls_item_data-sales_unit = 'EA'. ls_item_data-base_uom = 'EA'. APPEND ls_item_data TO lt_item_data. CLEAR ls_item_control. CLEAR lt_item_control[]. ls_item_control-deliv_numb = ls_lips-vbeln.. ls_item_control-deliv_item = ls_item_data-deliv_item. ls_item_control-chg_delqty = 'X'. APPEND ls_item_control TO lt_item_control. lv_delivery = p_vbeln. ls_header_data-deliv_numb = p_vbeln. ls_header_control-deliv_numb = p_vbeln. CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE' EXPORTING header_data = ls_header_data header_control = ls_header_control delivery = lv_delivery TABLES * HEADER_PARTNER = * HEADER_PARTNER_ADDR = * HEADER_DEADLINES = item_data = lt_item_data item_control = lt_item_control item_serial_no = lt_item_serial_no * SUPPLIER_CONS_DATA = * EXTENSION1 = * EXTENSION2 = return = lt_return * TOKENREFERENCE = * ITEM_DATA_SPL = * COLLECTIVE_CHANGE_ITEMS = * NEW_ITEM_DATA = * NEW_ITEM_DATA_SPL = * NEW_ITEM_ORG = * ITEM_DATA_DOCU_BATCH = . CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.
标签:partners,系列,DEMO,lt,ls,inx,conditions,order 来源: https://www.cnblogs.com/BruceKing/p/16326510.html