ABUMN_公司内资产转移
一、功能介绍
-
使用事务码ABUMN进行公司内资产转移
二、程序代码
-
程序代码:
*&---------------------------------------------------------------------* *& Report ZFIR218 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zfir218. TABLES :sscrfields. TYPE-POOLS: slis,icon. DATA:gs_functxt TYPE smp_dyntxt. DATA:gs_layout TYPE lvc_s_layo, gt_fieldcat TYPE lvc_t_fcat, gs_fieldcat TYPE lvc_s_fcat. TYPES:BEGIN OF ty_tab, bukrs TYPE string, anln1 TYPE string, anln2 TYPE string, acc_principle TYPE string, afabe_post TYPE string, blart TYPE string, monat TYPE string, bldat TYPE string, budat TYPE string, bzdat TYPE string, sgtxt TYPE string, panln1 TYPE string, panln2 TYPE string, END OF ty_tab. TYPES:BEGIN OF ty_data, box TYPE char1, tip TYPE char10, msg TYPE string, bukrs TYPE bukrs, anln1 TYPE anln1, anln2 TYPE anln2, acc_principle TYPE accounting_principle, afabe_post TYPE afabe_post, blart TYPE blart, monat TYPE monat, bldat TYPE bldat, budat TYPE budat, bzdat TYPE bzdat, sgtxt TYPE sgtxt, panln1 TYPE panl1, panln2 TYPE panl2, END OF ty_data. DATA:gt_data TYPE STANDARD TABLE OF ty_data, gs_data TYPE ty_data, gt_tab TYPE STANDARD TABLE OF ty_tab, gs_tab TYPE ty_tab. *------------------------------append by hand ylx 20220929 新增 字段 begin-----------------------------------------* *&------------------------------------------------* *&BDC的定义 *&------------------------------------------------* DATA gt_bdcdata TYPE TABLE OF bdcdata . "bdc执行内表 DATA gt_msgtab TYPE TABLE OF bdcmsgcoll . "bdc返回信息表 DATA gs_bdcdata TYPE bdcdata . "bdc执行内表 DATA gs_msgtab TYPE bdcmsgcoll . "bdc返回信息表 DATA p_mode TYPE c VALUE 'N'."bdc运行模式 SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. PARAMETERS:p_path TYPE string. SELECTION-SCREEN END OF BLOCK b1. SELECTION-SCREEN:FUNCTION KEY 1. INITIALIZATION. gs_functxt-icon_id = icon_mapped_relation. gs_functxt-icon_text = '下载资产数据模板'. sscrfields-functxt_01 = gs_functxt. AT SELECTION-SCREEN. IF sscrfields-ucomm = 'FC01'. PERFORM frm_download. ENDIF. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM f_get_filepath USING p_path. START-OF-SELECTION. "数据处理 PERFORM frm_check_filepath. PERFORM frm_upload_data. "ALV 显示 PERFORM frm_set_alv. PERFORM frm_dis_alv. END-OF-SELECTION. *&---------------------------------------------------------------------* *& Form frm_check_filepath *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_check_filepath . IF p_path IS INITIAL. MESSAGE '文件地址不能为空!' TYPE 'S' DISPLAY LIKE 'E'. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_upload_data *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_upload_data . DATA:lt_intern TYPE TABLE OF alsmex_tabline, ls_intern TYPE alsmex_tabline, l_message TYPE string. FIELD-SYMBOLS:<fs> TYPE any.. DATA:it_raw TYPE truxs_t_text_data. DATA lv_file TYPE rlgrap-filename. lv_file = p_path. "导入数据时,如果电脑中装了福昕PDF阅读器,会导致excel数据没有上传至内表并,同时sy-subrc = 2 CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = lv_file i_begin_col = 1 i_begin_row = 2 i_end_col = 13 i_end_row = 65535 TABLES intern = lt_intern EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. IF lt_intern IS NOT INITIAL. LOOP AT lt_intern INTO ls_intern. ASSIGN COMPONENT ls_intern-col OF STRUCTURE gs_tab TO <fs>. <fs> = ls_intern-value. AT END OF row. MOVE-CORRESPONDING gs_tab TO gs_data. gs_data-tip = icon_led_red. gs_data-msg = ''. APPEND gs_data TO gt_data. CLEAR:gs_data,gs_tab. ENDAT. CLEAR:ls_intern. ENDLOOP. ENDIF. LOOP AT gt_tab INTO gs_tab. MOVE-CORRESPONDING gs_tab TO gs_data. gs_data-tip = icon_led_red. gs_data-msg = ''. APPEND gs_data TO gt_data. CLEAR:gs_data,gs_tab. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_set_alv *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_set_alv . DATA: l_colpos TYPE lvc_s_fcat-col_pos VALUE 0. *&---------------------------------------------------------------------* *& 定义宏 *&---------------------------------------------------------------------* DEFINE macro_fill_fcat. CLEAR gs_fieldcat. &1 = &1 + 1. gs_fieldcat-col_pos = &1. gs_fieldcat-fieldname = &2. gs_fieldcat-coltext = &3. APPEND gs_fieldcat TO gt_fieldcat. END-OF-DEFINITION. FIELD-SYMBOLS: <fs_fieldcat> TYPE lvc_s_fcat. CLEAR gt_fieldcat. macro_fill_fcat: l_colpos 'TIP' '状态', l_colpos 'MSG' '消息提示', l_colpos 'BUKRS' '公司代码', l_colpos 'ANLN1' '主资产编号', l_colpos 'ANLN2' '子资产编号', l_colpos 'ACC_PRINCIPLE' '会计准则', l_colpos 'AFABE_POST' '折旧范围', l_colpos 'BLART' '凭证类型', l_colpos 'MONAT' '会计期间', l_colpos 'BLDAT' '凭证日期', l_colpos 'BUDAT' '过账日期', l_colpos 'BZDAT' '资产价值日', l_colpos 'SGTXT' '项目文本', l_colpos 'PANLN1' '现有主资产' , l_colpos 'PANLN2' '现有子资产'. CLEAR gs_layout. gs_layout-zebra = 'X'. gs_layout-box_fname = 'BOX'. gs_layout-cwidth_opt = 'X'. gs_layout-sel_mode = 'A'. "设置行模式" ENDFORM. *&---------------------------------------------------------------------* *& Form frm_dis_alv *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_dis_alv . DATA: lv_grid TYPE lvc_s_glay. lv_grid-edt_cll_cb = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = 'PF_STATUS_SET' i_callback_user_command = 'FRM_USER_COMMAND' i_grid_settings = lv_grid is_layout_lvc = gs_layout it_fieldcat_lvc = gt_fieldcat TABLES t_outtab = gt_data. ENDFORM. *&---------------------------------------------------------------------* *& Form PF_STATUS_SET *&---------------------------------------------------------------------* * gui状态 *----------------------------------------------------------------------* * -->TR_EXTAB text *----------------------------------------------------------------------* FORM pf_status_set USING pr_extab TYPE slis_t_extab. SET PF-STATUS 'STANDARD' . ENDFORM. *&---------------------------------------------------------------------* *& Form frm_user_command *&---------------------------------------------------------------------* * 用戶响应事件 *----------------------------------------------------------------------* * -->R_UCOMM text * -->RS_SELFIELD text *----------------------------------------------------------------------* FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. *刷新alv DATA:lob_grid TYPE REF TO cl_gui_alv_grid. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lob_grid. CALL METHOD lob_grid->check_changed_data. CASE r_ucomm. WHEN '&UPD'. PERFORM frm_bapi. ENDCASE. rs_selfield-refresh = 'X'. gs_layout-cwidth_opt = 'X'. gs_layout-no_toolbar = 'X'. CALL METHOD lob_grid->set_frontend_layout EXPORTING is_layout = gs_layout. CALL METHOD lob_grid->refresh_table_display. ENDFORM. *&---------------------------------------------------------------------* *& Form f_get_filepath *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> P_PATH *&---------------------------------------------------------------------* FORM f_get_filepath USING p_path. DATA:lv_rc TYPE i. DATA:lt_file_table TYPE filetable. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING window_title = '选择文件' file_filter = 'Microsoft Excel 文件(*.XLS;*.XLSX)|*.XLS;*.XLSX' CHANGING file_table = lt_file_table rc = lv_rc. IF sy-subrc = 0. READ TABLE lt_file_table INTO DATA(wa_file_table) INDEX 1. p_path = wa_file_table-filename. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_download *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_download . DATA: lv_fname TYPE string, lv_title TYPE string, lv_path TYPE string VALUE 'D:/', lv_fpath TYPE string VALUE 'D:/', pv_file TYPE rlgrap-filename . "下载文件 DATA: p_objid(20) TYPE c. DATA: ls_wdatb LIKE wwwdatatab. DATA: lv_subrc TYPE sy-subrc. DATA: gv_msg TYPE string. p_objid = 'ZFIR218'. lv_fname = '公司资产转移下载模板'. CONCATENATE lv_fname '下载' INTO lv_title. "保存文件 CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING window_title = lv_title default_extension = 'xls' default_file_name = lv_fname initial_directory = 'D:\' file_filter = 'EXCEL文件(*.xls)||全部文件 (*.*)||' prompt_on_overwrite = 'X' CHANGING filename = lv_fname path = lv_path fullpath = lv_fpath EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. "判断文件模板是否存在 SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF ls_wdatb WHERE srtf2 = 0 AND relid = 'MI' AND objid = p_objid. "P_OBJID就是传入模板的参数 IF ls_wdatb IS INITIAL. MESSAGE '模板文件不存在!' TYPE 'E'. ELSE. pv_file = lv_fpath. IF pv_file IS NOT INITIAL. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' EXPORTING key = ls_wdatb destination = pv_file IMPORTING rc = lv_subrc. IF lv_subrc NE 0. MESSAGE '模板下载失败!' TYPE 'E'. ELSE. CLEAR gv_msg. CONCATENATE '模板下载到本地文件' pv_file INTO gv_msg. MESSAGE gv_msg TYPE 'S' . ENDIF. ENDIF. ENDIF. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_bapi *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_bapi . DATA lv_message TYPE string. LOOP AT gt_data INTO gs_data WHERE box = 'X'. "BDC录屏,按照顺序填,在使用BDC录屏的时候需要添加回车,否则会录制失败 SET PARAMETER ID 'BUK' FIELD gs_data-bukrs. PERFORM bdc_dynpro USING 'SAPLAMDPS2I' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'RAIFP2-ANLN1' gs_data-anln1. PERFORM bdc_field USING 'RAIFP2-ANLN2' gs_data-anln2. PERFORM bdc_field USING 'RAIFP1-ACC_PRINCIPLE' gs_data-acc_principle. PERFORM bdc_field USING 'RAIFP1-AFABE_POST' gs_data-afabe_post. PERFORM bdc_field USING 'RAIFP1-BLDAT' gs_data-bldat . " 上线日期 PERFORM bdc_field USING 'RAIFP1-BUDAT' gs_data-budat. " 上线日期 PERFORM bdc_field USING 'RAIFP1-BZDAT' gs_data-bzdat. " 资产价值日 PERFORM bdc_field USING 'RAIFP2-SGTXT' gs_data-sgtxt. PERFORM bdc_field USING 'BDC_CURSOR' 'RAIFP3-ANLN1'. PERFORM bdc_field USING 'RAIFP3-ANLN1' gs_data-panln1. PERFORM bdc_field USING 'RAIFP3-ANLN2' gs_data-panln2. PERFORM bdc_dynpro USING 'SAPLAMDPS2I' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '=TAB02'. PERFORM bdc_dynpro USING 'SAPLAMDPS2I' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'."回车按钮 PERFORM bdc_field USING 'RAIFP2-MONAT' gs_data-monat. PERFORM bdc_field USING 'RAIFP1-BLART' gs_data-blart. PERFORM bdc_dynpro USING 'SAPLAMDPS2I' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE'. PERFORM bdc_field USING 'BDC_CURSOR' 'RAIFP2-ANLN1'. PERFORM bdc_field USING 'RAIFP2-ANLN1' gs_data-anln1. PERFORM bdc_field USING 'RAIFP2-ANLN2' gs_data-anln2. *然后是调用事物代码: CALL TRANSACTION 'ABUMN' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab UPDATE 'S'. "批导更新模式(A = '异步',S = '同步') READ TABLE gt_msgtab INTO gs_msgtab WITH KEY msgtyp = 'E'. IF sy-subrc = 0. LOOP AT gt_msgtab INTO gs_msgtab WHERE msgtyp = 'E'. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = gs_msgtab-msgid msgnr = gs_msgtab-msgnr msgv1 = gs_msgtab-msgv1 msgv2 = gs_msgtab-msgv2 msgv3 = gs_msgtab-msgv3 msgv4 = gs_msgtab-msgv4 IMPORTING message_text_output = lv_message. gs_data-msg = lv_message. CLEAR lv_message. ENDLOOP. gs_data-tip = icon_led_red. ELSE. LOOP AT gt_msgtab INTO gs_msgtab . CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = gs_msgtab-msgid msgnr = gs_msgtab-msgnr msgv1 = gs_msgtab-msgv1 msgv2 = gs_msgtab-msgv2 msgv3 = gs_msgtab-msgv3 msgv4 = gs_msgtab-msgv4 IMPORTING message_text_output = lv_message. gs_data-msg = gs_data-msg && ',' && lv_message. CLEAR lv_message. ENDLOOP. gs_data-msg = '资产转移成功!'. gs_data-tip = icon_led_green. ENDIF. MODIFY gt_data FROM gs_data. CLEAR: gs_bdcdata ,gs_msgtab,gt_bdcdata ,gt_msgtab,gs_data. ENDLOOP. ENDFORM. *创建一个记录bdc的form FORM bdc_field USING fnam fval. CLEAR gs_bdcdata. gs_bdcdata-fnam = fnam. gs_bdcdata-fval = fval. APPEND gs_bdcdata TO gt_bdcdata. ENDFORM. "BDC_FIELD FORM bdc_dynpro USING program dynpro. CLEAR gs_bdcdata. gs_bdcdata-program = program. gs_bdcdata-dynpro = dynpro. gs_bdcdata-dynbegin = 'X'. APPEND gs_bdcdata TO gt_bdcdata . ENDFORM.