Skip to end of metadata
Go to start of metadata

Author: Shailesh Kamath
Submitted: 13-Apr-2010
Overview
This report demonstrates how we can fetch the relevant checklist items for a bucket / item using standard xRPM cprojects tables and BAPI function modules.

In almost all xRPM / cProjects-related projects, such a report is often a common requirement. Hence, this report must be highly reusable for technical designers. It will also be useful for functional consultants who will find ready-to-use logic for using the standard xRPM tables and BAPIs. 



Report requirements / Business Rationale:

To allow reporting on all Checklist item associated with a project. This includes checklist and the checklist items linked with the project ID's.

This report provides the necessary details for the checklist items for each project, which can be then effectively monitored and managed.

Key Features
• Issues/Risks can be viewed and monitored at the bucket level
• Checklist item details can be viewed and monitored against the corresponding item.
• Issues details can be viewed and monitored effectively.
• This report can also be downloaded to the excel format.

Selection screen layout and description: 

The selection screen contains the following fields:

  1. Portfolio Bucket (mandatory)
  2. Item ID

and the following filtering criteria:

  1. Item Status
  2. Item Status Group
  3. Checklist System Status 
  4. Checklist User status
  5. Constraint Finish Date
  6. Checklist type

Every field is a SELECT-OPTION.

Report Layout:

The report output will be an ALV Grid which will contain the following fields:

  1. Bucket Name
  2. Item ID
  3. Item Name
  4. Item Description
  5. Item Status
  6. Item Status Group
  7. Checklist Header
  8. Checklist Items
  9. Checklist Description
  10. Checklist Notes
  11. Status
  12. Created on
  13. Created by
  14. Changed by
  15. Changed on
  16. Priority
  17. Constraint Finish date
  18. Actual Finish date
  19. Process

The report also contains a separate Download button with a Function Code 'DWLD'. This button is used for downloading the ALV report.

Psuedo Code:

1. Using the user input, fetch the Bucket GUID from the table /RPM/BUCKET_D.
2. Based on GUID, fetch the bucket description from the table /RPM/V_BUCKET_DB.
3. Check whether user has entered an item. If yes, fetch the GUID only for that item, otherwise fetch all item GUIDs for the bucket. Match the bucket GUID with the table field /RPM/ITEM_D-PARENT_GUID.
4. Filter the Item GUIDs: fetch only those entries where VERSION_ITEM = ' ' and ITEM_TEXT = ' '.
5. Fetch item name from table /RPM/V_DESC_ITMD-TEXT1, item status from /RPM/STATUS_T-TEXT and item status group from /RPM/ITEM_STATUS-STATUS_GROUP. If the user has entered filter criteria for status group in the selection screen, fetch only the relevant data.
6. Fetch the Project GUID for each item from the RPM_OBJ_LINK table (field OBJECT_KEY).
7. Loop at the item table.

7.1 Execute the BAPI BAPI_BUS2172_GET_TREE:
     CALL FUNCTION 'BAPI_BUS2172_GET_TREE'
       EXPORTING
         project_definition_guid = lv_pguid  "Project GUID
       TABLES
         et_tree                 = lt_tree.  "Tree list

7.2 Fetch Checklist Header (OBJECT_TYPE = 'CTO') and Checklist Items (OBJECT_TYPE = 'ITO' with SUPERIOR_OBJECT_TYPE = 'CTO') from the tree structure.
7.3 Populate the Checklist Item internal table with checklist header and checklist item GUIDs and Project GUIDs.

8. Fetch Checklist Item Status details from the view V_DPR_CHKLST_I_S. If the user has entered filter criteria for this field in the selection screen, fetch only the relevant data.
9. Fetch Checklist Type from the DPR_CHECKLIST_H table (field CLH_TYPE) . If the user has entered filter criteria for this field in the selection screen, fetch only the relevant data.
10. Loop at the checklist item table.

10.1 Execute the BAPI BAPI_BUS2174_GET_DETAIL

          CALL FUNCTION 'BAPI_BUS2174_GET_DETAIL'
            EXPORTING
              checklist_item_guid      = lv_c_item_guid
                                                "Checklist GUID
            IMPORTING
              es_checklist_item_detail = ls_c_item_detail
                                                "Item Details
            TABLES
              et_description           = lt_cdesc "Description
              et_status                = lt_cstatus. "Status

10.2 Fetch both system status and user status from the lt_status table. If the user has entered filter criteria for this field in the selection screen, fetch only the relevant data.
10.3 Fetch item description from lt_cdesc table
10.4 Fetch the Created By, Created On, Changed By and Changed on fields and Process Text from the Item Details table
10.5 Use FM 'READ TEXT' to fetch the Checklist Notes
          CALL FUNCTION 'READ_TEXT'
            EXPORTING
              client                  = sy-mandt
              id                      = 'LOG'
              language                = 'E'
              name                    = lv_itemname
              object                  = 'CGPL_TEXT'
            TABLES
              lines                   = gt_item_txt_line
            EXCEPTIONS
              id                      = 1
              language                = 2
              name                    = 3
              not_found               = 4
              object                  = 5
              reference_check         = 6
              wrong_access_to_archive = 7
    OTHERS                  = 8.
10.6 End loop.
11. Fetch Priority from the CGPL_TASK table, and then fetch the Priority Text from the DPR_PRIORITY_T-TEXT field.
12. Populate the ALV output table
13. Display the ALV Grid

Code snippets:

Instead of pasting the entire code, I am pasting the most relevant code segments:

Selection Screen  

*---------------------------------------------------------------------
* SELECTION SCREEN DEFINITION
*---------------------------------------------------------------------
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
* Portfolio Bucket
  s_bucket  FOR  /rpm/v_bucket_db-external_id
                 OBLIGATORY
                 MODIF ID m1
                 MATCHCODE OBJECT zh_rpm_bucket,
* Item ID
  s_itemid  FOR  /rpm/item_d-external_id
                 MODIF ID m2.
SELECTION-SCREEN: END OF BLOCK blk1.
SELECTION-SCREEN: BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
SELECT-OPTIONS:
* Item Status
  s_istat   FOR  /rpm/status-status MODIF ID m2,
* Item Status group
  s_isgrp   FOR  /rpm/item_status-status_group MODIF ID m2,
* Checklist System Status
  s_sstat   FOR  v_dpr_chklst_i_s-proc_status_own MODIF ID m2,
* Checklist User Status
  s_ustat   FOR  tj30t-estat MODIF ID m2,
* Finish Date
  s_fin_dt  FOR  sy-datum MODIF ID m2,
* Checklist Type
  s_ctype   FOR  dpr_checklist_h-clh_type MODIF ID m2.
SELECTION-SCREEN: END OF BLOCK blk2.

Step 6: Fetching the project GUID.

(Note that the item GUID is passed into the PROJECT_GUID field, whereas the actual project GUID is obtained from the field OBJECT_KEY)

* Use table RPM_OBJ_LINK, you will get the GUID in field PROJECT_GUID,
* then find the Project GUID in the field OBJECT_KEY
  SELECT  project_guid
          object_key
    FROM  rpm_obj_link
    INTO  TABLE gt_project_guid
     FOR  ALL ENTRIES IN gt_itemtable    "contains Item GUID, along with other item details
   WHERE  project_guid = gt_itemtable-guid
     AND  object_type = gc_objtype.

Step 7: Fetching the relevant checklist header and checklist item details 

      LOOP AT gt_itemtable INTO gs_wa_itemtable.
        CLEAR: lv_pguid,
               lt_tree[].
        CONDENSE gs_wa_itemtable-project_guid.
        lv_pguid = gs_wa_itemtable-project_guid.
        CALL FUNCTION 'BAPI_BUS2172_GET_TREE'
          EXPORTING
            project_definition_guid = lv_pguid
          TABLES
            et_tree                 = lt_tree.
*       Filter the tree output so that it only contain checklist
*       header and checklist item details. Remove all other
*       entries.
        REFRESH: gt_cto[].
        CLEAR: gs_wa_cto.
        LOOP AT lt_tree INTO ls_wa_tree.
          IF NOT ( ls_wa_tree-object_type = gc_cto OR
                   ls_wa_tree-object_type = gc_ito ).
            DELETE lt_tree.
            CONTINUE.
          ELSEIF ls_wa_tree-object_type = gc_ito AND
                 ls_wa_tree-superior_object_type NE gc_cto.
            DELETE lt_tree.
            CONTINUE.
          ELSEIF ls_wa_tree-object_type = gc_cto.
*           Store checklist headers (CTO entries) separately
            CLEAR: gs_wa_cto.
            gs_wa_cto-object_type = ls_wa_tree-object_type.
            gs_wa_cto-guid = ls_wa_tree-guid.
            gs_wa_cto-explanation = ls_wa_tree-explanation.
            APPEND gs_wa_cto TO gt_cto.
          ENDIF.
        ENDLOOP.
        CLEAR: ls_wa_tree.
*       Now fetch ITO entries (checklist items) which have CTO entries
*       as their superior
        LOOP AT lt_tree INTO ls_wa_tree WHERE object_type = gc_ito.
          CLEAR: gs_wa_cto.
          READ TABLE gt_cto INTO gs_wa_cto
                            WITH KEY guid = ls_wa_tree-superior_guid.
          IF sy-subrc = 0.
            CLEAR: gs_wa_checklist_tab.
            gs_wa_checklist_tab-pguid = gs_wa_itemtable-project_guid.
            gs_wa_checklist_tab-chk_hdr_id = gs_wa_cto-guid.
            gs_wa_checklist_tab-hdr_desc = gs_wa_cto-explanation.
            gs_wa_checklist_tab-chk_item_id = ls_wa_tree-guid.
            gs_wa_checklist_tab-item_exp = ls_wa_tree-explanation.
            APPEND gs_wa_checklist_tab TO gt_checklist_tab.
          ENDIF.
        ENDLOOP.
      ENDLOOP.

Step 10: Fetching checklist item details
Here, the checlist table has a deep structure, i.e. it has two internal tables within it, one to hold the item description (item_desc[]) and another for project notes (notes[]).

In ALV Grids, there is a limitation of 128 characters on each cell. However, the client had huge item descriptions and project notes associated with the checklist items. Hence, we decided to insert multiple rows to accommodate the text correctly. When generating the final output, a new row is inserted for each line in these tables thereby preserving the long texts.

*       Fetch all remaining details for the checklist items using the
*       BAPI BAPI_BUS2174_GET_DETAIL
        LOOP AT gt_checklist_tab ASSIGNING <ls_wa_checklist_tab>.
          lv_c_item_guid = <ls_wa_checklist_tab>-chk_item_id.
          CALL FUNCTION 'BAPI_BUS2174_GET_DETAIL'
            EXPORTING
              checklist_item_guid      = lv_c_item_guid
            IMPORTING
              es_checklist_item_detail = ls_c_item_detail
            TABLES
              et_description           = lt_cdesc
              et_status                = lt_cstatus.
*         If the user has entered contraint dates, filter the
*         output based on the entered values
          IF NOT s_fin_dt[] IS INITIAL.
            lv_constr_date+6(2) =
              ls_c_item_detail-fixed_finish_date+0(2).
            lv_constr_date+4(2) =
              ls_c_item_detail-fixed_finish_date+3(2).
            lv_constr_date+0(4) =
              ls_c_item_detail-fixed_finish_date+6(4).
            IF NOT lv_constr_date IN s_fin_dt[].
              DELETE gt_checklist_tab.
              CONTINUE.
            ENDIF.
          ENDIF.
*         If the user has entered contraint types, filter the
*         output based on the entered value
          IF NOT gt_chdr_type[] IS INITIAL.
            CONDENSE <ls_wa_checklist_tab>-chk_hdr_id.
            READ TABLE gt_chdr_type INTO gs_wa_chdr_type
                 WITH KEY guid = <ls_wa_checklist_tab>-chk_hdr_id.
            IF sy-subrc <> 0.
              DELETE gt_checklist_tab.
              CONTINUE.
            ENDIF.
          ENDIF.
*         If the user has entered status values, filter the
*         output based on the entered values. Note that the first
*         line gives system status whereas the second line gives
*         user status
          IF NOT lt_cstatus[] IS INITIAL.
            CLEAR: lv_ctext.
            LOOP AT lt_cstatus INTO ls_wa_cstatus.
              IF NOT lv_ctext IS INITIAL.
                CONCATENATE lv_ctext
                            '-'
                            ls_wa_cstatus-status_text_long
                            INTO lv_ctext SEPARATED BY space.
              ELSE.
                CONCATENATE lv_ctext
                            ls_wa_cstatus-status_text_long
                            INTO lv_ctext.
              ENDIF.
            ENDLOOP.
            CONDENSE lv_ctext.
            <ls_wa_checklist_tab>-status = lv_ctext.
*           Check the item status and match with both the system
*           status and the user status
            CLEAR: ls_wa_cstatus.
            IF NOT s_ustat[] IS INITIAL.
              READ TABLE lt_cstatus INTO ls_wa_cstatus INDEX 2.
              IF sy-subrc = 0.
                CONDENSE ls_wa_cstatus-status_key.
                IF NOT ls_wa_cstatus-status_key IN s_ustat[].
                  DELETE gt_checklist_tab.
                  CONTINUE.
                ENDIF.
              ELSE.
                DELETE gt_checklist_tab.
                CONTINUE.
              ENDIF.
            ENDIF.
            READ TABLE lt_cstatus INTO ls_wa_cstatus INDEX 1.
            IF sy-subrc = 0.
              CONDENSE ls_wa_cstatus-status_key.
              READ TABLE gt_citem_status INTO gs_wa_citem_status
                   WITH KEY guid = <ls_wa_checklist_tab>-chk_item_id
                            status = ls_wa_cstatus-status_key.
              IF sy-subrc <> 0.
                DELETE gt_checklist_tab.
                CONTINUE.
              ENDIF.
            ENDIF.
          ENDIF.
          IF NOT lt_cdesc[] IS INITIAL.
*           Fetch all lines in the item description into an item
*           description table
            CLEAR: lv_ctext,
                   lt_citem_desc[],
                   ls_wa_citem_desc.
            LOOP AT lt_cdesc INTO ls_wa_cdesc.
              ls_wa_citem_desc = ls_wa_cdesc-description_line.
              IF NOT ls_wa_citem_desc IS INITIAL.
                APPEND ls_wa_citem_desc TO lt_citem_desc.
              ENDIF.
            ENDLOOP.
            <ls_wa_checklist_tab>-item_desc[] = lt_citem_desc[].
          ENDIF.
*         Fetch checklist item creation details, constraint finish
*         and actual finish dates, and the process description
          IF NOT ls_c_item_detail IS INITIAL.
            <ls_wa_checklist_tab>-created_by =
              ls_c_item_detail-created_by.
            <ls_wa_checklist_tab>-created_on =
              ls_c_item_detail-created_on.
            <ls_wa_checklist_tab>-changed_by =
              ls_c_item_detail-changed_by.
            <ls_wa_checklist_tab>-changed_on =
              ls_c_item_detail-changed_on.
            <ls_wa_checklist_tab>-constr_fin_date
              = ls_c_item_detail-fixed_finish_date.
*           Date conversion from DDMMYYYY to SAP format
            <ls_wa_checklist_tab>-actual_fin_date+0(4)
              = ls_c_item_detail-actual_finish_date+4(4).
            <ls_wa_checklist_tab>-actual_fin_date+4(2)
              = ls_c_item_detail-actual_finish_date+2(2).
            <ls_wa_checklist_tab>-actual_fin_date+6(2)
              = ls_c_item_detail-actual_finish_date+0(2).
            <ls_wa_checklist_tab>-proc_txt
              = ls_c_item_detail-process_text.
          ENDIF.
*         Fetch checklist notes using the function module READ_TEXT
          CLEAR: gt_item_txt_line[],
                 gs_wa_item_txt_line,
                 lv_itemname,
                 lt_notes[],
                 ls_wa_notes.
          lv_itemname = <ls_wa_checklist_tab>-chk_item_id.
          CALL FUNCTION 'READ_TEXT'
            EXPORTING
              client                  = sy-mandt
              id                      = 'LOG'
              language                = 'E'
              name                    = lv_itemname
              object                  = 'CGPL_TEXT'
            TABLES
              lines                   = gt_item_txt_line
            EXCEPTIONS
              id                      = 1
              language                = 2
              name                    = 3
              not_found               = 4
              object                  = 5
              reference_check         = 6
              wrong_access_to_archive = 7
              OTHERS                  = 8.
          IF sy-subrc <> 0.
*         Insert any error handling code here if necessary
          ELSE.
            CLEAR: gs_wa_item_txt_line,
                   lv_flag,
                   lv_eofnote.
            LOOP AT gt_item_txt_line INTO gs_wa_item_txt_line.
*             The ampersand character has a known issue of misprinting
*             The following line corrects this problem
              REPLACE ALL OCCURRENCES OF gc_ampchar
                                      IN gs_wa_item_txt_line-tdline
                                    WITH gc_amp.
              CLEAR: ls_wa_notes.
*             The Checklist Notes are encapsulated between two tags
*             %TEXT% and %EOF_NOTE%. Since there can be multiple
*             checklist notes, fetch all text wherever these tags
*             are found.
              IF lv_flag = ' '.
                IF gs_wa_item_txt_line-tdline+0(6) = gc_htxt.
                  lv_notes_txt = gs_wa_item_txt_line-tdline+7.
                  CONDENSE lv_notes_txt.
                  ls_wa_notes = lv_notes_txt.
                  lv_eofnote = ' '.
                  lv_flag = gc_x.
                  IF NOT ls_wa_notes IS INITIAL.
                    APPEND ls_wa_notes TO lt_notes.
                  ENDIF.
                ENDIF.
              ELSEIF lv_flag =  gc_x.
                IF gs_wa_item_txt_line-tdline+0(10) = gc_enote.
                  lv_eofnote =  gc_x.
                  lv_flag = ' '.
                  CONTINUE.
                ELSEIF lv_eofnote = ' '.
                  lv_notes_txt = gs_wa_item_txt_line-tdline.
                  CONDENSE lv_notes_txt.
                  ls_wa_notes = lv_notes_txt.
                  IF NOT ls_wa_notes IS INITIAL.
                    APPEND ls_wa_notes TO lt_notes.
                  ENDIF.
                ENDIF.
              ENDIF.
            ENDLOOP.
            <ls_wa_checklist_tab>-notes[] = lt_notes[].
          ENDIF.
        ENDLOOP.

Populating the final ALV table

*---------------------------------------------------------------------
* Form FILL_OUTTAB
*---------------------------------------------------------------------
* This subroutine populates the ALV table
*---------------------------------------------------------------------
FORM fill_outtab.
  DATA: lt_notes_tab        TYPE  typ_notes,
        ls_wa_notes_tab     LIKE  LINE OF lt_notes_tab,
        lt_itemdesc_tab   TYPE  typ_notes,
        ls_wa_itemdesc_tab  LIKE  LINE OF lt_itemdesc_tab,
        lv_entries1       TYPE  i,
        lv_entries2       TYPE  i,
        lv_entries3       TYPE  i,
        lv_totlines       TYPE  i,
        lv_count          TYPE  i,
        lv_index          TYPE  i.
  REFRESH: gt_outtab[].
  CLEAR: gs_wa_outtab,
         gs_wa_checklist_tab,
         gs_wa_itemtable,
         gs_wa_bucket_desc.
  LOOP AT gt_checklist_tab INTO gs_wa_checklist_tab.
    READ TABLE gt_itemtable INTO gs_wa_itemtable
               WITH KEY project_guid = gs_wa_checklist_tab-pguid.
    IF sy-subrc = 0.
      READ TABLE gt_bucket_desc INTO gs_wa_bucket_desc
                 WITH KEY guid = gs_wa_itemtable-parent_guid.
    ENDIF.
    gs_wa_outtab-bucketname     = gs_wa_bucket_desc-text1.
    gs_wa_outtab-itemid         = gs_wa_itemtable-external_id.
    gs_wa_outtab-itemname       = gs_wa_itemtable-text1.
    gs_wa_outtab-istatus        = gs_wa_itemtable-stattext.
    gs_wa_outtab-isgroup        = gs_wa_itemtable-sgrp.
    gs_wa_outtab-c_header       = gs_wa_checklist_tab-hdr_desc.
    gs_wa_outtab-ci_exp         = gs_wa_checklist_tab-item_exp.
    gs_wa_outtab-ci_status      = gs_wa_checklist_tab-status.
    gs_wa_outtab-ci_crt_on      = gs_wa_checklist_tab-created_on.
    gs_wa_outtab-ci_crt_by      = gs_wa_checklist_tab-created_by.
    gs_wa_outtab-ci_chg_on      = gs_wa_checklist_tab-changed_on.
    gs_wa_outtab-ci_chg_by      = gs_wa_checklist_tab-changed_by.
    gs_wa_outtab-ci_prio        = gs_wa_checklist_tab-ptext.
    gs_wa_outtab-ci_cfin_date   = gs_wa_checklist_tab-constr_fin_date.
    gs_wa_outtab-ci_afin_date   = gs_wa_checklist_tab-actual_fin_date.
    gs_wa_outtab-ci_proc_txt    = gs_wa_checklist_tab-proc_txt.
    CLEAR: ls_wa_notes_tab,
           gs_wa_outtab-ci_notes,
           gs_wa_outtab-ci_desc.
    READ TABLE gs_wa_checklist_tab-notes INTO ls_wa_notes_tab
                                       INDEX 1.
    IF sy-subrc = 0.
      gs_wa_outtab-ci_notes = ls_wa_notes_tab.
    ENDIF.
    CLEAR: ls_wa_itemdesc_tab.
    READ TABLE gs_wa_checklist_tab-item_desc INTO ls_wa_itemdesc_tab
                                           INDEX 1.
    IF sy-subrc = 0.
      gs_wa_outtab-ci_desc = ls_wa_itemdesc_tab.
    ENDIF.
    APPEND gs_wa_outtab TO gt_outtab.
    CLEAR: lv_entries1,
           lv_entries2,
           lv_entries3.
    DESCRIBE TABLE gs_wa_checklist_tab-notes LINES lv_entries1.
    DESCRIBE TABLE gs_wa_checklist_tab-item_desc LINES lv_entries2.
    IF lv_entries1 > lv_entries2.
      lv_totlines = lv_entries1.
    ELSE.
      lv_totlines = lv_entries2.
    ENDIF.
    IF lv_totlines > 1.
      lv_count = lv_totlines - 1.
      lv_index = 1.
      DO lv_count TIMES.
        CLEAR: gs_wa_outtab,
               ls_wa_notes_tab,
               ls_wa_itemdesc_tab.
        lv_index = lv_index + 1.
        READ TABLE gs_wa_checklist_tab-notes INTO ls_wa_notes_tab
                                           INDEX lv_index.
        IF sy-subrc = 0.
          gs_wa_outtab-ci_notes = ls_wa_notes_tab.
        ENDIF.
        READ TABLE gs_wa_checklist_tab-item_desc INTO ls_wa_itemdesc_tab
                                               INDEX lv_index.
        IF sy-subrc = 0.
          gs_wa_outtab-ci_desc = ls_wa_itemdesc_tab.
        ENDIF.
        APPEND gs_wa_outtab TO gt_outtab.
      ENDDO.
    ENDIF.
  ENDLOOP.
  IF gt_outtab[] IS INITIAL.
    MESSAGE i000(za) WITH text-011.
  ENDIF.
ENDFORM.                    "fill_outtab 

Download button logic (to concatenate the long texts and download into Excel)

*---------------------------------------------------------------------
* FORM DOWNLOAD_TO_EXCEL
*---------------------------------------------------------------------
* This subroutine downloads the list to an Excel sheet. Here, the
* checklist item notes and item descriptions are correctly formatted.
*---------------------------------------------------------------------
FORM download_to_excel.
  DATA: lt_dwldtab     TYPE  STANDARD TABLE OF typ_outtab,
        ls_wa_dwldtab    LIKE  LINE OF lt_dwldtab,
        lt_header      TYPE  STANDARD TABLE OF typ_header,
        ls_wa_header     LIKE  LINE OF lt_header.
  DATA: lo_gui TYPE REF TO cl_gui_frontend_services.
  DATA: lv_itemdesc    TYPE  string,
        lv_chknotes    TYPE  string,
        lv_title       TYPE  string,
        lv_folder      TYPE  string,
        lv_filename    TYPE  string,
        lv_path        TYPE  string,
        lv_result      TYPE  i,
        lv_dir         TYPE  string.
  CLEAR: gs_wa_outtab.
  LOOP AT gt_outtab INTO gs_wa_outtab.
    IF NOT gs_wa_outtab-bucketname IS INITIAL.
      IF NOT ls_wa_dwldtab IS INITIAL.
        APPEND ls_wa_dwldtab TO lt_dwldtab.
      ENDIF.
      CLEAR: ls_wa_dwldtab,
             lv_itemdesc,
             lv_chknotes.
      ls_wa_dwldtab-bucketname = gs_wa_outtab-bucketname.
      ls_wa_dwldtab-itemid = gs_wa_outtab-itemid.
      ls_wa_dwldtab-itemname = gs_wa_outtab-itemname.
      ls_wa_dwldtab-istatus = gs_wa_outtab-istatus.
      ls_wa_dwldtab-isgroup = gs_wa_outtab-isgroup.
      ls_wa_dwldtab-c_header = gs_wa_outtab-c_header.
      ls_wa_dwldtab-ci_exp = gs_wa_outtab-ci_exp.
      ls_wa_dwldtab-ci_desc = gs_wa_outtab-ci_desc.
      ls_wa_dwldtab-ci_notes = gs_wa_outtab-ci_notes.
      ls_wa_dwldtab-ci_status = gs_wa_outtab-ci_status.
      ls_wa_dwldtab-ci_crt_on = gs_wa_outtab-ci_crt_on.
      ls_wa_dwldtab-ci_crt_by = gs_wa_outtab-ci_crt_by.
      ls_wa_dwldtab-ci_chg_on = gs_wa_outtab-ci_chg_on.
      ls_wa_dwldtab-ci_chg_by = gs_wa_outtab-ci_chg_by.
      ls_wa_dwldtab-ci_prio = gs_wa_outtab-ci_prio.
      ls_wa_dwldtab-ci_cfin_date = gs_wa_outtab-ci_cfin_date.
      ls_wa_dwldtab-ci_afin_date = gs_wa_outtab-ci_afin_date.
      ls_wa_dwldtab-ci_proc_txt = gs_wa_outtab-ci_proc_txt.
    ELSE.
*     Since there can be multiple lines of item description and
*     checklist item notes, concatenate the lines into a single
*     cell in the final Excelsheet
      IF NOT gs_wa_outtab-ci_desc IS INITIAL.
        CONCATENATE  ls_wa_dwldtab-ci_desc
                     gs_wa_outtab-ci_desc
               INTO  ls_wa_dwldtab-ci_desc.
      ENDIF.
      IF NOT gs_wa_outtab-ci_notes IS INITIAL.
        CONCATENATE  ls_wa_dwldtab-ci_notes
                     gs_wa_outtab-ci_notes
               INTO  ls_wa_dwldtab-ci_notes.
      ENDIF.
    ENDIF.
  ENDLOOP.
  IF NOT ls_wa_dwldtab IS INITIAL.
    APPEND ls_wa_dwldtab TO lt_dwldtab.
  ENDIF.
  CREATE OBJECT lo_gui.
  lv_title = text-039.
  lv_filename = gc_filenm.
  lv_folder = 'C:'.
* Display save dialog window
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title      = lv_title
      default_extension = 'XLS'
      default_file_name = lv_filename
      initial_directory = lv_folder
    CHANGING
      filename          = lv_filename
      path              = lv_path
      fullpath          = lv_dir
      user_action       = lv_result.
* Check whether the input is valid
  CHECK lv_result EQ '0'.
  CLEAR: gs_wa_fieldcat.
* Create the header row for the file
  LOOP AT gt_fieldcat INTO gs_wa_fieldcat.
    CLEAR: ls_wa_header.
    ls_wa_header-filed1 = gs_wa_fieldcat-coltext.
    APPEND ls_wa_header TO lt_header.
  ENDLOOP.
* Download the file
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = lv_dir
      filetype                = 'ASC'
      write_field_separator   = 'X'
    TABLES
      data_tab                = lt_dwldtab
      fieldnames              = lt_header
    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
      OTHERS                  = 22.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    "download_to_excel 

Related Links:

N/A

2 Comments

  1. Unknown User (hwwzhke)

    Hello Shailesh Kamath,

    This post is very very intresting and helps me a lot.

    Thank you very much for that and i will be delighted if you share with us an other experience or subject about Cproject and RPM.

    Best regards!

    Amal SALHI 

  2. Former Member

    Excelente pos!!! saludos

    Un Abrazo...

    Hugo Aravena