*& Report ZY_MARC_001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zy_marc_001.
TABLES: marc, mara, makt, cabn.
*&---------------------------------------------------------------------*
* ALV相关变量
*&---------------------------------------------------------------------*
TYPE-POOLS: slis, ibco2.
DATA:gs_layout TYPE slis_layout_alv,
g_repid TYPE sy-repid VALUE 'SY-REPID',
it_field TYPE slis_t_fieldcat_alv,
wa_field TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
* 宏定义
*&---------------------------------------------------------------------*
DEFINE add_field.
clear wa_field.
wa_field-fieldname = &1.
wa_field-seltext_s = &2.
append wa_field to it_field.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
* 宏调用
*&---------------------------------------------------------------------*
add_field 'MATNR' '物料编号'.
add_field 'MAKTX' '物料描述' .
add_field 'STDPD' '可配置物料编号' .
add_field 'WERKS' '生产工厂' .
add_field 'CHARACTDESCR' '特性描述'.
add_field 'CHARACTVALUESDESCR' '特性值'.
DATA: BEGIN OF ITAB_OUT OCCURS 0,
matnr TYPE marc-matnr,
maktx TYPE makt-maktx,
stdpd TYPE marc-stdpd,
werks TYPE marc-werks,
CHARACTDESCR TYPE STRING,
CHARACTVALUESDESCR TYPE STRING,
END OF ITAB_OUT.
DATA: BEGIN OF GT_TAB OCCURS 0,
matnr TYPE marc-matnr,
maktx TYPE makt-maktx,
werks TYPE marc-werks,
cuobj TYPE marc-cuobj,
stdpd TYPE marc-stdpd,
END OF GT_TAB.
DATA:BEGIN OF it_characteristic OCCURS 0,
matnr TYPE marc-matnr,
CHARACTDESCR TYPE STRING,
CHARACTVALUESDESCR TYPE STRING,
END OF it_characteristic.
DATA WA_CHAR LIKE LINE OF it_characteristic.
DATA: BEGIN OF CUOBJTAB OCCURS 0,
pr_cuobj TYPE marc-cuobj,
END OF CUOBJTAB.
DATA: pt_characteristic LIKE STANDARD TABLE OF it_characteristic.
SELECT-OPTIONS s_matkl FOR mara-matkl.
SELECT-OPTIONS s_matnr FOR marc-matnr.
SELECT-OPTIONS s_werks FOR marc-werks.
START-OF-SELECTION.
PERFORM getdata.
PERFORM DISPLAYLIST_ALV.
*&---------------------------------------------------------------------*
*& Form frm_get_characteristic
*&---------------------------------------------------------------------*
* text:得到一张内表,包括物料号,特征值,特征描述
*----------------------------------------------------------------------*
FORM frm_get_characteristic TABLES pt_characteristic STRUCTURE it_characteristic
USING pr_matnr pr_cuobj.
DATA:
it_value TYPE ibco2_instance_tab2,
wa_value LIKE LINE OF it_value,
wa_values LIKE LINE OF wa_value-values OCCURS 1 WITH HEADER LINE .
DATA:LT_RETURN TYPE TABLE OF BAPIRET2,
LT_CHARACT TYPE TABLE OF BAPICHARACTVALUESDESCR,
LS_CHARACT TYPE BAPICHARACTVALUESDESCR,
LT_BAPICHARACT TYPE TABLE OF BAPICHARACTDESCR WITH HEADER LINE.
*
DATA: CATNAM TYPE cabn-atnam.
CALL FUNCTION 'CE_C_GET_CBASE'
EXPORTING
instance = pr_cuobj
IMPORTING
configuration = it_value
EXCEPTIONS
internal_error = 1
instance_is_a_classification = 2
OTHERS = 3.
CHECK sy-subrc EQ 0.
READ TABLE it_value INTO wa_value INDEX 1.
LOOP AT wa_value-values INTO wa_values.
MOVE:pr_matnr TO pt_characteristic-matnr.
** 取得特性名称
SELECT SINGLE atnam
FROM cabn
INTO CATNAM
WHERE atinn EQ wa_values-atinn.
REFRESH:lt_charact,lt_return.
CALL FUNCTION 'BAPI_CHARACT_GETDETAIL'
EXPORTING
charactname = CATNAM
language = sy-langu
TABLES
CHARACTDESCR = LT_BAPICHARACT"特征值的表
charactvaluesdescr = LT_CHARACT[]"特征描述的表
return = lt_return.
IF LT_CHARACT IS NOT INITIAL.
LOOP AT LT_CHARACT INTO LS_CHARACT.
IF LS_CHARACT-VALUE_CHAR EQ wa_values-ATWRT.
pt_characteristic-CHARACTVALUESDESCR = LS_CHARACT-DESCRIPTION.
ENDIF.
ENDLOOP.
ELSE.
pt_characteristic-CHARACTVALUESDESCR = wa_values-ATWRT.
ENDIF.
LOOP AT LT_BAPICHARACT.
pt_characteristic-CHARACTDESCR = LT_BAPICHARACT-DESCRIPTION.
ENDLOOP.
APPEND pt_characteristic.
CLEAR pt_characteristic.
ENDLOOP.
ENDFORM. "frm_get_characteristic
*&---------------------------------------------------------------------*
*& Form DISPLAYLIST_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAYLIST_ALV.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IT_FIELDCAT = IT_FIELD
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
TABLES
T_OUTTAB = ITAB_OUT. "输出的内表
ENDFORM. "displaylist_alv
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM getdata.
* 根据输入条件将物料编号、物料描述、可配置物料号、生产工厂,cuibj存入内表GT_TAB
SELECT c~matnr b~maktx c~stdpd c~werks c~cuobj
INTO CORRESPONDING FIELDS OF TABLE GT_TAB
FROM mara AS a INNER JOIN makt AS b ON a~matnr = b~matnr
INNER JOIN marc AS c ON a~matnr = c~matnr
WHERE c~matnr in s_matnr AND a~matkl IN s_matkl AND c~werks IN s_werks AND b~spras = 1 AND c~cuobj <> 0.
*将所有输出信息包括特征值和特征描述存入内表ITAB_OUT
LOOP AT GT_TAB.
REFRESH pt_characteristic.
*根据可配置的物料获取其特征值和特征描述存入内表pt_characteristic
PERFORM frm_get_characteristic TABLES pt_characteristic USING GT_TAB-MATNR GT_TAB-CUOBJ.
LOOP AT pt_characteristic INTO WA_CHAR.
MOVE:WA_CHAR-MATNR TO ITAB_OUT-MATNR,
WA_CHAR-CHARACTDESCR TO ITAB_OUT-CHARACTDESCR,
WA_CHAR-CHARACTVALUESDESCR TO ITAB_OUT-CHARACTVALUESDESCR.
ITAB_OUT-WERKS = GT_TAB-WERKS.
ITAB_OUT-STDPD = GT_TAB-STDPD.
ITAB_OUT-MAKTX = GT_TAB-MAKTX.
APPEND ITAB_OUT.
ENDLOOP.
ENDLOOP.
ENDFORM. "GETDATA