matinal:SAP BSEG表有数,ACDOCA表数据为空

2023-10-14 14:51:59 浏览数 (1)

需求:acdoca和bseg数据不一致,bseg客户供应商字段有值,而acdoca为空

可能是由于项目之前做的增强,直接对源代码进行修改,导致acdoca数据和bseg不一致。

解决方法:找到了一个sap提供的类cl_fins_acdoc_change,经过测试,可以对acdoca数据进行修正。

代码如下:

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZFI_UPDATE_ACDOCA
*&---------------------------------------------------------------------*
*& 仅用于部分acdoca客户供应商字段为空的凭证
*&---------------------------------------------------------------------*
REPORT zfi_update_acdoca.

TABLES:acdoca,bseg.

"红绿灯
CONSTANTS:gc_red     LIKE icon-internal VALUE '@5C@',
          gc_yellow  LIKE icon-internal VALUE '@5D@',
          gc_green   LIKE icon-internal VALUE '@5B@',
          gc_status  TYPE slis_formname VALUE 'FRM_STATUS',
          gc_command TYPE slis_formname VALUE 'FRM_COMMAND'.

TYPES:BEGIN OF ty_data,
        sel,
        rldnr       TYPE acdoca-rldnr,
        rbukrs      TYPE acdoca-rbukrs,
        gjahr       TYPE acdoca-gjahr,
        belnr       TYPE acdoca-belnr,
        buzei       TYPE acdoca-buzei,
        docln       TYPE acdoca-docln,
        koart       TYPE acdoca-koart,
        racct       TYPE acdoca-racct,
        mwskz       TYPE acdoca-mwskz,
        bttype      TYPE acdoca-bttype,
        kunnr       TYPE acdoca-kunnr,
        bseg_kunnr  TYPE acdoca-kunnr,
        kunnr_name1 TYPE ze_kunnr_name,
        lifnr       TYPE acdoca-lifnr,
        bseg_lifnr  TYPE acdoca-lifnr,
        lifnr_name1 TYPE ze_lifnr_name,
        budat       TYPE acdoca-budat,
        blart       TYPE acdoca-blart,
        sgtxt       TYPE acdoca-sgtxt,
      END OF ty_data,
      ty_t_data TYPE TABLE OF ty_data.

DATA:gs_data     TYPE ty_data,
     gt_data     TYPE ty_t_data,
     gs_lay      TYPE lvc_s_layo,           " layout
     gt_fieldcat TYPE lvc_t_fcat,           " fieldcat
     gs_fieldcat TYPE lvc_s_fcat.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.

  PARAMETERS: p_gjahr TYPE acdoca-gjahr DEFAULT sy-datum 0(4) OBLIGATORY." 会计年度
  SELECT-OPTIONS: s_belnr FOR acdoca-belnr,   " 会计凭证
                  s_bukrs FOR acdoca-rbukrs.  " 公司代码

  SELECTION-SCREEN SKIP 1.
  SELECTION-SCREEN BEGIN OF LINE.
*第一个RADIOBUTTON
    SELECTION-SCREEN POSITION 1.
    PARAMETERS:p1 RADIOBUTTON GROUP r1 DEFAULT 'X' USER-COMMAND ucl.
    SELECTION-SCREEN COMMENT 3(15) TEXT-002 .

*第二个RADIOBUTTON
    SELECTION-SCREEN POSITION 25.
    PARAMETERS:p2 RADIOBUTTON GROUP r1.
    SELECTION-SCREEN COMMENT 27(15) TEXT-003 .
  SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
  PERFORM frm_get_data.            " 获取数据

END-OF-SELECTION.
  PERFORM frm_alv_dis.             " alv展示
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .

  DATA:lr_koart TYPE rseloption,
       lr_lifnr TYPE rseloption,
       lr_kunnr TYPE rseloption.

  REFRESH gt_data.

  CASE 'X'.
    WHEN p1.
*如果KOART=D,限定ACDOCA-KUNNR=空,
      lr_koart = VALUE #( ( sign = 'I' option = 'EQ' low = 'D' )  ).
      lr_kunnr = VALUE #( ( sign = 'I' option = 'EQ' low = '' )  ).
    WHEN p2.
*如果KOART=K,限定ACDOCA-LIFNR=空,
      lr_koart = VALUE #( ( sign = 'I' option = 'EQ' low = 'K' )  ).
      lr_lifnr = VALUE #( ( sign = 'I' option = 'EQ' low = '' )  ).
    WHEN OTHERS.
  ENDCASE.

  SELECT a~rldnr,
         a~rbukrs,
         a~gjahr,
         a~belnr,
         a~buzei,
         a~docln,
         a~koart,
         a~racct,
         a~mwskz,
         a~bttype,
         a~kunnr,
         b~kunnr AS bseg_kunnr,
         c~name1 AS kunnr_name1,
         a~lifnr,
         b~lifnr AS bseg_lifnr,
         d~name1 AS lifnr_name1,
         a~budat,
         a~blart,
         a~sgtxt
    FROM acdoca AS a
    LEFT OUTER JOIN bseg AS b
      ON a~rbukrs = b~bukrs
     AND a~belnr  = b~belnr
     AND a~gjahr  = b~gjahr
     AND a~buzei  = b~buzei
    LEFT OUTER JOIN kna1 AS c
      ON b~kunnr = c~kunnr
    LEFT OUTER JOIN lfa1 AS d
      ON b~lifnr = d~lifnr
    INTO CORRESPONDING FIELDS OF TABLE @gt_data
   WHERE a~gjahr = @p_gjahr
     AND a~rbukrs IN @s_bukrs
     AND a~belnr  IN @s_belnr
     AND a~koart  IN @lr_koart
     AND a~kunnr  IN @lr_kunnr
     AND a~lifnr  IN @lr_lifnr.

  IF gt_data IS INITIAL.

    MESSAGE '未查询到满足条件数据' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.

  ENDIF.

  SORT gt_data BY rldnr rbukrs gjahr belnr docln.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_alv_dis
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_alv_dis .

  gs_lay-cwidth_opt = 'X'.
  gs_lay-zebra = 'X'.
  gs_lay-no_toolbar = 'X'.
  gs_lay-box_fname = 'SEL'.    " 选择框
  CLEAR :gt_fieldcat[].
  DEFINE add_fieldcat.

    CLEAR:gs_fieldcat.
    gs_fieldcat-fieldname = &2.
    gs_fieldcat-scrtext_l = &1.
    gs_fieldcat-scrtext_m = &1.
    gs_fieldcat-scrtext_s = &1.
    gs_fieldcat-coltext   = &1.
    gs_fieldcat-col_opt   = &3.
    gs_fieldcat-ref_table = &4.
    gs_fieldcat-ref_field = &5.
    gs_fieldcat-edit_mask = &6.

    APPEND gs_fieldcat TO gt_fieldcat.

  END-OF-DEFINITION.

  add_fieldcat '分类账'        'RLDNR'             '' ''         ''           ''.
  add_fieldcat '公司代码'	     'RBUKRS'            '' ''         ''           ''.
  add_fieldcat '年度'	         'GJAHR'             '' ''         ''           ''.
  add_fieldcat '凭证编号'      'BELNR'             '' ''         ''           ''.
  add_fieldcat '行号'	         'BUZEI'             '' ''         ''           ''.
  add_fieldcat '行项目'        'DOCLN'             '' ''         ''           ''.
  add_fieldcat '科目类型'	     'KOART'             '' ''         ''           ''.
  add_fieldcat '科目'	         'RACCT'             '' ''         ''           ''.
  add_fieldcat '税码'          'MWSKZ'             '' ''         ''           ''.
  add_fieldcat '业务交易类型'	 'BTTYPE'            '' ''         ''           ''.
  add_fieldcat '客户'	         'KUNNR'             '' ''         ''           ''.
  add_fieldcat 'BSEG表-客户'	  'BSEG_KUNNR'        '' ''         ''           ''.
  add_fieldcat '客户名称'	     'KUNNR_NAME1'       '' ''         ''           ''.
  add_fieldcat '供应商'        'LIFNR'             '' ''         ''           ''.
  add_fieldcat 'BSEG表-供应商' 'BSEG_LIFNR'        '' ''         ''           ''.
  add_fieldcat '供应商名称'    'LIFNR_NAME1'       '' ''         ''           ''.
  add_fieldcat '过账日期'	     'BUDAT'             '' ''         ''           ''.
  add_fieldcat '凭证类型'	     'BLART'             '' ''         ''           ''.
  add_fieldcat '行项目文本'    'SGTXT'             '' ''         ''           ''.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = gc_status
      i_callback_user_command  = gc_command
      is_layout_lvc            = gs_lay
      it_fieldcat_lvc          = gt_fieldcat
      i_save                   = 'A'
    TABLES
      t_outtab                 = gt_data
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

  IF sy-subrc <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_STATUS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_status USING p_extab TYPE slis_t_extab.

  DATA lt_fcode TYPE TABLE OF sy-ucomm.
  DATA(lv_title) = ''.
  SET PF-STATUS 'ST1' EXCLUDING lt_fcode."隐藏功能按钮
  SET TITLEBAR  'TI1' WITH lv_title.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_COMMAND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_command USING p_ucomm TYPE sy-ucomm
                       ps_selfield  TYPE slis_selfield.

  DATA: lo_grid TYPE REF TO cl_gui_alv_grid,
        lv_code LIKE sy-ucomm.

  lv_code = p_ucomm.
  CLEAR:p_ucomm.

  CASE lv_code.
    WHEN 'ZCHG'.
      PERFORM frm_change_acdoca. 
  ENDCASE.

  ps_selfield-refresh = 'X'.
*刷新alv屏幕数据
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lo_grid.

  CALL METHOD lo_grid->check_changed_data.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_change_acdoca
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_change_acdoca .

  DATA: lo_acdoc_change  TYPE REF TO cl_fins_acdoc_change,
        lt_change_fields TYPE finst_fieldname,
        ls_change_fields LIKE LINE OF lt_change_fields,
        lt_acdoca_upd    TYPE finst_acdoca,
        lt_acdoca_sort   TYPE if_fins_acdoc_util_types=>tt_acdoca_sorted WITH HEADER LINE.

  CLEAR:lt_acdoca_sort,lt_acdoca_upd.

  " 需要更新字段
  ls_change_fields = 'KUNNR'.
  COLLECT ls_change_fields INTO lt_change_fields.

  ls_change_fields = 'LIFNR'.
  COLLECT ls_change_fields INTO lt_change_fields.

  ls_change_fields = 'MWSKZ'.
  COLLECT ls_change_fields INTO lt_change_fields.

  SORT gt_data BY rldnr rbukrs gjahr belnr docln.
  LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs_data>) WHERE sel = 'X'.

    APPEND VALUE #( rldnr   = <fs_data>-rldnr
                    rbukrs  = <fs_data>-rbukrs
                    gjahr   = <fs_data>-gjahr
                    belnr   = <fs_data>-belnr
                    docln   = <fs_data>-docln
                    mwskz   = '' " 销售/购买税代码
                    lifnr   = <fs_data>-bseg_lifnr
                    kunnr   = <fs_data>-bseg_kunnr ) TO lt_acdoca_sort.

  ENDLOOP.
  IF sy-subrc NE 0.
    MESSAGE '请选择行' TYPE 'S' DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

  IF lt_acdoca_sort[] IS NOT INITIAL.

    lt_acdoca_upd = lt_acdoca_sort[].
    CREATE OBJECT lo_acdoc_change.

    lo_acdoc_change->set_support_mode(
       EXPORTING
         it_change_fields = lt_change_fields ).

    lo_acdoc_change->change_acdoca(
       EXPORTING
         it_change_fields     = lt_change_fields
         it_acdoca_upd        = lt_acdoca_upd
         iv_write_change_docs = abap_false
         iv_direct_update     = abap_true ).

    COMMIT WORK.
    MESSAGE '更新成功' TYPE 'S'.

  ENDIF.

ENDFORM.

0 人点赞