2023 Jul 20 3:10 PM
Hello All,
I got a requirement like below to enhance the existing report. Please help in achieving this
1. Add new field on output, name it as “Path” on 1st ALV display and set it ‘X’, if the report holds selection-screen parameter accepting file name or path.
2. We need to export data to excel file, like report – ABC , having 3 variants. Then, export data on variant to each worksheet. for this example, excel file will hold 3 worksheets.
REPORT ZVARIANT_VALUES.
TYPE-POOLS: slis.
TABLES: trdir.
*global declarations - internal table and workareas
DATA: gt_varid TYPE STANDARD TABLE OF varid,
gs_varid TYPE varid.
*Selection Screen
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_pgm FOR trdir-name OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_variant_details.
IF gt_varid IS NOT INITIAL.
PERFORM display_variant_details.
ENDIF.
*&---------------------------------------------------------------------*
*& Form GET_VARIANT_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_variant_details .
DATA: lv_report TYPE rsvar-report,
lv_variant TYPE rsvar-variant.
*Fetching variant names associated with each program
SELECT * FROM varid
INTO TABLE gt_varid
WHERE report IN s_pgm.
ENDFORM. " GET_VARIANT_DETAILS
*&---------------------------------------------------------------------*
*& Form DISPLAY_VARIANT_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_variant_details .
DATA: lv_repid LIKE sy-repid,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_fieldcat1 TYPE slis_t_fieldcat_alv,
ls_fcat TYPE slis_fieldcat_alv.
DATA: alv_layout TYPE slis_layout_alv.
ls_fcat-tabname = 'GT_VARID'.
ls_fcat-fieldname = 'REPORT'.
ls_fcat-seltext_m = 'Program Name'.
APPEND ls_fcat TO lt_fieldcat.
CLEAR ls_fcat.
ls_fcat-tabname = 'GT_VARID'.
ls_fcat-FIELDNAME = 'VARIANT'.
ls_fcat-seltext_m = 'Variant'.
APPEND ls_fcat TO lt_fieldcat.
CLEAR ls_fcat.
lv_repid = sy-repid.
alv_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = lv_repid
i_callback_user_command = 'USER_COMMAND'
is_layout = alv_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_varid
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " DISPLAY_VARIANT_DETAILS
*&---------------------------------------------------------------------*
*& Form USER_COMMNAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
READ TABLE gt_varid INTO gs_varid INDEX rs_selfield-tabindex.
IF gs_varid IS NOT INITIAL.
PERFORM display_variant_info .
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form DISPLAY_VARIANT_INFO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_variant_info .
DATA: lt_val TYPE STANDARD TABLE OF rsparams,
ls_val TYPE rsparams.
DATA: lv_repid LIKE sy-repid,
lt_fieldcat1 TYPE slis_t_fieldcat_alv,
ls_fcat TYPE slis_fieldcat_alv.
DATA: alv_layout TYPE slis_layout_alv.
lv_repid = sy-repid.
alv_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'RS_VARIANT_CONTENTS'
EXPORTING
report = gs_varid-report
variant = gs_varid-variant
TABLES
valutab = lt_val.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF lt_val IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = 'RSPARAMS'
CHANGING
ct_fieldcat = lt_fieldcat1
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = lv_repid
i_grid_title = 'Variant Information'
is_layout = alv_layout
it_fieldcat = lt_fieldcat1
TABLES
t_outtab = lt_val
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDFORM. " DISPLAY_VARIANT_INFO
2023 Jul 20 3:19 PM
2023 Jul 20 3:23 PM
I want to know how to implement the below enhancement request for the existing one.
2023 Jul 20 3:24 PM
The existing report will fetch all the variant details of all the existing Reports in the system
2023 Jul 20 7:41 PM
Please edit your question (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!
At the same time, include your question.
2023 Jul 21 9:53 AM