Application Development and Automation 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: 
Read only

Component names via ( string )

Former Member
0 Likes
1,544

Hello Everybody!

I had a similar question previously about calling a column name based on a string placing a variable inbetween ( ) when using SQL queries.

However, I'm trying to call the name of a variable and component based on a string. When I try doing:

var1 = var2-(varColumn)

I get a dump saying var2 has no component named ''.

I've also tried to do the entire variable name, like:


column_name = '-c1'.
variable_name='whatever'.

CONCATENATE variable_name column_name INTO total_name.
var1 = (total_name).

This doesn't compile, and if I activate and try to run the program anyway I get an error over an non-exsistant variable.

My searches across google and here aren't really producing great results. Is doing it this way even possible?

Thanks for the help!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,247

You need to use field symbols like this;

  • 1. First declare the field symbol

FIELD-SYMBOLS <fs> like var2-col2.

*2 Now dynamically assign the column

ASSIGN COMPONENT 'COL2' OF STRUCTURE var2 to <fs>.

*<fs> now has the value var2-col2

6 REPLIES 6
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,247

Hello Bryan,

Are you trying to SELECT data using "dynamic" columns? Did you check the F1 help or the online documentation? [http://help.sap.com/abapdocu_702/en/abapselect_clause_cols.htm#!ABAP_ALTERNATIVE_3@3@]

BR,

Suhas

Read only

Former Member
0 Likes
1,247

Hey Suhas,

No, I've already gotten that one figured out.


  UPDATE (table_name)
    SET (column_name)
    WHERE LETTER = row.

I have a structure and a lengthy CASE block, for example:


  CASE column.
    WHEN 1.
      char = lc_board_s-c1.
    WHEN 2.
      char = lc_board_s-c2.
              ...
    WHEN 10.
      char = lc_board_s-c10.
  ENDCASE.

The SQL has query has been executed by this point. I just want to be able to call the component of the structure variably, so I can reduce the block to (psuedocoding).


   character = structure-(variable_component_name).

Read only

0 Likes
1,247

Check F1 help of ASSIGN COMPONENT

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,247

Hello Bryan,

Is this what you're looking for:

FIELD-SYMBOLS <val> TYPE ANY.

WHILE sy-subrc = 0.
  ASSIGN COMPONENT sy-index OF STRUCTURE wa TO <val>.
  CHECK <val> IS ASSIGNED.
  WRITE: / <val>.
  UNASSIGN <val>.
ENDWHILE.

BR,

Suhas

Read only

Former Member
0 Likes
1,248

You need to use field symbols like this;

  • 1. First declare the field symbol

FIELD-SYMBOLS <fs> like var2-col2.

*2 Now dynamically assign the column

ASSIGN COMPONENT 'COL2' OF STRUCTURE var2 to <fs>.

*<fs> now has the value var2-col2

Read only

Former Member
0 Likes
1,247

Thanks everybody! That's exactly what I was looking for. I was trying to search google and the forums here but wasn't sure what the proper term was for it.

Thanks!