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

move data from one internal table to dynamic internal table - column wise

former_member200872
Active Participant
0 Likes
674

Hi abap gurus,

i got two internal tables (one is dynamic).

itab1 has columns f1, f2 ... f8, with column headings in first row.

i.e date in itab looks like :

row1 matnr maktx meins.......

row2 0001 raw kg

row3 002 fert kg

<itab2> is dynamic internal table and has columns col1, col2 ... col8, where data in f1 is to be placed in col4 , f2 into col3 ... and so on

That is the order of f1, f2 .. (in itab1) differs in <itab2>

(Note : colunm names are also different. the relation between the columns of both tables in maintained in other internal table)

How to move data from one internal table to another internal table (dynamic internal table) column wise.

My requirement is that i need to move the data column wise . It is one column data should be moved to dynamic internal table cloumn and so on ...

This is an urgent requirement.

Any suggestions are appreciable and will be rewarded.

With Regards,

Wajid

Hi abap gurus,

i got two internal tables (one is dynamic).

itab1 has columns f1, f2 ... f8, with column headings in first row.

i.e date in itab looks like :

row1 matnr maktx meins.......

row2 0001 raw kg

row3 002 fert kg

<itab2> is dynamic internal table and has columns col1, col2 ... col8, where data in f1 is to be placed in col4 , f2 into col3 ... and so on

That is the order of f1, f2 .. (in itab1) differs in <itab2>

(Note : colunm names are also different. the relation between the columns of both tables in maintained in other internal table)

How to move data from one internal table to another internal table (dynamic internal table) column wise.

My requirement is that i need to move the data column wise . It is one column data should be moved to dynamic internal table cloumn and so on ...

This is an urgent requirement.

Any suggestions are appreciable and will be rewarded.

With Regards,

Wajid

1 REPLY 1
Read only

Former Member
0 Likes
399

Hi,

I think you could find inspiration in following source code example (see "assign component" instruction)

Regards.

David

DATA itTABLE TYPE REF TO data.

DATA stTABLE TYPE REF TO data.

PARAMETERS : P_TABLE TYPE TABNAME OBLIGATORY.

      • Field-symbols

FIELD-SYMBOLS : <TABLE> TYPE STANDARD TABLE,

<TABLE_wa> TYPE ANY,

<field> type any.

....

CREATE DATA itTABLE TYPE STANDARD TABLE OF (P_TABLE).

ASSIGN itTABLE->* TO <TABLE>.

CREATE DATA stTABLE TYPE (P_TABLE).

ASSIGN stTABLE->* TO <TABLE_wa>.

SELECT * FROM (P_TABLE) INTO TABLE <TABLE>.

data : w_file(250).

DATA : w_line type string.

data : w_tab type c.

CONCATENATE ..... into w_file

w_tab = CL_ABAP_CHAR_UTILITIES=>horizontal_tab.

open dataset w_file for output in text mode encoding default.

if sy-subrc ne 0.

message e276(8Z) with w_file.

exit.

endif.

      • GET STRUCTURE

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

LOOP AT IDETAILS INTO XDETAILS.

if sy-tabix = 1.

w_line = XDETAILS-name.

else.

concatenate w_line w_tab XDETAILS-name into w_line.

endif.

ENDLOOP.

transfer w_line to w_file.

clear w_line.

DATA : W_FIELD(23).

loop at <TABLE> assigning <TABLE_wa>.

do.

assign component sy-index

of structure <table_wa> to <field> . if sy-subrc <> 0.

exit.

endif.

READ TABLE IDETAILS INTO XDETAILS INDEX SY-INDEX.

CASE XDETAILS-TYPE_KIND.

WHEN 'P' OR 's' OR 'b' OR 'F' OR 'X' OR 'I'.

W_FIELD = <FIELD>.

if sy-index = 1.

w_line = W_field.

else.

concatenate w_line w_tab W_field into w_line.

endif.

WHEN OTHERS.

if sy-index = 1.

w_line = <field>.

else.

concatenate w_line w_tab <field> into w_line.

endif.

ENDCASE.

enddo.

transfer w_line to w_file.

clear w_line.

ENDLOOP.

close dataset w_file.