SAP 合并科目导入

这个SAP程序(ZGRP_AC_IMPORT)用于从Excel文件批量导入会计科目数据。它首先打开文件选择对话框,然后读取指定的Excel文件,并将数据转换为SAP可以处理的格式。接着,通过BDC(Batch Data Communication)技术,逐条执行会计科目维护事务代码,创建或更新科目。程序中包含了字段映射和事务代码调用,以确保科目数据的正确导入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*&---------------------------------------------------------------------*
*& Report  ZGRP_AC_IMPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  zgrp_ac_import.

TYPE-POOLS:TRUXS.

*                                                                Definition of TYPES
types:
         begin of typ_import ,
          saknr like glaccount_screen_coa-saknr,
          ktopl like glaccount_screen_coa-ktopl,
          ktoks like ska1-ktoks,
          xplacct like glaccount_screen_coa-xplacct,
          xbilk like glaccount_screen_coa-xbilk,
          txt20 like skat-txt20,
          txt50 like skat-txt50,
          vbund like ska1-vbund,
         end of typ_import.


*                                                                Definition of DATAS
data:
        gt_acdata type table of typ_import ,
        gui_object type ref to cl_gui_frontend_services,
        gt_file_path type  filetable with header line ,
        line type i,
        it_tab type TRUXS_T_TEXT_DATA.
*       Batchinputdata of single transaction
data:   bdcdata like bdcdata    occurs 0 with header line.
*       Nodata-Character
data:   nodata_character value '/'.

data MESSTAB type table of BDCMSGCOLL with header line.
data p_typ  type ctu_mode value 'N'.
*                                                                Definition of Symbos
field-symbols :
         <gt_acdata> type typ_import .



*                                                                Selection Screen
selection-screen begin of block b1 with frame title text-001.
parameters:p_file like rlgrap-filename.
selection-screen end of block b1.

at selection-screen on value-request for p_file .
  create object gui_object.
  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      window_title      = '选择导入文件'
      file_filter       = ',Microsoft Excel 文件,*.xls;*.xlsx;*.xlsm'".'
      initial_directory = 'C:\'
    changing
      file_table        = gt_file_path[]
      rc                = line.
  if sy-subrc = 0.
    read table gt_file_path index 1 .
    p_file = gt_file_path-filename.
  endif.



start-of-selection .

  call function 'TEXT_CONVERT_XLS_TO_SAP'
    exporting
*     I_FIELD_SEPERATOR          =
      i_line_header              = 'X'
      i_tab_raw_data             = it_tab
      i_filename                 = p_file
    tables
      i_tab_converted_data       =   gt_acdata
   exceptions
     conversion_failed          = 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.
    exit.
  endif.

loop at gt_acdata assigning <gt_acdata>.

  perform bdc_dynpro      using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
  perform bdc_field       using 'BDC_OKCODE'
        '=ACC_CRE'.
  perform bdc_field       using 'BDC_CURSOR'
        'GLACCOUNT_SCREEN_KEY-KTOPL'.
  perform bdc_field       using 'GLACCOUNT_SCREEN_KEY-SAKNR'
        <gt_acdata>-saknr.
  perform bdc_field       using 'GLACCOUNT_SCREEN_KEY-KTOPL'
        <gt_acdata>-ktopl.
  perform bdc_dynpro      using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
  perform bdc_field       using 'BDC_OKCODE'
        '=2102_GROUP'.
  perform bdc_field       using 'BDC_CURSOR'
        'GLACCOUNT_SCREEN_COA-KTOKS'.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-KTOKS'
        <gt_acdata>-ktoks.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-XPLACCT'
        <gt_acdata>-xplacct.
  perform bdc_dynpro      using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
  perform bdc_field       using 'BDC_OKCODE'
        '=2102_BS_PL'.
  perform bdc_field       using 'BDC_CURSOR'
        'GLACCOUNT_SCREEN_COA-XBILK'.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-KTOKS'
        <gt_acdata>-ktoks.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-XPLACCT'
        <gt_acdata>-xplacct.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-XBILK'
        <gt_acdata>-xbilk.
  perform bdc_dynpro      using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
  perform bdc_field       using 'BDC_OKCODE'
        '=SAVE'.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-KTOKS'
        <gt_acdata>-ktoks.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-XBILK'
        <gt_acdata>-xbilk.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-TXT20_ML'
        <gt_acdata>-txt20.
  perform bdc_field       using 'GLACCOUNT_SCREEN_COA-TXT50_ML'
        <gt_acdata>-txt50.
  perform bdc_field       using 'BDC_CURSOR'
        'GLACCOUNT_SCREEN_COA-VBUND'.
  perform bdc_transaction using     'FSP0' p_typ  'S' .
endloop.






*                                                                Definition of Forms

*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
form bdc_transaction using tcode p_typ cupdate.
  data: l_mstring(480).
  data: l_subrc like sy-subrc..
  refresh messtab.
  call transaction tcode using   bdcdata
        mode    p_typ
        update  cupdate  "更新模式 f1可看
        messages into messtab.

  if lines( messtab ) > 0. 
    loop at messtab .
      if messtab-msgtyp ne 'E' and messtab-msgtyp ne 'S'.
        continue.
      endif.
      select single text from t100 into l_mstring
      where sprsl = messtab-msgspra
      and arbgb = messtab-msgid
      and msgnr = messtab-msgnr.
      if sy-subrc = 0.
        if l_mstring cs '&1'. "
          replace '&1' with messtab-msgv1 into l_mstring.
          replace '&2' with messtab-msgv2 into l_mstring.
          replace '&3' with messtab-msgv3 into l_mstring.
          replace '&4' with messtab-msgv4 into l_mstring.
        else.
          replace '&' with messtab-msgv1 into l_mstring.
          replace '&' with messtab-msgv2 into l_mstring.
          replace '&' with messtab-msgv3 into l_mstring.
          replace '&' with messtab-msgv4 into l_mstring.
        endif.
        condense l_mstring.
        write:l_mstring.

      endif.
    endloop.
  endif.
  refresh bdcdata.

endform.                    " BDC_TRANSACTION

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
  clear bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  append bdcdata.
endform.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
  if fval <> nodata_character.
    clear bdcdata.
    bdcdata-fnam = fnam.
    bdcdata-fval = fval.
    append bdcdata.
  endif.
endform.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
form bdc_nodata using p_nodata.
  nodata_character = p_nodata.
endform.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值