READ TABLE s_head INDEX 1. IF sy-subrc = 0. ls_orders_h = s_head. *** 抬头 CLEAR: ls_header,ls_headerx. ls_header-doc_type = s_head-auart. "销售凭证类型 ls_header-sales_org = '8000'. "销售组织 ls_header-distr_chan = s_head-vtweg."分销渠道 ls_header-division = '10'. " 产品组默认 ls_header-purch_no_c = s_head-khdh. " 客户参考号 ls_header-req_date_h = s_head-sodate. "交货日期 ls_headerx-doc_type = abap_true. ls_headerx-sales_org = abap_true. ls_headerx-distr_chan = abap_true. ls_headerx-division = abap_true. ls_headerx-purch_no_c = abap_true. ls_headerx-req_date_h = abap_true. *退货原因 CASE s_head-augru . WHEN '10 '. ls_header-ord_reason = '900'. WHEN '20 '. ls_header-ord_reason = '910'. WHEN '30'. ls_header-ord_reason = '930'. ENDCASE. ls_headerx-ord_reason = abap_true. *** 抬头增强字段 CLEAR: ls_bape_vbak,ls_bape_vbakx. ls_bape_vbak-zzaykhdh = s_head-zkhdha. " ls_bape_vbak-zzsosourc = s_head-sosourc. " LOOP AT s_item. lv_matnr = s_item-matnr. CLEAR s_item. ENDLOOP. READ TABLE s_head INDEX 1. ls_orders_h-kunnr = s_head-kunnr. CALL FUNCTION 'ZSD_ORDER_TYPE' EXPORTING i_matnr = lv_matnr i_kunnr = ls_orders_h-kunnr IMPORTING o_type = ls_bape_vbak-zzbustype. ls_bape_vbak-zdddd = s_head-zddlxx. ls_bape_vbak-zddlll = s_head-zddlya. ls_bape_vbakx-zzykhdh = abap_true. ls_bape_vbakx-zzsosourc = abap_true. ls_bape_vbakx-zzbustype = abap_true. ls_bape_vbakx-zddlx = abap_true. ls_bape_vbakx-zddly = abap_true. CLEAR:lt_extensionin,ls_extensionin,str. CONCATENATE ls_extensionin-valuepart1 ls_extensionin-valuepart2 ls_extensionin-valuepart3 ls_extensionin-valuepart4 INTO str. MOVE 'BAPE_VBAK' TO ls_extensionin-structure. CALL METHOD cl_abap_container_utilities=>fill_container_c EXPORTING im_value = ls_bape_vbak IMPORTING * ex_container = ls_extensionin-valuepart1. ex_container = str. ls_extensionin-valuepart1 = str+0(240). ls_extensionin-valuepart2 = str+240(240). ls_extensionin-valuepart3 = str+480(240). ls_extensionin-valuepart4 = str+720(240). APPEND ls_extensionin TO lt_extensionin. CLEAR ls_extensionin. MOVE 'BAPE_VBAKX' TO ls_extensionin-structure. MOVE ls_bape_vbakx TO ls_extensionin-valuepart1. APPEND ls_extensionin TO lt_extensionin. ***合作伙伴 CLEAR: lt_partner,ls_partner. ls_partner-partn_role = 'AG'." 售达方 ls_partner-partn_numb = s_head-kunnr."SAP客户编码 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = ls_partner-partn_numb IMPORTING output = ls_partner-partn_numb. APPEND ls_partner TO lt_partner. ENDIF. LOOP AT s_item. * WHERE khdh = s_head-khdh. lv_posnr = lv_posnr + 10. lv_line = lv_line + 1. *** 行项目 CLEAR: ls_item,ls_item. ls_item-itm_number = lv_posnr."行项目号 ls_item-material_long = s_item-matnr."物料号 ls_item-material = s_item-matnr. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = ls_item-material_long IMPORTING output = ls_item-material_long. ls_item-target_qty = s_item-quantity."数量 IF s_item-price = 0. ls_item-item_categ = 'ZRNN'. ENDIF. APPEND ls_item TO lt_item. ls_itemx-itm_number = lv_posnr. ls_itemx-material = abap_true. ls_itemx-material_long = abap_true. ls_itemx-target_qty = abap_true. ls_item-item_categ = abap_true. APPEND ls_itemx TO lt_itemx. CLEAR: ls_schedule,ls_schedulex. ls_schedule-itm_number = lv_posnr. ls_schedule-sched_line = lv_line. ls_schedule-req_qty = s_item-quantity. ls_schedule-req_date = s_item-dedate. APPEND ls_schedule TO lt_schedule. ls_schedulex-itm_number = lv_posnr. ls_schedule-sched_line = lv_line. ls_schedulex-req_qty = abap_true. ls_schedulex-req_date = abap_true. APPEND ls_schedulex TO lt_schedulex. *** 行项目条件记录 CLEAR:ls_condx,ls_cond. ls_cond-itm_number = lv_posnr. ls_cond-cond_type = 'ZSG'. "定价条件 ls_cond-cond_value = s_item-price / 10."价格 APPEND ls_cond TO lt_cond. ls_condx-itm_number = lv_posnr. ls_condx-cond_type = abap_true. ls_condx-cond_value = abap_true. APPEND ls_condx TO lt_condx. *** 行项目增强 CLEAR:ls_bape_vbap,ls_bape_vbapx,ls_extensionin,gt_vbap,gs_vbap. ls_bape_vbap-posnr = lv_posnr. ls_bape_vbap-zzecode = s_item-ecode. ls_bape_vbap-zzrckhdh = s_item-rckhdh. ls_bape_vbap-zzkhdh = s_item-khdh. ls_bape_vbap-zzdeparte = s_item-zzdeparte. ls_bape_vbapx-posnr = lv_posnr. ls_bape_vbapx-zzecode = abap_true. ls_bape_vbapx-zzrckhdh = abap_true. ls_bape_vbapx-zzkhdh = abap_true. ls_bape_vbapx-zzdeparte = abap_true. MOVE 'BAPE_VBAP' TO ls_extensionin-structure. CALL METHOD cl_abap_container_utilities=>fill_container_c EXPORTING im_value = ls_bape_vbap IMPORTING ex_container = ls_extensionin-valuepart1. APPEND ls_extensionin TO lt_extensionin. CLEAR ls_extensionin. MOVE 'BAPE_VBAPX' TO ls_extensionin-structure. MOVE ls_bape_vbapx TO ls_extensionin-valuepart1. APPEND ls_extensionin TO lt_extensionin. ENDLOOP. CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE' EXPORTING * SALESDOCUMENTIN = return_header_in = ls_header return_header_inx = ls_headerx IMPORTING salesdocument = lv_salesdocument TABLES return = lt_return return_items_in = lt_item return_items_inx = lt_itemx return_partners = lt_partner return_schedules_in = lt_schedule return_schedules_inx = lt_schedulex return_conditions_in = lt_cond extensionin = lt_extensionin. LOOP AT lt_return INTO ls_return WHERE type = 'A' OR type = 'E'. lv_message = lv_message && ls_return-message. ENDLOOP.
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^