Tuesday, 1 January 2019

Implementing ATC in the system during Task Release

Following are the steps for implementing ATC into the system during Task Release.

1. Goto transaction 'SCI' and create a variant of 'Global Type'


2. Goto transaction 'ATC' and double click on 'Configure ATC'


3. Set the configuration as mentioned below. In the 'Global Check Variant', provide the name of the variant that has been created in step 1. Here, it is 'ZTEST_VARIANT'.

4. The table 'SCICHKV_ALTER' stores the default check variant for Code Inspector.
Default - This variant is used during normal checking like we do in SE38
Transport - This variant is used during transport release
Change the value of these two records with the new custom variant that has been created in step 1.

5.Goto transaction SE19 and create a new implementation of BADI - CTS_REQUEST_CHECK

6. In CHECK_BEFORE_RELEASE methods write the below codes:

  METHOD if_ex_cts_request_check~check_before_release.
    DATA: lv_exit TYPE char10.

    CALL FUNCTION 'TRINT_TDR_USER_COMMAND'
      EXPORTING
        iv_object  = request
        iv_type    = 'TASK'
        iv_command = 'CHAO'
      IMPORTING
        ev_exit    = lv_exit.
    DATA: lv_field TYPE char70.
    FIELD-SYMBOLS: <fs_okcode> TYPE any.

    lv_field = '(SAPLSTR7)GV_OKCODE'.
    ASSIGN (lv_field) TO <fs_okcode>.
    IF <fs_okcode> EQ 'CANC'.
      RAISE cancel.
    ENDIF.
  ENDMETHOD.

7. Now, while releasing the task, the pop-up will appear:
8. If the requirement is to directly open the ATC results then write the below codes in the method:
 METHOD if_ex_cts_request_check~check_before_release.
        DATA is_ok TYPE abap_bool VALUE abap_true.
        TRY.
        DATA(or_factory) = NEW cl_satc_api_factory( ).
        DATA(it_objects) = cl_satc_object_set_factory=>create_for_transport( request )->if_satc_object_set~get_object_keys( ).
        DATA(or_objects) = cl_satc_object_set_factory=>create_for_object_keys( it_objects ).

        DATA(or_variant) = NEW cl_satc_ci_check_variant( ).
        or_variant->set_name( 'ZTEST_VARIANT' ).  "check variant
        DATA(or_run_config) = or_factory->create_run_config_with_chk_var( EXPORTING i_object_set = or_objects
                                                                                i_check_variant = or_variant
                                                                                i_description = |Transport release { request } | ).

        DATA(or_run_controller) = or_factory->create_run_controller( or_run_config ).
        or_run_controller->run( IMPORTING e_result_access = DATA(or_result_access) ).
        or_result_access->get_findings( IMPORTING e_findings = DATA(it_f) ).

        LOOP AT it_f ASSIGNING FIELD-SYMBOL(<wa_f>) WHERE ( kind = 'E' OR kind = 'W' ) "errors/warnings
                                                      AND exceptn <> 'P'. "pseudo comments and pragmas
          is_ok = abap_false.
          EXIT.
        ENDLOOP.

      CATCH cx_satc_failure cx_satc_not_found INTO DATA(cx).
        DATA(exc_text) = cx->get_text( ).
        MESSAGE exc_text TYPE 'E'.
        is_ok = abap_false.
      CATCH cx_satc_empty_object_set cx_satc_invalid_argument INTO cx.  "ok, if transport is empty or contains only non-checkable objects
    ENDTRY.

    IF is_ok = abap_true.
      MESSAGE s007(zs_dev_tools_local).  "success message – create your own message
    ELSE.

      "we only get the execution ID with this “dirty” cast:
      DATA(or_result_access_int) = CAST cl_satc_result_access( or_result_access ).
      CALL FUNCTION 'SATC_AC_DISPL_RESULT_BY_EXEC'
        EXPORTING
          i_execution_id     = or_result_access_int->if_satc_result_access~result_id
        EXCEPTIONS
          xpt_no_results     = 1
          xpt_not_authorized = 2
          xpt_display_used   = 3
          OTHERS             = 4.
      CHECK sy-subrc = 0.
      RAISE cancel.
    ENDIF.
  ENDMETHOD.

Now, whenever the task will be released automatically ATC results will be shown if there is any.



Reference Link:

Monday, 8 October 2018

FM to fill Blank Space

FUNCTION zfm_table_fill.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IV_CONS) TYPE  CHAR10 DEFAULT 'NA'
*"  CHANGING
*"     REFERENCE(CT_TABLE) TYPE  STANDARD TABLE
*"----------------------------------------------------------------------
*^ Description : Fills the blank spaces of the internal table with a constant value
*^--------------------------------------------------------------------^*

  DATA: lo_struct_descr TYPE REF TO cl_abap_structdescr,
        lt_where        TYPE TABLE OF string.

  CHECK ct_table[] IS NOT INITIAL.
  ASSIGN ct_table[ 1 ] TO FIELD-SYMBOL(<fs_table>).
  CHECK sy-subrc EQ 0.

  lo_struct_descr ?= cl_abap_structdescr=>describe_by_data( <fs_table> ).

  "Column wise updating with a constant value
  APPEND INITIAL LINE TO lt_where ASSIGNING FIELD-SYMBOL(<fs_where>).

  LOOP AT lo_struct_descr->components ASSIGNING FIELD-SYMBOL(<fs_cmp>).
    ASSIGN ct_table[ (<fs_cmp>-name) = space ] TO <fs_table>.
    IF sy-subrc EQ 0.
      TRY .
          ASSIGN COMPONENT <fs_cmp>-name OF STRUCTURE <fs_table> TO FIELD-SYMBOL(<fs_table_field>).
          <fs_table_field> = iv_cons.
          <fs_where> = |{ <fs_cmp>-name } EQ space|.
          MODIFY ct_table FROM <fs_table> TRANSPORTING (<fs_cmp>-name) WHERE (lt_where).
        CATCH cx_sy_conversion_no_number.
      ENDTRY.
    ENDIF.
  ENDLOOP.
ENDFUNCTION.

Wednesday, 29 November 2017

Email Attachment

Note: In many places I haven't removed the hard coding. Please remove it while coding. In some places I have used ABAP 7.4 syntax just to write less codes (highlighted by red).
*&---------------------------------------------------------------------*
*& Report  ZEMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*& Email Attachment - Excel and PDF
*&---------------------------------------------------------------------*
REPORT zemail_attachment.

DATA:
  gv_attachment_string TYPE string.

START-OF-SELECTION.
  PERFORM create_merge_text.
  PERFORM send_email.

FORM create_merge_text.
  DATA: lv_string_tmp TYPE string.

  lv_string_tmp = |Hello| & |{ cl_abap_char_utilities=>horizontal_tab }| &
                  |World| & |{ cl_abap_char_utilities=>horizontal_tab }|
                  .

  gv_attachment_string = |{ lv_string_tmp }| & |{ cl_abap_char_utilities=>cr_lf }|.

************************* FOR PDF ATTACHMENT ***************************
  CALL FUNCTION 'SET_PRINT_PARAMETERS'
    EXPORTING
      destination = 'LOCL' " Printer
      layout      = 'X_65_512/2' "Format
      line_count  = '65' "Line Count
      line_size   = '1024'. "Line Size

  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.

  NEW-PAGE PRINT ON NO DIALOG.
  WRITE: / |HELLO WORLD FOR PDF|.
  NEW-PAGE PRINT OFF.

ENDFORM.

FORM send_email.
  TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.

  DATA:
    lv_mlrec          TYPE so_obj_nam,
    lv_sent_to_all    TYPE os_boolean,
    lv_email          TYPE adr6-smtp_addr,
    lv_subject        TYPE so_obj_des,
    lt_text           TYPE bcsy_text,
    lo_send_request   TYPE REF TO cl_bcs,
    lo_bcs_exception  TYPE REF TO cx_bcs,
    lo_recipient      TYPE REF TO if_recipient_bcs,
    lo_sender         TYPE REF TO cl_sapuser_bcs,
    lo_document       TYPE REF TO cl_document_bcs,
    lt_binary_content TYPE solix_tab,
    lv_size           TYPE so_obj_len,
    lt_dl_entry       TYPE TABLE OF sodlienti1,
    lt_pdf_output     TYPE ty_t_pdf,
    ls_pdf_output     TYPE tline,
    lv_buffer         TYPE string,
    lt_mess_att       TYPE TABLE OF solisti1,
    ls_mess_att       TYPE solisti1,
    lv_spool          TYPE rspoid,
    ls_print          TYPE slis_print_alv,
    ls_print_ctrl     TYPE alv_s_pctl.

  CONSTANTS:
    lc_subject   TYPE so_obj_des VALUE 'Test Mail with Excel & PDF Attachment',
    lc_raw       TYPE char03 VALUE 'RAW',
    lc_container TYPE c LENGTH 30 VALUE 'CC',
    lc_col1      TYPE c LENGTH 2 VALUE ' ~',
    lc_col2      TYPE c LENGTH 2 VALUE '~ ',
    lc_255       TYPE i VALUE 255.

  TRY.
      "Create send request
      lo_send_request = cl_bcs=>create_persistent( ).


      "Email FROM...
      lo_sender = cl_sapuser_bcs=>create( sy-uname ).
      "Add sender to send request
      CALL METHOD lo_send_request->set_sender
        EXPORTING
          i_sender = lo_sender.

      "Email TO...
      lv_email = |TEST| & |@TEST.COM|.
      lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).

      "Add recipient to send request
      CALL METHOD lo_send_request->add_recipient
        EXPORTING
          i_recipient = lo_recipient
          i_express   = 'X'.

      "Email BODY
      APPEND INITIAL LINE TO lt_text ASSIGNING FIELD-SYMBOL(<fs_text>).
      <fs_text>-line = |Hi|.

      lo_document = cl_document_bcs=>create_document(
      i_type    = lc_raw
      i_text    = lt_text
      i_length  = '12'
      i_subject = lc_subject
      ).

      "Add document to send request
      CALL METHOD lo_send_request->set_document( lo_document ).

      "Excel Attachment
      IF gv_attachment_string IS NOT INITIAL.
        TRY.
            cl_bcs_convert=>string_to_solix(
            EXPORTING
              iv_string   = gv_attachment_string
              iv_codepage = '4103'  "suitable for MS Excel, leave empty
              iv_add_bom  = 'X'     "for other doc types
            IMPORTING
              et_solix  = lt_binary_content
              ev_size   = lv_size ).
          CATCH cx_bcs.
*             message E445(SO).
            EXIT.
        ENDTRY.

        lo_document->add_attachment(
        i_attachment_type    = 'CSV'
        i_attachment_subject = 'Excel Attachment'
        i_attachment_size    = lv_size
        i_att_content_hex    = lt_binary_content ).

************************* PDF ATTACHMENT *******************************

        ls_print-print = abap_true.
        lv_spool = sy-spono.
        CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
          EXPORTING
            src_spoolid              = lv_spool
            no_dialog                = space
            dst_device               = 'LOCL'
            get_size_from_format     = abap_true
          TABLES
            pdf                      = lt_pdf_output
          EXCEPTIONS
            err_no_abap_spooljob     = 1
            err_no_spooljob          = 2
            err_no_permission        = 3
            err_conv_not_possible    = 4
            err_bad_destdevice       = 5
            user_cancelled           = 6
            err_spoolerror           = 7
            err_temseerror           = 8
            err_btcjob_open_failed   = 9
            err_btcjob_submit_failed = 10
            err_btcjob_close_failed  = 11
            OTHERS                   = 12.
        IF sy-subrc EQ 0.
          LOOP AT lt_pdf_output INTO ls_pdf_output.
            TRANSLATE ls_pdf_output USING lc_col1.
            CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer.
            CLEAR ls_pdf_output.
          ENDLOOP.
          TRANSLATE lv_buffer USING lc_col2.
          DO.
            ls_mess_att = lv_buffer.
            APPEND ls_mess_att TO lt_mess_att.
            SHIFT lv_buffer LEFT BY lc_255 PLACES.
            IF lv_buffer IS INITIAL.
              EXIT.
            ENDIF.
            CLEAR ls_mess_att.
          ENDDO.
        ENDIF.

        lo_document->add_attachment(
        i_attachment_type    = 'PDF'
        i_attachment_subject = 'PDF Attachment'
        i_att_content_text    = lt_mess_att[] ).
      ENDIF.

      "Send email
      CALL METHOD lo_send_request->send(
        EXPORTING
          i_with_error_screen = abap_true
        RECEIVING
          result              = lv_sent_to_all ).
      IF lv_sent_to_all = abap_true.
        "Commit to send email
        COMMIT WORK.
        MESSAGE text-041 TYPE 'S'.  "Email sent!
      ENDIF.

      "Exception handling
    CATCH cx_bcs INTO lo_bcs_exception.
      WRITE:
      'Error!',
      'Error type:',
      lo_bcs_exception->error_type.
  ENDTRY.
ENDFORM.

Thursday, 20 April 2017

Hierarchical ALV

On selecting the header record, corresponding item record is shown. This has been done using hierarchical ALV:
*&---------------------------------------------------------------------*
*& Report  YHIERARCHY
*&
*&---------------------------------------------------------------------*
*& HIERARCHICAL ALV
*& Help: http://sapabap-4.blogspot.in/2015/11/alv-hierarchical-report.html
*&---------------------------------------------------------------------*
*
REPORT yhierarchy.

TYPE-POOLS: slis.

TYPES: BEGIN OF gty_ekko.
        INCLUDE STRUCTURE ekko.
TYPES: expand.
TYPES: END OF gty_ekko.

DATA: gt_ekko    TYPE TABLE OF gty_ekko,
      gt_ekpo    TYPE TABLE OF ekpo,
      gt_fcat    TYPE slis_t_fieldcat_alv,
      gt_tmp     TYPE slis_t_fieldcat_alv,
      gs_fcat    TYPE slis_fieldcat_alv,
      gs_layout  TYPE slis_layout_alv,
      gs_key     TYPE slis_keyinfo_alv "FOR HIERARCHICAL ALV
      .

START-OF-SELECTION.
  SELECT * FROM ekko INTO TABLE gt_ekko UP TO 10 ROWS.

  SELECT *
  FROM ekpo
  INTO TABLE gt_ekpo
  FOR ALL ENTRIES IN gt_ekko
  WHERE ebeln = gt_ekko-ebeln
  .

  DATA lv_col TYPE i VALUE 0.

  IF gt_ekko IS NOT INITIAL.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'EBELN'.
    gs_fcat-tabname   = 'IT_EKKO'.
    gs_fcat-seltext_l = 'Purchase Order'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'BUKRS'.
    gs_fcat-tabname   = 'IT_EKKO'.
    gs_fcat-seltext_l = 'Company Code'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'AEDAT'.
    gs_fcat-tabname   = 'IT_EKKO'.
    gs_fcat-seltext_l = 'Creation Date'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'ERNAM'.
    gs_fcat-tabname   = 'IT_EKKO'.
    gs_fcat-seltext_l = 'Created By'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'LIFNR'.
    gs_fcat-tabname   = 'IT_EKKO'.
    gs_fcat-seltext_l = 'Vendor'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'BEDAT'.
    gs_fcat-tabname   = 'IT_EKKO'.
    gs_fcat-seltext_l = 'Purchasing Document Date'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.
  ENDIF.

  IF gt_ekpo IS NOT INITIAL.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'EBELN'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Purchase Order'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'EBELP'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Item'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'MATKL'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Material Group'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'AEDAT'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Creation Date'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'MENGE'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'PO Quantity'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'MEINS'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Unit'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'NETPR'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Net Price'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.

    lv_col            = lv_col + 1.
    gs_fcat-col_pos   = lv_col.
    gs_fcat-fieldname = 'PEINH'.
    gs_fcat-tabname   = 'IT_EKPO'.
    gs_fcat-seltext_l = 'Price Unit'.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.
  ENDIF.

  CONSTANTS: lc_expand TYPE slis_fieldname VALUE 'EXPAND'.

  gs_layout-zebra             = 'X'. "Zebra looks
  gs_layout-colwidth_optimize = 'X'. "Column width optimized
  gs_layout-expand_fieldname  = 'EXPAND'. "Expand operation
  gs_layout-window_titlebar   = 'Hierarchical PO Header & Item Display'.

  gs_key-header01 = 'EBELN'. "Purchase Order number
  gs_key-item01   = 'EBELN'. "is the key for header & item table

  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = gs_layout
      it_fieldcat        = gt_fcat
      i_tabname_header   = 'IT_EKKO'
      i_tabname_item     = 'IT_EKPO'
      is_keyinfo         = gs_key
    TABLES
      t_outtab_header    = gt_ekko
      t_outtab_item      = gt_ekpo
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.

Wednesday, 19 April 2017

Change the Description of Released TR

Once a TR has been Released, it cannot be edited in normal way. The released TR cannot be deleted also. Only the Basis team can delete it from OS level. But there are some ways in which you can change the description of the released TR, although it is not recommend.

>> One way of doing this is by changing the entry of table E07T through debugging technique. Click Here

>> The other way is by using the FM:

1) Got o FM 'TRINT_CHECK_REQUEST_CHANGEABLE'
At the line number 111 IF is_request_header-trstatus CA sctsc_states_released, put the break point.
2) Double click the released request which you want to change the description.
3) your EDIT option will be disabled. Just type '/h' in the tcpode area and press enter, your debugging will switched on.
4) Then Press ENTER again, it will open the debugger screen, in the variable change the SY_UCOMM field to 'WB_DISP_EDIT_TOGGLE' . Then press F8.
5) your control will be in the FM 'TRINT_CHECK_REQUEST_CHANGEABLE' line number 111. Try to skip this IF condition by using debug technique.
6) Now you can change the description.Now you cant save this as Save button is disabled.Just press back button, you will get the message for save the changes.Just save it.

Tuesday, 18 April 2017

Changing The Entry of Standard Table

Although this is not recommended, but by the following way you can change the entry of any standard table.
  1. Open the table in SE16 and select the record that needs to be changed.
  2. Click on the Display icon or press F7.
  3. Type /H in the tcode area to switch on the Debug Mode.
  4. Again press 'Enter' to turn the debugger on.
  5. Press F7. You will see the code something like this:
    if code = 'show'
  6. Change the value of Code to 'EDIT' and press F8.
    and in case of deleting any entry change the value of Code to 'DELE' and press F8.
  7. Press Save after the operation is done.

Monday, 17 April 2017

Excel output with Coloured Cell

The following program has been copied from here. Only a small change has been made for the cell colour so that the background remains transparent and only the heading have a cell colour. The followings are the valid colour indexes:



*&---------------------------------------------------------------------*
*& Report  ZEXCEL
*&
*&---------------------------------------------------------------------*
*&
*& EXCEL OUTPUT WITH CELL COLOURING
*&---------------------------------------------------------------------*

REPORT zexcel.

INCLUDE ole2incl.
FIELD-SYMBOLS: <val> TYPE any.
DATA: row_cnt TYPE i.
TYPES: BEGIN OF t_excel,
  material_info(20),
  sugg_price(20),
  cost(20),
  comments(100),
END OF t_excel.
DATA: r_excel TYPE t_excel.
DATA: i_excel TYPE TABLE OF t_excel WITH HEADER LINE.
CONSTANTS:
  xlcenter TYPE i VALUE '-4108',
  xlbottom TYPE i VALUE '-4107',
  xlleft TYPE i VALUE '-4131',
  xlright TYPE i VALUE '-4152'.
CONSTANTS:
  xlcontinuous TYPE i VALUE '1',
  xlinsidevertical TYPE i VALUE '11',
  xlthin TYPE i VALUE '2',
  xllandscape TYPE i VALUE '2',
  xlportrait TYPE i VALUE '1',
  xlletter TYPE i VALUE '1',
  xllegal TYPE i VALUE '5',
  xlthick TYPE i VALUE '4',
  xlnone TYPE i VALUE '-4142',
  xlautomatic TYPE i VALUE '-4105'.
DATA:
  hexcel TYPE ole2_object, " Excel object
  hworkbooks TYPE ole2_object, " list of workbooks
  hworkbook TYPE ole2_object, " workbook
  hsheet TYPE ole2_object, " worksheet object
  hrange TYPE ole2_object, " range object
  hrange2 TYPE ole2_object, " range object
  hborders TYPE ole2_object, " Border object
  hinterior TYPE ole2_object, " interior object - for coloring
  hcolumn TYPE ole2_object, "column
  hcell TYPE ole2_object, " cell
  hfont TYPE ole2_object, " font
  hselected TYPE ole2_object, " range object
  hpicture TYPE ole2_object, "picture object
  hlogo TYPE ole2_object. "Logo object


SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECTION-SCREEN SKIP 1.
PARAMETER: wraptext AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.


row_cnt = 1.
PERFORM build_dummy_vals.
PERFORM start_excel.
PERFORM build_header_line USING row_cnt.
PERFORM pass_records USING row_cnt.
PERFORM release_excel.
*&---------------------------------------------------------------------*
*&      Form  Build_Dummy_Vals
*&---------------------------------------------------------------------*
FORM build_dummy_vals .
  DATA: matnum(5) TYPE n.
  DATA: baseprice(3) TYPE n.
  DO 5 TIMES.
    matnum = matnum + 50.
    CLEAR r_excel.
    CONCATENATE 'Material ' matnum INTO r_excel-material_info
    SEPARATED BY space.
    r_excel-sugg_price = baseprice * matnum.
    r_excel-cost = ( baseprice * matnum ) / 2.
    CONCATENATE 'Comments for Material ' matnum INTO r_excel-comments
    SEPARATED BY space.
    APPEND r_excel TO i_excel.
  ENDDO.
ENDFORM. " Build_Dummy_Vals
*&---------------------------------------------------------------------*
*&      Form  Start_Excel
*&---------------------------------------------------------------------*
FORM start_excel.
  CREATE OBJECT hexcel 'EXCEL.APPLICATION'.
  PERFORM err_hdl.

*get list of workbooks, initially empty
  CALL METHOD OF
      hexcel
      'Workbooks' = hworkbooks.
  PERFORM err_hdl.

*add a new workbook
  CALL METHOD OF
      hworkbooks
      'Add'      = hworkbook.
  PERFORM err_hdl.

*Get Worksheet object.
  GET PROPERTY OF hworkbook 'ActiveSheet' = hsheet.
ENDFORM.                    "Start_Excel
*&---------------------------------------------------------------------*
*&      Form  Build_Header_Line
*&---------------------------------------------------------------------*
FORM build_header_line USING p_row_cnt.
  DATA: l_range(30).
  DATA: row_start(10).

  PERFORM fill_the_cell USING p_row_cnt 1 1 'Material'.
  PERFORM fill_the_cell USING p_row_cnt 2 1 'Suggested Price'.
  PERFORM fill_the_cell USING p_row_cnt 3 1 'Cost'.
  PERFORM fill_the_cell USING p_row_cnt 4 1 'Comments'.
  PERFORM format_column USING 1 15 xlcenter ' ' xlcenter 0.
  PERFORM format_column USING 2 10 xlcenter ' ' xlcenter 1.
  PERFORM format_column USING 3 35 xlcenter ' ' xlcenter 0.
  IF wraptext = 'X'.
    PERFORM format_column USING 4 35 xlleft ' ' xlcenter 1.
  ELSE.
    PERFORM format_column USING 4 100 xlleft ' ' xlcenter 0.
  ENDIF.

*Build the range object.
  row_start = p_row_cnt.
  CONCATENATE 'A' row_start ':D' row_start INTO l_range.
  CONDENSE l_range NO-GAPS.

*Set row color to yellow.
  CALL METHOD OF
      hexcel
      'RANGE' = hrange
    EXPORTING
      #1      = l_range.
  CALL METHOD OF
      hrange
      'Interior' = hinterior.
  SET PROPERTY OF hinterior 'ColorIndex' = 15. "6. "yellow
  p_row_cnt = p_row_cnt + 1.
ENDFORM. " Build_Header_Line
*&---------------------------------------------------------------------*
*&      Form  Format_Column
*&---------------------------------------------------------------------*
FORM format_column USING  p_colnum
                          p_colwidth
                          p_colhalign
                          p_colformat
                          p_colvalign
                          p_wraptext.
  CALL METHOD OF
      hexcel
      'COLUMNS' = hcolumn
    EXPORTING
      #1        = p_colnum. "column number
  SET PROPERTY OF hcolumn 'HorizontalAlignment' = p_colhalign.
  SET PROPERTY OF hcolumn 'VerticalAlignment' = p_colvalign.
  SET PROPERTY OF hcolumn 'ColumnWidth' = p_colwidth.
  SET PROPERTY OF hcolumn 'WrapText' = p_wraptext.
ENDFORM. " Format_Column
*&---------------------------------------------------------------------*
*&      Form  Pass_Records
*&---------------------------------------------------------------------*
FORM pass_records USING p_row_cnt.
  DATA: col_cnt TYPE i.
  DATA: l_range(30).
  DATA: row_start(10).
  col_cnt = 1.
*Pass the internal table values to the spreadsheet.
  LOOP AT i_excel INTO r_excel.
    DO 4 TIMES.
      ASSIGN COMPONENT sy-index OF STRUCTURE r_excel TO <val>.
      PERFORM fill_the_cell USING p_row_cnt col_cnt 0 <val>.
      col_cnt = col_cnt + 1. "increment column
    ENDDO.

*Build the range object.
    row_start = p_row_cnt.
    CONCATENATE 'A' row_start ':D' row_start INTO l_range.
    CONDENSE l_range NO-GAPS.

*Set row color to yellow.
    CALL METHOD OF
        hexcel
        'RANGE' = hrange
      EXPORTING
        #1      = l_range.
    CALL METHOD OF
        hrange
        'Interior' = hinterior.
*    SET PROPERTY OF hinterior 'ColorIndex' = 2. "7. "yellow
    p_row_cnt = p_row_cnt + 1. "increment row
    col_cnt = 1. "reset column to A (ie. col 1)
  ENDLOOP.
ENDFORM.                    "Pass_Records
*&---------------------------------------------------------------------*
*&      Form  Release_Excel
*&---------------------------------------------------------------------*
FORM release_excel .
  SET PROPERTY OF hexcel 'Visible' = 1.
  FREE OBJECT hexcel.
  PERFORM err_hdl.
ENDFORM. " Release_Excel
*---------------------------------------------------------------------
*FORM Fill_The_Cell
*---------------------------------------------------------------------
*
*Sets cell at coordinates i,j to value val boldtype bold *
*
*BOLD --> 1 = true, set bold ON 0 = false, set bold OFF
*---------------------------------------------------------------------
FORM fill_the_cell USING i j bold thevalue.
  CALL METHOD OF
      hexcel
      'Cells' = hcell
    EXPORTING
      #1      = i
      #2      = j.
  PERFORM err_hdl.
  SET PROPERTY OF hcell 'Value' = thevalue.
  PERFORM err_hdl.
  GET PROPERTY OF hcell 'Font' = hfont.
  PERFORM err_hdl.
  SET PROPERTY OF hfont 'Bold' = bold.
  PERFORM err_hdl.
ENDFORM.                    "Fill_The_Cell
*&---------------------------------------------------------------------*
*&      Form  ERR_HDL
*&---------------------------------------------------------------------*
FORM err_hdl.
  IF sy-subrc <> 0.
    MESSAGE i000(zz) WITH 'OLE Automation error: ' sy-subrc.
    EXIT.
  ENDIF.
ENDFORM. " ERR_HDL

Report to find CDS view of Standard Table

A small change has been made to the original program ( SAP YARD Article ) so that it can also display the common CDS used by multiple table...