Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to sort a structure by the col_pos from a field catalog table?

walkerist
Participant
0 Kudos
270

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?

<code>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, 
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 EIND

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_final-werks x_final-eindt x_final-uzeit x_final-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

<br>

1 ACCEPTED SOLUTION

jens_michaelsen
Participant
211

Try it like this

FIELD-SYMBOLS: <fs_value> TYPE ANY. 
DATA: x_line type STRING. 

DATA: x_value TYPE STRING.
LOOP AT t_fieldcat ASSIGNING FIELD-SYMBOL(<fs_fieldcat>). 
    ASSIGN COMPONENT <fs_fieldcat>-fieldname OF STRUCTURE x_final TO <fs_value>. 

    x_value = <fs_value>. 
    CONCATENATE x_line x_value INTO x_line. 
ENDLOOP. <br>
2 REPLIES 2

jens_michaelsen
Participant
212

Try it like this

FIELD-SYMBOLS: <fs_value> TYPE ANY. 
DATA: x_line type STRING. 

DATA: x_value TYPE STRING.
LOOP AT t_fieldcat ASSIGNING FIELD-SYMBOL(<fs_fieldcat>). 
    ASSIGN COMPONENT <fs_fieldcat>-fieldname OF STRUCTURE x_final TO <fs_value>. 

    x_value = <fs_value>. 
    CONCATENATE x_line x_value INTO x_line. 
ENDLOOP. <br>

0 Kudos
211

But be sure, that you can convert every part of x_final to a string.