*&---------------------------------------------------------------------* *& Report ZFIR027 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZFIR027. type-pools: slis. tables: anla, bkpf, anlz. types: begin of ty_output_line, bukrs type anla-bukrs, anlkl type anla-anlkl, lbtxk type ankt-txk50, anln1 type anla-anln1, anln2 type anla-anln2, mctxk type anla-txt50, aktiv type anla-aktiv, kostl type anlz-kostl, ltext type cskt-ltext, bwasl type anep-bwasl, bwatxt type tabwt-bwatxt, belnr type anep-belnr, budat type bkpf-budat, anbtr type anep-anbtr, adatu type anlz-adatu, fbflg type c, end of ty_output_line. data: wa_output_line type ty_output_line, it_output_itab type table of ty_output_line with header line. field-symbols: <fs_output_line> type ty_output_line. types: begin of ty_anla_line, bukrs type anla-bukrs, anlkl type anla-anlkl, anln1 type anla-anln1, anln2 type anla-anln2, mctxk type anla-txt50, aktiv type anla-aktiv, end of ty_anla_line. data: wa_anla_line type ty_anla_line, it_anla_itab type table of ty_anla_line with header line. types: begin of ty_ankt_line, anlkl type ankt-anlkl, txk50 type ankt-txa50, end of ty_ankt_line. data: wa_ankt_line type ty_ankt_line, it_ankt_itab type table of ty_ankt_line with header line. types: begin of ty_cskt_line, kostl type cskt-kostl, ltext type cskt-ltext, end of ty_cskt_line. data: wa_cskt_line type ty_cskt_line, it_cskt_itab type table of ty_cskt_line with header line. types: begin of ty_anlz_line, bukrs type anlz-bukrs, anln1 type anlz-anln1, anln2 type anlz-anln2, bdatu type anlz-bdatu, adatu type anlz-adatu, kostl type anlz-kostl, end of ty_anlz_line. data: wa_anlz_line type ty_anlz_line, it_anlz_itab type table of ty_anlz_line with header line. types: begin of ty_anep_line, bukrs type anep-bukrs, anln1 type anep-anln1, anln2 type anep-anln2, gjahr type anep-gjahr, bwasl type anep-bwasl, belnr type anep-belnr, anbtr type anep-anbtr, lnsan type anep-lnsan, end of ty_anep_line. data: wa_anep_line type ty_anep_line, it_anep_itab type table of ty_anep_line with header line. types: begin of ty_tabwt_line, bwasl type tabwt-bwasl, bwatxt type tabwt-bwatxt, end of ty_tabwt_line. data: wa_tabwt_line type ty_tabwt_line, it_tabwt_itab type table of ty_tabwt_line with header line. types: begin of ty_bkpf_line, bukrs type bkpf-bukrs, belnr type bkpf-belnr, gjahr type bkpf-gjahr, awkey type bkpf-awkey, budat type bkpf-budat, end of ty_bkpf_line. data: wa_bkpf_line type ty_bkpf_line, it_bkpf_itab type table of ty_bkpf_line with header line. ranges: rs_awkey for bkpf-awkey. data: col_pos type i. data: gt_fieldcat type slis_t_fieldcat_alv. data: gs_layout type slis_layout_alv. data: control_title type lvc_title. data: gt_sort type slis_t_sortinfo_alv. selection-screen begin of block b1 with frame title text-001. select-options: s_bukrs for anla-bukrs. parameters: p_gjahr type bkpf-gjahr obligatory. select-options: s_monat for bkpf-monat, s_anlkl for anla-anlkl, s_anln1 for anla-anln1, s_anln2 for anla-anln2, s_kostl for anlz-kostl. * s_ord41 for anla-ord41. selection-screen end of block b1. start-of-selection. perform frm_get_data. end-of-selection. perform frm_out_data. *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_get_data . data: l_index type sy-tabix, l_index1 type sy-tabix, l_begin_datum type sy-datum, l_end_datum type sy-datum. *按照查询条件读取资产主记录 select bukrs anlkl anln1 anln2 txt50 as mctxk aktiv into table it_anla_itab from anla where bukrs in s_bukrs and anln1 in s_anln1 and anln2 in s_anln2 and anlkl in s_anlkl. if not it_anla_itab[] is initial. *读取资产分类描述 select anlkl txk50 into table it_ankt_itab from ankt for all entries in it_anla_itab where spras eq sy-langu and anlkl eq it_anla_itab-anlkl. *读取资产分配相关信息 select bukrs anln1 anln2 bdatu adatu kostl into table it_anlz_itab from anlz for all entries in it_anla_itab where bukrs eq it_anla_itab-bukrs and anln1 eq it_anla_itab-anln1 and anln2 eq it_anla_itab-anln2 * and bdatu >= sy-datum * and adatu <= sy-datum and kostl in s_kostl. sort it_anlz_itab by bukrs anln1 anln2. *读取资产行项目信息 select bukrs anln1 anln2 gjahr bwasl belnr anbtr lnsan into table it_anep_itab from anep for all entries in it_anla_itab where bukrs eq it_anla_itab-bukrs and anln1 eq it_anla_itab-anln1 and anln2 eq it_anla_itab-anln2 and gjahr eq p_gjahr and afabe eq '1'. sort it_anep_itab by bukrs anln1 anln2. endif. if not it_anlz_itab[] is initial. *读取成本中心描述 select kostl ltext into table it_cskt_itab from cskt for all entries in it_anlz_itab where spras eq sy-langu and kostl eq it_anlz_itab-kostl. endif. if not it_anep_itab[] is initial. loop at it_anep_itab. clear rs_awkey. rs_awkey-sign = 'I'. rs_awkey-option = 'CP'. concatenate it_anep_itab-belnr '*' into rs_awkey-low. append rs_awkey. endloop. *读取资产处理类型文本 select bwasl bwatxt into table it_tabwt_itab from tabwt for all entries in it_anep_itab where spras eq sy-langu and bwasl eq it_anep_itab-bwasl. *读取会计凭证信息 select bukrs belnr gjahr awkey budat into table it_bkpf_itab from bkpf for all entries in it_anep_itab where bukrs eq it_anep_itab-bukrs and gjahr eq it_anep_itab-gjahr and awkey in rs_awkey. *读取会计凭证信息 select bukrs belnr gjahr awkey budat appending table it_bkpf_itab from bkpf for all entries in it_anep_itab where bukrs eq it_anep_itab-bukrs and belnr eq it_anep_itab-belnr and gjahr eq it_anep_itab-gjahr. endif. *将取出的数据组合ALV数据 sort it_ankt_itab by anlkl. sort it_anlz_itab by bukrs anln1 anln2. sort it_cskt_itab by kostl. sort it_tabwt_itab by bwasl. sort it_bkpf_itab by bukrs gjahr belnr. loop at it_anla_itab. clear: wa_anep_line, wa_ankt_line, wa_cskt_line, l_index, wa_anlz_line, wa_tabwt_line, it_output_itab. it_output_itab-bukrs = it_anla_itab-bukrs. it_output_itab-anlkl = it_anla_itab-anlkl. read table it_ankt_itab into wa_ankt_line with key anlkl = it_anla_itab-anlkl binary search. it_output_itab-lbtxk = wa_ankt_line-txk50. it_output_itab-anln1 = it_anla_itab-anln1. it_output_itab-anln2 = it_anla_itab-anln2. it_output_itab-mctxk = it_anla_itab-mctxk. it_output_itab-aktiv = it_anla_itab-aktiv. clear l_index1. read table it_anlz_itab into wa_anlz_line with key bukrs = it_anla_itab-bukrs anln1 = it_anla_itab-anln1 anln2 = it_anla_itab-anln2 binary search. if sy-subrc eq 0. l_index1 = sy-tabix. else. continue. endif. loop at it_anlz_itab into wa_anlz_line from l_index1. if wa_anlz_line-bukrs ne it_anla_itab-bukrs or wa_anlz_line-anln1 ne it_anla_itab-anln1 or wa_anlz_line-anln2 ne it_anla_itab-anln2. exit. endif. clear: it_output_itab-kostl, it_output_itab-adatu, l_index. it_output_itab-kostl = wa_anlz_line-kostl. it_output_itab-adatu = wa_anlz_line-adatu. read table it_cskt_itab into wa_cskt_line with key kostl = wa_anlz_line-kostl binary search. it_output_itab-ltext = wa_cskt_line-ltext. read table it_anep_itab into wa_anep_line with key bukrs = it_anla_itab-bukrs anln1 = it_anla_itab-anln1 anln2 = it_anla_itab-anln2. if sy-subrc ne 0. continue. else. l_index = sy-tabix. loop at it_anep_itab into wa_anep_line from l_index. if wa_anep_line-bukrs ne it_anla_itab-bukrs or wa_anep_line-anln1 ne it_anla_itab-anln1 or wa_anep_line-anln2 ne it_anla_itab-anln2. exit. endif. clear: it_output_itab-bwasl, it_output_itab-bwatxt, it_output_itab-belnr, it_output_itab-budat, it_output_itab-anbtr, it_output_itab-fbflg. it_output_itab-bwasl = wa_anep_line-bwasl. read table it_tabwt_itab into wa_tabwt_line with key bwasl = wa_anep_line-bwasl binary search. it_output_itab-bwatxt = wa_tabwt_line-bwatxt. read table it_bkpf_itab into wa_bkpf_line with key bukrs = wa_anep_line-bukrs gjahr = wa_anep_line-gjahr awkey(10) = wa_anep_line-belnr binary search. if sy-subrc eq 0. it_output_itab-belnr = wa_bkpf_line-belnr. else. it_output_itab-belnr = wa_anep_line-belnr. read table it_bkpf_itab into wa_bkpf_line with key bukrs = wa_anep_line-bukrs gjahr = wa_anep_line-gjahr belnr = wa_anep_line-belnr binary search. endif. if not s_monat is initial. if not wa_bkpf_line-budat+4(2) in s_monat. continue. endif. endif. it_output_itab-budat = wa_bkpf_line-budat. it_output_itab-anbtr = wa_anep_line-anbtr. if not wa_anep_line-lnsan is initial. it_output_itab-fbflg = 'X'. endif. append it_output_itab. endloop. endif. endloop. endloop. endform. " FRM_GET_DATA *&---------------------------------------------------------------------* *& Form FRM_OUT_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_out_data . *ALV数据输出 gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. perform frm_e01_fieldcat_init using : 'BUKRS' '公司代码' 04 '' '' 'X' '' '' '' '' '' '0' '' '', 'ANLKL' '资产类别' 18 '' '' 'X' '' '' '' '' '' '0' '' '', 'LBTXK' '资产类别名称' 20 '' '' 'X' '' '' '' '' '' '0' '' '', 'ANLN1' '资产编号' 06 '' '' 'X' '' '' '' '' '' '0' '' '', 'ANLN2' '资产次级编号' 10 '' '' 'X' '' '' '' '' '' '0' '' '', 'MCTXK' '资产名称' 20 '' '' '' '' '' '' '' '' '0' '' '', 'AKTIV' '资本化日期' 20 '' '' '' '' '' '' '' '' '0' '' '', 'KOSTL' '成本中心' 10 '' '' '' '' '' '' '' '' '0' '' '', 'LTEXT' '成本中心描述' 13 '' '' '' '' '' '' '' '' '0' '' '', 'ADATU' '调拨日期' 13 '' '' '' '' '' '' '' '' '0' '' '', 'BWASL' '业务类型' 06 '' '' '' '' '' '' '' '' '0' '' '', 'BWATXT' '业务类型描述' 10 '' '' '' '' '' '' '' '' '0' '' '', 'BELNR' '凭证编号' 20 '' '' '' '' '' '' '' '' '0' '' '', 'BUDAT' '过账日期' 20 '' '' '' '' '' '' '' '' '0' '' '', 'ANBTR' '记账金额' 10 '' '' '' '' '' '' '' '' '2' '' '', 'FBFLG' '冲销' 13 '' '' '' '' '' '' '' '' '0' '' ''. call function 'REUSE_ALV_GRID_DISPLAY' exporting i_callback_program = sy-cprog it_fieldcat = gt_fieldcat[] is_layout = gs_layout i_save = 'X' tables t_outtab = it_output_itab. endform. " FRM_OUT_DATA *&--------------------------------------------------------------------* *& Form FRM_E01_FIELDCAT_INIT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->FIELD_NAME text * -->FIELD_TEXT text * -->FIELD_LENTHtext * -->FIELD_EDIT text * -->FIELD_TYPE text * -->FIELD_KEY text * -->FIELD_HOTSPtext * -->FIELD_CHECKtext * -->FIELD_NO_ZEtext * -->FIELD_REF_TtextME * -->FIELD_EMPHAtext *---------------------------------------------------------------------* form frm_e01_fieldcat_init using field_name type c field_text type c field_lenth type i field_edit type c field_type type c field_key type c field_hotspot type c field_checkbox type c field_no_zero type c field_ref_tabname type c field_emphasize type c "change cell backgorund color field_decimals_out type c field_do_sum type c field_no_out type c. data: ls_fieldcat type slis_fieldcat_alv. clear ls_fieldcat. col_pos = col_pos + 1. * LS_FIELDCAT-COL_POS = COL_POS. ls_fieldcat-fieldname = field_name. ls_fieldcat-seltext_l = field_text. ls_fieldcat-seltext_m = field_text. ls_fieldcat-seltext_s = field_text. ls_fieldcat-checkbox = field_checkbox. ls_fieldcat-round = 0. ls_fieldcat-edit = field_edit. if field_type = 'Q'. ls_fieldcat-just = 'R'. ls_fieldcat-datatype = 'QUAN'. else. ls_fieldcat-just = 'L'. endif. ls_fieldcat-key = field_key. ls_fieldcat-hotspot = field_hotspot . ls_fieldcat-outputlen = field_lenth. ls_fieldcat-no_zero = field_no_zero. ls_fieldcat-emphasize = field_emphasize . ls_fieldcat-ref_tabname = field_ref_tabname. ls_fieldcat-decimals_out = field_decimals_out. ls_fieldcat-do_sum = field_do_sum. ls_fieldcat-no_out = field_no_out. append ls_fieldcat to gt_fieldcat. *COLOR endform. " frm_e01_fieldcat_init
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18626.html