Wednesday, 24 June 2020

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 tables.

*&---------------------------------------------------------------------*
*& Report YCDS_FIND
*&---------------------------------------------------------------------*
*& Report to find the common CDS view of multiple table
*&---------------------------------------------------------------------*
REPORT ycds_find.

TABLES: ddldependency,dd25t,dd26s.

DATA: gt_25t TYPE  STANDARD TABLE OF dd25t,
      gs_25t TYPE dd25t.

CONSTANTS: gc_true  TYPE sap_bool VALUE 'X',
           gc_false TYPE sap_bool VALUE ' '.

* Deferred Class Definition
CLASS lcl_handle_events DEFINITION DEFERRED.

DATA: gt_outtab TYPE STANDARD TABLE OF alv_t_t2.
DATA: gr_table   TYPE REF TO cl_salv_table.
DATA: gr_container TYPE REF TO cl_gui_custom_container.

*...  object for handling the events of cl_salv_table
DATA: gr_events TYPE REF TO lcl_handle_events.
DATA: g_okcode TYPE syucomm.
DATA: it_bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE      .
DATA:wa_bdcdata TYPE bdcdata .

* Event Handler Class Definition
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_link_click FOR EVENT link_click OF cl_salv_events_table
        IMPORTING row column.
ENDCLASS .

* Event Handler Class Implementation
CLASS lcl_handle_events IMPLEMENTATION.

* On Click Method
  METHOD on_link_click.

    READ TABLE gt_25t INTO DATA(ls_25t) INDEX row.

    PERFORM bdc_dynpro      USING 'SAPLSD_ENTRY' '1000'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RSRD1-TBMA_VAL'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=WB_DISPLAY'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=WB_DISPLAY'.
    PERFORM bdc_field       USING 'RSRD1-TBMA'
                                  'X'.
    PERFORM bdc_field       USING 'RSRD1-TBMA_VAL'
                                  ls_25t-viewname.
*   Navigate to Data Dictionary
    CALL TRANSACTION 'SE11' USING it_bdcdata
                                  MODE 'E'
                                  UPDATE 'A' .

    CLEAR: it_bdcdata[].

  ENDMETHOD.

ENDCLASS.

* Selection Screen
SELECT-OPTIONS: s_tab  FOR dd26s-tabname NO INTERVALS,
                s_view FOR dd25t-ddtext NO INTERVALS.


PARAMETERS : p_norm RADIOBUTTON GROUP rb1,
             p_join RADIOBUTTON GROUP rb1 DEFAULT 'X'.

* At Selection Screen
AT SELECTION-SCREEN.

* Start of Selection
START-OF-SELECTION.

* Pull the data from the db tables
  SELECT
  a~viewname,
  ddtext,
  objecttype
    FROM dd25t AS a INNER JOIN ddldependency AS b
    ON a~viewname = b~objectname
    INNER JOIN dd26s AS c
    ON a~viewname = c~viewname
    INTO TABLE @DATA(lt_final)
    WHERE a~ddlanguage = 'E' AND
          a~ddtext IN @s_view AND
          c~tabname IN @s_tab AND
          a~as4local EQ 'A'.

  LOOP AT lt_final INTO DATA(ls_final).
    MOVE-CORRESPONDING ls_final TO gs_25t .
    APPEND gs_25t TO gt_25t.
    CLEAR:gs_25t.
  ENDLOOP.

  SORT gt_25t BY viewname ASCENDING.

  IF p_join EQ abap_true.
    DATA lt_tmp TYPE STANDARD TABLE OF dd25t WITH NON-UNIQUE SORTED KEY viewname COMPONENTS viewname .
    lt_tmp = gt_25t[].
  ENDIF.

  DELETE ADJACENT DUPLICATES FROM gt_25t COMPARING viewname.

  IF p_join EQ abap_true.
    LOOP AT gt_25t ASSIGNING FIELD-SYMBOL(<lfs_25t>).

      DATA(lt_tmp2) = FILTER #( lt_tmp USING KEY viewname WHERE viewname = <lfs_25t>-viewname ).

      IF lines( lt_tmp2 ) NE lines( s_tab ).
        <lfs_25t>-viewname = space.
      ENDIF.
    ENDLOOP.
    DELETE gt_25t WHERE viewname = space.
  ENDIF.

  DESCRIBE TABLE  gt_25t LINES DATA(l_tabix).

  DATA: l_count TYPE c LENGTH 7.
  l_count = l_tabix.

  CONCATENATE 'Total no. of CDS found' l_count INTO DATA(msg).
  MESSAGE msg TYPE 'I'.

* Call Factory Method
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = gr_table
    CHANGING
      t_table      = gt_25t[].

  DATA: lr_columns TYPE REF TO cl_salv_columns_table,
        lr_column  TYPE REF TO cl_salv_column_table.

  lr_columns = gr_table->get_columns( ).
  lr_columns->set_optimize( gc_true ).

  lr_column ?= lr_columns->get_column( 'VIEWNAME' ).
  lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
  lr_column->set_icon( if_salv_c_bool_sap=>true ).
  lr_column->set_long_text( 'VIEWNAME' ).

  DATA: lr_events TYPE REF TO cl_salv_events_table.

  lr_events = gr_table->get_event( ).

  CREATE OBJECT gr_events.

* Set Handler
  SET HANDLER gr_events->on_link_click FOR lr_events.

* Display ALV
  gr_table->display( ).

*---------------------------------------------------
* form for bdc dynpro
*---------------------------------------------------
FORM bdc_dynpro USING program
                      dynpro.
  CLEAR it_bdcdata.
  wa_bdcdata-program = program.
  wa_bdcdata-dynpro = dynpro.
  wa_bdcdata-dynbegin = 'X'.
  APPEND wa_bdcdata TO it_bdcdata.
  CLEAR:wa_bdcdata.

ENDFORM.                    "bdc_dynpro
*---------------------------------------------------
*        form for bdc field
*---------------------------------------------------
FORM bdc_field  USING fnam
                      fval.
  CLEAR it_bdcdata.
  wa_bdcdata-fnam = fnam.
  wa_bdcdata-fval = fval.
  APPEND wa_bdcdata TO it_bdcdata.
  CLEAR:wa_bdcdata.
ENDFORM.                    "bdc_field

Wednesday, 9 October 2019

Send Mail

&---------------------------------------------------------------------*
& Form SENT_MAIL
&---------------------------------------------------------------------*
& Mail Sent incase of errors
&---------------------------------------------------------------------*
FORM sent_mail.
  DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL,
        lo_document     TYPE REF TO cl_document_bcs VALUE IS INITIAL, "document object
        lo_sender       TYPE REF TO if_sender_bcs VALUE IS INITIAL, "sender
        lo_recipient    TYPE REF TO if_recipient_bcs VALUE IS INITIAL, "recipient
        lt_text         TYPE bcsy_text, "Table for body
        lt_lines        TYPE TABLE OF tline.

  CONSTANTS: lc_st   TYPE thead-tdid     VALUE 'ST',
             lc_en   TYPE thead-tdspras  VALUE 'EN',
             lc_name TYPE thead-tdname   VALUE 'ZAHLPLANAENDERUNG', "<=change it
             lc_text TYPE thead-tdobject VALUE 'TEXT'.

  lo_send_request = cl_bcs=>create_persistent( ).

  "Read the email body template from SO10 text
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      id                      = lc_st
      language                = lc_en
      name                    = lc_name
      object                  = lc_text
    TABLES
      lines                   = lt_lines
    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 EQ 0.
    "Set email body
    LOOP AT lt_lines ASSIGNING FIELD-SYMBOL(<lfs_lines>).
      APPEND INITIAL LINE TO lt_text ASSIGNING FIELD-SYMBOL(<lfs_text>).
      <lfs_text>-line = <lfs_lines>-tdline.
    ENDLOOP.
  ENDIF.

  "create document
  lo_document = cl_document_bcs=>create_document( i_type = 'TXT' "Type of document - HTM, TXT etc
                                                  i_text =  lt_text "email body
                                                  i_subject = TEXT-016 ). "email subject
  "Pass the document to send request
  lo_send_request->set_document( lo_document ).

  "Set sender to send request
  TRY.
      lo_sender = cl_sapuser_bcs=>create( sy-uname ). "sender is the logged in user
      lo_send_request->set_sender( EXPORTING i_sender = lo_sender ).
    CATCH cx_address_bcs INTO DATA(lv_address_bcs).
  ENDTRY.

  "Set recipient
  lo_recipient = cl_cam_address_bcs=>create_internet_address( 'test@deloitte.com' ). "Recipient email
  TRY.
      lo_send_request->add_recipient( EXPORTING
                                        i_recipient = lo_recipient
                                        i_express = abap_true ).
    CATCH cx_send_req_bcs INTO DATA(lo_send_req_bcs).
  ENDTRY.

  "Send email
  TRY.
      CALL METHOD lo_send_request->set_send_immediately
        EXPORTING
          i_send_immediately = abap_true.

      lo_send_request->send( EXPORTING
                                i_with_error_screen = abap_true ).
      COMMIT WORK.

      IF sy-subrc = 0. "mail sent successfully
        WRITE :/ 'Mail sent successfully'.
      ENDIF.
    CATCH cx_send_req_bcs INTO lo_send_req_bcs.
  ENDTRY.
ENDFORM.

Tuesday, 8 October 2019

File listing in AL11

Using this FM ensures to return only the filename. It will not return any directory name.

    CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'
      EXPORTING
        iv_dir_name            = CONV eps2filnam( me->gv_filepath )
      TABLES
        dir_list               = lt_dir_list
      EXCEPTIONS
        invalid_eps_subdir     = 1
        sapgparam_failed       = 2
        build_directory_failed = 3
        no_authorization       = 4
        read_directory_failed  = 5
        too_many_read_errors   = 6
        empty_directory_list   = 7
        OTHERS                 = 8.
    IF sy-subrc <> 0 OR lt_dir_list IS INITIAL.
      MESSAGE TEXT-029 TYPE gc_e .
    ENDIF.

Change Pointer Activation

Activate the change pointer in the system by going to BD61












Go to WE81 and create a new Message type: ZMATMAS_AMPL:

Add an entry for ZMATMAS_AMPL in BD50 and activate the change pointer for the same

Goto BD52 and maintain the fields for which the change pointer should get triggered
Now, whenever there will be any changes in those particular fields, changes will get saved in table BDCP2. You can also check CDPOS and CDHDR to get the old value and new value.Use table TBD62 to get the Object ID for the change pointer

Monday, 6 May 2019

JSON to Internal Tables & vice-versa

DATA: lt_flight TYPE STANDARD TABLE OF sflight,
      lrf_descr TYPE REF TO cl_abap_typedescr,
      lv_json   TYPE string.

SELECT * FROM sflight INTO TABLE lt_flight.

* serialize table lt_flight into JSON, skipping initial fields and
* converting ABAP field names into camelCase
lv_json = /ui2/cl_json=>serialize(
                data = lt_flight
                compress = abap_true
                pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).
WRITE / lv_json.

* LV_JSON will have the coverted records to JSON

CLEAR lt_flight.

* deserialize JSON string json into internal table
* lt_flight doing camelCase to ABAP like field name mapping
/ui2/cl_json=>deserialize(
  EXPORTING
    json = lv_json
    pretty_name = /ui2/cl_json=>pretty_mode-camel_case
    CHANGING
      data = lt_flight ).

* LT_FLIGHT[] will have the coverted records from JSON

Wednesday, 10 April 2019

AL11: Move file from one path to another

*&---------------------------------------------------------------------*
*& Form MOVE_FILE
*&---------------------------------------------------------------------*
*& Archiving the file
*&---------------------------------------------------------------------*
FORM move_file USING pv_s_filepath TYPE string
                     pv_t_filepath TYPE string.

  DATA: lv_eof_reached   TYPE flag,
        lv_buffer(20480),
        lv_buflen        TYPE i.

  "open source and target files and start copying
  OPEN DATASET pv_s_filepath FOR INPUT IN BINARY MODE.
  IF sy-subrc NE 0.
    "Add error handling
  ENDIF.

  OPEN DATASET pv_t_filepath FOR OUTPUT IN BINARY MODE.
  IF sy-subrc NE 0.
    "Add error handling
  ENDIF.

  CLEAR lv_eof_reached.
  DO.
    CLEAR lv_buffer.

    READ DATASET pv_s_filepath
    INTO lv_buffer LENGTH lv_buflen.

    IF sy-subrc = 4.
      lv_eof_reached = abap_true.
    ELSEIF sy-subrc > 4.
      "Add error handling
    ENDIF.

    TRANSFER lv_buffer TO pv_t_filepath
    LENGTH lv_buflen.

    IF sy-subrc NE 0.
      "Add error handling
ENDIF. IF lv_eof_reached = abap_true. EXIT. ENDIF. ENDDO. "Delete the source file DELETE DATASET pv_s_filepath. "Close the connection CLOSE DATASET pv_s_filepath. CLOSE DATASET pv_t_filepath. IF sy-subrc <> 0. "Add error handling ENDIF. ENDFORM. "MOVE_FILE

Monday, 18 March 2019

Editable ALV with F4 Help on cell

Report: Z_R_ALV
REPORT z_r_alv.
CLASS gcl_event_handler DEFINITION DEFERRED.

"Data Declaration
INCLUDE z_r_alv_top.

"Class Declaration
INCLUDE z_r_alv_cl.

"Screen Module Declaration
INCLUDE z_r_alv_mod.

"Subroutines Declaraion
INCLUDE z_r_alv_sub.

START-OF-SELECTION.
  CALL SCREEN 1100.


Include: Z_R_ALV_TOP
*&---------------------------------------------------------------------*
*&  Include           Z_R_ALV_TOP
*&---------------------------------------------------------------------*

  TYPES: BEGIN OF gty_extract,
           call_req_id    TYPE  zzcall_req_id,
           object         TYPE  zzobjname,
           serviceid      TYPE  zzcall_sys_id,
           servicekey     TYPE  zzcall_sys_key,
           batch_size     TYPE  zzbsize,
           compression    TYPE  zzkdpcompress,
           mdata          TYPE  zzkdpchar1,
           format         TYPE  zzkdpformat,
           projections    TYPE  string,
           selections     TYPE  string,
           numb_of_lines  TYPE  zzkdpnolines,
           from_date      TYPE  zztimestamp,
           to_date        TYPE  zztimestamp,
           extract_mode   TYPE  zzkdpchar1,
           execution_mode TYPE  zzkdpchar1,
           response_mode  TYPE  zzkdpchar1,
           celltab        TYPE lvc_t_styl,
         END OF gty_extract,
         gtt_extract TYPE STANDARD TABLE OF gty_extract,
         gtt_t_f4    TYPE STANDARD TABLE OF lvc_s_f4.

  DATA: gt_extract          TYPE STANDARD TABLE OF gty_extract,
        go_container        TYPE scrfname VALUE 'CONT1',
        go_grid1            TYPE REF TO cl_gui_alv_grid,
        go_custom_container TYPE REF TO cl_gui_docking_container,
        gs_layout           TYPE lvc_s_layo,
        gv_max              TYPE i VALUE 100.
Include: Z_R_ALV_CL
*&---------------------------------------------------------------------*
*&  Include           Z_R_ALV_CL
*&---------------------------------------------------------------------*
*************************************************************************************************
*LOCAL CLASS DEFINITION
*************************************************************************************************
*Class definition to handle the ONF4 event
CLASS gcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS: on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
      IMPORTING sender
                  e_fieldname
                  e_fieldvalue
                  es_row_no
                  er_event_data
                  et_bad_cells
                  e_display.
ENDCLASS.                    "lcl_event_handler DEFINITION
*************************************************************************************************
*LOCAL CLASS IMPLEMENTATION
*************************************************************************************************
*Class implementation to handle the ONF4 event
CLASS gcl_event_handler IMPLEMENTATION.
  METHOD on_f4.
    TYPES:  BEGIN OF lty_exe_mode,
              mode TYPE zzkdpchar1,
            END OF lty_exe_mode.
    DATA: lt_data   TYPE STANDARD TABLE OF lty_exe_mode,
          lt_ret    TYPE STANDARD TABLE OF ddshretval,
          ls_data   LIKE LINE OF lt_data,
          ls_sel    LIKE LINE OF lt_ret,
          ls_modi   TYPE lvc_s_modi,
          ls_stable TYPE lvc_s_stbl.

    FIELD-SYMBOLS: <lfs_extract> TYPE gty_extract.
    CASE e_fieldname.
      WHEN 'EXECUTION_MODE'.
        "Add the custom F4 values; here we are adding 2 values 'Uncertain' and 'Relevant' for the field STATE
        IF lt_data[] IS INITIAL.
          ls_data-mode = 'B'.
          APPEND ls_data TO lt_data.
          CLEAR ls_data.
          ls_data-mode = 'R'.
          APPEND ls_data TO lt_data.
        ENDIF.
        "Call the function module to display the custom F4 values
        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield        = 'MODE'
            window_title    = 'Execution Mode'
            value_org       = 'S'
          TABLES
            value_tab       = lt_data[]
            return_tab      = lt_ret[]
          EXCEPTIONS
            parameter_error = 1
            no_values_found = 2
            OTHERS          = 3.

        IF sy-subrc = 0.
          READ TABLE lt_ret INTO ls_sel INDEX 1.
          IF sy-subrc EQ 0.
            READ TABLE gt_extract INDEX es_row_no-row_id ASSIGNING <lfs_extract>.
            IF sy-subrc EQ 0.
              <lfs_extract>-execution_mode = ls_sel-fieldval.
              IF go_grid1 IS BOUND.
                ls_stable-row = abap_true.
                ls_stable-col = abap_true.
                CALL METHOD go_grid1->refresh_table_display
                  EXPORTING
                    is_stable = ls_stable
                  EXCEPTIONS
                    finished  = 1
                    OTHERS    = 2.
                IF sy-subrc <> 0.
*             Implement suitable error handling here
                ENDIF.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.

      WHEN 'PROJECTIONS'.
        "Write the code for the other columns
      WHEN OTHERS.
    ENDCASE.
    er_event_data->m_event_handled = abap_true. "(to inform grid that f4 was handled manually)
  ENDMETHOD.
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
Include: Z_R_ALV_MOD
*&---------------------------------------------------------------------*
*&  Include           Z_R_ALV_MOD
*&---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* MODULE PBO OUTPUT *
*---------------------------------------------------------------------*
MODULE status_1100 OUTPUT.
  SET PF-STATUS 'PF_STATUS'.
  "Preapre the ALV
  PERFORM prepare_alv.
ENDMODULE.                    "pbo OUTPUT
*---------------------------------------------------------------------*
* MODULE PAI INPUT *
*---------------------------------------------------------------------*
MODULE user_command_1100 INPUT.
*  save_ok = ok_code.
*  CLEAR ok_code.
  CASE sy-ucomm.
    WHEN '&EXE'.
      CALL METHOD go_grid1->check_changed_data.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                    "pai INPUT
Include: Z_R_ALV_SUB
*&---------------------------------------------------------------------*
*&  Include           Z_R_ALV_SUB
*&---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* PREPARE_ALV *
*---------------------------------------------------------------------*
FORM prepare_alv.
  DATA: lt_fieldcatalog TYPE lvc_t_fcat,
        lt_f4           TYPE lvc_t_f4,
        lt_f4_tmp       TYPE gtt_t_f4,
        lo_event_obj    TYPE REF TO gcl_event_handler.

  IF go_custom_container IS INITIAL.
    CREATE OBJECT go_custom_container
      EXPORTING
        repid                       = sy-repid
        dynnr                       = '1100'
        ratio                       = '90'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CREATE OBJECT go_grid1
      EXPORTING
        i_parent = go_custom_container.

    "Build Field Catalog
    PERFORM populate_fcat USING '1' 'CALL_REQ_ID' 'Call Req ID' CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '2' 'OBJECT' 'Object'           CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '3' 'SERVICEID' 'Service ID'    CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '4' 'SERVICEKEY' 'Service Key'  CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '5' 'BATCH_SIZE' 'Batch Size'   CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '6' 'COMPRESSION' 'Compression' CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '7' 'MDATA' 'MDATA'             CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '8' 'FORMAT' 'Format'           CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '9' 'PROJECTIONS' 'Projection'  CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '10' 'SELECTIONS' 'Selection'   CHANGING lt_fieldcatalog.

    PERFORM populate_fcat USING '11' 'NUMB_OF_LINES' 'Number of lines'  CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '12' 'FROM_DATE' 'From Date'            CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '13' 'TO_DATE' 'To Date'                CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '14' 'EXTRACT_MODE' 'Extract Mode'      CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '15' 'EXECUTION_MODE' 'Execution Mode'  CHANGING lt_fieldcatalog.
    PERFORM populate_fcat USING '16' 'RESPONSE_MODE' 'Response Mode'    CHANGING lt_fieldcatalog.

    "Prepare F4 help
    PERFORM prepare_f4 USING 'PROJECTIONS' CHANGING lt_f4_tmp.
    PERFORM prepare_f4 USING 'EXECUTION_MODE' CHANGING lt_f4_tmp.

    "Register for F4
    lt_f4[] = lt_f4_tmp[].
    CREATE OBJECT lo_event_obj.
    SET HANDLER lo_event_obj->on_f4 FOR go_grid1.
    CALL METHOD go_grid1->register_f4_for_fields
      EXPORTING
        it_f4 = lt_f4.

    "enable for input
    PERFORM enable_input_cell CHANGING gt_extract.

    "add new entry
    PERFORM add_new_entry CHANGING gt_extract.
    PERFORM add_new_entry CHANGING gt_extract.

    CALL METHOD go_grid1->set_table_for_first_display
      EXPORTING
        i_structure_name = 'GTY_EXTRACT'
        is_layout        = gs_layout
      CHANGING
        it_fieldcatalog  = lt_fieldcatalog
        it_outtab        = gt_extract[].
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* PREPARE_F4 *
*---------------------------------------------------------------------*
FORM prepare_f4 USING pv_fieldname TYPE lvc_fname
             CHANGING ct_f4        TYPE gtt_t_f4.
  DATA: ls_f4 LIKE LINE OF ct_f4.
  ls_f4-fieldname  = pv_fieldname.
  ls_f4-register   = abap_true.
  ls_f4-getbefore  = space.
  ls_f4-chngeafter = space.
  APPEND ls_f4 TO ct_f4.
ENDFORM.
*---------------------------------------------------------------------*
* ADD_NEW_ENTRY *
*---------------------------------------------------------------------*
FORM add_new_entry CHANGING ct_extract TYPE gtt_extract.
  FIELD-SYMBOLS: <lfs_extract> LIKE LINE OF ct_extract.
  APPEND INITIAL LINE TO gt_extract ASSIGNING <lfs_extract>.
  <lfs_extract>-serviceid = '1001'.
  <lfs_extract>-batch_size = '2000'.
  <lfs_extract>-compression = 'GZIP'.
  <lfs_extract>-format = 'JSON'.
  <lfs_extract>-extract_mode = 'F'.
  <lfs_extract>-execution_mode = 'B'.
  <lfs_extract>-response_mode = 'H'.
ENDFORM.
*---------------------------------------------------------------------*
* ENABLE_INPUT_CELL *
*---------------------------------------------------------------------*
FORM enable_input_cell CHANGING ct_extract TYPE gtt_extract.
  DATA: lt_celltab TYPE lvc_t_styl,
        l_mode     TYPE raw4,
        lv_index   TYPE i.
  FIELD-SYMBOLS: <lfs_extract> LIKE LINE OF ct_extract,
                 <lfs_celltab> LIKE LINE OF lt_celltab.

  l_mode = cl_gui_alv_grid=>mc_style_enabled.

  LOOP AT ct_extract ASSIGNING <lfs_extract>.
    lv_index = sy-tabix.
    CLEAR: lt_celltab[].

    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'CALL_REQ_ID'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'OBJECT'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'SERVICEID'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'SERVICEKEY'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'BATCH_SIZE'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'COMPRESSION'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'MDATA'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'FORMAT'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'PROJECTIONS'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'SELECTIONS'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'NUMB_OF_LINES'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'FROM_DATE'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'TO_DATE'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'EXTRACT_MODE'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'EXECUTION_MODE'.
    <lfs_celltab>-style = l_mode.
    APPEND INITIAL LINE TO lt_celltab ASSIGNING <lfs_celltab>.
    <lfs_celltab>-fieldname = 'RESPONSE_MODE'.
    <lfs_celltab>-style = l_mode.

    <lfs_extract>-celltab[] = lt_celltab[].
    CLEAR: lt_celltab[].
  ENDLOOP.

  "set edit enabled cells ready for input
  CALL METHOD go_grid1->set_ready_for_input
    EXPORTING
      i_ready_for_input = 1.
ENDFORM.
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
FORM exit_program.
  LEAVE PROGRAM.
ENDFORM.                    "exit_program
*---------------------------------------------------------------------*
* FORM POPULATE_FCAT *
*---------------------------------------------------------------------*
FORM populate_fcat USING pv_col_pos   TYPE lvc_colpos
                         pv_fieldname TYPE lvc_fname
                         pv_scrtext_m TYPE scrtext_m
                CHANGING ct_fcat TYPE lvc_t_fcat.
  FIELD-SYMBOLS: <lfs_fieldcatalog> LIKE LINE OF ct_fcat.
  APPEND INITIAL LINE TO ct_fcat ASSIGNING <lfs_fieldcatalog>.
  <lfs_fieldcatalog>-col_pos   = pv_col_pos.
  <lfs_fieldcatalog>-edit      = abap_true.
  <lfs_fieldcatalog>-fieldname = pv_fieldname.
  <lfs_fieldcatalog>-scrtext_m = pv_scrtext_m.

  IF pv_fieldname = 'EXECUTION_MODE' OR  pv_fieldname = 'PROJECTIONS'.
    <lfs_fieldcatalog>-f4availabl  = abap_true.
  ENDIF.
ENDFORM.                    "populate_fcat


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...