2010 Nov 28 11:48 AM
Dear Friends, Requirement: I have used field symbol(F_TABLE) to fetch the data from MARA table dynamically and now during loop statement I want to assign the value of <f_line> to LT_EDIDD-SDATA. I have given the example code below. Could you please tell me how we can do this?
DATA: LT_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <F_TABLE> TYPE ANY TABLE,
<F_LINE> TYPE ANY.
DATA: W_TABNAME TYPE W_TABNAME,
W_DREF TYPE REF TO DATA,
LR_DATA TYPE REF TO DATA.
START-OF-SELECTION.
W_TABNAME = 'MARA'.
CREATE DATA W_DREF TYPE TABLE OF (W_TABNAME).
ASSIGN W_DREF->* TO <F_TABLE>.
SELECT * FROM (W_TABNAME) INTO TABLE <F_TABLE> UP TO 5 ROWS.
LOOP AT <F_TABLE> ASSIGNING <F_LINE>.
LT_EDIDD-SDATA = <F_LINE>. -----------------> Giving dump here
APPEND LT_EDIDD.
ENDLOOP.
2010 Nov 28 1:02 PM
Hi,
1. first of all the field 'SDATA' is not available in the table 'MARA'. That field you are trying to assigning.
2. I changed your code a bit. Please refer the tag "newly added in the below code. Now it will work fine.
DATA: lt_edidd LIKE edidd OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <f_table> TYPE ANY TABLE,
<f_line> TYPE ANY,
<fs_value> TYPE ANY."newly added
DATA : field_name TYPE string."newly added
DATA: w_tabname TYPE w_tabname,
w_dref TYPE REF TO data,
lr_data TYPE REF TO data,
wa_mara TYPE REF TO data."newly added.
START-OF-SELECTION.
w_tabname = 'MARA'.
CREATE DATA w_dref TYPE TABLE OF (w_tabname).
ASSIGN w_dref->* TO <f_table>.
*newly added
CREATE DATA wa_mara LIKE LINE OF <f_table>.
ASSIGN wa_mara->* TO <f_line>.
SELECT * FROM (w_tabname) INTO TABLE <f_table> UP TO 5 ROWS.
LOOP AT <f_table> ASSIGNING <f_line>.
CONCATENATE '<F_LINE>-' 'MATNR' INTO field_name.
ASSIGN (field_name) TO <fs_value>.
WRITE : <fs_value>.
* LT_EDIDD-SDATA = <F_LINE>. -----------------> Giving dump here
* APPEND LT_EDIDD.
ENDLOOP.Please check the same.
Regards,
Anversha
2010 Nov 28 1:45 PM
I think what you want to achieve is populating SDATA field for preparation of IDoc. If so, you need to change the structrured field symbol (of type line of MARA) to character container (flattening it), then move it to SDATA.
DATA g_container_c TYPE c LENGTH 1000.
cl_abap_container_utilities=>fill_container_c(
EXPORTING im_value = <F_LINE>
IMPORTING ex_container = g_container_c ).
"now you should be able to move flatten data
LT_EDIDD-SDATA = g_container_c.
Regards
Marcin
2010 Nov 28 3:35 PM
Hello Marcin,
Now it is not giving any dump and populating the EDIDD-SDATA properly. But now I got another issue, some of the fields in the segment converted to characters like ###########, ###䦌#Ē煤抜R2D HHT etc.
Do you know how we can avoid this. Thanks a lot for your help in advance.
Thanks & Regards,
Nagaraj Kalbavi
2010 Nov 29 4:05 PM
I think the issue lies in fact, that MARA consists both of character fields and quantity ones (packed numbers). The latter cannot be interpreted as a character correctly (as the bytes for P type are stored differently compared to character type fields). That's why you get odd characters while the system tries to convert these bytes. So the solution is to move all non-character fields to character ones. So in fact you would need a target structure consisting of same fields as MARA but each has to be of type C. Then you don't need any further conversions like filling container, because such structure in memory is already interpreted as character sequence (same as g_container_c ).
Anyhow the solution above is cumbersome as you need to define such structure manually. What you should do is to use standard IDoc segments (which are already of character type). Populate them with your data from MARA. The fields in segments should be named the same so you can use move-corresponding approach. Then move this segment to SDATA field. This is a standard approach and requires not much efford when moving data b/w MARA to segments. All you need is to find appropriate MESSAGE TYPE for MARA and use its segments. I believe this should not be a challenge.
Regards
Marcin
2010 Nov 30 4:23 AM
Dear Marcin, Thank you for the input. Even I had a same doubt. I had given it as MARA table but actually I need to use a 35 Ztables whcih created by business for the requirement 3 years back. I thought of doing it dynamically so that no need use any hard code in the program. I could not find a way to do it so I used case statement for each table and moved it data. Also I am using custom IDOC and Message Type for this case. Thanks a lot for your input which could help in future. Thanks & Regards, Nagaraj Kalbavi
2010 Nov 29 5:46 AM
Hi,
Here i modified some code accourding to your requriment i added the code where u r facing the dump once u look at that one.
that field name it must be in a MARA table then only it will be accessible.
DATA: LT_EDIDD LIKE EDIDD OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <F_TABLE> TYPE ANY TABLE,
<F_LINE> TYPE ANY,
<VALUE> TYPE ANY.
DATA: W_TABNAME TYPE W_TABNAME,
W_DREF TYPE REF TO DATA,
LR_DATA TYPE REF TO DATA.
START-OF-SELECTION.
W_TABNAME = 'MARA'.
CREATE DATA W_DREF TYPE TABLE OF (W_TABNAME).
ASSIGN W_DREF->* TO <F_TABLE>.
SELECT * FROM (W_TABNAME) INTO TABLE <F_TABLE> UP TO 5 ROWS.
LOOP AT <F_TABLE> ASSIGNING <F_LINE>.
ASSIGN COMPONENT 'EDATE' OF STRUCTURE <F_LINE TO <value>.
***EDATE IS A FIELD NAME IN PLACE OF EDATE WE CAN PLACE ANY FIELDNAME OR OTHER WISE WE CAN PLACE DYNAMICALLY************
IF sy-subrc = 0 AND <value> IS NOT INITIAL.
LT_EDIDD-SDATA = <value>. "HERE ONLY FIELD VALUE IS ASSING NOT STRUCTURE.
APPEND LT_EDIDD TO LT_EDIDD[].
ENDIF.
ENDLOOP.
thanks,
muralii
2010 Nov 30 4:24 AM
It is not possible to use dynamic as table has got both Character as well Integrer and packed data types.
2010 Nov 30 3:54 PM
2010 Nov 30 3:58 PM