1、SGLPOS_N_GL_CT、SGLPOS_N_CT两个结构新增自定义字段
2、执行t-code:HDBVIEWS
3、实施增强 FAGL_LIB
4、使用select data方法
5、代码示例:
method IF_FAGL_LIB~SELECT_DATA.FIELD-SYMBOLS: <fs> TYPE any.FIELD-SYMBOLS <ls_data> TYPE any.FIELD-SYMBOLS <ld_data> TYPE any.DATA: ls_component LIKE LINE OF it_component.DATA lr_data TYPE REF TO data.DATA lo_descr TYPE REF TO cl_abap_typedescr.DATA lo_str_descr_in TYPE REF TO cl_abap_structdescr.DATA ls_abap_comp_descr TYPE abap_compdescr.DATA: lv_id TYPE c LENGTH 50,lv_name TYPE c LENGTH 200.CREATE DATA lr_data LIKE LINE OF ct_data.ASSIGN lr_data->* TO <ls_data>.* Get structure description of data tableCALL METHOD cl_abap_structdescr=>describe_by_dataEXPORTINGp_data = <ls_data>RECEIVINGp_descr_ref = lo_descr.lo_str_descr_in ?= lo_descr.LOOP AT ct_data ASSIGNING <ls_data>.* Go over the components of the structureLOOP AT lo_str_descr_in->componentsINTO ls_abap_comp_descr."贷款银行CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZBAK'."贷款银行代码ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztfi_zbak_helpt WHERE banka = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZEBANK'."贷款银行名称ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."政府补助CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZBZTYPE'."政府补助项目ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztfi_zbztyp_helt WHERE zzbztype = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZBZNAME'."政府补助项目名称ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."现金流量码CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZCASHFLOW'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztficashflowt WHERE zzcashflow = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZCASHNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."在建工程公告项目CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZDWGGXM'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztfi0076t WHERE zzdwggxm = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZGGXMNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."费用类型CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZEXPTYPE'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztfi0078t WHERE zzexptype = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZFYLXNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."附加成本中心CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZKOSTL'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE ltext INTO lv_name FROM cskt WHERE kostl = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZKOSTLNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."附加客户CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZKUNNR'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE name1,name2 INTO (@DATA(lv_name1),@DATA(lv_name2)) FROM kna1 WHERE kunnr = @lv_id.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZKUNNRNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name1 && lv_name2.ENDIF.ENDIF."附加供应商CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZLIFNR'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE name1,name2 INTO (@DATA(lv_name3),@DATA(lv_name4)) FROM lfa1 WHERE lifnr = @lv_id.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZLIFNRNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name3 && lv_name4.ENDIF.ENDIF."摊销费用类型文本CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZSHARE'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztfi0001t WHERE zzshare = lv_id AND spras = sy-langu.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZEFYLXNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."投资文号CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZTZWH'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE zzktext INTO lv_name FROM ztfi_aux_tzwh WHERE zzplantcp = lv_id.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZKTEXT'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."国家专项CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZXMBH'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE xmmc INTO lv_name FROM ztfi0010 WHERE xmbh = lv_id.IF sy-subrc = 0.ls_abap_comp_descr-name = 'XMMC'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF."变动原因CLEAR:lv_id,lv_name.IF ls_abap_comp_descr-name = 'ZZYWLX'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.lv_id = <ld_data>.SELECT SINGLE txt50 INTO lv_name FROM ztfi0077t WHERE zzywlx = lv_id.IF sy-subrc = 0.ls_abap_comp_descr-name = 'ZZBDYZNAME'.ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>.IF sy-subrc NE 0.EXIT.ENDIF.<ld_data> = lv_name.ENDIF.ENDIF.ENDLOOP.ENDLOOP.endmethod.