Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Move Data from TYPE ANY to SDATA field of internal table

former_member70391
Contributor
0 Kudos
2,728

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.

9 REPLIES 9
Read only

anversha_s
Active Contributor
0 Kudos
1,331

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

Read only

MarcinPciak
Active Contributor
0 Kudos
1,331

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

Read only

0 Kudos
1,331

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

Read only

0 Kudos
1,331

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

Read only

0 Kudos
1,331

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

Read only

Former Member
0 Kudos
1,331

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

Read only

former_member70391
Contributor
0 Kudos
1,331

It is not possible to use dynamic as table has got both Character as well Integrer and packed data types.

Read only

former_member70391
Contributor
0 Kudos
1,331

Re-opening the ticket as got the comment from Matt.

Read only

former_member70391
Contributor
0 Kudos
1,331

Closed