2012 Feb 28 11:08 AM
Hi
i have an internal table with more than 60 fields and i am using COPA tables CE1PL01 to fill my data internal table.
i got all the required data into internal table.
But the final table should have all the fields and all the reference fields which are in rows should be positioned as columns in the final internal table.if the reference field i.e. currency field is empty i should not populate in to final internal table.
i am able to use ASSIGN component to fetch the fields in the main internal table but struck on how to populate them into final internal table?
do (components) times.
ASSIGN COMPONENT SY-TABIX OF of structure WA_DATA TO <FS_dATA>.
enddo.
now my currency fields start from index 30. how should i populate them i.e. append them to my final internal table?
should i move each and every field are is there any other way to work with field symbols in building final internal table?
need some input help
2012 Feb 28 1:07 PM
Hi,
Not sure I understood this properly... you mean you want to transpose all the fields or just part of them (from 30th field) ?
Can you give us a concrete example?
Is it something like:
A B C f1 f2 f3 that should be transposed like:
A B C f1
A B C f2
A B C f3 ?
Kr,
Manu.
Hi,
Not sure I understood this properly... you mean you want to transpose all the fields or just part of them (from 30th field) ?
Can you give us a concrete example?
Is it something like:
A B C f1 f2 f3 that should be transposed like:
A B C f1
A B C f2
A B C f3 ?
Kr,
Manu.
2012 Feb 28 1:07 PM
Hi,
Not sure I understood this properly... you mean you want to transpose all the fields or just part of them (from 30th field) ?
Can you give us a concrete example?
Is it something like:
A B C f1 f2 f3 that should be transposed like:
A B C f1
A B C f2
A B C f3 ?
Kr,
Manu.
2012 Feb 28 1:15 PM
Hi
Yes i want to trasnpose the fields in the way u understood.
if i have A B C D F1 F2 F3...F40
now i want my final table to be like the below
A B C D F1
A B C D F2
.
.
.
A B C D F40.
assign COMPONENT IS PICKING UP THE FIELD BUT NOT ABLE TO UNDERSTAND how to populate in the above manner.
2012 Feb 28 2:20 PM
Hi,
There are probably plenty of ways to do that... here is one of them. I quickly wrote this in a wordpad to give the logic, there can be syntax issues here...
LOOP AT itab ASSIGNING <stab>.
DO 30 TIMES. "Number of components to transpose
l_idx = sy-index + 30. "Offset of component to transpose
ASSIGN COMPONENT l_idx OF STRUCTURE <stab> TO <cfield>.
IF sy-subrc <> 0. EXIT. ENDIF.
IF <cfield> IS NOT INITIAL. "If currency filled, add a new entry in final table
APPEND INITIAL LINE TO gt_final ASSIGNING <ftab>.
<ftab>-cfield = <cfield>. "Populate currency value
DO 30 TIMES. "Populate the non-transposable fields
ASSIGN COMPONENT sy-index OF STRUCTURE <stab> TO <src>.
ASSIGN COMPONENT sy-index OF STRUCTURE <ftab> TO <dst>.
<dest> = <src>.
ENDDO.
ENDIF.
ENDDO.
ENDLOOP.
Cheers,
Manu.
2012 Feb 28 2:29 PM
Hi Manu,
I understood this. i will implement this logic and try to complete my code.
many many thanks
2012 Feb 28 2:41 PM
hi
i am writing my code but struck @ below point.
DO 30 TIMES. "Populate the non-transposable fields
ASSIGN COMPONENT sy-index OF STRUCTURE <stab> TO <src>.
ASSIGN COMPONENT sy-index OF STRUCTURE <ftab> TO <dst>.
<dest> = <src>.
ENDDO.
i didnt understand the logic in the above mentioned line in BOLD.assigning ftab to dst. and <dest> = <src>.
can u please throw some light on tat.
2012 Feb 28 2:48 PM
IF <cfield> IS NOT INITIAL. "If currency filled, add a new entry in final table
APPEND INITIAL LINE TO gt_final ASSIGNING <ftab>.
<ftab>-cfield = <cfield>. "Populate currency value
Here above, a new line is appended to the final table and <ftab> points to that new entry.
...
ASSIGN COMPONENT sy-index OF STRUCTURE <stab> TO <src>.
ASSIGN COMPONENT sy-index OF STRUCTURE <ftab> TO <dst>.
After those statements, <src> points to each field of source table (the 30 first fields actually)
While <dst> points to the corresponding field of the final table.
Then
<dest> = <src>.
simply do the assignemnt between source and destination field.
Remark: if your tables (source and destination) are typed, I guess you could also replace this all part by a move-corresponding....
Kr,
Manu.
Edited by: Manu D'Haeyer on Feb 28, 2012 3:49 PM
2012 Feb 28 2:54 PM
With two typed tables:
LOOP AT itab ASSIGNING <stab>.
DO 30 TIMES. "Number of components to transpose
l_idx = sy-index + 30. "Offset of component to transpose
ASSIGN COMPONENT l_idx OF STRUCTURE <stab> TO <cfield>.
IF sy-subrc 0. EXIT. ENDIF.
IF <cfield> IS NOT INITIAL. "If currency filled, add a new entry in final table
APPEND INITIAL LINE TO gt_final ASSIGNING <ftab>.
MOVE-CORRESPONDING <stab> to <ftab>.
<ftab>-cfield = <cfield>. "Populate currency value
ENDIF.
ENDDO.
ENDLOOP.
2012 Mar 01 11:16 AM
hi
Thanks for the support its working fine. if i need to get the field names dynamically for the assigned currency fields how can i do that?i tried assigning component of a structure with same index to another field symbol object type any but its picking only value. if i need field name how to do?
2012 Mar 01 11:42 AM
Hi,
You could use RTTS classes for that...
Check this:
TYPES: BEGIN OF ty_data, "Your table type definition
f1 TYPE c,
f2 TYPE c,
f3 TYPE c,
END OF ty_data.
DATA: ls_data TYPE ty_data, "Itab work area
lo_sdescr TYPE REF TO cl_abap_structdescr,
ls_abap_compdescr TYPE abap_compdescr,
l_hlp TYPE string.
FIELD-SYMBOLS: <f1> TYPE ANY.
* Sample values
ls_data-f1 = 'A'.
ls_data-f2 = 'B'.
ls_data-f3 = 'C'.
lo_sdescr ?= cl_abap_typedescr=>describe_by_name( 'TY_DATA' ).
LOOP AT lo_sdescr->components INTO ls_abap_compdescr.
ASSIGN COMPONENT ls_abap_compdescr-name OF STRUCTURE ls_data TO <f1>.
WRITE: / ls_abap_compdescr-name, <f1>.
ENDLOOP.
Kr,
Manu.
2012 Feb 28 1:17 PM
Hi,
I had a similar requirment where i had to copy 50 rows of internal table to 50 individual fields.
This is a part of code which may help you,
LOOP AT gwa_nhh_sub_details-trading_per_quant INTO gwa_profile_values.
gv_field_pos = sy-tabix + gc_field_pos. "getting the field name dynamically
ASSIGN COMPONENT gv_field_pos OF STRUCTURE gwa_zted_nhh_submisn TO <fs_profile_values>.
<fs_profile_values> = gwa_profile_values-quantity.
ENDLOOP.
.
Here gc_field_pos is the position of field in the table and in your case 30.
Hope you get hint for your code.
thanks and regards.
Aswath.
2012 Feb 28 2:26 PM
hi
i am still unable to understand hw will i loop my table and move values to final internal table of format mentioned above.
can u show me loopoing the same way?atleast for 2-3 fields?
should i use append to append the values?as field symbols points the address im confused here.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |