2013 Jul 18 2:11 PM
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,
| Parameter | Value |
|---|---|
| var_a | K |
| var_b | 500 |
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.
2013 Jul 18 2:25 PM
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 .
2013 Jul 18 3:13 PM
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
2013 Jul 18 8:19 PM
2013 Jul 18 3:21 PM
2013 Jul 18 4:19 PM
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
2013 Jul 18 10:30 PM
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
2013 Jul 19 1:00 PM