Skip to Content
author's profile photo Former Member
Former Member

dynamic columns

Hi all,

Suppose i have this code:

<b>loop at table into line.

....

if line-column1 eq 'something'.

....

endloop.</b>

with that i search if the column line-column1 is equal to 'something', and if it is i do something. That works fine, but now i'm facing a problem.

The column that i need to search may be other of about 60 columns. It's the column i get in a string. For instance:

<b>data: text type string.

text = 'column1'.</b>

Is anyway to somehow get the value of a column by a string? In other words:

- if <b>text='column1'</b> the validation should look as <b>if line-column1 eq 'something'.</b>

- if <b>text='column2'</b> the validation should look as <b>if line-column2 eq 'something'.</b>

If the table had few columns a simple case/when, or even if/else would work, but this is a table with more than 60 columns, so it's an option i'm trying to avoid.

Most likelly i need to store the value of the column i want to search in a string and then use it to compare in IF, but i don't know how.

Some people told me that it might me done with field-symbols and appends, but since i'm kind of newbie in abap world i'm not managing to do that.

Can anyone help me with this?

Thanks in advanced for any help.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Oct 24, 2006 at 02:34 AM

    field-symbols <col> type any.

    loop at table into line.

    assign component (text) of structure line to <col>.

    if <col> eq 'something'.

    ....

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 24, 2006 at 01:44 AM

    Hello Luis

    You are already quite close to the solution to your problem.

    DATA:
      ld_column_1   TYPE string,
      ld_column_2   TYPE string.
    
    FIELD-SYMBOLS:
      <ls_line>     TYPE any,
      <ld_column>   TYPE any.
    
      ld_column_1 = 'COL_1'.  " upper case !!!
      ld_column_2 = 'COL_2'.  " upper case !!!
    
    LOOP AT itab ASSIGNING <ls_line>.
    * First column
      UNASSIGN: <ld_column>.
      ASSIGN COMPONENT (ld_column_1) OF STRUCTURE <ls_line>
        TO <ld_column>.
      IF ( <ld_column> IS ASSIGNED ).
    *   Do something if condition is fulfilled
        IF ( <ld_column> eq 'something' ).
        ...
        ENDIF. 
      ENDIF.
    
    * Second column
      UNASSIGN: <ld_column>.
      ASSIGN COMPONENT (ld_column_2) OF STRUCTURE <ls_line>
        TO <ld_column>.
      IF ( <ld_column> IS ASSIGNED ).
    *   Do something if condition is fulfilled
        IF ( <ld_column> eq 'something' ).
        ...
        ENDIF. 
      ENDIF.  
    
    ENDLOOP.

    Regards

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.