10-01-2009 11:07 AM
Hello Friends,
I need to move data from table lt_source ( TYPE well defined) to table lt_target. I know the type of lt_target also but the table type of table lt_target gets defined only at runtime.
Also as both tables have some common fields and MOVE-CORRESPONDING cannot be used. Nonetheless the main issue is assigning any value from lt_source to lt_target.
Regards,
Aayush
10-01-2009 11:15 AM
Hi
U need to use the field-symbols, u should store the name of the field it_source in a internal table and use it for the mapping:
LOOP AT IT_SOURCE.
LOOP AT IT_FIELD.
ASSIGN COMPONENT IT_FIELD-NAME OF STRUCTURE IT_SOURCE TO <FS_SOURCE>.
ASSIGN COMPONENT IT_FIELD-NAME OF STRUCTURE IT_TARGET TO <FS_TARGET>.
IF SY-SUBRC = 0.
<FS_TARGET> = <FS_SOURCE>.
ENDIF.
ENDLOOP.
APPEND IT_TARGET.
ENDLOOP.
Max
10-01-2009 11:31 AM
Hello Max,
Thanks for the quick help but i couldn't understand the code provided by you. I do not know usage of FIELD SYBBOLS yet so please find the code snippet attached and guide me further. Also provide the code where you define field symbols
DATA:
lt_campaigns TYPE ZTESTCAMPAIGN_TAB,
ls_campaigns TYPE ZTESTCAMPAIGN.
*............Some code here which fills lt_campaigns table .................
* Things to be done
* MOVE the contents from lt_campaigns to table CT_DB_DATA
* The TYPE of table CT_DB_DATA is assigned only at runtime
* table CT_DB_DATA is transparent table with table type CRMT_MKTPL_WEC which inturn has line type CRMD_MKTPL_WEC
* Also you can assume that ls_campaigns is a different structure from CRMD_MKTPL_WEC with only some fields common.
* All rows are to be copied from lt_campaign to CT_DB_DATA. Some fields are missing but thats OK
10-01-2009 11:44 AM
Hi
Here u've the solution:
.
table CT_DB_DATA is transparent table with table type CRMT_MKTPL_WEC which inturn has line type CRMD_MKTPL_WEC.
So u know the CT_DB_DATA is like CRMT_MKTPL_WEC having a like like CRMD_MKTPL_WEC.
So u need to declare a variable like CRMD_MKTPL_WEC and transfer it to CT_DB_DATA
Max
10-01-2009 12:01 PM
Hi Max,
Thanks for the prompt reply again. I too understand that i need to loop through the table and assign the data to new structure of TYPE CRMD_MKTPL_WEC. Then i should transfer the structure to CT_DB_DATA. But the issue is i do not know how to transfer the data to CT_DB_DATA. What is the syntax for it ? That is the reason i ask question in this forum. Please let me know the code for assignment which is commented in below snippet. Thanks in advance.
DATA:
lt_campaigns TYPE ZTESTCAMPAIGN_TAB,
ls_campaigns TYPE ZTESTCAMPAIGN,
ls_CT_DB_DATA TYPE CRMD_MKTPL_WEC,
lt_CT_DB_DATA TYPE CRMT_MKTPL_WEC.
*............Some code here which fills lt_campaigns table .................
LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
ls_CT_DB_DATA-APPLICATION = LS_CAMPAIGNS-APPLICAION.
LS_CT_DB_DATA-WCMAVERSION = LS_CAMPAIGNS-VERSION_ID.
*ASSIGNMENT CODE HERE
ENDLOOP.
*ADDITIONAL ASSIGNMENT CODE HERE
Regards,
Aayush
10-01-2009 1:02 PM
Hi
U should show the contest where your code need to be placed, I don't know how the table CT_DB_DATA is, i.e. you need to fill it (because it's empty) or u need to change it.
If you need to fill an empty table, u have to fill a workarea and then append it to CT_DB_DATA
.DATA: lt_campaigns TYPE ZTESTCAMPAIGN_TAB,
ls_campaigns TYPE ZTESTCAMPAIGN,
ls_CT_DB_DATA TYPE CRMD_MKTPL_WEC.
LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
MOVE-CORRESPONDING LS_CAMPAIGNS TO LS_CT_DB_DATA.
APPEND LS_CT_DB_DATA TO CT_DB_DATA.
ENDLOOP.
10-01-2009 1:48 PM
By using field symbols i am getting this error now:
" Data objects in Unicode programs cannot be converted"
DATA:
lt_campaigns TYPE ZTESTCAMPAIGN_TAB,
ls_campaigns TYPE ZTESTCAMPAIGN,
ls_CT_DB_DATA TYPE CRMD_MKTPL_WEC,
lt_CT_DB_DATA TYPE CRMT_MKTPL_WEC.
FIELD-SYMBOLS <fs_ct_db_data> TYPE CRMD_MKTPL_WEC.
ASSIGN LS_CT_DB_DATA TO <FS_CT_DB_DATA>.
*............Some code here which fills lt_campaigns table .................
LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
ls_CT_DB_DATA-APPLICATION = LS_CAMPAIGNS-APPLICAION.
LS_CT_DB_DATA-WCMAVERSION = LS_CAMPAIGNS-VERSION_ID.
<fs_ct_db_data>-APPLICATION = LS_CAMPAIGNS-APPLICAION.
<fs_ct_db_data>-WCMAVERSION = LS_CAMPAIGNS-VERSION_ID.
APPEND <FS_CT_DB_DATA> TO CT_DB_DATA.
ENDLOOP.
10-01-2009 1:51 PM
Hi
Can u give me in which context you're working?
You're in a user-exit, BADI......
What's CT_DB_DATA?
Max
10-01-2009 1:52 PM
10-01-2009 1:59 PM
Hi
U don't need to use the field-symbol, because u know CT_DB_DATA is based on type table CRMT_MKTPL_WEC, and this type is based on CRMD_MKTPL_WEC.
So u need to use a workarea like CRMD_MKTPL_WEC only:
DATA: lt_campaigns TYPE ZTESTCAMPAIGN_TAB,
ls_campaigns TYPE ZTESTCAMPAIGN,
ls_CT_DB_DATA TYPE CRMD_MKTPL_WEC.
Now u need to transfer the data from lt_campaigns to ls_CT_DB_DATA and append it to CT_DB_DATA
LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
ls_CT_DB_DATA-APPLICATION = LS_CAMPAIGNS-APPLICAION.
LS_CT_DB_DATA-WCMAVERSION = LS_CAMPAIGNS-VERSION_ID.
APPEND LS_CT_DB_DATA TO CT_DB_DATA.
ENDLOOP.
The solution above is valid is CT_DB_DATA is define TYPE TABLE
If CT_DB_DATA is defined just like a generic DATA, so TYPE REF TO DATA, in this case u need to use the field-symbols:
DATA: lt_campaigns TYPE ZTESTCAMPAIGN_TAB,
ls_campaigns TYPE ZTESTCAMPAIGN,
ls_CT_DB_DATA TYPE CRMD_MKTPL_WEC.
FIELD-SYMBOLS <CT_DB_DATA_TAB> TYPE TABLE.
ASSIGN CT_DB_DATA->* TO <CT_DB_DATA_TAB>.
LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
ls_CT_DB_DATA-APPLICATION = LS_CAMPAIGNS-APPLICAION.
LS_CT_DB_DATA-WCMAVERSION = LS_CAMPAIGNS-VERSION_ID.
APPEND LS_CT_DB_DATA TO<CT_DB_DATA_TAB>.
ENDLOOP.
How CT_DB_DATA is defined?
Max
10-01-2009 2:08 PM
Dear Max,
As i am syaing from the starting that the TYPE assignment to table CT_DB_DATA happens only at runtime. and yes even if i replace the FIELD-SYMBOL <fs_ct_db_data> with LS_CT_DB_DATA and still it gives the same error.
Data objects in Unicode programs cannot be converted
Best Regards,
Aayush
10-01-2009 2:16 PM
10-01-2009 2:21 PM
10-01-2009 2:23 PM
Ok
And when u've the error:
Data objects in Unicode programs cannot be converted
Max
10-01-2009 2:27 PM
At the append statement in the loop.
APPEND <FS_CT_DB_DATA> TO CT_DB_DATA. or even if i change it to APPEND LS_CT_DB_DATA TO CT_DB_DATA.
10-01-2009 2:33 PM
Just last question (I hope)
You obtain the error at runtime or it's a sintax error
Max
10-01-2009 2:36 PM
10-01-2009 2:46 PM
Uhm
I think that means the following sentence
table CT_DB_DATA is transparent table with table type CRMT_MKTPL_WEC which inturn has line type CRMD_MKTPL_WEC
is not true.
I've tried a code like your and it works fine, no dump.
Can you check the type of CT_DB_DATA by debug?
Anyway I'll give you a code with field-symbol
Max
10-01-2009 2:56 PM
Try to use a code like this:
DATA: LT_CAMPAIGNS TYPE ZTESTCAMPAIGN_TAB,
LS_CAMPAIGNS TYPE ZTESTCAMPAIGN.
DATA: DFIES_TAB TYPE TABLE OF DFIES,
DFIES_WA TYPE DFIES.
DATA DYN_WA TYPE REF TO DATA.
FIELD-SYMBOLS <WA> TYPE ANY.
FIELD-SYMBOLS: <FS_TARGET> TYPE ANY,
<FS_SOURCE> TYPE ANY.
* Create the workarea
CREATE DATA DYN_WA LIKE LINE OF CT_DB_DATA.
ASSIGN DYN_WA->* TO <WA>.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = 'ZTESTCAMPAIGN'
TABLES
DFIES_TAB = DFIES_TAB.
LOOP AT LT_CAMPAIGNS INTO LS_CAMPAIGNS.
CLEAR <WA>.
LOOP AT DFIES_TAB INTO DFIES_WA.
ASSIGN COMPONENT DFIES_WA-FIELDNAME OF STRUCTURE LS_CAMPAIGNS TO <FS_SOURCE>.
ASSIGN COMPONENT DFIES_WA-FIELDNAME OF STRUCTURE <WA> TO <FS_TARGET>.
IF SY-SUBRC = 0.
<FS_TARGET> = <FS_SOURCE>.
ENDIF.
ENDLOOP.
CHACK NOT <WA> IS INITIAL.
APPEND <WA> TO CT_DB_DATA.
ENDLOOP.
Max