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

Dynamically Assign N Length

Former Member
0 Likes
700

Hi All,

I have a requirement for the user to dictate the length of a field. A field in the selection screen would ask for a length (a number) for example 6.

The program would then read this field and use the value 6 to be the length of an internal variable, CTR.

DATA: CTR(4) TYPE N.

CTR's default length is 4, but since the user wants it to be 6, it should be changed.

This is important since this field will be used to split a string into exact number of characters.

Please help.

Thanks,

Kenny

6 REPLIES 6
Read only

athavanraja
Active Contributor
0 Likes
667

here is the code sample.

parameters: size(10) .

data: elem type ref to CL_ABAP_ELEMDESCR .
data: len type i .
data:  dref type ref to data .
field-symbols: <field> type any.

start-of-selection .
len = size .
elem = cl_abap_elemdescr=>get_c( len ).

create data dref type handle elem.

assign dref->* to <field>.

clear len .

describe field <field> length len in character mode .

write:/ len .

Regards

Raja

Read only

0 Likes
667

Hi Durairaj,

Thanks for the reply.

This method doesn't exist though.

cl_abap_elemdescr=>get_c

Please help.

Thanks,

Kenny

Read only

0 Likes
667

which version of SAP you are using?

Raja

Read only

0 Likes
667

4.6B

Thanks.

Read only

0 Likes
667

sorry, the code sample i had given wont work in 4.6B, you need atleast WAS6.20

i dont know how this can be done in 4.6B

Regards

Raja

Read only

Former Member
0 Likes
667

Hi,

Is the program going to be used by various users @ the same time?

If yes then I guess it would be very difficult to do it otherwise if it's going to be used by only one user @ a time then I can give you a very crude way of doing it.

Reply if needed.

Regards

Nishant