3 Temmuz 2010 Cumartesi

SAP/ABAP: XLS to SAP, Excel to SAP, FM KCD_EXCEL_OLE_TO_INT_CONVERT, Excel Upload

*&---------------------------------------------------------------------*
*&      Form  upload_data
*&---------------------------------------------------------------------*
FORM upload_data.
  DATA: lo_typedescr TYPE REF TO cl_abap_typedescr.
  DATA: lv_is_field TYPE c,
        lv_is_num   TYPE c,
        lv_is_date  TYPE c.

  PERFORM  sapgui_progress  USING  'Read data'.

  DATA : lt_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.
  DATA : ld_index TYPE i.
  FIELD-SYMBOLS: <fs>.
  CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
    EXPORTING
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = 1
      i_end_col               = 256
      i_end_row               = 65000
    TABLES
      intern                  = lt_intern
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.

  CLEAR: gs_excel.
  REFRESH: gt_excel[].


  LOOP AT lt_intern.

*    IF p_head EQ 'X' AND lt_intern-row EQ 1.
*      CONTINUE.
*    ENDIF.

    MOVE lt_intern-col TO ld_index.
    ASSIGN COMPONENT ld_index OF STRUCTURE
    gs_excel TO <fs>.

    CLEAR: lv_is_field, lv_is_num, lv_is_date.

    lo_typedescr = cl_abap_elemdescr=>describe_by_data( <fs> ).

    IF lo_typedescr->type_kind EQ cl_abap_elemdescr=>typekind_num    OR
   lo_typedescr->type_kind EQ cl_abap_elemdescr=>typekind_packed OR
   lo_typedescr->type_kind EQ cl_abap_elemdescr=>typekind_float  OR
   lo_typedescr->type_kind EQ cl_abap_elemdescr=>typekind_int.
      lv_is_num = abap_true.
    ENDIF.
    IF lo_typedescr->type_kind EQ cl_abap_elemdescr=>typekind_date.
      lv_is_date = abap_true.
    ENDIF.
    FREE: lo_typedescr.

    IF lv_is_date IS NOT INITIAL.
      CONCATENATE lt_intern-value+6(4) lt_intern-value+3(2) lt_intern-value(2) INTO <fs>.
    ELSEIF lv_is_num IS NOT INITIAL.
      IF lt_intern-value CO '0123456789., '.
        REPLACE ALL OCCURRENCES OF '.' IN lt_intern-value WITH ''.
        REPLACE ALL OCCURRENCES OF ',' IN lt_intern-value WITH '.'.
        <fs> = lt_intern-value.
      ELSE.
*                CLEAR: wa_log, lv_msg.
*                lv_msg = text-003.
*                REPLACE '&1' IN lv_msg WITH lt_intern-row.
*                REPLACE '&2' IN lv_msg WITH lt_intern-col.
*                wa_log-msj = lv_msg.
*                APPEND wa_log TO it_log.
      ENDIF.
    ELSE.
      <fs> = lt_intern-value.
    ENDIF.

    AT END OF row.
      APPEND gs_excel TO gt_excel.
      CLEAR gs_excel.
    ENDAT.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SAPGUI_PROGRESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_1407   text
*----------------------------------------------------------------------*
FORM     sapgui_progress  USING  if_text  TYPE  tdline.

* Display progress info
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = 0
      text       = if_text.

ENDFORM.

İnsdroid

Sabahtan beri çatada çutada çatada çutada… Bitmedi yine de… Neyse, yolumuz uzun, toparlıyorum çantamı, adaptörü falan tıkıştırıyorum bir şe...