英文:
How to sort a structure according to col_pos of field catalog table?
问题
Is it possible that X_FINAL-EINDT will be concatenated first instead of X_FINAL-WERKS? Is there a way to do it without hard coding the field names?
DATA: begin of t_final,
werks like ekpo-werks,
eindt like ekes-eindt,
uzeit like ekes-uzeit,
slfdt TYPE eket-slfdt,
ekgrp like ekko-ekgrp,
buyer(18) type c,
mtart TYPE mara-mtart,
wrkst like mara-wrkst,
raube TYPE mara-raube,
tempb TYPE mara-tempb,
profl like mara-profl,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
matnr like ekpo-matnr,
maktx like makt-maktx,
END of t_final.
DATA: t_fieldcat TYPE slis_fieldcat_alv,
x_final LIKE LINE OF t_final.
IN T_FIELDCAT, the first column is EINDT.
While in T_FINAL and X_FINAL, the first column is WERKS.
Is it possible or useful to align the sorting order of t_final from t_fieldcat?
The reason I'm asking is because X_FINAL is being used in a CONCATENATE code:
CONCATENATE
x_final2-werks x_final2-eindt x_final2-uzeit x_final2-ekgrp
Instead of WERKS always being the first to be concatenated, I want to concatenate the first field according to COL_POS from T_FIELDCAT.
Example:
T_FIELDCAT-FIELDNAME: EIDNT
T_FIELDCAT-COL_POS: 1
T_FIELDCAT-FIELDNAME: WERKS
T_FIELDCAT-COL_POS: 2
The problem with the code below is that sometimes EIDNT has a COL_POS of 1, but sometimes it has a value like 15. Can I concatenate without hard coding?
CONCATENATE
X_FINAL-EIDNT X_FINAL-WERKS
英文:
Is it possible that the X_FINAL-EINDT will be concatenated first instead of X_FINAL-WERKS? Is there a way to it without hard coding the field names?
DATA: begin of t_final,
werks like ekpo-werks,
eindt like ekes-eindt,
uzeit like ekes-uzeit,
slfdt TYPE eket-slfdt,
ekgrp like ekko-ekgrp,
buyer(18) type c,
mtart TYPE mara-mtart,
wrkst like mara-wrkst,
raube TYPE mara-raube,
tempb TYPE mara-tempb,
profl like mara-profl,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
matnr like ekpo-matnr,
maktx like makt-maktx,
END of t_final.
DATA: t_fieldcat TYPE slis_fieldcat_alv,
x_final LIKE LINE OF t_final.
IN T_FIELDCAT, the first column is EINDT
WHile in the T_FINAL and X_FINAL, the first column is WERKS.
Is it possible or useful to align the sorting orber of t_final from t_fieldcat?
The reason I'm asking because the X_FINAL is being used in a CONCATENATE code:
CONCATENATE
x_final2-werks x_final2-eindt x_final2-uzeit x_final2-ekgrp
Instead of WERKS being always the first to be concatenated, I want to concatenate the first field according to COL_POS from T_FIELDCAT.
Example:
T_FIELDCAT-FIELDNAME: EIDNT
T_FIELDCAT-COL_POS: 1
T_FIELDCAT-FIELDNAME: WERKS
T_FIELDCAT-COL_POS: 2
The problem with the code below is sometimes the EIDNT has a col_pos of 1 but sometimes it has a value of like 15. can I concatenate without hard coding?
CONCATENATE
X_FINAL-EIDNT X_FINAL-WERKS
答案1
得分: 1
你可以按col_pos对fieldcatalog进行排序,然后循环处理它。在循环中,将结构t_final中的字段与fieldcatalog中的字段名分配给一个字段符号,并连接到需要的变量中。类似这样的代码:
field-symbols: <v_field> type any.
data: v_concat type string.
sort t_fieldcat by col_pos.
loop at t_fieldcat into s_fieldcat.
assign component s_fieldcat-fieldname of structure t_final to <v_field>.
if sy-subrc = 0.
concatenate v_concat <v_field> into v_concat.
endif.
endloop.
可能需要将字段符号写入charlike变量,以确保连接始终正常工作,并根据需要压缩结果。
英文:
You could sort the fieldcatalog by col_pos and loop over it. In the loop you assign the field in the structure t_final with the name from the fieldcatalog to a field-symbol and concatenate into the variable you need it to be in. Something like this:
field-symbols: <v_field> type any.
data: v_concat type string.
sort t_fieldcat by col_pos.
loop at t_fieldcat into s_fieldcat.
assign component s_fieldcat-fieldname of structure t_final to <v_field>.
if sy-subrc = 0.
concatenate v_concat <v_field> into v_concat.
endif.
endloop.
You might have to write the field-symbol into a charlike variable to get the concatenate to work properly all the time and also condense the results as needed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论