Excel erzeugen von beliebigen Tabellendef. X-System mit ABAP2XLSX

Posten Sie hier Tutorials & Cookbooks.
1 Beitrag • Seite 1 von 1
1 Beitrag Seite 1 von 1

Excel erzeugen von beliebigen Tabellendef. X-System mit ABAP2XLSX

Beitrag von Tron (Top Expert / 1327 / 35 / 332 ) »
Hallo Gemeinde.
Hier ein nützliches Coding für die Speicherung / Archivierung von Datentabellen aus verschiedenen SAP-Systemen, auch unterschiedlicher Releases, in Excel-Sheets mit ABAP2XLSX.

Bild


Besonderer Dank an SAP-Mentors und Stefan Schmöcker
für die kontinuierliche Arbeit am ABAP2XLSX-Projekt 😃

Example to download Service Orders with BAPI_ALM_ORDER_GET_DETAIL and BAPI_CUSTOMER_GETDETAIL2

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*& Report  ZBC_XLSX_DOWNLOAD_FUMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zbc_xlsx_download_fumo_csord.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*

DATA ls_sel TYPE ddshselopt.
DATA lt_sel TYPE TABLE OF ddshselopt.

"USAGE:  m_selopt 'FIELD' S_SELOPT.
DEFINE m_selopt .
  CLEAR ls_sel.
  ls_sel-shlpfield = &1.
  LOOP AT &2.
    MOVE-CORRESPONDING &2 TO ls_sel.
    APPEND ls_sel TO lt_sel.
  ENDLOOP.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*

CONSTANTS htab(1) VALUE %_horizontal_tab.

DATA: excel         TYPE REF TO zcl_excel ##NEEDED,
      act_worksheet TYPE REF TO zcl_excel_worksheet.


DATA msg_text(80).

TYPE-POOLS: abap.

**** Keyfields
TYPES:
  BEGIN OF ty_key,
    aufnr TYPE aufnr,
  END OF ty_key.

**** for Excel Headline
TYPES:
  BEGIN OF ty_hdr,
    tablname  TYPE tabname,
    fieldname TYPE fieldname,
    ddtext    TYPE ddtext,
    reptext   TYPE reptext,
  END OF ty_hdr.

DATA lt_hdr TYPE TABLE OF ty_hdr.
DATA ls_hdr TYPE ty_hdr.

FIELD-SYMBOLS:
  <dyn_field>                TYPE any,
  <dyn_rec>                  TYPE any,
  <dyn_tab>                  TYPE  STANDARD TABLE,

  " table for BAPI_ALM_ORDER_GET_DETAIL
  <et_partner>               TYPE STANDARD TABLE,
  <et_components>            TYPE STANDARD TABLE,
  <et_operations>            TYPE STANDARD TABLE,
  <et_relations>             TYPE STANDARD TABLE,
  <et_srules>                TYPE STANDARD TABLE,
  <et_olist>                 TYPE STANDARD TABLE,
  <et_oprol>                 TYPE STANDARD TABLE,
  <et_texts>                 TYPE STANDARD TABLE,
  <et_text_lines>            TYPE STANDARD TABLE,
  <et_prts>                  TYPE STANDARD TABLE,
  <et_costs_sum>             TYPE STANDARD TABLE,
  <et_costs_details>         TYPE STANDARD TABLE,
  <et_reforder_serno_olist>  TYPE STANDARD TABLE,
  <et_serviceoutline>        TYPE STANDARD TABLE,
  <et_servicelines>          TYPE STANDARD TABLE,
  <et_servicelimit>          TYPE STANDARD TABLE,
  <et_servicecontractlimits> TYPE STANDARD TABLE,
  <et_permit>                TYPE STANDARD TABLE,
  <et_permit_issue>          TYPE STANDARD TABLE,

  " Header table dummy
  <et_header>                TYPE STANDARD TABLE,
  <et_srvdata>               TYPE STANDARD TABLE,
  <et_reforder_item>         TYPE STANDARD TABLE,
  <t_customeraddress>        TYPE STANDARD TABLE,

  " Header structure
  <es_header>                TYPE any,
  <es_srvdata>               TYPE any,
  <es_reforder_item>         TYPE any,
  <es_partner>               TYPE any,
  <s_customeraddress>        TYPE any.

DATA t_operations TYPE STANDARD TABLE OF bapi_alm_order_operation_e.


DATA lt_key TYPE TABLE OF ty_key.
DATA ls_key TYPE ty_key.

DATA:
  toptions    TYPE TABLE OF rfc_db_opt,
  tfields     TYPE TABLE OF rfc_db_fld,
  tdata       TYPE TABLE OF ytab4000,
  sdata       TYPE ytab4000,
  i_excel     TYPE  solix_tab,
  i_excel_len TYPE  i.

DATA t_bapiret TYPE TABLE OF bapiret2.
DATA s_bapiret TYPE  bapiret2.


DATA lv_path TYPE string VALUE 'C:\Temp\STULI\ZBC_XLSX_DOWNLOAD_'.
DATA lv_pfad TYPE string .
DATA gv_matnr TYPE mara-matnr.
DATA g_msg TYPE tab512.
DATA l_datuv TYPE datuv_bi.
DATA l_cust TYPE bapicustomer_id-customer.

PARAMETERS p_upl(40) TYPE c LOWER CASE OBLIGATORY DEFAULT 'C:\temp\CSORD\KEY\CSORD_key.txt'.
PARAMETERS p_dwn(40) TYPE c LOWER CASE OBLIGATORY DEFAULT 'C:\Temp\CSORD\'.
PARAMETERS p_log(40) TYPE c LOWER CASE OBLIGATORY DEFAULT 'C:\Temp\CSORD\LOG\'.
PARAMETERS p_lang TYPE sy-langu DEFAULT sy-langu.

PARAMETERS p_des1 TYPE rfcdes-rfcdest OBLIGATORY DEFAULT 'SGPCLNT200'.
PARAMETERS p_max TYPE soid-accnt DEFAULT '10000'.

lv_path = p_dwn.

* Tables
PERFORM create_itab USING 'BAPI_ALM_ORDER_PARTNER' . ASSIGN <dyn_tab> TO  <et_partner>. ASSIGN <dyn_rec> TO <es_partner>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_OPERATION_E' . ASSIGN <dyn_tab> TO  <et_operations>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_COMPONENT_E' . ASSIGN <dyn_tab> TO  <et_components>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_RELATION_EXPORT' . ASSIGN <dyn_tab> TO  <et_relations>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_SRULE_E' . ASSIGN <dyn_tab> TO  <et_srules>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_OBJECTLIST' . ASSIGN <dyn_tab> TO  <et_olist>.
PERFORM create_itab USING 'BAPI_ALM_OLIST_RELATION' . ASSIGN <dyn_tab> TO  <et_oprol>.
PERFORM create_itab USING 'BAPI_ALM_TEXT' . ASSIGN <dyn_tab> TO  <et_texts>.
PERFORM create_itab USING 'BAPI_ALM_TEXT_LINES' . ASSIGN <dyn_tab> TO  <et_text_lines>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_PRT_E' . ASSIGN <dyn_tab> TO  <et_prts>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_COSTS_SUM_E' . ASSIGN <dyn_tab> TO  <et_costs_sum>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_COSTS_DETAIL_E' . ASSIGN <dyn_tab> TO  <et_costs_details>.
PERFORM create_itab USING 'BAPI_REFORDER_SERNO_OLIST' . ASSIGN <dyn_tab> TO  <et_reforder_serno_olist>.
PERFORM create_itab USING 'BAPI_ALM_SRV_OUTLINE' . ASSIGN <dyn_tab> TO  <et_serviceoutline>.
PERFORM create_itab USING 'BAPI_ALM_SRV_SERVICE_LINE' . ASSIGN <dyn_tab> TO  <et_servicelines>.
PERFORM create_itab USING 'BAPI_ALM_SRV_LIMIT_DATA' . ASSIGN <dyn_tab> TO  <et_servicelimit>.
PERFORM create_itab USING 'BAPI_ALM_SRV_CONTRACT_LIMITS' . ASSIGN <dyn_tab> TO  <et_servicecontractlimits>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_PERMIT_READ' . ASSIGN <dyn_tab> TO  <et_permit>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_PER_ISSUE_R' . ASSIGN <dyn_tab> TO  <et_permit_issue>.

PERFORM create_itab USING 'BAPI_ALM_ORDER_HEADER_E'. ASSIGN <dyn_tab> TO  <et_header>. ASSIGN <dyn_rec> TO <es_header>.
PERFORM create_itab USING 'BAPI_ALM_ORDER_SRVDAT_E'. ASSIGN <dyn_tab> TO  <et_srvdata>. ASSIGN <dyn_rec> TO <es_srvdata>.
PERFORM create_itab USING 'BAPI_REFORDER_ITEM'. ASSIGN <dyn_tab> TO  <et_reforder_item>. ASSIGN <dyn_rec> TO <es_reforder_item>.

PERFORM create_itab USING 'BAPICUSTOMER_04' . ASSIGN <dyn_tab> TO  <t_customeraddress>. ASSIGN <dyn_rec> TO <s_customeraddress>.



PERFORM upload_keys.

LOOP AT lt_key INTO ls_key.

  REFRESH:
  <et_partner>  ,
  <et_operations>,
  <et_components>,
  <et_relations>,
  <et_srules>,
  <et_olist>,
  <et_oprol>,
  <et_texts>,
  <et_text_lines>,
  <et_prts>,
  <et_costs_sum>,
  <et_costs_details>,
  <et_reforder_serno_olist>,
  <et_serviceoutline>,
  <et_servicelines>,
  <et_servicelimit>,
  <et_servicecontractlimits>,
  <et_permit>,
  <et_permit_issue>,

  <t_customeraddress>,

    <et_header>,
    <et_srvdata>,
    <et_reforder_item>.

  " Header structure
  CLEAR:
  <s_customeraddress>,
  <es_header>,
  <es_srvdata>,
  <es_reforder_item>.


  CONCATENATE ls_key-aufnr '.xlsx'  INTO lv_pfad .
  CONCATENATE lv_path lv_pfad INTO lv_pfad.


  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = ls_key-aufnr
    IMPORTING
      output = ls_key-aufnr.

  CALL FUNCTION 'BAPI_ALM_ORDER_GET_DETAIL' DESTINATION p_des1
    EXPORTING
      number                   = ls_key-aufnr
    IMPORTING
      es_header                = <es_header>
      es_srvdata               = <es_srvdata>
      es_reforder_item         = <es_reforder_item>
    TABLES
      et_partner               = <et_partner>
      et_operations            = <et_operations>
      et_components            = <et_components>
      et_relations             = <et_relations>
      et_srules                = <et_srules>
      et_olist                 = <et_olist>
      et_oprol                 = <et_oprol>
      et_texts                 = <et_texts>
      et_text_lines            = <et_text_lines>
      et_prts                  = <et_prts>
      et_costs_sum             = <et_costs_sum>
      et_costs_details         = <et_costs_details>
      return                   = t_bapiret
      et_reforder_serno_olist  = <et_reforder_serno_olist>
      et_serviceoutline        = <et_serviceoutline>
      et_servicelines          = <et_servicelines>
      et_servicelimit          = <et_servicelimit>
      et_servicecontractlimits = <et_servicecontractlimits>
      et_permit                = <et_permit>
      et_permit_issue          = <et_permit_issue>
    EXCEPTIONS
      communication_failure    = 1 MESSAGE msg_text
      system_failure           = 2 MESSAGE msg_text
      OTHERS                   = 3.

  IF NOT <es_header> IS INITIAL. APPEND <es_header> TO <et_header>. ENDIF.
  IF NOT <es_srvdata> IS INITIAL. APPEND <es_srvdata> TO <et_srvdata>. ENDIF.
  IF NOT <es_reforder_item> IS INITIAL. APPEND <es_reforder_item> TO <et_reforder_item>. ENDIF.



  IF sy-subrc <> 0.
*    CONCATENATE 'BOM:' gv_matnr
*                'Plant:' ls_mast-werks
*                'Type:' ls_mast-stlan
*                'Altern.:' ls_mast-stlal
*                '===> failed to read' INTO
*                g_msg SEPARATED BY space.
*    PERFORM collect_log USING ' ' g_msg .
    CONTINUE.
  ENDIF.

* Get Partner AG Address
  LOOP AT <et_partner> INTO  <es_partner>.
    UNASSIGN <dyn_field>.
    ASSIGN COMPONENT 'PARTN_ROLE_OLD' OF STRUCTURE <es_partner> TO <dyn_field>.
    IF sy-subrc = 0.
      IF <dyn_field> = 'AG'.
        UNASSIGN <dyn_field>.
        ASSIGN COMPONENT 'PARTNER_OLD' OF STRUCTURE <es_partner> TO <dyn_field>.
        IF sy-subrc = 0.

          CLEAR s_bapiret.
          l_cust = <dyn_field>.
          CALL FUNCTION 'BAPI_CUSTOMER_GETDETAIL2' DESTINATION p_des1
            EXPORTING
              customerno            = l_cust
            IMPORTING
              customeraddress       = <s_customeraddress>
              return                = s_bapiret
            EXCEPTIONS
              communication_failure = 1 MESSAGE msg_text
              system_failure        = 2 MESSAGE msg_text
              OTHERS                = 3.

          IF NOT  <s_customeraddress> IS INITIAL.
            APPEND  <s_customeraddress> TO  <t_customeraddress>.
          ENDIF.

        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

*  PERFORM append_to_file.


  " Header Structures
  IF NOT <et_header>[] IS INITIAL. PERFORM create_excel TABLES <et_header> USING 'BAPI_ALM_ORDER_HEADER_E'. ENDIF.
  IF NOT <et_srvdata>[] IS INITIAL. PERFORM create_excel TABLES <et_srvdata> USING 'BAPI_ALM_ORDER_SRVDAT_E'. ENDIF.
  IF NOT <et_reforder_item>[] IS INITIAL. PERFORM create_excel TABLES <et_reforder_item> USING 'BAPI_REFORDER_ITEM'. ENDIF.

  IF NOT <et_partner>[] IS INITIAL. PERFORM create_excel TABLES <et_partner> USING 'BAPI_ALM_ORDER_PARTNER'. ENDIF.
  IF NOT <et_operations>[] IS INITIAL. PERFORM create_excel TABLES <et_operations> USING 'BAPI_ALM_ORDER_OPERATION_E'. ENDIF.
  IF NOT <et_components>[] IS INITIAL. PERFORM create_excel TABLES <et_components> USING 'BAPI_ALM_ORDER_COMPONENT_E'. ENDIF.
  IF NOT <et_relations>[] IS INITIAL. PERFORM create_excel TABLES <et_relations> USING 'BAPI_ALM_ORDER_RELATION_EXPORT'. ENDIF.
  IF NOT <et_srules>[] IS INITIAL. PERFORM create_excel TABLES <et_srules> USING 'BAPI_ALM_ORDER_SRULE_E'. ENDIF.
  IF NOT <et_olist>[] IS INITIAL. PERFORM create_excel TABLES <et_olist> USING 'BAPI_ALM_ORDER_OBJECTLIST'. ENDIF.
  IF NOT <et_oprol>[] IS INITIAL. PERFORM create_excel TABLES <et_oprol> USING 'BAPI_ALM_OLIST_RELATION'. ENDIF.
  IF NOT <et_texts>[] IS INITIAL. PERFORM create_excel TABLES <et_texts> USING 'BAPI_ALM_TEXT'. ENDIF.
  IF NOT <et_text_lines>[] IS INITIAL. PERFORM create_excel TABLES <et_text_lines> USING 'BAPI_ALM_TEXT_LINES'. ENDIF.
  IF NOT <et_prts>[] IS INITIAL. PERFORM create_excel TABLES <et_prts> USING 'BAPI_ALM_ORDER_PRT_E'. ENDIF.
  IF NOT <et_costs_sum>[] IS INITIAL. PERFORM create_excel TABLES <et_costs_sum> USING 'BAPI_ALM_ORDER_COSTS_SUM_E'. ENDIF.
  IF NOT <et_costs_details>[] IS INITIAL. PERFORM create_excel TABLES <et_costs_details> USING 'BAPI_ALM_ORDER_COSTS_DETAIL_E'. ENDIF.
  IF NOT <et_reforder_serno_olist>[] IS INITIAL. PERFORM create_excel TABLES <et_reforder_serno_olist> USING 'BAPI_REFORDER_SERNO_OLIST'. ENDIF.
  IF NOT <et_serviceoutline>[] IS INITIAL. PERFORM create_excel TABLES <et_serviceoutline> USING 'BAPI_ALM_SRV_OUTLINE'. ENDIF.
  IF NOT <et_servicelines>[] IS INITIAL. PERFORM create_excel TABLES <et_servicelines> USING 'BAPI_ALM_SRV_SERVICE_LINE'. ENDIF.
  IF NOT <et_servicelimit>[] IS INITIAL. PERFORM create_excel TABLES <et_servicelimit> USING 'BAPI_ALM_SRV_LIMIT_DATA'. ENDIF.
  IF NOT <et_servicecontractlimits>[] IS INITIAL. PERFORM create_excel TABLES <et_servicecontractlimits> USING 'BAPI_ALM_SRV_CONTRACT_LIMITS'. ENDIF.
  IF NOT <et_permit>[] IS INITIAL. PERFORM create_excel TABLES <et_permit> USING 'BAPI_ALM_ORDER_PERMIT_READ'. ENDIF.
  IF NOT <et_permit_issue>[] IS INITIAL. PERFORM create_excel TABLES <et_permit_issue> USING 'BAPI_ALM_ORDER_PER_ISSUE_R'. ENDIF.

  IF NOT <t_customeraddress>[] IS INITIAL. PERFORM create_excel TABLES <t_customeraddress> USING 'BAPICUSTOMER_04'. ENDIF.


  IF excel IS  BOUND.


    TRY.
        excel->set_active_sheet_index( i_active_worksheet = 1 ).
      CATCH zcx_excel .
    ENDTRY.

    PERFORM write_excel_file USING lv_pfad.

    FREE excel.

  ENDIF.

ENDLOOP.

PERFORM collect_log USING 'X' g_msg .

*&---------------------------------------------------------------------*
*&      Form  stxcompare
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM fill_itab.
  DATA lt TYPE TABLE OF tab512.
  DATA ls TYPE tab512.
  DATA l_idx TYPE i.

  DATA s_fields TYPE rfc_db_fld.

  FIELD-SYMBOLS <ls> TYPE tab512.

  LOOP AT tdata INTO sdata.

    SPLIT sdata-wa AT htab INTO TABLE lt.

    " delete all ":" in time vars
    LOOP AT tfields INTO s_fields WHERE type = 'T'.
      READ TABLE lt ASSIGNING <ls> INDEX sy-tabix.
      IF sy-subrc = 0.
        REPLACE ALL OCCURRENCES OF ':' IN <ls> WITH ''.
      ENDIF.
    ENDLOOP.

    LOOP AT lt INTO ls.
      l_idx = sy-tabix.
      ASSIGN COMPONENT l_idx OF STRUCTURE <dyn_rec> TO <dyn_field>.
      <dyn_field> = ls-wa.
    ENDLOOP.

    INSERT <dyn_rec> INTO TABLE <dyn_tab>.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  stxcompare
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM create_excel TABLES i_tab  USING i_sheetname TYPE zexcel_sheet_title.
  CONSTANTS    : first_column   TYPE char1     VALUE 'A'
               .
  DATA         : worksheet      TYPE REF TO zcl_excel_worksheet
               , worksheet_title TYPE zexcel_sheet_title
               , table_settings TYPE zexcel_s_table_settings
               .
  DATA           lo_theme       TYPE REF TO zcl_excel_theme.

  DATA: lv_row   TYPE zexcel_cell_row,
        lv_col   TYPE i,
        lv_value TYPE string.


  table_settings-table_style    = zcl_excel_table=>builtinstyle_medium2.
  table_settings-show_row_stripes
                                = abap_true.
  table_settings-nofilters      = abap_true.
  table_settings-top_left_column
                                = first_column.
  table_settings-top_left_row   = 02.

  TRY.

      IF excel IS NOT BOUND.
        CREATE OBJECT excel.
        worksheet                   = excel->get_active_worksheet( ).
      ELSE.
        worksheet                   = excel->add_new_worksheet( ).
      ENDIF.

*      lo_theme->set_latin_font(
*       EXPORTING
*         iv_type        = zcl_excel_theme_font_scheme=>c_minor
*         iv_typeface    = 'Arial monospaced for SAP'
**      iv_panose      =
**      iv_pitchfamily =
**      iv_charset     =
*     ).

      worksheet_title               = i_sheetname.
      worksheet->set_title( worksheet_title ).
      worksheet->bind_table(
        ip_table                    = i_tab[]
        is_table_settings           = table_settings
        ).

      lv_row = 1.
      LOOP AT lt_hdr INTO ls_hdr WHERE tablname = i_sheetname.

        lv_col = lv_col + 1.
        lv_value = ls_hdr-reptext.

        worksheet->set_cell( ip_column = lv_col ip_row = lv_row ip_value = lv_value ).

        worksheet->change_cell_style(  ip_column           = lv_col
                                       ip_row              = lv_row
                                       ip_fill_filltype    = zcl_excel_style_fill=>c_fill_solid
                                       ip_fill_fgcolor_rgb = zcl_excel_style_color=>c_gray ).
      ENDLOOP.

    CATCH zcx_excel .
  ENDTRY.


ENDFORM.
FORM write_excel_file USING i_file TYPE string.

*** Create output
  DATA:
    cl_writer TYPE REF TO zif_excel_writer.

  DATA: xdata     TYPE xstring.         " Will be used for sending as email
  " t_rawdata TYPE solix_tab,           " Will be used for downloading or open directly
  " bytecount TYPE i.                   " Will be used for downloading or open directly

  CREATE OBJECT cl_writer TYPE zcl_excel_writer_2007.

  xdata = cl_writer->write_file( excel ).
  i_excel = cl_bcs_convert=>xstring_to_solix( iv_xstring  = xdata ).
  i_excel_len = xstrlen( xdata ).

* Get trailing blank
  cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = i_excel_len
                                                    filename     = i_file
                                                    filetype     = 'BIN'
                                           CHANGING data_tab     = i_excel ).

ENDFORM.


FORM upload_keys.
  DATA l_path TYPE string.
  l_path = p_upl.

  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = l_path
*     filetype                = 'ASC'
      has_field_separator     = 'X'
*     header_length           = 0
*     read_by_line            = 'X'
*     dat_mode                = SPACE
*     codepage                = SPACE
*     ignore_cerr             = ABAP_TRUE
*     replacement             = '#'
*     virus_scan_profile      =
*  IMPORTING
*     filelength              =
*     header                  =
    CHANGING
      data_tab                = lt_key
*     isscanperformed         = SPACE
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      not_supported_by_gui    = 17
      error_no_gui            = 18
      OTHERS                  = 19.
  IF sy-subrc <> 0.
  ENDIF.



ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  create_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM create_itab USING i_tdef TYPE dd02l-tabname .
  DATA t_field_def TYPE TABLE OF rpy_fiel.
  DATA s_field_def TYPE rpy_fiel.

  UNASSIGN:
    <dyn_field>,
    <dyn_rec>,
    <dyn_tab>.


  CALL FUNCTION 'RPY_TABLE_READ' DESTINATION p_des1
    EXPORTING
*     ACTIVATION_TYPE_I     = 'M'
      language              = p_lang
      table_name            = i_tdef
*     WITH_DOCU             = ' '
*     DOCUTYPE              = 'U'
* IMPORTING
*     TABL_INF              =
*     TABL_TECHNICS         =
*     ACTIVATION_TYPE_O     =
    TABLES
      tabl_fields           = t_field_def
*     DOCU_TABLE_USER       =
*     DOCU_TABLE_TECH       =
    EXCEPTIONS
      cancelled             = 1
      not_found             = 2
      permission_error      = 3
      illegal_type          = 4
      communication_failure = 5 MESSAGE msg_text
      system_failure        = 6 MESSAGE msg_text
      OTHERS                = 7.

  IF sy-subrc <> 0.
    EXIT.
  ENDIF.


  DATA:
    ldp_dyn_table     TYPE REF TO data,
    lop_tabledescr    TYPE REF TO cl_abap_tabledescr,
    ldp_dynaic_record TYPE REF TO data,
    lop_strucdescr    TYPE REF TO cl_abap_structdescr,
    ls_component      TYPE abap_componentdescr,
    lt_component      TYPE abap_component_tab,
    lv_desc           TYPE REF TO cl_abap_typedescr.

  DATA l_field_length	TYPE i.
  DATA l_decimals	TYPE i.
  DATA fields TYPE  rfc_db_fld.

  DATA lv_int1 TYPE int1.
  DATA lv_int2 TYPE int2.
  DATA lv_int4 TYPE int4.


  LOOP AT t_field_def INTO s_field_def WHERE intlength > 0.

    MOVE-CORRESPONDING s_field_def TO ls_hdr.
    APPEND ls_hdr TO lt_hdr.

    "    READ TABLE t_field_def INTO s_field_def WITH KEY fieldname = fields-fieldname.

    IF sy-subrc = 0.
      CASE s_field_def-datatype.
        WHEN 'CHAR' OR 'UNIT' OR 'CUKY'
.         l_field_length = s_field_def-length.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_c( p_length = l_field_length ).
          APPEND ls_component TO lt_component.

        WHEN 'LANG'.
          l_field_length = s_field_def-length.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_c( p_length = l_field_length ).
          APPEND ls_component TO lt_component.

        WHEN 'DEC' OR 'QUAN' OR 'CURR'.
          l_field_length = s_field_def-intlength
.           l_decimals = s_field_def-decimals.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_p( p_length = l_field_length  p_decimals = l_decimals ).
          APPEND ls_component TO lt_component.

        WHEN 'NUMC'.
          l_field_length = s_field_def-length.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_n( p_length = l_field_length ).
          APPEND ls_component TO lt_component.

        WHEN 'INT1' OR 'INT2' OR 'INT4'.

          ls_component-name = s_field_def-fieldname.

          IF s_field_def-datatype = 'INT1'.
            ls_component-type ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int1 ).
          ELSEIF  s_field_def-datatype = 'INT2'.
            ls_component-type ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int2 ).
          ELSEIF  s_field_def-datatype = 'INT4'.
            ls_component-type ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int4 ).
          ENDIF.

          APPEND ls_component TO lt_component.

        WHEN 'DATS'.
          l_field_length = s_field_def-length.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_d( ).
          APPEND ls_component TO lt_component.

        WHEN 'TIMS'.
          l_field_length = s_field_def-length.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_t( ).
          APPEND ls_component TO lt_component.

        WHEN OTHERS.
          break-point.
          l_field_length = s_field_def-length.
          ls_component-name = s_field_def-fieldname.
          ls_component-type = cl_abap_elemdescr=>get_c( p_length = l_field_length ).
          APPEND ls_component TO lt_component.

      ENDCASE.
    ENDIF.

  ENDLOOP.

  lop_strucdescr = cl_abap_structdescr=>create( lt_component ).
  CREATE DATA ldp_dynaic_record TYPE HANDLE lop_strucdescr.
  lop_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = lop_strucdescr ).

  CREATE DATA ldp_dyn_table TYPE HANDLE lop_tabledescr.

  ASSIGN ldp_dynaic_record->* TO <dyn_rec>.
  ASSIGN ldp_dyn_table->* TO <dyn_tab>.

*    ACCP
*    CHAR
*    CLNT
*    CUKY
*    CURR
*    DATS
*    DEC
*    DF16_DEC
*    DF16_RAW
*    DF16_SCL
*    DF34_DEC
*    DF34_RAW
*    DF34_SCL
*    FLTP
*    INT1
*    INT2
*    INT4
*    LANG
*    LCHR
*    LRAW
*    NUMC
*    PREC
*    QUAN
*    RAW
*    RAWSTRING
*    SSTRING
*    STRING
*    TIMS
*    UNIT
*    VARC

ENDFORM.

FORM collect_log USING i_coll TYPE xfeld i_msg TYPE tab512.
  "PARAMETERS p_log(40) TYPE c LOWER CASE OBLIGATORY DEFAULT 'C:\Temp\STULI\'.
  DATA fn TYPE string.
  DATA s_msg TYPE tab512.

  STATICS t_msg TYPE TABLE OF tab512.

  IF i_coll IS INITIAL.
    s_msg-wa = i_msg.
    APPEND s_msg TO t_msg.
  ELSE.
    IF NOT t_msg[] IS INITIAL.
      CONCATENATE p_log 'stueli_log' sy-datum '_' sy-uzeit '.txt' INTO fn.

      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
          filename                = fn
          trunc_trailing_blanks   = 'X'
        CHANGING
          data_tab                = t_msg
        EXCEPTIONS
          file_write_error        = 1
          no_batch                = 2
          gui_refuse_filetransfer = 3
          invalid_type            = 4
          no_authority            = 5
          unknown_error           = 6
          header_not_allowed      = 7
          separator_not_allowed   = 8
          filesize_not_allowed    = 9
          header_too_long         = 10
          dp_error_create         = 11
          dp_error_send           = 12
          dp_error_write          = 13
          unknown_dp_error        = 14
          access_denied           = 15
          dp_out_of_memory        = 16
          disk_full               = 17
          dp_timeout              = 18
          file_not_found          = 19
          dataprovider_exception  = 20
          control_flush_error     = 21
          not_supported_by_gui    = 22
          error_no_gui            = 23
          OTHERS                  = 24.

      IF sy-subrc <> 0.
      ENDIF.
    ENDIF.

  ENDIF.

ENDFORM.

*FORM append_to_file.
*  DATA fn TYPE string.
*
*  CONCATENATE p_dwn 'STKO_API.txt' INTO fn.
*
*  CALL METHOD cl_gui_frontend_services=>gui_download
*    EXPORTING
**     bin_filesize              =
*      filename                  = fn
*      filetype                  = 'ASC'
*      append                    = 'X'
*      write_field_separator     = 'X'
**     header                    = '00'
*      trunc_trailing_blanks     = 'X'
*      trunc_trailing_blanks_eol = 'X'
*    CHANGING
*      data_tab                  = <t_stko>[]
*    EXCEPTIONS
*      file_write_error          = 1
*      no_batch                  = 2
*      gui_refuse_filetransfer   = 3
*      invalid_type              = 4
*      no_authority              = 5
*      unknown_error             = 6
*      header_not_allowed        = 7
*      separator_not_allowed     = 8
*      filesize_not_allowed      = 9
*      header_too_long           = 10
*      dp_error_create           = 11
*      dp_error_send             = 12
*      dp_error_write            = 13
*      unknown_dp_error          = 14
*      access_denied             = 15
*      dp_out_of_memory          = 16
*      disk_full                 = 17
*      dp_timeout                = 18
*      file_not_found            = 19
*      dataprovider_exception    = 20
*      control_flush_error       = 21
*      not_supported_by_gui      = 22
*      error_no_gui              = 23
*      OTHERS                    = 24.
*  .
*  IF sy-subrc <> 0.
** Implement suitable error handling here
*  ENDIF.
*
*
*  CONCATENATE p_dwn 'STPO_API.txt' INTO fn.
*
*  CALL METHOD cl_gui_frontend_services=>gui_download
*    EXPORTING
**     bin_filesize              =
*      filename                  = fn
*      filetype                  = 'ASC'
*      append                    = 'X'
*      write_field_separator     = 'X'
**     header                    = '00'
*      trunc_trailing_blanks     = 'X'
*      trunc_trailing_blanks_eol = 'X'
*    CHANGING
*      data_tab                  = <t_stpo>[]
*    EXCEPTIONS
*      file_write_error          = 1
*      no_batch                  = 2
*      gui_refuse_filetransfer   = 3
*      invalid_type              = 4
*      no_authority              = 5
*      unknown_error             = 6
*      header_not_allowed        = 7
*      separator_not_allowed     = 8
*      filesize_not_allowed      = 9
*      header_too_long           = 10
*      dp_error_create           = 11
*      dp_error_send             = 12
*      dp_error_write            = 13
*      unknown_dp_error          = 14
*      access_denied             = 15
*      dp_out_of_memory          = 16
*      disk_full                 = 17
*      dp_timeout                = 18
*      file_not_found            = 19
*      dataprovider_exception    = 20
*      control_flush_error       = 21
*      not_supported_by_gui      = 22
*      error_no_gui              = 23
*      OTHERS                    = 24.
*  .
*  IF sy-subrc <> 0.
** Implement suitable error handling here
*  ENDIF.
*
*ENDFORM.

INITIALIZATION.
  DATA:
    l_report   TYPE raldb_repo,
    l_variante TYPE raldb_vari,
    BEGIN OF t_info OCCURS 0,
      typ(1),
      null(1),
      line(120),
    END OF t_info.

** Lade Variante sy-uname
  l_report   = sy-repid.
  l_variante = sy-uname.


  CALL FUNCTION 'RS_COVERPAGE_SELECTIONS'
    EXPORTING
      report  = l_report
      variant = l_variante
    TABLES
      infotab = t_info
    EXCEPTIONS
      OTHERS  = 3.
gruß Jens
<:: XING-Gruppe Tricktresor::>
Die deutsche Rechtschreibung ist Freeware, du darfst sie kostenlos nutzen –
Aber sie ist nicht Open Source, d. h. du darfst sie nicht verändern oder in veränderter Form veröffentlichen.

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Seite 1 von 1

Vergleichbare Themen

4
Antw.
1933
Views
Excel erzeugen mit Kopfzeile
von Michi83 » 06.03.2013 11:56 • Verfasst in ABAP® für Anfänger
5
Antw.
7534
Views
Excel-Tabelle in der SAP-Hintergrundverarbeitung erzeugen
von Gast » 07.02.2006 08:58 • Verfasst in ABAP Objects®
4
Antw.
5876
Views
Makro aus SAP heraus im Excel erzeugen
von hfahrian » 22.06.2005 11:44 • Verfasst in ABAP® Core
2
Antw.
1984
Views
Excel-Datei im Hintergrundlauf eines ALV's erzeugen?
von eschi78 » 04.03.2005 14:35 • Verfasst in ABAP Objects®
0
Antw.
2625
Views

Über diesen Beitrag

Tron
Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Aktuelle Forenbeiträge

Regex in where
Gestern von tar 8 / 369
Daten an Tabelle binden
vor 2 Tagen von Bright4.5 3 / 1636
Programm anlegen mit Vorlage
vor 2 Tagen von DeathAndPain 2 / 288
IT0024 Qualifikationen CP-ID
vor 2 Tagen von DeathAndPain 2 / 529

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Aktuelle Forenbeiträge

Regex in where
Gestern von tar 8 / 369
Daten an Tabelle binden
vor 2 Tagen von Bright4.5 3 / 1636
Programm anlegen mit Vorlage
vor 2 Tagen von DeathAndPain 2 / 288
IT0024 Qualifikationen CP-ID
vor 2 Tagen von DeathAndPain 2 / 529

Unbeantwortete Forenbeiträge

BUSOBJEKT zu CMIS PHIO ermitteln
vor 2 Tagen von snooga87 1 / 221
aRFC im OO-Kontext
letzen Monat von ralf.wenzel 1 / 3403
Hilfe bei SWEC/SWE2
September 2024 von retsch 1 / 9953