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

type conversions

Former Member
0 Likes
485

Hi Experts,

I have an internal table consiting of 20 fileds(any type) and 100 records

I have another internal table consiting of only 1 field of type string

Now i need to move all the 100 records from first internal table to 2nd internal table

Thanks .

3 REPLIES 3
Read only

Former Member
0 Likes
464

Try this sample code:

DATA: BEGIN OF itab OCCURS 0,
       f1(20) VALUE 'AGJHGJGKLGK',
       f2(20) VALUE 'BGJHGJGKLGK',
       f3(20) VALUE 'CGJHGJGKLGK',
      END OF itab.

DATA: itab1 TYPE TABLE OF string WITH HEADER LINE.

APPEND itab.
APPEND itab.

LOOP AT itab.
  MOVE itab TO itab1.
  APPEND itab1.
ENDLOOP.

Read only

Former Member
0 Likes
464

Hi Karthick,

Try this sample code. This might be helpful to you.

**********************************************************************

types : begin of x_1 ,

f1 type any,

f2 type any,

.

.

.

.

.

.

.

.

.

. f20 type any,

end of x_1.

types : begin of x_2,

S type string,

end of x_2.

data : it_tab1 type standard table of x_1,

wa_tab1 like line of it_tab1,

it_tab2 type standard table of x_2,

wa_tab2 like line of it_tab2.

loop at it_tab1 into wa_tab1.

move wa_tab1-f1 to wa_tab2-s.

append wa_tab2 to it_tab2.

.

.

.

. " Similarly for all the 20 fields.

.

.

endloop.

loop at it_tab2 into wa_tab2.

write:/ wa_tab2-s.

endloop.

**********************************************************************

Hope this is helpful to you. If you need further information, revert back.

Reward all the helpful answers.

Regards

Nagaraj T

Read only

former_member435013
Active Participant
0 Likes
464

Hi,

perhaps the following code will help you:

REPORT test.

DATA:

BEGIN OF f OCCURS 0,

matnr LIKE mara-matnr,

p5(5) TYPE p DECIMALS 2,

datum LIKE sy-datum,

END OF f,

my_str TYPE string.

f-matnr = '000000000000123456'.

f-p5 = '1.75'.

f-datum = sy-datum.

PERFORM move_struc_to_string USING f

CHANGING my_str.

WRITE: my_str.

&----


*& Form MOVE_STRUC_TO_STRING

&----


FORM move_struc_to_string USING struc

CHANGING str.

DATA:

l_oref_structure TYPE REF TO cl_abap_structdescr,

l_fields_table TYPE TABLE OF rfc_fields,

l_field TYPE rfc_fields,

field_str(1024),

tmp_str TYPE string,

fieldname(32),

first_loop_done.

FIELD-SYMBOLS:

<fs>.

l_oref_structure ?= cl_abap_typedescr=>describe_by_data( struc ).

PERFORM build_field_table TABLES l_fields_table

USING l_oref_structure.

LOOP AT l_fields_table INTO l_field.

CONCATENATE 'STRUC-' l_field-fieldname INTO fieldname.

ASSIGN (fieldname) TO <fs>.

WRITE <fs> TO field_str LEFT-JUSTIFIED.

tmp_str = my_str.

IF first_loop_done IS INITIAL.

CONCATENATE tmp_str field_str INTO my_str.

first_loop_done = 'X'.

ELSE.

CONCATENATE tmp_str field_str INTO my_str SEPARATED BY space.

ENDIF.

UNASSIGN <fs>.

ENDLOOP.

ENDFORM. " MOVE_STRUC_TO_STRING

&----


*& Form build_field_table

&----


FORM build_field_table TABLES pc_tab_fields STRUCTURE rfc_fields

USING value(pi_oref_structure)

TYPE REF TO cl_abap_structdescr.

DATA l_tabname TYPE dd02l-tabname.

DATA l_component TYPE abap_compdescr.

DATA l_field TYPE rfc_fields.

DATA l_offset TYPE i.

SEARCH pi_oref_structure->absolute_name FOR '\TYPE='.

IF sy-subrc = 0.

sy-fdpos = sy-fdpos + STRLEN( '\TYPE=' ) .

l_tabname = pi_oref_structure->absolute_name+sy-fdpos.

ELSE.

l_tabname = 'UNKNOWN'.

ENDIF.

CLEAR l_offset.

l_field-tabname = l_tabname.

LOOP AT pi_oref_structure->components INTO l_component.

MOVE-CORRESPONDING l_component TO l_field.

l_field-fieldname = l_component-name.

l_field-exid = l_component-type_kind.

l_field-intlength = l_component-length.

l_field-position = sy-tabix.

l_field-offset = l_offset.

l_offset = l_offset + l_field-intlength.

APPEND l_field TO pc_tab_fields.

ENDLOOP.

ENDFORM. " BUILD_FIELD_TABLE

regards

Walter Habich