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

Dynamic Array

Former Member
0 Likes
1,038

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

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
762

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

5 REPLIES 5
Read only

naimesh_patel
Active Contributor
0 Likes
763

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

Read only

0 Likes
762

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

Read only

0 Likes
762

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

Read only

0 Likes
762

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

Read only

0 Likes
762

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>.