2016 Jan 12 7:24 AM
every body,
there is a very interesting thing,i didn't use before.
in a programe,i want to transfer data from a internal table to a dynamic table,and the table tb_data may be diffrent every time,so i coded follow:
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT
IMPORTING
EP_TABLE = DREF.
ASSIGN DREF->* TO <GT_DYN_TABLE>.
ASSIGN COMPONENT 0 OF STRUCTURE TB_DATA[] TO <GT_DYN_TABLE>.
not used work area and assign filed one by one,the <GT_DYN_TABLE> get structure and has all data from TB_DATA.but the <GT_DYN_TABLE> is diffrent with DREF now.
ps,i don't want the table <GT_DYN_TABLE> has the same fileds with tb_data,maybe one field more,is there any solution?
2016 Jan 12 8:49 AM
Hi,
first of all, the answer is yes.
Now for your code-sample. Upto ASSIGN DREF->* TO <GT_DYN_TABLE> everything is fine.
With the next Statement however, you messed it up..
Provided you are on NW 7.4 or later, you could just use
MOVE_CORRESPONDING TB_DATA[] TO <GT_DYN_TABLE>.
BTW. does your TB_DATA really have a headerline? And if so, to what purpose?
Otherwise the brackets [] aren't necessary.
On lower Releases, you'll need at least another set of field-symbols, one for each table.
Then, you can just
LOOP A TB_DATA ASSIGNING <FS1>.
APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.
MOVE-CORRESPONDING <FS1> TO <FS2>.
ENDLOOP.
Or, in case you really have a Header line use:
LOOP AT TB_DATA INTO TB_DATA.
APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.
MOVE-CORRESPONDING TB_DATA TO <GT_DYN_TABLE>.
ENDLOOP.
That should do the trick.
Best regards - Jörg
every body,
there is a very interesting thing,i didn't use before.
in a programe,i want to transfer data from a internal table to a dynamic table,and the table tb_data may be diffrent every time,so i coded follow:
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT
IMPORTING
EP_TABLE = DREF.
ASSIGN DREF->* TO <GT_DYN_TABLE>.
ASSIGN COMPONENT 0 OF STRUCTURE TB_DATA[] TO <GT_DYN_TABLE>.
not used work area and assign filed one by one,the <GT_DYN_TABLE> get structure and has all data from TB_DATA.but the <GT_DYN_TABLE> is diffrent with DREF now.
ps,i don't want the table <GT_DYN_TABLE> has the same fileds with tb_data,maybe one field more,is there any solution?
2016 Jan 12 8:49 AM
Hi,
first of all, the answer is yes.
Now for your code-sample. Upto ASSIGN DREF->* TO <GT_DYN_TABLE> everything is fine.
With the next Statement however, you messed it up..
Provided you are on NW 7.4 or later, you could just use
MOVE_CORRESPONDING TB_DATA[] TO <GT_DYN_TABLE>.
BTW. does your TB_DATA really have a headerline? And if so, to what purpose?
Otherwise the brackets [] aren't necessary.
On lower Releases, you'll need at least another set of field-symbols, one for each table.
Then, you can just
LOOP A TB_DATA ASSIGNING <FS1>.
APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.
MOVE-CORRESPONDING <FS1> TO <FS2>.
ENDLOOP.
Or, in case you really have a Header line use:
LOOP AT TB_DATA INTO TB_DATA.
APPEND INITIAL LINE TO <GT_DYN_TABLE> ASSIGNING <FS2>.
MOVE-CORRESPONDING TB_DATA TO <GT_DYN_TABLE>.
ENDLOOP.
That should do the trick.
Best regards - Jörg
2016 Jan 12 11:23 AM
hi,Jörg
thank you for your response and i will try your suggest later
and the code is a part of a form,because of the tb_data is not static, so i didn't declare the type, like this
FORM ASSIGNDATATODYNTABLE TABLES TB_DATA.
before the form,there is no header line.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |