‎2008 Jun 02 10:31 PM
Hi,
I want to declare a char array dynamically.
Example:
data: size type i.
size = 30. "size gets populated from another function module
data:
begin of table1,
STR(size) type c,
end of table1.Can any one please tell me on how to declare the above STR correctly?
Thanks,
Uma
‎2008 Jun 02 10:38 PM
Use type STRING instead of the C.
Based on the input, string will adjust its length.
DATA: BEGIN OF ITAB OCCURS 0,
STR TYPE STRING,
END OF ITAB.
Regards,
Naimesh Patel
‎2008 Jun 02 10:38 PM
Use type STRING instead of the C.
Based on the input, string will adjust its length.
DATA: BEGIN OF ITAB OCCURS 0,
STR TYPE STRING,
END OF ITAB.
Regards,
Naimesh Patel
‎2008 Jun 02 10:43 PM
Hi Naimesh Patel,
Thanks for your reply.
I want char array only, as this char array will input to next function call.
Also, i cannot define a maximum size in char array.
I want to exactly define the variable "size" as char array size.
Thanks,
Uma
‎2008 Jun 02 10:53 PM
This was raja's reply in one of related threads:
here is the code sample.
codeparameters: 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 .[/code]
Regards
Raja
https://forums.sdn.sap.com/click.jspa?searchID=12438498&messageID=2356304
‎2008 Jun 03 4:00 PM
Thank you Aparna.
With this I am able to declare a temp string as below. But I dont know how to use this inside itab.
FIELD-SYMBOLS <tempstr> type c.
describe field <tempstr> length fsize in character mode.Can anyone please help me?
Thanks,
Uma
‎2008 Jun 03 4:13 PM
I think it's easier with a dynamic table
DATA: i_lvc TYPE lvc_t_fcat WITH HEADER LINE,
i_table TYPE REF TO data,
l_style TYPE lvc_fname.
FIELD-SYMBOLS <fs> TYPE table.
PARAMETERS p_lenght TYPE i.
START-OF-SELECTION.
i_lvc-fieldname = 'Varchar'.
i_lvc-inttype = 'C'.
i_lvc-intlen = p_lenght.
APPEND i_lvc.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_lvc[]
IMPORTING
ep_table = i_table
e_style_fname = l_style.
ASSIGN i_table->* TO <fs>.