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 I define variable variant???

Former Member
0 Kudos

Hi experts.

I need to define variable variant. I mean if a user input a count, for example 10, there should be var01, var02, var03 ... var10 or input 5 then var01, var02, ... var05.

Is there any solution??

7 REPLIES 7

Former Member
0 Kudos

Hi,

Could you please explain a little more?

A variant can be configured to have dynamic values for the selection parameters by using the SELECTION VARIABLE option while saving the variant.

Your requirement looks different.

Regards,

Ravi

Former Member
0 Kudos

HI

GOOD

To avoid having to create a new variant each time you use different values, you can use variables in variants.

There are three ways to do this:

Variable date calculations (see also Creating variables for date calculation)

You can use this option when you need to use a date in a variant, for example, today's date, or the last day of the previous month.

User-specific values (see also User-specific selection variables)

You can use this option to enter user-specific values in a selection field.

Values defined in table TVARV (see also Fixed values in table TVARV)

To fill selection fields for a specific task using a variant you can save fixed values in table TVARV. To avoid having to create new variants for each minor change in the selection values, you can assign a value in table TVARV to a selection and then just change this value. This is particularly

GO THROUGH THIS LINK

http://help.sap.com/saphelp_nw04/helpdata/en/c0/980398e58611d194cc00a0c94260a5/content.htm

THANKS

MRUTYUN

0 Kudos

You can do this in the dynamic variant itself.

Please follow these steps

1. Enter the values in the selection screen

2. Save the variant using the SAVE button

3. In the next screen for the date variable select the 'Selection variable' checkbox (L) and click on the button 'Selection variable' in the toolbar.

4. Now you will see this variable in the next screen with 3 types of buttons. Click on the middle button (ie. D - Dynamic date calculation).

5. Click on the down arrow button and select the option 'Current Date'.

6. Save the variant.

Former Member
0 Kudos

Hi.

I think there is some miscommunication between us because of my poor English writing skill :-(.

Well... How can I explain my problem...

there is an value that user can input like 5 or 10. I don't know what number is inputed before runtime. And I need variant as many as the number that user inputed.

If user input 5, then

I need below,

data : var01(2) type c.

data : var02(2) type c.

data : var03(2) type c.

data : var04(2) type c.

data : var05(2) type c.

But, if user input 3, then

data : var01(2) type c.

data : var02(2) type c.

data : var03(2) type c.

Could it be??

Message was edited by: Jung Jongwon

0 Kudos

Hi,

Looks like you want to create variables dynamically. You can do that using CREATE DATA statement. However, you still need to know, how many dynamic variables you would require.

else you will have work with field symbols.

If you can tell, what exactly you are doing with these variable, we can offer a solution.

regards,

Ravi

Note : Please mark the helpful answers

0 Kudos

Thanks Ravi.

I want to use a code belowe

data : t_num(2) type i.

data : t_field(8) type c.

data : t_date type d.

field-symobls <fs> type any.

CONCATENATE 'T_DATE' t_num INTO t_field.

ASSIGN (t_field) TO <fs>.

IF sy-subrc = 0 .

MOVE t_date TO <fs>.

ENDIF.

But, I didn't define variable T_DATEXX. XX means number like 01, 02, 03 ... So, I can't assign (t_field) to <fs>. So, how I can define variable dinamically?

0 Kudos

Hi,

I see your point ...

But unless you know how many fields you want you cannot do this, usually the way it happens is you have specific number of fields in a structure and dynamically you want to deal with a specific field, so the logic here works.

Alright here is a thought, what you can do is to build a internal table dynamically and then a work area structure from that. I am not sure if I am complicating the problem too much here.

Build a field catalog manually depending on the number the user has entered.

If the user enters n

do n times.

concatenate 'var' sy-index into varname.

fcat-fieldname = varname.

...

append fcat

enddo.

Now create a table out of this and then a work area.

Take a look at this weblog, you should get an idea what I am talking about.

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards,

Ravi

Note : Please mark all the helpful answers