SAP ABAP通过代码关闭账期

文章目录

  • 需求
  • 代码
  • 总结


需求

通过代码关闭账期


代码

其中 rfperiod_close 程序是关闭账期的标准程序 但其只能关闭一种类型的账期,账期内有多种类型,所以需要LOOP整个公司下的类型。
年度与期间也可改为输入参数,下面的代码再替换即可

*&---------------------------------------------------------------------*
*& Report  ZRFPERIOD_CLOSE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zrfperiod_close.

TABLES:t001.
DATA:lv_year  TYPE gjahr,
     lv_monat TYPE frper,
     lv_date  TYPE dats.


SELECT-OPTIONS: s_bukrs FOR t001-bukrs NO INTERVALS.
*PARAMETERS: p_year  TYPE gjahr,
*            p_monat TYPE frper.

START-OF-SELECTION.

  lv_date = sy-datum.
  lv_date = lv_date+(6) && '01'.
  lv_date = lv_date - 1.
  lv_year = lv_date+(4).
  lv_monat = '0' && lv_date+4(2).


  LOOP AT s_bukrs[] INTO DATA(ls_bukrs).

    SELECT * INTO TABLE @DATA(lt_t001b)
          FROM t001b
          WHERE bukrs EQ @ls_bukrs-low.
    IF lt_t001b IS NOT INITIAL.

      LOOP AT lt_t001b INTO DATA(ls_t001b).

        SUBMIT rfperiod_close AND RETURN
        WITH cocovar = ls_t001b-bukrs
        WITH fyear = lv_year
        WITH prd1_to = lv_monat
        WITH actyp EQ ls_t001b-mkoar.

      ENDLOOP.

      CLEAR:lt_t001b.
    ENDIF.

  ENDLOOP.


  DATA:lv_bukrs  TYPE t001-bukrs,
       e_oper    LIKE t001b-frpe1,
       lv_pererr TYPE char1.

  lv_bukrs = s_bukrs-low.

  CALL FUNCTION 'FI_PERIOD_CHECK'
    EXPORTING
      i_bukrs          = lv_bukrs
*     I_OPVAR          = ' '
      i_gjahr          = lv_year
      i_koart          = '+'
      i_konto          = '+'
      i_monat          = lv_monat
*     I_SPERI          =
*     I_RLDNR          =
*     I_GLVOR          = 'RFBU'
*     I_LDGRP          =
    IMPORTING
      e_oper           = e_oper
    EXCEPTIONS
      error_period     = 1
      error_period_acc = 2
      invalid_input    = 3
      OTHERS           = 4.

  IF sy-subrc NE 0 OR e_oper EQ '000'.
*    账期关闭成功
*    更新任务状态为成功
    CLEAR:lv_pererr.
  ELSE.
    lv_pererr = 'X'.
  ENDIF.
  IF lv_pererr IS INITIAL.
    MESSAGE s000(zmsg_fi) WITH s_bukrs-low '关账成功'.
  ELSE.
    MESSAGE e000(zmsg_fi) WITH s_bukrs-low '关账成功'.
  ENDIF.

END-OF-SELECTION.

总结

以上

你可能感兴趣的:(ABAP小记,ABAP小工具,SAP,ABAP,关闭账期)