背景:对于按单生产业务,销售通常会将客户的一些特殊需求备注到销售订单长文本,而这些长文本中经常会有一些客户对生产的要求,如果一个个订单将这些备注复制到生产订单又太麻烦,有没有办法将销售订单的文本直接代入到生产订单文本。
思路:业务背景是按单生产(当然按库也不会有这种需求),那么在系统层面生产订单和销售订单是有关联关系的,那是不是可以在创建生产订单时,根据生产订单表里的销售订单号用函数读取长文本,然后写入生产订单的长文本里面?
如是就找到下面这篇文章(作者给力,直接代码),大概逻辑是在生产订单保存的增强里将销售订单的长文本读取出来然后写入。
PP生产订单的BADI增强 WORKORDER_UPDATE
METHOD if_ex_workorder_update~before_update.
*---------------------->增强1 开始
* "当生产订单类型为PP01时,如果该生产订单有参考相关的销售订单,
* "那么在此生产订单存盘时,就需要判断该生产订单是否已经维护了相关的长文本数据,如果没有长文本数据,就需要查看
* "所对应的销售订单行项目上是否有长文本数据,如果有则将销售订单行项目的长文本带到该生产订单长文本中。
* "反之,如果此生产订单已经维护有相关的长文本数据,则不需要再去考虑销售订单行项目中的长文本
FIELD-SYMBOLS: <f1> TYPE cobai_t_header,
<f2> TYPE LINE OF cobai_t_header.
DATA v_program(50) TYPE c VALUE ‘(SAPLCOBT)CAUFV_BT[]‘.
DATA: wa_header TYPE LINE OF cobai_t_header,
v_flag.
DATA: v_tdname TYPE thead-tdname,
lt_lines TYPE STANDARD TABLE OF tline,
lt_lines0 TYPE STANDARD TABLE OF tline,
lt_lines1 TYPE STANDARD TABLE OF tline,
lt_lines2 TYPE STANDARD TABLE OF tline,
lt_lines3 TYPE STANDARD TABLE OF tline,
ls_line TYPE tline,
ls_line1 TYPE tline.
CLEAR: v_tdname, lt_lines0, lt_lines1, lt_lines2, lt_lines3,
lt_lines, ls_line, ls_line1.
CASE sy-tcode.
WHEN ‘CO40‘ OR ‘CO08‘ OR ‘CO01‘ OR ‘CO41‘.
READ TABLE it_header INTO wa_header INDEX 1.
"AUART订单类型、LTEXT长文本标识、KDAUF_AUFK参考销售订单号、KDPOS_AUFK参考销售订单行项目号
IF wa_header-auart EQ ‘PP01‘ AND wa_header-ltext EQ space AND wa_header-kdauf_aufk IS NOT INITIAL
AND wa_header-kdpos_aufk IS NOT INITIAL.
CONCATENATE wa_header-kdauf_aufk wa_header-kdpos_aufk INTO v_tdname. "销售订单行项目长文本的Name
"读取参考的销售订单行项目长文本
CALL FUNCTION ‘READ_TEXT‘
EXPORTING
id = ‘Z002‘
language = sy-langu
name = v_tdname
object = ‘VBBP‘
TABLES
lines = lt_lines0
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
v_tdname = wa_header-kdauf_aufk.
"读取参考的销售订单行项目长文本
CALL FUNCTION ‘READ_TEXT‘
EXPORTING
id = ‘ZV06‘
language = sy-langu
name = v_tdname
object = ‘VBBK‘
TABLES
lines = lt_lines1
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
CONCATENATE wa_header-kdauf_aufk wa_header-kdpos_aufk INTO v_tdname. "销售订单行项目长文本的Name
"读取参考的销售订单行项目长文本
CALL FUNCTION ‘READ_TEXT‘
EXPORTING
id = ‘Z001‘
language = sy-langu
name = v_tdname
object = ‘VBBP‘
TABLES
lines = lt_lines2
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
* CONCATENATE wa_header-kdauf_aufk wa_header-kdpos_aufk INTO v_tdname. "销售订单行项目长文本的Name
* "读取参考的销售订单行项目长文本
* CALL FUNCTION ‘READ_TEXT‘
* EXPORTING
* id = ‘Z002‘
* language = sy-langu
* name = v_tdname
* object = ‘VBBP‘
* TABLES
* lines = lt_lines3
* EXCEPTIONS
* id = 1
* language = 2
* name = 3
* not_found = 4
* object = 5
* reference_check = 6
* wrong_access_to_archive = 7
* OTHERS = 8.
ls_line1-tdline = ‘行项目备注:‘.
INSERT ls_line1 INTO lt_lines0 INDEX 1.
ls_line1-tdline = ‘此单特殊要求:‘.
INSERT ls_line1 INTO lt_lines1 INDEX 1.
ls_line1-tdline = ‘开模信息:‘.
INSERT ls_line1 INTO lt_lines2 INDEX 1.
*
* ls_line1-tdline = ‘行项目备注:‘.
* INSERT ls_line1 INTO lt_lines3 INDEX 1.
LOOP AT lt_lines0 INTO ls_line.
APPEND ls_line TO lt_lines.
ENDLOOP.
LOOP AT lt_lines1 INTO ls_line.
APPEND ls_line TO lt_lines.
ENDLOOP.
LOOP AT lt_lines2 INTO ls_line.
APPEND ls_line TO lt_lines.
ENDLOOP.
* LOOP AT lt_lines3 INTO ls_line.
* APPEND ls_line TO lt_lines.
* ENDLOOP.
IF lt_lines IS NOT INITIAL.
CONCATENATE sy-mandt wa_header-aufnr INTO v_tdname."生产订单行项目长文本的Name
CALL FUNCTION ‘CREATE_TEXT‘
EXPORTING
fid = ‘KOPF‘
flanguage = sy-langu
fname = v_tdname
fobject = ‘AUFK‘
TABLES
flines = lt_lines
EXCEPTIONS
no_init = 1
no_save = 2
OTHERS = 3.
IF sy-subrc = 0.
ASSIGN (v_program) TO <f1>.
READ TABLE <f1> ASSIGNING <f2> INDEX 1.
<f2>-ltext = ‘1‘.
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
*--------------------------->增强1结束
ENDMETHOD. "if_ex_workorder_update~before_update
PP生产订单的BADI增强 WORKORDER_UPDATE
网友评论