2012 Oct 23 3:22 PM
hi guru,
I need to creatre a abap program (SAP CRM) that allows me to load all the tables (obviously one at a time) via a CSV file.
the input parameters of the program are in fact 2:
path and file name of the table.
I am experiencing various problems for the creation of dynamic internal tables and structures.
could you give me a hand? you've done a similar program?
thanks in advance
Valerio
Moderator Message: Please use "english" language from next time. I have translated for you this time.
Message was edited by: Kesavadas Thekkillath
2012 Oct 23 4:46 PM
Hello
Hope this code solve your query.
TYPE-POOLS : abap.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>,
<dyn_field>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
*******Creates a dynamic internal table*********
PERFORM get_data.
PERFORM write_out.
*&---------------------------------------------------------------------*
*& Form get_structure
*&---------------------------------------------------------------------*
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
* xfc-datatype = xdetails-type_kind.
CASE xdetails-type_kind.
WHEN 'C'.
xfc-datatype = 'CHAR'.
WHEN 'N'.
xfc-datatype = 'NUMC'.
WHEN 'D'.
xfc-datatype = 'DATE'.
WHEN 'P'.
xfc-datatype = 'PACK'.
WHEN OTHERS.
xfc-datatype = xdetails-type_kind.
ENDCASE.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
*&---------------------------------------------------------------------*
*& Form create_dynamic_itab
*&---------------------------------------------------------------------*
FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
i_length_in_byte = 'X' "added by Paul Robert Oct 28, 2009 17:04
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM. "create_dynamic_itab
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data.
* Select Data from table.
SELECT * INTO TABLE <dyn_table>
FROM (p_table).
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form write_out
*&---------------------------------------------------------------------*
FORM write_out.
LOOP AT <dyn_table> INTO <dyn_wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ <dyn_field>.
ELSE.
WRITE: <dyn_field>.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out
Happy Coding
Sandeep
2012 Oct 23 7:31 PM
If you are uploading data from csv (Il mio italiano non è molto buono, isn't it) just use a dynamic internal table via
Try to execute a small code like :
FIELD-SYMBOLS: <itab> TYPE ANY TABLE.
CREATE DATA dref TYPE STANDARD TABLE OF (dbtab).
ASSIGN dref->* to <itab>.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\test.csv'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ',' " Put your actual csv separator "," or other
TABLES
DATA_TAB = <itab>
* ...
Regards,
Raymond