首页 > 其他分享 >SAP ABAP BOM组件展开BAPI

SAP ABAP BOM组件展开BAPI

时间:2024-09-03 14:26:03浏览次数:9  
标签:BAPI matnr mat TYPE ABAP ls bom data BOM

TYPE-POOLS slis.


TABLES: marc.

TYPES: BEGIN OF ty_data,
matnr TYPE matnr, "母件
stufe TYPE histu, "阶层
idnrk TYPE idnrk, "子件
END OF ty_data,
BEGIN OF ty_marc,
matnr TYPE matnr, "物料
beskz TYPE beskz, "采购类型
sobsl TYPE sobsl, "特殊采购类型
END OF ty_marc,
BEGIN OF ty_stko,
matnr TYPE matnr, "物料
stlan TYPE stlan, "BOM用途
stlal TYPE stlal, "备选
bmeng TYPE basmn, "基础数量
END OF ty_stko,
BEGIN OF ty_bom_mat,
matnr TYPE matnr,
stufe TYPE histu,
END OF ty_bom_mat.

DATA: gt_data TYPE TABLE OF ty_data,
gt_stko TYPE TABLE OF ty_stko.

DATA: gs_layout TYPE lvc_s_layo, "布局
gt_fieldcat TYPE lvc_t_fcat. "字段

 

PARAMETERS: p_werks LIKE marc-werks DEFAULT 'C100' OBLIGATORY.

SELECT-OPTIONS: s_matnr FOR marc-matnr.


INITIALIZATION.


AT SELECTION-SCREEN.


AT SELECTION-SCREEN OUTPUT.


TOP-OF-PAGE.

END-OF-PAGE.

START-OF-SELECTION.

"获取数据
PERFORM frm_get_data.
"显示数据
PERFORM frm_display_data.

END-OF-SELECTION.

FORM frm_get_data .

DATA: lt_mat TYPE TABLE OF ty_marc,
lt_marc TYPE TABLE OF ty_marc,
lt_bom_mat TYPE TABLE OF ty_bom_mat,
lt_stpox TYPE TABLE OF stpox,
ls_data TYPE ty_data,
ls_mat TYPE ty_marc,
ls_marc TYPE ty_marc,
ls_bom_mat TYPE ty_bom_mat,
ls_stpox TYPE stpox.

DATA: lv_lev TYPE histu VALUE 0.

"工厂数据
SELECT matnr beskz sobsl INTO TABLE lt_marc
FROM marc
WHERE werks = p_werks
AND lvorm = ''.

"需要展BOM的料号
SELECT matnr beskz sobsl INTO TABLE lt_mat
FROM marc
WHERE werks = p_werks
AND lvorm = ''
AND matnr IN s_matnr.

"需要展BOM的料号的BOM单头
SELECT mast~matnr mast~stlan mast~stlal stko~bmeng
INTO TABLE gt_stko
FROM mast
INNER JOIN stko ON mast~stlnr = stko~stlnr
AND mast~stlal = stko~stlal
WHERE mast~werks = p_werks
AND mast~stlan = '1'
AND stko~loekz = ''
AND stko~lkenz = ''.

SORT: lt_marc BY matnr,
gt_stko BY matnr.

LOOP AT lt_mat INTO ls_mat.

READ TABLE lt_marc INTO ls_marc WITH KEY
matnr = ls_mat-matnr
BINARY SEARCH.
IF sy-subrc = 0.

"委外件(分包)和自制件展开下阶BOM
IF ls_marc-beskz = 'E' OR ( ls_marc-beskz = 'F' AND ls_marc-sobsl = '30' ).

CLEAR: lt_bom_mat.

ls_bom_mat-matnr = ls_mat-matnr.
ls_bom_mat-stufe = 0.
APPEND ls_bom_mat TO lt_bom_mat.
CLEAR ls_bom_mat.

LOOP AT lt_bom_mat INTO ls_bom_mat.

lv_lev = ls_bom_mat-stufe.

CLEAR lt_stpox.

PERFORM frm_get_bom TABLES lt_stpox USING ls_bom_mat-matnr.

"剔除原材料和废料
DELETE lt_stpox WHERE idnrk+0(2) = 'MT'.

IF lt_stpox IS INITIAL.
"如果无BOM或者BOM下只有原材料或废料,则为最低阶非原材料零件
ls_data-matnr = ls_mat-matnr.
ls_data-idnrk = ls_bom_mat-matnr.
ls_data-stufe = ls_bom_mat-stufe.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ELSE.

lv_lev = ls_bom_mat-stufe + 1.

LOOP AT lt_stpox INTO ls_stpox.

CLEAR ls_marc.

"删除替代料
IF ls_stpox-alpgr NE '' AND ls_stpox-ewahr IS INITIAL.
CONTINUE.
ENDIF.

READ TABLE lt_marc INTO ls_marc WITH KEY
matnr = ls_stpox-idnrk
BINARY SEARCH.
IF ls_marc-beskz = 'E' OR ( ls_marc-beskz = 'F' AND ls_marc-sobsl = '30' ).

"如果是委外件(分包)和自制件展开下阶BOM,则加入展BOM清单继续往下展开
ls_bom_mat-matnr = ls_stpox-idnrk.
ls_bom_mat-stufe = lv_lev.
APPEND ls_bom_mat TO lt_bom_mat.
CLEAR ls_bom_mat.

ELSE.
"如果是直接外购件,则为最低阶非原材料零件
ls_data-matnr = ls_mat-matnr.
ls_data-idnrk = ls_stpox-idnrk.
ls_data-stufe = lv_lev.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ENDIF.

ENDLOOP.

ENDIF.
ENDLOOP.

ELSE.
ls_data-matnr = ls_data-idnrk = ls_mat-matnr.
ls_data-stufe = 0.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ENDIF.

ELSE.
ls_data-matnr = ls_data-idnrk = ls_mat-matnr.
ls_data-stufe = 0.
APPEND ls_data TO gt_data.
CLEAR ls_data.
ENDIF.

ENDLOOP.
ENDFORM.


FORM frm_display_data .

"栏位最适宽度
gs_layout-cwidth_opt = 'X'.

"ALV条纹
gs_layout-zebra = 'X'.

"构建ALV的栏位
PERFORM frm_create_field.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid "当前程序名
is_layout_lvc = gs_layout "Layout
it_fieldcat_lvc = gt_fieldcat "Fieldcat
i_save = 'A'
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.

FORM frm_create_field .

DATA: ls_fieldcat TYPE lvc_s_fcat,
lv_count TYPE i.

DEFINE fieldcat.
ADD 1 TO lv_count.

"栏位显示顺序
ls_fieldcat-col_pos = lv_count.
"内表栏位
ls_fieldcat-fieldname = &1.
"参考栏位
ls_fieldcat-ref_field = &2.
"参考表
ls_fieldcat-ref_table = &3.
"单位
ls_fieldcat-qfieldname = &4.
"栏位标题(长文或中等文或短文)
ls_fieldcat-scrtext_s = ls_fieldcat-scrtext_m =
ls_fieldcat-scrtext_l = &5.
"显示长文或中等文或短文
ls_fieldcat-colddictxt = &6.

APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
END-OF-DEFINITION.

fieldcat 'MATNR' 'MATNR' 'MARC' '' '' ''.
fieldcat 'STUFE' '' '' '' '阶层' 'L'.
fieldcat 'IDNRK' 'IDNRK' 'STPO' '' '' ''.

ENDFORM.

FORM frm_get_bom TABLES et_stpox STRUCTURE stpox
USING iv_matnr.

DATA: ls_stko TYPE ty_stko.

READ TABLE gt_stko INTO ls_stko WITH KEY
matnr = iv_matnr
BINARY SEARCH.

IF sy-subrc = 0.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = 'PP01' "生产BOM
datuv = sy-datum
emeng = ls_stko-bmeng "用量
* mdmps = 'X' " 展开虚拟件
* mehrs = 'X' " 多阶
mmory = '0'
mtnrv = ls_stko-matnr
stlal = ls_stko-stlal
stlan = ls_stko-stlan
werks = p_werks
TABLES
stb = et_stpox
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
conversion_error = 8
OTHERS = 9.
ENDIF.

* STUFE为阶层, MNGLG为根据展BOM的用量计算出各个下阶的用量
ENDFORM.

标签:BAPI,matnr,mat,TYPE,ABAP,ls,bom,data,BOM
From: https://www.cnblogs.com/zsy1/p/18077132

相关文章

  • .Net 5.0 WebAPI 发布至 Linux 系统
    阅读目录〇、前言一、Linux环境准备1.1CentOS7.x在线安装.net5.01.2CentOS8.x在线安装.net5.01.3查看是否安装成功二、示例项目创建和发布2.1创建一个测试项目2.2发布步骤三、服务开启和配置自启动3.1服务开启3.2将服务配置为系统自启动......
  • .Net 5.0 WebAPI 发布至 CentOS 7 系统
    〇、前言本文主要介绍了在CentOS7上部署WebAPI项目的过程。先安装.net5.0的环境,再创建一个示例项目并发布至CentOS上,同时列明了一些注意的点;最后将dotnet命令添加到系统自启动服务。一、Linux环境准备1.1centos7.x在线安装.net5.0第一行命令是添加包源,第二......
  • webapi 获取参数值的几种方式
    [FromRoute(Name="名字")],捕捉的值会被自动赋值给Action中同名的参数;如果名字不一致,可以用[FromRoute(Name="名字")][FromQuery]来获取QueryString中的值。如果名字一致,只要为参数添加[FromQuery]即可;而如果名字不一致,[FromQuery(Name=名字)][FromForm]从Content-Type为mult......
  • ASP.NET WebApi + Autofac 实现依赖注入
    方法11.1、项目情况框架:.NETFramework4.5Autofac3.5.0Autofac.WebApi24.3.0 1.2、定义接口与对应实现//接口1publicinterfaceIBaseUserService{List<BaseUser>GetBaseUserList();}//接口2publicinterfaceIBaseCloseLoopService{List<BaseCloseLoop>GetBase......
  • .NET Core 处理 WebAPI JSON 返回烦人的null为空
    前言   项目开发中不管是前台还是后台都会遇到烦人的null,数据库表中字段允许空值,则代码实体类中对应的字段类型为可空类型Nullable<>,如int?,DateTime?,null值字段序列化返回的值都为null,前台对应字段赋值需要做null值判断,怎么才能全局把null替换为空。    本文分享Web......
  • Altium Designer如何生成BOM表
    如何使用AD20导出BOM表:1.打卡AltiumDesigner20软件,在原理图界面,点击报告(Reports)→BillofMaterials(材料清单);界面就变成了这样2.点击右侧的Columns(专栏),在右下角勾选要导出的属性,选择所需要的BOM表表头,如下图;3.参数和表头设置好以后,就可导出BOM表,点击Export(导出......
  • CF1996F Bomb
    前言大概是一个经典题,只不过比较难想思路首先考虑\(O(k)\)的做法,很明显,每次我们可以选取一个最大值,然后在把他放回优先队列里面,只不过这样不足以通过此题而我们又发现只要我们知道最后一次选取的数(第\(k\)大)是多少,则前面的数全都可以知道(即对于每个\(a_i\),看比这个数大......
  • 根据销售订单创建交货单(BAPI_DELIVERYPROCESSING_EXEC)
    可以指定对应的仓库和销售订单创建交货单 创建交货单:BAPI_DELIVERYPROCESSING_EXEC交货单过账:WS_DELIVERY_UPDATE 创建交货单:functionZTEST1.*"----------------------------------------------------------------------*"*"本地接口:*"IMPORTING*"VALUE(IV_W......
  • 浏览器对象模型 BOM和文档对象模型DOM
    DOM(文档对象模型,DocumentObjectModel)是一个平台和语言无关的接口,它提供了一种结构化的方法来表示和操作HTML和XML文档。通过DOM,文档被表示为一个树状结构,文档的每个部分都可以作为一个对象进行访问和操作。一DOM的基本概念节点(Node):DOM树由各种节点组成,每个节......
  • Bomb(数位DP)
    题目描述Thecounter-terroristsfoundatimebombinthedust.Butthistimetheterroristsimproveonthetimebomb.Thenumbersequenceofthetimebombcountsfrom1toN.Ifthecurrentnumbersequenceincludesthesub-sequence"49",thepowero......