按照字段目录表的col_pos如何对结构进行排序?

huangapple go评论154阅读模式
英文:

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

按照字段目录表的col_pos如何对结构进行排序?

按照字段目录表的col_pos如何对结构进行排序?

英文:

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
按照字段目录表的col_pos如何对结构进行排序?

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

按照字段目录表的col_pos如何对结构进行排序?

按照字段目录表的col_pos如何对结构进行排序?

答案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: &lt;v_field&gt; 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 &lt;v_field&gt;.
  if sy-subrc = 0.
    concatenate v_concat &lt;v_field&gt; 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.

huangapple
  • 本文由 发表于 2023年5月23日 01:21:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76308585.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定