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

How to dynamically find variables based on condition.

Former Member
0 Likes
643

Hi Gurus,

We have a peculiar requirement..

Consider we have below variables.
DATA(lv_c1d1_month) = sy-datum+4(2). "03 - Current month for date 27/03/2019
a)below variables can contain values: 1..12 (similar to above)
we have lv_c1d1_month, lv_c2d2_month, lv_c3d3_month,... lv_c24d24_month.

DATA(lv_c1d1_year) = sy-datum+0(4) . "2019 - Current Year for date 27/03/2019
b) below variables can contain values: 2019 or preceding year. (similar to above)
we have lv_c1d1_year,lv_c2d2_year,lv_c3d3_year, ... lv_c24d24_year.

Case:

Based on certain condition if lv_c4d4_month has the value '12' then we need to set corresponding lv_c4d4_year as preceding year (2018).

Any ideas on how to approach this?

1 ACCEPTED SOLUTION
Read only

ChrisSolomon
Active Contributor
558

Why in the world are you doing this with sooooo many variables?!?!! Why not just make 2 data structures/internal tables and then have them related by index....ie. if table1[03] = 12 then table2[03] = 18 (preceding year). That is WAY more simple to "set" and "get" the right, related fields from each set. Past that, why can't you just store the date in one single data structure (table of dates) and just do your calculation on the fly?

Hi Gurus,

We have a peculiar requirement..

Consider we have below variables.
DATA(lv_c1d1_month) = sy-datum+4(2). "03 - Current month for date 27/03/2019
a)below variables can contain values: 1..12 (similar to above)
we have lv_c1d1_month, lv_c2d2_month, lv_c3d3_month,... lv_c24d24_month.

DATA(lv_c1d1_year) = sy-datum+0(4) . "2019 - Current Year for date 27/03/2019
b) below variables can contain values: 2019 or preceding year. (similar to above)
we have lv_c1d1_year,lv_c2d2_year,lv_c3d3_year, ... lv_c24d24_year.

Case:

Based on certain condition if lv_c4d4_month has the value '12' then we need to set corresponding lv_c4d4_year as preceding year (2018).

Any ideas on how to approach this?

1 REPLY 1
Read only

ChrisSolomon
Active Contributor
559

Why in the world are you doing this with sooooo many variables?!?!! Why not just make 2 data structures/internal tables and then have them related by index....ie. if table1[03] = 12 then table2[03] = 18 (preceding year). That is WAY more simple to "set" and "get" the right, related fields from each set. Past that, why can't you just store the date in one single data structure (table of dates) and just do your calculation on the fly?