‎2010 Oct 26 1:00 AM
Hi All
I have a following requirement.
1.. I have internal table with 1 text field of length 1000, this is field with data uploaded from text file having data tab seprated
2. I have a dyanamic table in which i have to fill the using the above internal table splited by tab seprated into the corresponding fields of dyanamic table.
please suggest some solution for the above.
thanks
bobby
‎2010 Oct 26 3:21 AM
Hi,
you need to use field symbols to loop over all fields of structure and assign value to each field. Check ABAP documentation for statement ASSIGN COMPONENT.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>.
Cheers
‎2010 Oct 26 11:00 AM
Hi Martin,
But How to assign to dyanmic table fields if we are using
split t_intab at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into .
where t_intab has 1 field of lenth say 1000 in which data stored is tab seprated.
please find below my code, please check loop at t_intab
FUNCTION Z_TEXT.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(I_EXPTABLE) TYPE LVC_T_FCAT
*" VALUE(I_DELIMETER) TYPE C DEFAULT 'T'
*" TABLES
*" T_INTAB
*" T_OUTTAB
*"----
Data declarations
DATA:
dtab TYPE REF TO data,
newstr2 TYPE REF TO cl_abap_typedescr,
tab_type1 TYPE REF TO cl_abap_tabledescr,
lref_ditab TYPE REF TO data,
lref_new_line TYPE REF TO data.
Field-Symbols declarations
FIELD-SYMBOLS:
<fs_dyn_tab1> TYPE ANY TABLE,
<fs_dyn_wa> TYPE ANY,
<fs> type any.
Create dynamic table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_exptable
IMPORTING
ep_table = lref_ditab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assign the dynamic table reference to a field-symbol
ASSIGN lref_ditab->* TO <fs_dyn_tab1>.
Create a structure similar to the dynamic table created
CREATE DATA lref_new_line LIKE LINE OF <fs_dyn_tab1>.
ASSIGN lref_new_line->* TO <fs_dyn_wa>.
loop at t_intab.
if I_DELIMETER = 'T'.
split t_intab at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into .
endif.
endloop.
ENDFUNCTION.
thanks
bobby
‎2010 Oct 26 12:40 PM
Refer this code. In the below code i have a fixed structure i_po_t. Its not dynamic.
In you case you have to use assign component for the target structure and then append it to dynaic internal table.
DO.
CLEAR wf_string.
READ DATASET pu_path INTO wf_string.
IF sy-subrc IS NOT INITIAL.
IF sy-index EQ 1.
MESSAGE s904 WITH 'No records in file to reprocess'(036)
DISPLAY LIKE 'E'.
wf_flag = abap_true.
CLOSE DATASET pu_path.
EXIT.
ELSE. "End of File
CLOSE DATASET pu_path.
EXIT.
ENDIF.
ENDIF.
CLEAR i_tab[]. "<--from here
SPLIT wf_string AT
cl_abap_char_utilities=>horizontal_tab
INTO TABLE i_tab.
LOOP AT i_tab ASSIGNING <fs_line>.
ASSIGN COMPONENT sy-tabix OF STRUCTURE wa_po TO <fs_comp>.
IF sy-subrc IS NOT INITIAL.
EXIT.
ELSE.
IF sy-tabix = '3'.
PERFORM conv_alpha_inp USING <fs_line>
CHANGING <fs_comp>.
ELSE.
<fs_comp> = <fs_line>.
ENDIF.
ENDIF.
ENDLOOP.
APPEND wa_po TO i_po_t.
CLEAR wa_po.
ENDDO.
‎2010 Oct 27 1:22 AM
Hi Keshav,
Could you please help me as I am having internal table with following structure
begin of t_intab occurs 0,
text(1000) type c,
end of t_intab
the data in the above structure is tab seprated. Therfore I have to fill the data from above internal table to the dyanamic table created in the above program in my thread. for that I have to loop at t_intab and inside it i have to split the row at tab and assign the data to field in dyanamic table . Therfore to do this what should I do, please help me.
thanks
bobby
‎2010 Oct 27 9:02 AM
Hi,
what i could suggest based on ur codes is;
1. split data from t_intab into another itab1.
2. loop at itab1 to get the full it_fieldcatalog
3. create dynamic itab2 based on it_fieldcatalog.
4. declare wa based on it_fieldcatalog.
5. to fill up the dynamic table, loop at itab1 again and assign the value into each column created. you might want to use do...endo statement here.
i dont have actual codes with me now, but hopefully these pseudo code would help..
‎2010 Oct 27 3:18 PM
Use this logic as your example
loop at t_intab into wa_inttab.
SPLIT wa_inttab-text AT
cl_abap_char_utilities=>horizontal_tab
INTO TABLE i_tab.
LOOP AT i_tab ASSIGNING <fs_line>.
ASSIGN COMPONENT sy-tabix OF STRUCTURE <fs_dyn_wa> TO <fs_comp>.
IF sy-subrc IS NOT INITIAL.
EXIT.
ELSE.
<fs_comp> = <fs_line>.
ENDIF.
AT LAST.
append <fs_dyn_wa> to <fs_dyn_tab1>.
ENDAT.
ENDLOOP.
endloop.