SAP ABAP Bom按层展开的几种实现方法

2023-10-12 18:48:47 浏览数 (1)

'SAP ABAP Bom按层展开的几种实现方法

代码语言:javascript复制
*递归的方式实现
FUNCTION zbomexplode.
* "--------------------------------------------------------- *"
* "Local Interface:
*"IMPORTING
* "REFERENCE(MATNR) TYPE MATNR
*"REFERENCE(WERKS) TYPE WERKS_D
* "TABLES
*"PARENT STRUCTURE SBOM
* "CHILDREN STRUCTURE SBOM
*"EXCEPTIONS
* " NO_BOM_FOUND *"----------------------------------------------------------
DATA: it_a TYPE TABLE OF sbom.
DATA: it_b TYPE TABLE OF sbom.
IF parent[] IS INITIAL.
* first time that call to the FM
SELECT stpo~idnrk INTO TABLE it_a
FROM mast INNER JOIN stpo
ON mast~stlnr = stpo~stlnr
WHERE mast~matnr = matnr
AND mast~werks = werks.
IF it_a[] IS INITIAL.
RAISE no_bom_found.
ENDIF.
ELSE.
SELECT stpo~idnrk INTO TABLE it_a
FROM mast
INNER JOIN stpo ON mast~stlnr = stpo~stlnr
FOR ALL ENTRIES IN parent
WHERE mast~matnr = parent-matnr
AND mast~werks = werks.
* if there is no any sub item, then stop the recursion IF it_a[] IS INITIAL.
EXIT .
ENDIF .
ENDIF .
APPEND LINES OF it_a TO children .
* get sub items recursively
CALL FUNCTION ' Z_BOM_EXPLODE '
EXPORTING
matnr = ''
werks = werks
TABLES
parent = it_a
children = it_b .
APPEND LINES OF it_b TO children .
* delete duplicate sub items at the end
IF parent [] IS INITIAL .
SORT children BY matnr .
DELETE ADJACENT DUPLICATES FROM children .
ENDIF .
ENDFUNCTION .
*使用循环代替递归的一种做法1,更便于做异常处理,程序运行时系统也不要维护递归堆栈。这个程序不好的地方在于要用两个 itab 频繁 copy 数据。
FUNCTION zbomexplode1 .
*"--------------------------------------------------------- *"
*" Local Interface :
*" IMPORTING
*" VALUE ( MATNR ) TYPE MATNR
*" VALUE ( WERKS ) TYPE WERKS_D *" TABLES
*" CHILDREN STRUCTURE SBOM *" EXCEPTIONS
*" NO_BOM_FOUND *"---------------------------------------------------------
DATA : it_a TYPE TABLE OF sbom ,
it_b TYPE TABLE OF sbom ,
it_result TYPE TABLE OF sbom .
SELECT stpo ~ idnrk
INTO TABLE it_a
FROM mast
INNER JOIN stpo ON mast ~ stlnr = stpo ~ stlnr
WHERE mast ~ matnr = matnr
AND mast ~ werks = werks .
APPEND LINES OF it_a TO it_result .
WHILE NOT it_a [] IS INITIAL .
SELECT stpo ~ idnrk
INTO TABLE it_b
FROM mast INNER JOIN stpo
ON mast ~ stlnr = stpo ~ stlnr
FOR ALL ENTRIES IN it_a
WHERE mast ~ matnr = it_a - matnr
AND mast ~ werks = werks .
APPEND LINES OF it_b TO it_result .
it_a [] = it_b [].
ENDWHILE .
* delete duplicate sub items
SORT it_result BY matnr .
DELETE ADJACENT DUPLICATES FROM it_result .
children [] = it_result [].
ENDFUNCTION .
FUNCTION zbomexplode2 .
*"---------------------------------------------------------- *"
*" Local Interface : *" IMPORTING
*" VALUE ( MATNR ) TYPE MATNR
*" VALUE ( WERKS ) TYPE WERKS_D
*" TABLES
*" CHILDREN STRUCTURE SBOM
*" EXCEPTIONS *" NO_BOM_FOUND
*"----------------------------------------------------------
DATA : it_result TYPE TABLE OF sbom ,
wa_bom TYPE sbom .
SELECT stpo ~ idnrk
INTO TABLE it_result
FROM mast INNER JOIN stpo
ON mast ~ stlnr = stpo ~ stlnr
WHERE mast ~ matnr = matnr
AND mast ~ werks = werks .
LOOP AT it_result INTO wa_bom .
SELECT stpo ~ idnrk
APPENDING TABLE it_result
FROM mast INNER JOIN stpo
ON mast ~ stlnr = stpo ~ stlnr
WHERE mast ~ matnr = wa_bom - matnr
AND mast ~ werks = werks .
ENDLOOP .
*& nbsp; delete duplicate  sub items
sort it_result by matnr.
delete adjacent duplicates from it_result.
children[] = it_result[].
ENDFUNCTION.
*调用BAPI实现
FUNCTION zbomexplode.
* "--------------------------------------------------------- *"
* "Local Interface: *" IMPORTING
* " VALUE(MATNR) LIKE MARA-MATNR
*" VALUE(WERKS) LIKE MARC-WERKS OPTIONAL
* " VALUE(CAPID) LIKE TC04-CAPID DEFAULT 'PP01'
*" TABLES
* " STB STRUCTURE STPOX
*" RETURN STRUCTURE BAPIRET2
* "---------------------------------------------------------
IF werks IS INITIAL."Added in case external call does not know
werks = '1000'.
ENDIF.
IF capid IS INITIAL.
capid = 'PP01'.
ENDIF.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = capid
datuv = sy-datum
mehrs = 'X'
mtnrv = matnr
werks = werks
TABLES
stb = stb
EXCEPTIONS
no_bom_found = 1.
IF sy-subrc & lt;& gt; 0.
msg_typ = 'E'.
msg_id = 'Z_EF'.
msg_no = '002'.
msg_v1 = matnr.
IF NOT msg_typ IS INITIAL.
* append error to table RETURN
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = msg_typ
cl = msg_id
number = msg_no
par1 = msg_v1
par2 = msg_v2
par3 = msg_v3
par4 = msg_v4
parameter = space
row = space
field = space
IMPORTING
return = wa_return_tmp.
APPEND wa_return_tmp TO return.
ENDIF.
ENDIF.
ENDFUNCTION
代码语言:javascript复制
REPORT  ztestian2.
 
 
TYPE-POOLS: slis.
TABLES: mast, "BOM 链接物料
mara, "常规物料数据
stko, "BOM 表头
makt. "物料描述
DATA: stb LIKE stpox OCCURS 0 WITH HEADER LINE,
wa_alv_field TYPE slis_fieldcat_alv, "列描述内表,列清单
wa_alv_fieldcat TYPE slis_t_fieldcat_alv, "定义内表
layout TYPE slis_layout_alv,
gs_layout TYPE slis_layout_alv,
gt_list_top_of_page TYPE slis_t_listheader,
counter TYPE i VALUE 0,
g_repid LIKE sy-repid,
dc(1) TYPE c VALUE 'X', "是否多层展开默为多层展开
g_user_command TYPE slis_formname VALUE 'USER_COMMAND'.
DATA: BEGIN OF selpool.
        INCLUDE STRUCTURE cstmat.
DATA: END OF selpool.
DATA: dstst_flg LIKE csdata-xfeld. "BOM 帮助字段
DATA: BEGIN OF it_data OCCURS 0,
level(20) TYPE c,
stufe LIKE stpox-stufe, "层次
matnr LIKE mara-matnr, "父件物料编码
ojtxb(80) TYPE c, "父件物料描述
bmeng TYPE i, "BOM 中的基本数量
idnrk LIKE stpox-idnrk, "子件物料编码
ojtxp(80) TYPE c, "子件物料描述
alprf LIKE stpo-alprf, "优先级
ewahr LIKE stpo-ewahr, "使用可能性
stlan LIKE stpox-stlan, "BOM 用途
stlal LIKE stpox-stlal, "可选的BOM
alpgr LIKE stpox-alpgr, "替代组
mtart LIKE stpox-mtart, "物料类型
mmein LIKE stpox-mmein, "基本计量单位
stprs LIKE stpox-stprs, "标准价格
mnglg LIKE stpox-mnglg, "以基本计量单位为准的已计算的组件数量
mngko LIKE stpox-mngko, "以组件计量单位为准的已计算的组件数量
menge LIKE stpox-menge, "组件数量
datuv LIKE stpox-datuv, "开始生效/有效截止日期
aennr LIKE stpox-aennr, "更改编号
andat LIKE stpox-andat, "日期记录创建于
annam LIKE stpox-annam, "创建记录的用户
ausch LIKE stpox-ausch, "工序报废
avoau LIKE stpox-avoau, "工序废品
ntgew LIKE mara-ntgew, "净重
brgew LIKE mara-brgew, "毛重
weigh LIKE mara-brgew, "重量 = BOM 用量 * 单重
stawn LIKE marc-stawn, "外贸的商品代码和进口代码
stawt(200) TYPE c, "海关编码描述
sel TYPE c,
END OF it_data.
DATA: BEGIN OF matcat OCCURS 50.
        INCLUDE STRUCTURE cscmat.
DATA: END OF matcat.
DATA: BEGIN OF mats.
        INCLUDE STRUCTURE cscmat.
DATA: END OF mats.
DATA: BEGIN OF dllh_data,
matnr LIKE mara-matnr, "物料编码
bmeng TYPE i, "BOM 中的基本数量
END OF dllh_data.
DATA: tdllh_data LIKE dllh_data OCCURS 0.
DATA: BEGIN OF wlxx_data,
matnr LIKE mara-matnr, "物料编码
normt LIKE mara-normt, "延伸机种,即机型
maktx(80) TYPE c, "物料描述
groes LIKE mara-groes, "描述补充
ntgew LIKE mara-ntgew, "净重
brgew LIKE mara-brgew, "毛重
stawn LIKE marc-stawn, "外贸的商品代码和进口代码
END OF wlxx_data.
DATA: twlxx_data LIKE wlxx_data OCCURS 0.
DATA: BEGIN OF hgbm_data,
stawn LIKE t604t-stawn, "外贸的商品代码和进口代码
text1(200) TYPE c, "描述
text2 LIKE t604t-text2, "描述
text3 LIKE t604t-text3, "描述
text4 LIKE t604t-text4, "描述
text5 LIKE t604t-text5, "描述
text6 LIKE t604t-text6, "描述
text7 LIKE t604t-text7, "描述
END OF hgbm_data.
DATA: thgbm_data LIKE hgbm_data OCCURS 0.
SELECTION-SCREEN BEGIN OF BLOCK scr1 WITH FRAME TITLE text-001.
PARAMETERS :
pm_werks LIKE marc-werks MEMORY ID wrk.
*SELECT-OPTIONS: S_WERKS FOR MAST-WERKS DEFAULT '2021'. "
**工厂
SELECT-OPTIONS: s_matnr FOR mara-matnr, "
*成品编码
s_mtart FOR mara-mtart, "
*物料类型
s_matkl FOR mara-matkl, "
*物料组
s_maktx FOR makt-maktx, "
*物料描述
s_normt FOR mara-normt. "
*机型
PARAMETERS: p_emeng LIKE stko-bmeng ,"OBLIGATORY DEFAULT '1', "Required quantity
p_stlan LIKE mast-stlan DEFAULT '1'. "BOM 用途
SELECTION-SCREEN SKIP 1.
PARAMETERS:rb_mcb RADIOBUTTON GROUP rg1 DEFAULT 'X', "多层展开
rb_scb RADIOBUTTON GROUP rg1. "单层展开
SELECTION-SCREEN SKIP 1.
PARAMETERS:rb_ytd RADIOBUTTON GROUP rg2 DEFAULT 'X', "有替代料
rb_wtd RADIOBUTTON GROUP rg2. "无替代料
SELECTION-SCREEN SKIP 1.
PARAMETERS:rb_all RADIOBUTTON GROUP rg3, "显示所有列
rb_hgy RADIOBUTTON GROUP rg3 DEFAULT 'X'. "仅显示海关专用列
SELECTION-SCREEN SKIP 1.
PARAMETERS:rb_ybc RADIOBUTTON GROUP rg4, "仅计算原材料重量
rb_wbc RADIOBUTTON GROUP rg4 DEFAULT 'X'. "计算所有物料重量
SELECTION-SCREEN END OF BLOCK scr1.
 
INITIALIZATION.
  g_repid = sy-repid.
 
START-OF-SELECTION.
  SELECT mara~matnr
  INTO CORRESPONDING FIELDS OF TABLE tdllh_data "取得物料编码内表
  FROM mara
  INNER JOIN makt ON mara~matnr = makt~matnr
  WHERE mara~matnr IN s_matnr AND mara~mtart IN s_mtart AND mara~normt
  IN s_normt AND makt~maktx IN s_maktx AND mara~matkl IN s_matkl AND makt~spras = sy-langu.
  SORT tdllh_data BY matnr.
  SELECT t604t~stawn t604t~text1 t604t~text2 t604t~text3 t604t~text4 t604t~text5 t604t~text6 t604t~text7
  INTO TABLE thgbm_data "取得海关编码及描述内表
  FROM t604t
  WHERE t604t~spras = sy-langu.
  SORT thgbm_data BY stawn.
  LOOP AT thgbm_data INTO hgbm_data.
    CONCATENATE hgbm_data-text1 hgbm_data-text2 hgbm_data-text3 hgbm_data-text4 hgbm_data-text5 hgbm_data-text6 hgbm_data-text7 INTO hgbm_data-text1.
    MODIFY thgbm_data FROM hgbm_data.
  ENDLOOP.
  IF rb_mcb = ''. "如果选择为单层展开则把原来的默认值由X 改为空
    dc = ''.
  ENDIF.
  CLEAR: dllh_data.
  LOOP AT tdllh_data INTO dllh_data. "循环每个物料号
    CLEAR: stb.
    CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
      EXPORTING
        capid                 = 'PP01' "BOM 应用程序
        datuv                 = sy-datum "有效起始日
        emeng                 = p_emeng " 基本数量 Required quantity STKO-BMENG
        mtnrv                 = dllh_data-matnr "成品号或半成品号
        stlan                 = '1' "BOM 用途,1 代表生产
        stlal                 = '' "可选BOM
        mktls                 = 'X'
        mehrs                 = dc "是否多层展开,'X' 代表多层
        rndkz                 = '1' "Round off: ' '=always, '1'=never, '2'=only levels > 1 是否取整
        werks                 = pm_werks "工厂
      IMPORTING
        topmat                = selpool "开始BOM 展开的物料显示
        dstst                 = dstst_flg "BOM 帮助字段
      TABLES
        stb                   = stb
        matcat                = matcat "下面含有组件的物料存放在该内表对应 STB-TTIDX 在类别表内的索引﹐标志直属哪个物料下的 BOM
      EXCEPTIONS
        alt_not_found         = 1
        call_invalid          = 2
        material_not_found    = 3
        missing_authorization = 4
        no_bom_found          = 5
        no_plant_data         = 6
        no_suitable_bom_found = 7
        OTHERS                = 8.
    LOOP AT stb.
      it_data-stufe = stb-stufe. "层次
      it_data-ojtxb = stb-ojtxb. "父件描述
      it_data-bmeng = selpool-bmeng.
      it_data-idnrk = stb-idnrk. "子件编码
      it_data-ojtxp = stb-ojtxp. "子件描述
      it_data-alprf = stb-alprf. "优先级
      it_data-ewahr = stb-ewahr. "使用可能性
      it_data-stlan = stb-stlan. "BOM 用途
      it_data-stlal = stb-stlal. "可选的BOM
      it_data-alpgr = stb-alpgr. "替代组
      it_data-mtart = stb-mtart. "物料类型
      it_data-mmein = stb-mmein. "基本计量单位
      it_data-stprs = stb-stprs. "标准价格
      it_data-mnglg = stb-mnglg. "以基本计量单位为准的已计算的组件数量
      it_data-mngko = stb-mngko. "以组件计量单位为准的已计算的组件数量
      it_data-menge = stb-menge. "组件数量
      it_data-ausch = stb-ausch. "工序报废
      it_data-avoau = stb-avoau. "工序废品
      it_data-datuv = stb-datuv. "生效日期
      it_data-stawn = stb-stawn. "外贸的商品代码和进口代码
      it_data-aennr = stb-aennr. "更改编号
      it_data-andat = stb-andat. "创建于
      it_data-annam = stb-annam. "创建者
      READ TABLE matcat INTO mats WITH KEY INDEX = stb-ttidx. " 根据STB-TTIDX 找MATCAT 中对应的 INDEX 可以得到其相对的上阶物料号
      it_data-matnr = mats-matnr. "相对的父件编码
      APPEND it_data.
    ENDLOOP.
  ENDLOOP.
*SORT IT_DATA BY MATNR STUFE ALPGR ALPRF IDNRK. "按成品号层 次 号 替 代组优先级 原料号排序
  IF rb_wtd = ''. "如果选择无替代料则把替代料删除
    DELETE it_data WHERE alpgr <> '' AND alprf <> '1'. "ALPGR 替代组 ALPRF 为优先组 1 为第一优先使用可性为 100 视为主料
  ENDIF.
  SELECT mara~matnr mara~normt makt~maktx mara~groes mara~ntgew mara~brgew marc~stawn
  INTO TABLE twlxx_data "取得物料信息
  FROM mara
  INNER JOIN makt ON mara~matnr = makt~matnr
  INNER JOIN marc ON mara~matnr = marc~matnr
  WHERE makt~spras = sy-langu AND marc~werks = '1000'.
  SORT twlxx_data BY matnr.
  LOOP AT it_data.
    CLEAR: wlxx_data,hgbm_data.
    READ TABLE twlxx_data INTO wlxx_data WITH KEY matnr = it_data-idnrk
    BINARY SEARCH.
    CONCATENATE wlxx_data-maktx wlxx_data-groes INTO wlxx_data-maktx.
    it_data-ojtxp = wlxx_data-maktx. "连接后的完全的组件物料描述
    it_data-ntgew = wlxx_data-ntgew.
    IF rb_wbc = 'X' AND it_data-mtart <> '805'.
      it_data-weigh = it_data-mngko * wlxx_data-ntgew.
    ENDIF.
    MODIFY it_data.
  ENDLOOP.
  LOOP AT it_data.
    CLEAR: wlxx_data,hgbm_data.
    READ TABLE twlxx_data INTO wlxx_data WITH KEY matnr = it_data-matnr
    BINARY SEARCH.
    CONCATENATE wlxx_data-maktx wlxx_data-groes INTO wlxx_data-maktx.
    it_data-ojtxb = wlxx_data-maktx. "连接后的完全的父件物料描述
    READ TABLE thgbm_data INTO hgbm_data WITH KEY stawn = it_data-stawn
    BINARY SEARCH.
    it_data-stawt = hgbm_data-text1. "根据海关编码得到相应的描述
    DATA : temp TYPE i.
    CLEAR :temp , it_data-level.
    temp = it_data-stufe.
    DO temp TIMES.
      CONCATENATE '.' it_data-level INTO it_data-level.
    ENDDO.
    DATA c(10) TYPE c.
    CLEAR c.
    c = it_data-stufe.
    CONCATENATE it_data-level c INTO it_data-level.
    CONDENSE it_data-level NO-GAPS.
    MODIFY it_data.
  ENDLOOP.
  PERFORM comment_build CHANGING gt_list_top_of_page[].
  PERFORM sub_fieldcat.
  PERFORM layout_init CHANGING gs_layout.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "调用ALV 显示表单数据
  EXPORTING
  i_callback_program = sy-repid
  i_callback_top_of_page = 'TOP_OF_PAGE'
  it_fieldcat = wa_alv_fieldcat
  is_layout = gs_layout
  i_callback_user_command = g_user_command
  TABLES
  t_outtab = it_data
  EXCEPTIONS
  program_error = 1
  OTHERS = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  SUB_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_fieldcat.
  PERFORM add_field USING 'LEVEL' '层次' 'C111' 'X'.
  PERFORM add_field USING 'MATNR' '父件编码' 'C111' 'X'.
  PERFORM add_field USING 'OJTXB' '父件描述' 'C111' 'X'.
  PERFORM add_field USING 'BMENG' '基本数量' 'C602' 'X'.
  PERFORM add_field USING 'IDNRK' '子件编码' 'C111' 'X'.
  PERFORM add_field USING 'OJTXP' '子件描述' 'C111' 'X'.
* PERFORM ADD_FIELD USING 'MNGLG' 'MNGLG' 'C111' 'X'.
  PERFORM add_field USING 'MNGKO' '用量' 'C111' 'X'.
  PERFORM add_field USING 'NTGEW' '单重' 'C111' 'X'.
  PERFORM add_field USING 'WEIGH' '重量' 'C111' 'X'.
  PERFORM add_field USING 'STAWN' '海关编码' 'C111' ''. "外贸的商品代码和进口代码显示前导 0
  PERFORM add_field USING 'STAWT' '描述' 'C111' 'X'. "外贸的商品代码和进口代码描述
  IF rb_all = 'X'.
    PERFORM add_field USING 'MENGE' '组件数量' 'C111' 'X'.
    PERFORM add_field USING 'MMEIN' '基本计量单位' 'C111' 'X'.
    PERFORM add_field USING 'ALPGR' '替代组' 'C111' ''.
    PERFORM add_field USING 'ALPRF' '优先级' 'C111' 'X'.
    PERFORM add_field USING 'EWAHR' '使用可能性' 'C111' 'X'.
    PERFORM add_field USING 'MTART' '物料类型' 'C111' 'X'.
    PERFORM add_field USING 'AVOAU' '工序废品' 'C111' 'X'.
    PERFORM add_field USING 'AUSCH' '工序报废' 'C111' 'X'.
    PERFORM add_field USING 'STLAN' 'BOM 用途' 'C111' 'X'.
    PERFORM add_field USING 'STLAL' '可选的BOM' 'C111' 'X'.
    PERFORM add_field USING 'DATUV' '生效日期' 'C111' 'X'.
    PERFORM add_field USING 'AENNR' '更改编号' 'C111' 'X'.
    PERFORM add_field USING 'ANDAT' '创建于' 'C111' 'X'.
    PERFORM add_field USING 'ANNAM' '创建者' 'C111' 'X'.
  ENDIF.
ENDFORM.                    "SUB_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  ADD_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_FIELDNAME  text
*      -->I_TEXT       text
*      -->I_NO         text
*      -->I_ZERO       text
*----------------------------------------------------------------------*
FORM add_field USING i_fieldname TYPE slis_fieldname i_text TYPE string i_no TYPE c i_zero TYPE c.
  CLEAR wa_alv_field.
  wa_alv_field-fieldname = i_fieldname.
  wa_alv_field-tabname = 'IT_DATA'.
  wa_alv_field-ddictxt = 'L'.
  wa_alv_field-no_zero = i_zero. "为空时显示前导0 为X 时不显示前导0
  wa_alv_field-seltext_l = i_text.
  IF wa_alv_field-fieldname = 'BMENG'.
    wa_alv_field-emphasize = 'C602'.
  ENDIF.
  IF wa_alv_field-fieldname = 'MNGKO'.
    wa_alv_field-emphasize = 'C510'.
  ENDIF.
  APPEND wa_alv_field TO wa_alv_fieldcat.
ENDFORM. "ADD_FIELD
*&---------------------------------------------------------------------*
*&      Form  LAYOUT_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RS_LAYOUT  text
*----------------------------------------------------------------------*
FORM layout_init CHANGING rs_layout TYPE slis_layout_alv.
  rs_layout-colwidth_optimize = 'X'.
  rs_layout-box_fieldname = 'SEL'.
  rs_layout-zebra = 'X'.
  rs_layout-detail_popup = 'X'.
ENDFORM. "LAYOUT_INIT
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = gt_list_top_of_page.
ENDFORM. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form  COMMENT_BUILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->LT_TOP_OF_PAGE  text
*----------------------------------------------------------------------*
FORM comment_build CHANGING lt_top_of_page TYPE slis_t_listheader.
  DATA ls_line TYPE slis_listheader.
  CLEAR ls_line.
  ls_line-typ = 'H'.
  ls_line-info = 'BOM 展开'.
  APPEND ls_line TO lt_top_of_page.
  CLEAR ls_line.
  ls_line-typ = 'S'.
  ls_line-key = '做成时间:'.
  ls_line-info = sy-datum.
  APPEND ls_line TO lt_top_of_page.
  ls_line-key = '做成者:'.
  ls_line-info = sy-uname.
  APPEND ls_line TO lt_top_of_page.
ENDFORM. "COMMENT_BUILD
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
  CASE r_ucomm.
    WHEN '&IC1'. " SAP STANDARD CODE FOR DOUBLE-CLICKING
      IF rs_selfield-sel_tab_field = 'IT_DATA-MATNR'.
        SET PARAMETER ID 'MAT' FIELD rs_selfield-value.
        CALL TRANSACTION 'CS03' AND SKIP FIRST SCREEN.
      ENDIF.
      IF rs_selfield-sel_tab_field = 'IT_DATA-IDNRK'.
        SET PARAMETER ID 'MAT' FIELD rs_selfield-value.
        CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
      ENDIF.
      IF rs_selfield-sel_tab_field = 'IT_DATA-MBLNR'.
        SET PARAMETER ID 'MBN' FIELD rs_selfield-value.
        CALL TRANSACTION 'MB51' AND SKIP FIRST SCREEN.
      ENDIF.
  ENDCASE.
ENDFORM.                    "USER_COMMAND

0 人点赞