首页 > 其他分享 >SAP ABAP FICO FAGLL03H CODING BLOCK新增自定义字段

SAP ABAP FICO FAGLL03H CODING BLOCK新增自定义字段

时间:2022-11-15 11:23:35浏览次数:41  
标签:name 自定义 comp CODING abap lv ABAP ls descr

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

相关文章

  • 自定义一个python pip包
    新建一个目录mkdirexample基本说明文件README.rstLICENSEsetup.cfgsetup.pyMANIFEST.indocsexample/README.rst点击查看代码=====example=====Pollsi......
  • 自定义定时器
    自定义定时器#include<iostream>#include<sys/epoll.h>#include<chrono>#include<functional>#include<memory>#include<set>int64_tgid{0};structNodeBa......
  • 【AGC】远程配置如何传入自定义属性
    ​背景:现在AGC远程配置端侧服务提供的SDK支持传入自定义属性获取和更新云端配置数据了。下面将通过一个demo集成远程配置SDK来实现这一功能。 集成准备1.在AGC创建工......
  • 1710. 卡车上的最大单元数 ----- 贪心算法,自定义sort排序
    请你将一些箱子装在一辆卡车上。给你一个二维数组boxTypes,其中boxTypes[i]=[numberOfBoxesi,numberOfUnitsPerBoxi]:numberOfBoxesi是类型i的箱子的数量。numb......
  • JavaScript自定义数据类型判断函数
    functionjudgeType(ele){letres=typeofele;if(res==="object"){//短路表达式,第一个成立则返回第二个的值,第一个不成立,则返回第一个的值......
  • 自定义组件
    创建自定义组件类似于页面,一个自定义组件由jsonwxmlwxssjs4个文件组成。要编写一个自定义组件,首先需要在json文件中进行自定义组件声明(将component字段设为true......
  • 自定义页面
    [Page构造器]Page({/***页面的初始数据*/data:{},/***生命周期函数--监听页面加载*/onLoad:function(e){},/**......
  • 自定义组件传参
    参数声明Component({//参数properties:{//这里定义了innerText属性,属性值可以在组件使用时指定innerText:{type:String,value:'def......
  • 自定义组件事件
    子组件<viewbindtap="onItemChildClick"data-item="item">{{item}}</view>Component({methods:{onItemChildClick(event){this.trigger......
  • 第四十七章 开发自定义标签 - 服务器文档对象模型
    第四十七章开发自定义标签-服务器文档对象模型当CSP编译器处理CSP文档时,它首先查找与规则匹配相关的所有标记。当编译器扫描文档时,它会创建一个与CSP文档中包含的标记......