‎2009 Sep 03 3:10 PM
Hello,
I have a dynamic internal table and this is my code.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = <FS_DATA>
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
assign <FS_DATA>->* to <FS_1>.
create data NEW_LINE like line of <FS_1>.
assign NEW_LINE->* to <FS_2>.
Now my problem is that i want to populate the internal table <FS_1> without using a loop. Something like populating the work-area <FS_2> one field at a time and then appending it to <FS_1>.
The biggest challenge here is that the fieldnames are not know until runtime. So, i cant use expressions like <FS_2>-field1.
If Field1 is my field name how do i write code to populate the internal table.
Please let me know if you need clarifications. I know that the explanation is not the best.
Thanks in advance
Mz
‎2009 Sep 04 6:50 AM
Hi,
Please use the following links:
Very useful documents which could solve exactly your problem:
Happy Learning!
Thanks and Best Regards,
Suresh
‎2009 Sep 03 5:52 PM
Hi,
The biggest challenge here is that the fieldnames are not know until runtime. So, i cant use expressions like <FS_2>-field1This answers your query. Your dynamic internal table is created during runtime.
It as been declared as <fs> type ANYwhich implies that it doesnt hold any particular structure.
When you try to move values using MOVE-CORRESPONDING in a loop, after assigning the reference through a pointer you would see that in DEBUG mode it will show you <FS_2>-field1 has a value.
But if you try doing some like,
MOVE <fs>-field1 to <FS_2>-field1.It will give you a dump.
As far as I know, I have faced the same issue once and it didnt work out well.
Regards,
Amit
‎2009 Sep 03 6:11 PM
Hi
U've all information about your fields in catalog table, so how to fill the dynamic table should depend on your source where u get the values to be transfered to the table:
LT_FIELDCATALOG.
ASSIGN COMPONENT LT_FIELDCATALOG-FIELDNAME OF STRUCTURE <FS_2> TO <FS_3>.
* Here u need a logic in order to decid how to transfer the information:
CASE LT_FIELDCATALOG-FIELDNAME.
WHEN 'FIELD1'.
SELECT SINGLE * FROM <TABLE> WHERE .......
IF SY-SUBRC EQ 0.
<FS_3> = <TABLE>-FIELD1.
ENDIF.
.......
ENDCASE.
ENDLOOP.
APPEND <FS_2> TO <FS_1>.
Max
‎2009 Sep 04 6:42 AM
Thanks Max and Amit for your replies.
Max,
Your reply is actually very near to my requirement. But my problem is that i am not using select statements to fill up my internal table.
Let me be a bit more precise.
Let TAB be my internal table and WA be my work area (Both dynamic).......
I want to fillup data in my internal table similar to the funcitonality given below.
clear TAB.
do 10 times.
If (condiiton A).
WA-Field1 = 'XYZ'. <--------------------------
else.
WA-Field1 = 'ABC'. <--------------------------------
endif.
append WA to TAB.
enddo.
Here the challenge is that Field1 is not know until runtime. So is there any statement i can use which has the same functionality as the above marked lines.
The Statement Assign Component X of structure Y into Z assigns the field X of a structure Y into the Field Z. I want to do something like the opposite of this.
Maybe a kind of assign Z to component X of structure Y.
Sorry for the confusion created............ but that is exactly how i feel at the moment.
Thanks in advance.
Mz
‎2009 Sep 04 8:14 AM
Hi
My post was a sample only, u can replace the SELECT statament with another statament, but I don't know which is your condition in IF statament.
Maybe a kind of assign Z to component X of structure Y.No U can't, but
ASSIGN COMPONENT X OF STRUCTURE Y TO Z
IF SY-SUBRC EQ 0.
Z = ....
ENDIF.this code line just does what u need: assign the value of Z to the component X of structure Y.
Let's know more information in order to help you
Why do u need a DO cycle?
Max
‎2009 Sep 04 8:32 AM
I don't know if I fully understand the requirement.
Maybe you cna use index to point to component rather than using component name.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>.
Thanks,
Regards,
Mohaiyuddin
‎2009 Sep 04 6:50 AM
Hi,
Please use the following links:
Very useful documents which could solve exactly your problem:
Happy Learning!
Thanks and Best Regards,
Suresh
‎2009 Sep 04 8:40 AM
hi mz,
you should have a look at rtts - run time type services in abap. With special system classes you can get infos about your data types during runtime. As far as I know you can get the structure of dynamic i.e. data types usually you don't know.
(see i.e. cl_abap_typedescr=>describe_by_data().
As far as I understand your problem this is what you need.
Regards,
Jens
‎2009 Sep 04 9:45 AM
Thanks Max and Suresh.....
Suresh, the first document was particularly helpful.
This is my final code.
Data : lt_dyn_table TYPE REF TO data,
lw_dyn_table TYPE REF TO data,
lt_fieldcat type lvc_t_fcat,
lw_fieldcat like line of lt_fieldcat.
field-symbols : <FS_TABLE> type standard table,
<FS_WA> type ANY,
<FS_VARIABLE> type ANY.
clear lt_fieldcat.
lw_fieldcat-fieldname = 'CUST_TEAM'.
lw_fieldcat-inttype = 'C'.
lw_fieldcat-outputlen = '10'.
lw_fieldcat-coltext = 'Customer Team'.
lw_fieldcat-seltext = lw_fieldcat-coltext.
append lw_fieldcat to lt_fieldcat.
lw_fieldcat-fieldname = 'GRP'.
lw_fieldcat-inttype = 'C'.
lw_fieldcat-outputlen = '10'.
lw_fieldcat-coltext = 'Category Group'.
lw_fieldcat-seltext = lw_fieldcat-coltext.
append lw_fieldcat to lt_fieldcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcat
IMPORTING
ep_table = lt_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assign lt_dyn_table->* to <FS_TABLE>.
create data lw_dyn_table like line of <FS_TABLE>.
Assign lw_dyn_table->* to <FS_WA>.
Assign component 'CUST_TEAM' of structure <FS_WA> to <FS_VARIABLE>.
<FS_VARIABLE> = 'Team 1'.
Assign component 'GRP' of structure <FS_WA> to <FS_VARIABLE>.
<FS_VARIABLE> = 'GRP1'.
append <FS_WA> to <FS_TABLE>.