04-26-2015 3:34 AM
Hi Gurus,
I have a structure <lw_rtab_wa> with the below fields:
RECNO I(4)
DOC_NUMBER C(10)
S_ORD_ITM N(6)
CH_ON D(8)
CREATEDON D(8)
There is also a field symbol <LT_RTAB> which has the below structure:
RECNO I(4)
DOC_NUMBER C(20)
S_ORD_ITM N(12)
CH_ON D(8)
CREATEDON D(8)
Basically the lengths of DOC_NUMBER & S_ORD_ITM are different. When I use the statement
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <lw_rtab_wa> TO <lt_rtab>.
IF sy-subrc NE 0.
NEW-LINE. " Shift Cursor to next line
EXIT. " EXIT to next work area
ENDIF. " IF sy-subrc NE 0.
ENDDO.
I get the message ASSIGN_TYPE_CONFLICT.
If I just try to use APPEND <LW_RTAB_WA> to <LT_RTAB>, I see that the data in <LT_RTAB> is all clubbed together in the first 3 columns as lengths of DOC_NUMBER & S_ORD_ITM are bigger in <LT_RTAB>.
How do I use the APPEND statement but also make sure that data is split accurately into individual columns and not clubbed together?
Thanks
Arvind
04-26-2015 8:36 AM
I am not going to give you code, but rather the information you need to do this yourself.
<lw_rtab_wa> is a structure - say with structure my_structure
<lt_rtab> is an internal table which has fields with the same name as my_structure but two of them are longer. Let's call the table structure tab_structure.
Now forget all about field symbols.
DATA wa type my_structure,
DATA tab type standard table of tab_structure.
You (I really hope) can see that APPEND wa to tab is going to fail - different structures.
You'd get round that (pre 7.4), like this - again, I really hope that you know this already.
DATA wa type my_structure
DATA tab_wa type tab_structure
DATA tab type standard table of tab_structure
either
MOVE CORRESPONDING wa TO tab_wa.
or
tab_wa-field1 = wa-field1.
tab_wa-field2 = wa-field2.
etc.
followed by
APPEND tab_wa to tab.
Back to field symbols
You've already got most of your solution now to apply the same to field symbols. But you need a work area for the <lt_rtab>. You get that like:
CREATE DATA ref_to_data LIKE LINE OF <lt_rtab>.
FIELD-SYMBOLS <tab_wa>.
ASSIGN ref_to_data->* TO <tab_wa>.
Finally, you really to be very clear about what is happening at each stage and what the data looks like. Read again the ABAP (F1) help on ASSIGN, ASSIGN COMPONENT and APPEND. Think about your data - run your program in debugger and see how the data changes.
04-26-2015 6:58 AM
Hi Arvind,
You can´t assign a componet to a full structure
ASSIGN COMPONENT sy-index OF STRUCTURE <lw_rtab_wa> TO <lt_rtab>.
I don't think you could do what you need in a single statement. There are only 5 fields. Why don't you assign each of them like fields and not structures?
Regards
04-26-2015 7:46 AM
Hello Rodrigo,
The structures are dynamic and the fields keep changing depending on the main program that is being used.
The original statement in the code is below:
APPEND <LW_RTAB_WA> to <LT_RTAB>.
Here what is happening is that the contents of <LW_RTAB_WA> are written together in <LT_RTAB>, for example DOC_NUMBER & S_ORD_ITM data are clubbed together in the DOC_NUMBER field in <LT_RTAB>.
The question basically is, when using an APPEND structure, how do you ensure that the contents of each column in the source is copied into the corresponding column in the target?
Thanks
Arvind
04-26-2015 8:36 AM
I am not going to give you code, but rather the information you need to do this yourself.
<lw_rtab_wa> is a structure - say with structure my_structure
<lt_rtab> is an internal table which has fields with the same name as my_structure but two of them are longer. Let's call the table structure tab_structure.
Now forget all about field symbols.
DATA wa type my_structure,
DATA tab type standard table of tab_structure.
You (I really hope) can see that APPEND wa to tab is going to fail - different structures.
You'd get round that (pre 7.4), like this - again, I really hope that you know this already.
DATA wa type my_structure
DATA tab_wa type tab_structure
DATA tab type standard table of tab_structure
either
MOVE CORRESPONDING wa TO tab_wa.
or
tab_wa-field1 = wa-field1.
tab_wa-field2 = wa-field2.
etc.
followed by
APPEND tab_wa to tab.
Back to field symbols
You've already got most of your solution now to apply the same to field symbols. But you need a work area for the <lt_rtab>. You get that like:
CREATE DATA ref_to_data LIKE LINE OF <lt_rtab>.
FIELD-SYMBOLS <tab_wa>.
ASSIGN ref_to_data->* TO <tab_wa>.
Finally, you really to be very clear about what is happening at each stage and what the data looks like. Read again the ABAP (F1) help on ASSIGN, ASSIGN COMPONENT and APPEND. Think about your data - run your program in debugger and see how the data changes.
04-28-2015 12:01 PM
Hello Matthew,
Thank You very much for your detailed explanation!!. It really helped us in resolving our issue.
Thanks
Arvind