之前用MMRV,MMPV来一次一个月来修改会计期间。
如果是老的测试机,可能是10几年前的,一次1个月,更新到当前期间,搞个100多次,手都抖。
SAP MM学习笔记 - 错误 M7053 - Posting only possible in periods 2010/08 and 2010/07 in company code 1000_sap m7053-CSDN博客
所以就想找那种可以一次搞定的方法,下面来看一下。
TODO:最终也没搞成,先放这里,给朋友们参考下,以后有空再说
1,MMRV - 查看当前会计期间
比如这里是 2009/11
2,OMSY - 初期化会计年月
修改前:2009/11
啊,出错了
会社Code 3000 无法初期化。
Msg 番号 MM011
看来也不是随便能改的哈
我在另一个会社Code上更新是可以更新的。
OMSY and OB52 - SAP Community
这个帖子里大致说了OMSY,MMPV/MMRV,OB52 的用途:
- OMSY - 初期化某个公司代码的会计期间,只能用一次
OMSY to fix up the Initial Period and Year for a company code for material management .
After setting you should touch this setting & used only once.
- MMPV / MMRV:MM中的日常开关账期用
For opening & closing periods in MM side, you used MMPV and MMRV to
set back posting allowed and to check which period is open in SAP system.
- OB52:FI 用
OB52 is used for FI side only. It control period in all Account Types A, K, D,M, S
and specially Account Type ?+? which stands for valid for all accounts type .
既然OMSY只能运行一次,那就只能从MMPV,MMRV身上着手想办法了。
3,通过ABAP代码自动批量开关账期
SAP ABAP 自动批量开关账期程序 OB52和MMPV_sap ob52-CSDN博客
TA的代码里面有几个错误:
a),Type "SLIS_T_FIELDCAT_ALV" 未定義
[ABAP] The type "slis_formname"is unknown._abap slis-CSDN博客
这就需要加上 type-pools,就可以include进来了:
type-pools: slis. "调用类型组
b),不支持関係演算子 "-"
好像也没啥好办法,先放到一个变量里面,再放到关系演算子里面
c),SELECT * using a JOIN must have an INTO clause.
項目 "@GT_T001" 未定義,相似的名称是 "GT_T001"
c),v_comp_code,v_process,v_year 这3个参数,要放到汎用Module的Import参数里面
实行前
会社Code:3000
当期:2009/11
运行Report
输入参数:
- S_COMP:会社Code, 比如这里输入 3000
- S_POPER:当期会计期间,比如这里输入 10 (因为现在是2024/10)
- P_EXECUT:选这项表示执行批量更新
执行完只会发现其实根本没变:)
TODO:看来还有需要修改的地方,以后有时间再继续改
原文里也说了实现思路了,我这里把自己的图贴一贴,有需要的可以参考一下,反正我也没成。
要是你搞成了,给我发个Message告诉哪里错了啊。
3-1,ABAP代码
a),SE38 Report
*&---------------------------------------------------------------------*
*& REPORT ZTOOLSR0001
*&---------------------------------------------------------------------*
*& 自动开账期程序
*&---------------------------------------------------------------------*
* OB52 参考SAP程序 RFPERIOD_OPEN 和 RFPERIOD_CLOSE
* 直接更新 T001B 这个表
*--------------------------------------------------------------------*
REPORT ztoolsr0001.
TABLES: t001b.
TABLES: t001.
type-pools: slis. "调用类型组
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_comp FOR t001b-bukrs,
s_poper FOR t001b-frpe1 MODIF ID ty1 NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN SKIP 1.
PARAMETERS: p_select RADIOBUTTON GROUP g1 USER-COMMAND uc DEFAULT 'X',
p_execut RADIOBUTTON GROUP g1,
p_close RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK blk1.
TYPES: BEGIN OF ty_result,
bukrs TYPE t001-bukrs,
mkoar TYPE t001b-mkoar,
bkont TYPE t001b-bkont,
vkont TYPE t001b-vkont,
frye1 TYPE t001b-frye1,
frpe1 TYPE t001b-frpe1,
toye1 TYPE t001b-toye1,
tope1 TYPE t001b-tope1,
frye2 TYPE t001b-frye2,
frpe2 TYPE t001b-frpe2,
toye2 TYPE t001b-toye2,
tope2 TYPE t001b-tope2,
lfgja TYPE marv-lfgja,
lfmon TYPE marv-lfmon,
vmgja TYPE marv-vmgja,
vmmon TYPE marv-vmmon,
blankcell TYPE c,
END OF ty_result.
DATA: gt_result TYPE STANDARD TABLE OF ty_result.
DATA: gt_t001 TYPE STANDARD TABLE OF t001,
gt_t001b TYPE STANDARD TABLE OF t001b,
gt_marv TYPE STANDARD TABLE OF marv.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_layout TYPE slis_layout_alv.
DATA: lv_dateDiff TYPE i.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 EQ 'TY1' AND p_execut EQ 'X'.
screen-active = 1.
ELSEIF screen-group1 EQ 'TY1' AND p_execut NE 'X'.
screen-active = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
START-OF-SELECTION.
PERFORM frm_select_comp_code.
IF NOT gt_t001 IS INITIAL.
IF NOT p_select IS INITIAL. " 查询账期
PERFORM frm_select_posting_process. " 查询财务账期
PERFORM frm_select_material_periods." 查询物料账期
PERFORM frm_set_result_and_alv_show.
ELSEIF NOT p_execut IS INITIAL. " 打开账期
IF NOT p_execut IS INITIAL AND NOT s_poper IS INITIAL.
lv_dateDiff = s_poper-low+1(2) - sy-datum+4(2) .
IF s_poper-low+1(2) LT sy-datum+4(2).
MESSAGE '输入期间不可小于当前期间' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ELSEIF lv_dateDiff GT 1 .
MESSAGE '输入期间 - 当前期间不可大于 1' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
ENDIF.
PERFORM frm_select_posting_process.
PERFORM frm_set_new_posting_process. " 开财务账期
PERFORM frm_post_material_process. " 开物料账期
MESSAGE '执行成功,请退出后等待一会儿(约1min)再重新进入查看' TYPE 'S'.
ELSEIF NOT p_close IS INITIAL. " 关闭账期 - 只针对财务账期
PERFORM frm_select_posting_process.
PERFORM frm_set_new_posting_process. " 关财务账期
ENDIF.
ELSE.
MESSAGE '未查询到公司数据,请检查后重试;或联系系统管理员维护ZMASTERT0001表' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
END-OF-SELECTION.
FORM frm_select_comp_code.
*--------------------------------------------------------------------*
* 有一个公司代码主数据 ZMASTERT0001
* 如果这个表忘记维护怎么办
* 加一个不更新账期的字段
*--------------------------------------------------------------------*
SELECT
*
FROM
t001
INNER JOIN zmastert0001 ON t001~bukrs EQ zmastert0001~bukrs
INTO CORRESPONDING FIELDS OF TABLE gt_t001
WHERE t001~ktopl EQ 'CAUS'
AND zmastert0001~not_up_acc_date NE 'X'
AND t001~bukrs IN s_comp
.
ENDFORM.
FORM frm_select_posting_process.
IF NOT gt_t001 IS INITIAL.
SELECT
*
FROM
t001b
INTO CORRESPONDING FIELDS OF TABLE gt_t001b
FOR ALL ENTRIES IN gt_t001
WHERE bukrs EQ gt_t001-bukrs
.
ENDIF.
ENDFORM.
FORM frm_select_material_periods.
SELECT
*
FROM
marv
INTO CORRESPONDING FIELDS OF TABLE gt_marv
FOR ALL ENTRIES IN gt_t001
WHERE bukrs EQ gt_t001-bukrs
.
ENDFORM.
FORM frm_set_new_posting_process.
DATA: ls_t001b LIKE LINE OF gt_t001b.
DATA: lv_from_year_1 TYPE t001b-frye1,
lv_from_process_1 TYPE t001b-frpe1,
lv_to_year_1 TYPE t001b-toye1,
lv_to_process_1 TYPE t001b-tope1,
lv_from_year_2 TYPE t001b-frye2,
lv_from_process_2 TYPE t001b-frpe2,
lv_to_year_2 TYPE t001b-toye2,
lv_to_process_2 TYPE t001b-tope2,
lv_year TYPE t001b-frye1.
FIELD-SYMBOLS: <lfs_t001b> LIKE LINE OF gt_t001b.
*--------------------------------------------------------------------*
* 初始化值
*--------------------------------------------------------------------*
lv_year = sy-datum+0(4).
IF NOT p_close IS INITIAL. " 关闭账期
lv_from_year_1 = lv_year.
lv_from_process_1 = sy-datum+4(2).
ENDIF.
lv_to_year_1 = lv_year.
IF s_poper IS INITIAL.
lv_to_process_1 = sy-datum+4(2).
ELSEIF s_poper-low+1(2) GE sy-datum+4(2).
lv_to_process_1 = s_poper-low+1(2).
ENDIF.
lv_from_year_2 = lv_year.
lv_from_process_2 = '13'.
lv_to_year_2 = lv_year.
lv_to_process_2 = '16'.
LOOP AT gt_t001b ASSIGNING <lfs_t001b>.
IF NOT p_close IS INITIAL.
<lfs_t001b>-frye1 = lv_from_year_1.
<lfs_t001b>-frpe1 = lv_from_process_1.
ENDIF.
<lfs_t001b>-toye1 = lv_to_year_1.
<lfs_t001b>-tope1 = lv_to_process_1.
<lfs_t001b>-frye2 = lv_from_year_2.
<lfs_t001b>-frpe2 = lv_from_process_2.
<lfs_t001b>-toye2 = lv_to_year_2.
<lfs_t001b>-tope2 = lv_to_process_2.
ENDLOOP.
MODIFY t001b FROM TABLE gt_t001b. " 更新 T001B 表
ENDFORM.
*--------------------------------------------------------------------*
* 开物料账期
*--------------------------------------------------------------------*
FORM frm_post_material_process.
DATA: ls_t001 TYPE t001.
DATA: lv_year TYPE lfgja,
lv_process TYPE nperi.
*--------------------------------------------------------------------*
* 初始化值
*--------------------------------------------------------------------*
lv_year = sy-datum+0(4).
IF s_poper IS INITIAL.
lv_process = sy-datum+4(2).
ELSEIF s_poper-low+1(2) GE sy-datum+4(2).
lv_process = s_poper-low+1(2).
ENDIF.
LOOP AT gt_t001 INTO ls_t001.
CALL FUNCTION 'ZTOOLSFM04_MMPV_JOB'
EXPORTING
v_comp_code = ls_t001-bukrs
v_year = lv_year
v_process = lv_process.
ENDLOOP.
ENDFORM.
FORM frm_set_result_and_alv_show.
DATA: ls_result TYPE ty_result,
ls_t001b TYPE t001b,
ls_marv TYPE marv.
SORT gt_t001b BY bukrs mkoar.
LOOP AT gt_t001b INTO ls_t001b.
MOVE-CORRESPONDING ls_t001b TO ls_result.
AT NEW bukrs.
READ TABLE gt_marv INTO ls_marv WITH KEY bukrs = ls_t001b-bukrs.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING ls_marv TO ls_result.
ENDIF.
ENDAT.
APPEND ls_result TO gt_result.
CLEAR: ls_result, ls_t001b, ls_marv.
ENDLOOP.
SORT gt_result BY bukrs mkoar.
PERFORM frm_init_layout.
PERFORM frm_set_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_ALV_PF_STATUS'
i_callback_user_command = 'FRM_ALV_USER_COMMAND'
is_layout = gs_layout
it_fieldcat = gt_fieldcat
TABLES
t_outtab = gt_result
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM frm_init_layout.
gs_layout-colwidth_optimize = 'X'.
gs_layout-zebra = 'X'.
ENDFORM.
FORM frm_set_fieldcat.
DATA: ls_fieldcat TYPE LINE OF slis_t_fieldcat_alv.
PERFORM frm_init_fieldcat USING:
'BUKRS' '公司代码',
'MKOAR' '账户类型',
'BKONT' '终止科目',
'VKONT' '起始科目',
'FRYE1' '年度',
'FRPE1' '从',
'TOYE1' '年度',
'TOPE1' '到',
'FRYE2' '年度',
'FRPE2' '从',
'TOYE2' '年度',
'TOPE2' '到',
'BLANKCELL' '财务账和物料账分隔列',
'LFGJA' '当期会计年度',
'LFMON' '当期过账期间',
'VMGJA' '上期会计年度',
'VMMON' '上期过账期间'.
ENDFORM.
FORM frm_init_fieldcat USING fieldname TYPE slis_fieldcat_alv-fieldname
seltext TYPE slis_fieldcat_alv-seltext_l.
DATA: ls_fieldcat TYPE LINE OF slis_t_fieldcat_alv.
ls_fieldcat-fieldname = fieldname.
ls_fieldcat-seltext_s = seltext.
ls_fieldcat-seltext_m = seltext.
ls_fieldcat-seltext_l = seltext.
ls_fieldcat-no_zero = 'X'.
APPEND ls_fieldcat TO gt_fieldcat.
ENDFORM.
FORM frm_alv_pf_status USING lt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZTOOLSR0001'.
ENDFORM.
FORM frm_alv_user_command USING lv_ucomm LIKE sy-ucomm
ls_selfield TYPE slis_selfield.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
DATA: ls_layout TYPE lvc_s_layo.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
ls_selfield-refresh = 'X'.
ls_selfield-row_stable = 'X'.
ls_selfield-col_stable = 'X'.
CALL METHOD lr_grid->get_frontend_layout
IMPORTING
es_layout = ls_layout.
ls_layout-cwidth_opt = 'X'.
CALL METHOD lr_grid->set_frontend_layout
EXPORTING
is_layout = ls_layout.
IF lv_ucomm EQ 'ZUPDATE'.
PERFORM frm_set_new_posting_process. " 开财务账期
PERFORM frm_post_material_process. " 开物料账期
MESSAGE '执行成功,请退出后等待一会儿(约1min)再重新进入查看' TYPE 'S'.
ENDIF.
CALL METHOD lr_grid->refresh_table_display.
ENDFORM.
b),SE37 共通Module
本质上是在共通Module里面调用了MMRV/MMPV来1次一个月进行更新
FUNCTION ztoolsfm04_mmpv_job .
*"----------------------------------------------------------------------
*"*"ローカルインタフェース:
*" IMPORTING
*" REFERENCE(V_COMP_CODE) TYPE BUKRS
*" REFERENCE(V_PROCESS) TYPE NPERI
*" REFERENCE(V_YEAR) TYPE LFGJA
*"----------------------------------------------------------------------
* DATA: v_mode TYPE rfpdo-allgazmd.
* DATA: wa_bdcdata TYPE bdcdata,
* it_bdcdata TYPE STANDARD TABLE OF bdcdata.
*
* v_mode = 'N'.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-program = 'RMMMPERI'.
* wa_bdcdata-dynpro = '1000'.
* wa_bdcdata-dynbegin = 'X'.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'BDC_CURSOR'.
* wa_bdcdata-fval = 'I_XCOMP'.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'BDC_OKCODE'.
* wa_bdcdata-fval = '=ONLI'.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'I_VBUKR'.
* wa_bdcdata-fval = v_comp_code.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'I_LFMON'.
* wa_bdcdata-fval = v_process.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'I_LFGJA'.
* wa_bdcdata-fval = v_year.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'I_XCOMP'.
* wa_bdcdata-fval = 'X'.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CLEAR wa_bdcdata.
* wa_bdcdata-fnam = 'I_XMOVE'.
* wa_bdcdata-fval = ''.
* APPEND wa_bdcdata TO it_bdcdata.
*
* CALL TRANSACTION 'MMPV' USING it_bdcdata MODE v_mode.
*
* COMMIT WORK AND WAIT.
*--------------------------------------------------------------------*
* 使用 BDC 录屏并不能实现
* 只能直接调用程序 RMMMPERI
* 直接调用程序 RMMPERI 会返回日志屏幕
* 所以还得去后台调用
*--------------------------------------------------------------------*
* Job
DATA: v_start_time LIKE sy-uzeit,
v_report TYPE sy-repid,
v_jobcount TYPE tbtcjob-jobcount,
v_jobname TYPE tbtcjob-jobname.
* v_jobname = 'ZMMPVJOB' && sy-datum.
CONCATENATE 'ZMMPVJOB' sy-datum INTO v_jobname.
v_report = 'ZREPORTXXX'.
v_start_time = sy-uzeit + 7. " 系统当期时间后21s
* 定义后台作业
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = v_jobname
jobclass = 'A'
IMPORTING
jobcount = v_jobcount.
SUBMIT rmmmperi
WITH i_vbukr = v_comp_code
WITH i_bbukr = v_comp_code
WITH i_lfmon = v_process
WITH i_lfgja = v_year
WITH i_xcomp = 'X'
WITH i_xinco = ''
WITH i_xmove = ''
USER sy-uname
VIA JOB v_jobname
NUMBER v_jobcount
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = v_jobcount
jobname = v_jobname
sdlstrtdt = sy-datum
sdlstrttm = v_start_time
* strtimmed = 'X'
.
ENDFUNCTION.
c),SE11 新规Table ZMASTERT0001
该表用于控制具体要执行哪些公司的账期。
比如我这里填了 会社Code 3000,表示要执行会社Code3000 的账期
3-2,SE38 执行
说是成功了
TODO:其实没有成功
以上代码的原文请参照如下文章:
SAP ABAP 自动批量开关账期程序 OB52和MMPV_sap ob52-CSDN博客
以上就是本章的内容。
更多SAP顾问业务知识请点击下面目录链接
https://blog.csdn.net/shi_ly/category_12216766.html