1、SGLPOS_N_GL_CT、SGLPOS_N_CT两个结构新增自定义字段
2、执行t-code:HDBVIEWS
3、实施增强 FAGL_LIB
4、使用select data方法
5、代码示例:
1 method IF_FAGL_LIB~SELECT_DATA. 2 FIELD-SYMBOLS: <fs> TYPE any. 3 FIELD-SYMBOLS <ls_data> TYPE any. 4 FIELD-SYMBOLS <ld_data> TYPE any. 5 6 DATA: ls_component LIKE LINE OF it_component. 7 DATA lr_data TYPE REF TO data. 8 DATA lo_descr TYPE REF TO cl_abap_typedescr. 9 DATA lo_str_descr_in TYPE REF TO cl_abap_structdescr. 10 DATA ls_abap_comp_descr TYPE abap_compdescr. 11 12 DATA: lv_id TYPE c LENGTH 50, 13 lv_name TYPE c LENGTH 200. 14 15 CREATE DATA lr_data LIKE LINE OF ct_data. 16 ASSIGN lr_data->* TO <ls_data>. 17 18 * Get structure description of data table 19 CALL METHOD cl_abap_structdescr=>describe_by_data 20 EXPORTING 21 p_data = <ls_data> 22 RECEIVING 23 p_descr_ref = lo_descr. 24 25 lo_str_descr_in ?= lo_descr. 26 27 LOOP AT ct_data ASSIGNING <ls_data>. 28 29 * Go over the components of the structure 30 LOOP AT lo_str_descr_in->components 31 INTO ls_abap_comp_descr. 32 "贷款银行 33 CLEAR:lv_id,lv_name. 34 IF ls_abap_comp_descr-name = 'ZZBAK'."贷款银行代码 35 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 36 IF sy-subrc NE 0. 37 EXIT. 38 ENDIF. 39 lv_id = <ld_data>. 40 SELECT SINGLE txt50 INTO lv_name FROM ztfi_zbak_helpt WHERE banka = lv_id AND spras = sy-langu. 41 IF sy-subrc = 0. 42 ls_abap_comp_descr-name = 'ZZEBANK'."贷款银行名称 43 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 44 IF sy-subrc NE 0. 45 EXIT. 46 ENDIF. 47 <ld_data> = lv_name. 48 ENDIF. 49 ENDIF. 50 "政府补助 51 CLEAR:lv_id,lv_name. 52 IF ls_abap_comp_descr-name = 'ZZBZTYPE'."政府补助项目 53 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 54 IF sy-subrc NE 0. 55 EXIT. 56 ENDIF. 57 lv_id = <ld_data>. 58 SELECT SINGLE txt50 INTO lv_name FROM ztfi_zbztyp_helt WHERE zzbztype = lv_id AND spras = sy-langu. 59 IF sy-subrc = 0. 60 ls_abap_comp_descr-name = 'ZZBZNAME'."政府补助项目名称 61 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 62 IF sy-subrc NE 0. 63 EXIT. 64 ENDIF. 65 <ld_data> = lv_name. 66 ENDIF. 67 ENDIF. 68 "现金流量码 69 CLEAR:lv_id,lv_name. 70 IF ls_abap_comp_descr-name = 'ZZCASHFLOW'. 71 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 72 IF sy-subrc NE 0. 73 EXIT. 74 ENDIF. 75 lv_id = <ld_data>. 76 SELECT SINGLE txt50 INTO lv_name FROM ztficashflowt WHERE zzcashflow = lv_id AND spras = sy-langu. 77 IF sy-subrc = 0. 78 ls_abap_comp_descr-name = 'ZZCASHNAME'. 79 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 80 IF sy-subrc NE 0. 81 EXIT. 82 ENDIF. 83 <ld_data> = lv_name. 84 ENDIF. 85 ENDIF. 86 "在建工程公告项目 87 CLEAR:lv_id,lv_name. 88 IF ls_abap_comp_descr-name = 'ZZDWGGXM'. 89 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 90 IF sy-subrc NE 0. 91 EXIT. 92 ENDIF. 93 lv_id = <ld_data>. 94 SELECT SINGLE txt50 INTO lv_name FROM ztfi0076t WHERE zzdwggxm = lv_id AND spras = sy-langu. 95 IF sy-subrc = 0. 96 ls_abap_comp_descr-name = 'ZZGGXMNAME'. 97 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 98 IF sy-subrc NE 0. 99 EXIT. 100 ENDIF. 101 <ld_data> = lv_name. 102 ENDIF. 103 ENDIF. 104 "费用类型 105 CLEAR:lv_id,lv_name. 106 IF ls_abap_comp_descr-name = 'ZZEXPTYPE'. 107 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 108 IF sy-subrc NE 0. 109 EXIT. 110 ENDIF. 111 lv_id = <ld_data>. 112 SELECT SINGLE txt50 INTO lv_name FROM ztfi0078t WHERE zzexptype = lv_id AND spras = sy-langu. 113 IF sy-subrc = 0. 114 ls_abap_comp_descr-name = 'ZZFYLXNAME'. 115 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 116 IF sy-subrc NE 0. 117 EXIT. 118 ENDIF. 119 <ld_data> = lv_name. 120 ENDIF. 121 ENDIF. 122 "附加成本中心 123 CLEAR:lv_id,lv_name. 124 IF ls_abap_comp_descr-name = 'ZZKOSTL'. 125 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 126 IF sy-subrc NE 0. 127 EXIT. 128 ENDIF. 129 lv_id = <ld_data>. 130 SELECT SINGLE ltext INTO lv_name FROM cskt WHERE kostl = lv_id AND spras = sy-langu. 131 IF sy-subrc = 0. 132 ls_abap_comp_descr-name = 'ZZKOSTLNAME'. 133 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 134 IF sy-subrc NE 0. 135 EXIT. 136 ENDIF. 137 <ld_data> = lv_name. 138 ENDIF. 139 ENDIF. 140 "附加客户 141 CLEAR:lv_id,lv_name. 142 IF ls_abap_comp_descr-name = 'ZZKUNNR'. 143 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 144 IF sy-subrc NE 0. 145 EXIT. 146 ENDIF. 147 lv_id = <ld_data>. 148 SELECT SINGLE name1,name2 INTO (@DATA(lv_name1),@DATA(lv_name2)) FROM kna1 WHERE kunnr = @lv_id. 149 IF sy-subrc = 0. 150 ls_abap_comp_descr-name = 'ZZKUNNRNAME'. 151 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 152 IF sy-subrc NE 0. 153 EXIT. 154 ENDIF. 155 <ld_data> = lv_name1 && lv_name2. 156 ENDIF. 157 ENDIF. 158 "附加供应商 159 CLEAR:lv_id,lv_name. 160 IF ls_abap_comp_descr-name = 'ZZLIFNR'. 161 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 162 IF sy-subrc NE 0. 163 EXIT. 164 ENDIF. 165 lv_id = <ld_data>. 166 SELECT SINGLE name1,name2 INTO (@DATA(lv_name3),@DATA(lv_name4)) FROM lfa1 WHERE lifnr = @lv_id. 167 IF sy-subrc = 0. 168 ls_abap_comp_descr-name = 'ZZLIFNRNAME'. 169 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 170 IF sy-subrc NE 0. 171 EXIT. 172 ENDIF. 173 <ld_data> = lv_name3 && lv_name4. 174 ENDIF. 175 ENDIF. 176 "摊销费用类型文本 177 CLEAR:lv_id,lv_name. 178 IF ls_abap_comp_descr-name = 'ZZSHARE'. 179 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 180 IF sy-subrc NE 0. 181 EXIT. 182 ENDIF. 183 lv_id = <ld_data>. 184 SELECT SINGLE txt50 INTO lv_name FROM ztfi0001t WHERE zzshare = lv_id AND spras = sy-langu. 185 IF sy-subrc = 0. 186 ls_abap_comp_descr-name = 'ZZEFYLXNAME'. 187 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 188 IF sy-subrc NE 0. 189 EXIT. 190 ENDIF. 191 <ld_data> = lv_name. 192 ENDIF. 193 ENDIF. 194 "投资文号 195 CLEAR:lv_id,lv_name. 196 IF ls_abap_comp_descr-name = 'ZZTZWH'. 197 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 198 IF sy-subrc NE 0. 199 EXIT. 200 ENDIF. 201 lv_id = <ld_data>. 202 SELECT SINGLE zzktext INTO lv_name FROM ztfi_aux_tzwh WHERE zzplantcp = lv_id. 203 IF sy-subrc = 0. 204 ls_abap_comp_descr-name = 'ZZKTEXT'. 205 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 206 IF sy-subrc NE 0. 207 EXIT. 208 ENDIF. 209 <ld_data> = lv_name. 210 ENDIF. 211 ENDIF. 212 "国家专项 213 CLEAR:lv_id,lv_name. 214 IF ls_abap_comp_descr-name = 'ZZXMBH'. 215 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 216 IF sy-subrc NE 0. 217 EXIT. 218 ENDIF. 219 lv_id = <ld_data>. 220 SELECT SINGLE xmmc INTO lv_name FROM ztfi0010 WHERE xmbh = lv_id. 221 IF sy-subrc = 0. 222 ls_abap_comp_descr-name = 'XMMC'. 223 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 224 IF sy-subrc NE 0. 225 EXIT. 226 ENDIF. 227 <ld_data> = lv_name. 228 ENDIF. 229 ENDIF. 230 "变动原因 231 CLEAR:lv_id,lv_name. 232 IF ls_abap_comp_descr-name = 'ZZYWLX'. 233 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 234 IF sy-subrc NE 0. 235 EXIT. 236 ENDIF. 237 lv_id = <ld_data>. 238 SELECT SINGLE txt50 INTO lv_name FROM ztfi0077t WHERE zzywlx = lv_id. 239 IF sy-subrc = 0. 240 ls_abap_comp_descr-name = 'ZZBDYZNAME'. 241 ASSIGN COMPONENT ls_abap_comp_descr-name OF STRUCTURE <ls_data> TO <ld_data>. 242 IF sy-subrc NE 0. 243 EXIT. 244 ENDIF. 245 <ld_data> = lv_name. 246 ENDIF. 247 ENDIF. 248 249 250 ENDLOOP. 251 252 ENDLOOP. 253 endmethod.View Code
标签:name,自定义,comp,CODING,abap,lv,ABAP,ls,descr From: https://www.cnblogs.com/coderfarmer/p/16891768.html