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

to change variable defaulted values dynamically using field symbol

Former Member
0 Likes
996

Hi Team,

Suppose in my program, I have declared two variables and defaulted values there itself.

data:var_a  type c value 'X',

       var_b  type i value '102.

***********************************************

***********************************************

Now in the middle of program I want ot change the values based on what is present in data base .

In my datbase table the values are like this,

ParameterValue
var_aK
var_b500

I have to fetch teh new values and change the variable var_a and var_b values , and those values are used in later part of my program.

After the change write:var_a, var_2. should print K and 500.

Can anybody help me with  a very small smaple program that does that.

Thanks,

Sourya Prakash.

7 REPLIES 7
Read only

Former Member
0 Likes
913

Hi Prakash

As you have not declared the variables as constants ,you can overwrite the values where ever you want 

just go for a select query on the table .

loop your internal table and overwrite the values .

Read only

Former Member
0 Likes
913

This sample should work for you.

Before running this code, I had created new entry in TVARVC table with TVARVC-NAME = 'VAR_A' and TVARVC-LOW = '54321'.

DATA: var_a TYPE string VALUE '12345',
      lv_varname TYPE string VALUE 'VAR_A'.

FIELD-SYMBOLS <fs> TYPE any.

WRITE:/ var_a.   "12345 value

ASSIGN (lv_varname) TO <fs>.
IF sy-subrc EQ 0.
   SELECT SINGLE low FROM tvarvc INTO <fs> WHERE name EQ lv_varname.
ENDIF.

WRITE:/ var_a.   "54321 value, stored in database table
Read only

0 Likes
913

Excellent Manish !

It solved my problem.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
913

SELECT * FROM yourtable INTO TABLE aninternaltable.
LOOP AT internaltable INTO wa.
   TRY.
       ASSIGN (wa-parameter) TO <fs>.
       <fs> = wa-value.
     CATCH cx_root.
   ENDTRY.
ENDLOOP.

(But I'm really not sure to have understood your purpose ?)

Regards,

Raymond

Read only

Former Member
0 Likes
913

Hi Sourya Prakash,

What is the exact requirement? You want to pick up values of 2 fields and assign them to your local variables?

Regards,

Koushik

Read only

Former Member
0 Likes
913

Hi Chaudhury, you can try this

DATA: var_a TYPE c,

       var_b TYPE i VALUE '102',

       go_ref     TYPE REF TO cx_root,

      gt_ztable TYPE TABLE OF ztable,

      g_text     TYPE string.

FIELD-SYMBOLS: <fs_ztable> TYPE ztable.

                            <fs>            TYPE any.

START-OF-SELECTION.

* Assuming your table is called ZTABLE

SELECT *

  INTO TABLE gt_ztable

    FROM ztable.

LOOP AT gt_ztable ASSIGNING <fs_ztable>.

   ASSIGN (<fs_ztable>-parameter) TO <fs>.

  IF sy-subrc = 0.

     TRY.

       <fs> = <fs_ztable>-value.

    CATCH cx_root INTO go_ref.

      g_text = go_ref->get_text( ).

      WRITE g_text.

    ENDTRY.

  ENDIF.

ENDLOOP.

I hope this helps you

Regard

David Carballido

Read only

0 Likes
913

Thank You David for teh response. It helps.