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: 

How to create dynamic ON CHANGE statement? Please help!

gopalkrishna_baliga
Participant
0 Kudos
96

Hi Experts,

I have a requirement where my ON CHANGE criteria is dynamic. It is based on wa_charakeyfrmt-value which I am reading from a table. If it is 'DO' then ON CHANGE will have wa_errtabcopy-DO. Else if it is 'LI' then ON CHANGE will have wa_errtabcopy-LI. There will be many cases like this. So instead of writing so many IF/ELSE or SWITCH/CASE conditions is it possible to dynamically create ON CHANGE criteria for the last field. See the example code below:

IF wa_charakeyfrmt-value = 'DO'. "On DO change

LOOP AT i_errtabcopy into wa_errtabcopy

WHERE sold_to = wa_errtab-sold_to.

ON CHANGE OF wa_errtabcopy-key_value

OR wa_errtabcopy-rep_created_date

OR wa_errtabcopy-rep_created_time

OR wa_errtabcopy-rep_counter

OR wa_errtabcopy-DO.

ENDON.

ENDLOOP.

ELSEIF wa_charakeyfrmt-value = 'LI'. "On LI change

LOOP AT i_errtabcopy into wa_errtabcopy

WHERE sold_to = wa_errtab-sold_to.

ON CHANGE OF wa_errtabcopy-key_value

OR wa_errtabcopy-rep_created_date

OR wa_errtabcopy-rep_created_time

OR wa_errtabcopy-rep_counter

OR wa_errtabcopy-LI.

ENDON.

ENDLOOP.

|

Thanks

Gopal

4 REPLIES 4

Former Member
0 Kudos
63

TRY TO USE DO...VARYING...

0 Kudos
63

Hi Anupama,

Can you explain what do you mean?

It will be great if you can give some sample code.

Thanks

Gopal

Former Member
0 Kudos
63

Hi

I dont think there is any dynamic calling of fields using on change of statement. Instead of on change of you can use at new (<field name which you wish to mention>).

Regards

Haritha.

Former Member
0 Kudos
63

DATA: BEGIN OF text,

word1(4) TYPE c VALUE 'This',

word2(4) TYPE c VALUE 'is',

word3(4) TYPE c VALUE 'a',

word4(4) TYPE c VALUE 'loop',

END OF text.

DATA: string1(4) TYPE c, string2(4) TYPE c.

DO 4 TIMES VARYING string1 FROM text-word1 NEXT text-word2.

WRITE string1.

IF string1 = 'is'.

string1 = 'was'.

ENDIF.

ENDDO.

SKIP.

DO 2 TIMES VARYING string1 FROM text-word1 NEXT text-word3

VARYING string2 FROM text-word2 NEXT text-word4.

WRITE: string1, string2.

ENDDO.