启用可配置物料之后,每次创建新的物料需要通过CU41创建可配置物料,没找大批量创建的程序,所以SHDB录屏搞了一个代码。
前提:物料主数据初始化通过程序导入时,可配置物料参数文件已按照物料代码赋值。
效果:
源代码:
*&---------------------------------------------------------------------*
*& Report ZCU41
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zcu41
NO STANDARD PAGE HEADING LINE-SIZE 255.
TABLES: sscrfields.
TABLES:mara,mseg.
TYPE-POOLS: icon, slis.
*-------- ALV structures
DATA: wa_fieldcat TYPE slis_fieldcat_alv,
it_fieldcat TYPE slis_t_fieldcat_alv,
g_layout TYPE slis_layout_alv,
g_title TYPE lvc_title,
pos TYPE i,
l_field TYPE slis_fieldcat_alv, "字段列结构
l_fieldcat TYPE slis_t_fieldcat_alv, "字段列内表
l_status_01 TYPE slis_formname VALUE 'L_STATUS_01'.
DATA : BEGIN OF itab_data OCCURS 0,
icon TYPE icon_d,
type(1),
sel(1),
matnr TYPE marc-matnr, "物料代码
maktx TYPE makt-maktx,
message(200),
END OF itab_data.
DATA:itab_bdctab TYPE TABLE OF bdcdata WITH HEADER LINE.
DATA:p_mode TYPE char1 VALUE 'N',
p_upda TYPE char1 VALUE 'L'.
DATA lv_mess TYPE string.
DATA BEGIN OF messtab OCCURS 10.
INCLUDE STRUCTURE bdcmsgcoll.
DATA END OF messtab.
DEFINE add_col.
CLEAR wa_fieldcat.
ADD 1 TO pos.
wa_fieldcat-col_pos = pos.
wa_fieldcat-fieldname = &1.
wa_fieldcat-ref_fieldname = &2.
wa_fieldcat-ref_tabname = &3.
wa_fieldcat-seltext_m = &4.
wa_fieldcat-tabname = &5.
wa_fieldcat-do_sum = &6.
wa_fieldcat-edit_mask = &7.
wa_fieldcat-hotspot = &8.
wa_fieldcat-checkbox = &9.
APPEND wa_fieldcat TO it_fieldcat.
END-OF-DEFINITION.
START-OF-SELECTION.
PERFORM frm_get_data.
PERFORM frm_display_data.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM frm_display_data .
REFRESH: it_fieldcat.
CLEAR g_layout.
add_col 'ICON' space space '状态' 'ITAB_DATA' space space space space.
add_col 'SEL' space space '选择' 'ITAB_DATA' space space 'X' 'X'.
add_col 'MATNR' space space '物料代码' 'ITAB_DATA' space '==ALPHA' space space.
add_col 'MAKTX' space space '物料描述' 'ITAB_DATA' space space space space.
add_col 'MESSAGE' space space '处理消息' 'ITAB_DATA' space space space space.
g_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'L_STATUS100'
i_callback_user_command = 'FRM_USER_COMMAND'
is_layout = g_layout
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab_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.
ENDFORM.
FORM l_status100 USING extab TYPE slis_t_extab.
SET PF-STATUS 'ST01'.
ENDFORM. "L_STATUS100
*&---------------------------------------------------------------------*
*& Form frm_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
DATA: ref TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref.
CALL METHOD ref->check_changed_data.
CASE r_ucomm.
WHEN '&IC1'.
IF rs_selfield-fieldname = 'SEL'.
READ TABLE itab_data INDEX rs_selfield-tabindex.
IF itab_data-sel = ''.
itab_data-sel = 'X'.
ELSE.
itab_data-sel = ''.
ENDIF.
MODIFY itab_data INDEX rs_selfield-tabindex.
CLEAR itab_data.
ENDIF.
WHEN 'ALL'.
itab_data-sel = 'X'.
MODIFY itab_data FROM itab_data TRANSPORTING sel WHERE sel = '' .
WHEN 'SAL'.
itab_data-sel = ''.
MODIFY itab_data FROM itab_data TRANSPORTING sel WHERE sel = 'X' .
WHEN 'IMP'.
PERFORM frm_excute.
ENDCASE.
rs_selfield-refresh = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM bdc_dynpro USING name value.
CLEAR itab_bdctab.
itab_bdctab-program = name.
itab_bdctab-dynpro = value.
itab_bdctab-dynbegin = 'X'.
APPEND itab_bdctab.
ENDFORM. "BDC_DYNPRO
*&---------------------------------------------------------------------*
*& FORM BDC_FIELD
*&---------------------------------------------------------------------*
FORM bdc_field USING name value.
CLEAR itab_bdctab.
itab_bdctab-fnam = name.
itab_bdctab-fval = value.
APPEND itab_bdctab.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form frm_excute
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_excute .
LOOP AT itab_data INTO DATA(lw_data) WHERE sel = 'X' AND type NE 'S'.
REFRESH:itab_bdctab,itab_bdctab[],messtab,messtab[].
PERFORM bdc_dynpro USING 'SAPLCUCO' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RCUCO-DATUM'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RCUCO-MATNR'
lw_data-matnr."物料代码
PERFORM bdc_field USING 'RCUCO-DATUM'
'20230101'."日期,默认20230101
PERFORM bdc_dynpro USING 'SAPLCUCO' '0200'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RCUCO-KLART(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RCUCO-PRFID(01)'
lw_data-matnr."参数名,默认物料代码
PERFORM bdc_field USING 'RCUCO-KLART(01)'
'300'."固定值300
PERFORM bdc_dynpro USING 'SAPLCUCO' '0200'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
CALL TRANSACTION 'CU41' USING itab_bdctab
MODE p_mode
UPDATE p_upda
MESSAGES INTO messtab.
READ TABLE messtab WITH KEY msgtyp = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = messtab-msgid
lang = '1'
no = messtab-msgnr
v1 = messtab-msgv1
v2 = messtab-msgv2
v3 = messtab-msgv3
v4 = messtab-msgv4
IMPORTING
msg = lv_mess
EXCEPTIONS
not_found = 1
OTHERS = 2.
lw_data-message = lv_mess.
lw_data-type = 'E'.
lw_data-icon = icon_red_light.
ELSE.
lw_data-message = '创建成功'.
lw_data-type = 'S'.
lw_data-icon = icon_green_light.
ENDIF.
MODIFY itab_data FROM lw_data TRANSPORTING message type icon WHERE matnr = lw_data-matnr AND SEL = 'X' AND type NE 'S'.
CLEAR lw_data.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data .
SELECT mara~matnr,makt~maktx
INTO CORRESPONDING FIELDS OF TABLE @itab_data
FROM mara INNER JOIN makt ON mara~matnr = makt~matnr AND makt~spras = '1'
WHERE mara~kzkfg = 'X'.
LOOP AT itab_data.
SELECT SINGLE objek
FROM cuco
INTO @DATA(lv_objek)
WHERE objek = @itab_data-matnr.
IF sy-subrc = 0.
DELETE itab_data.
ENDIF.
ENDLOOP.
ENDFORM.