Showing posts with label Notes. Show all posts
Showing posts with label Notes. Show all posts

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

Tuesday, 26 February 2019

Excel Sheet Creation from ABAP

TYPE-POOLS ole2.
DATA: wf_cell_from  TYPE ole2_object,
      wf_cell_from1 TYPE ole2_object,
      wf_cell_to    TYPE ole2_object,
      wf_cell_to1   TYPE ole2_object,
      wf_excel      TYPE ole2_object,   " Excel object
      wf_mapl       TYPE ole2_object,   " list of workbooks
      wf_map        TYPE ole2_object,   " workbook
      wf_worksheet  TYPE ole2_object,   " Worksheet
      wf_cell       TYPE ole2_object,   " Cell Range
      wf_cell1      TYPE ole2_object,
      wf_range      TYPE ole2_object,   " Range of cells to be formatted
      wf_range2     TYPE ole2_object,
      wf_column1    TYPE ole2_object.   " Column to be Autofit
 
 
DATA: BEGIN OF t_hex,
      l_tab TYPE x,
      END OF t_hex.
 
DATA: wf_deli(1) TYPE c,            "delimiter
      wf_action TYPE i,
      wf_file TYPE string,
      wf_path TYPE string,
      wf_fullpath TYPE string.
 
 
 
TYPES: t_data1(1500) TYPE c,
       int_ty TYPE TABLE OF t_data1. "line type internal table
 
*All the data was prepared as line type internal tables for faster
*download
 
DATA: int_matl  TYPE int_ty ,
      int_matl1 TYPE int_ty ,
      wa_matl   TYPE t_data1.
 
TYPES: BEGIN OF ty_mara,
       matnr TYPE matnr,
       mtart TYPE mtart,
       matkl TYPE matkl,
       meins TYPE meins,
       END OF ty_mara.
 
DATA: int_mara TYPE STANDARD TABLE OF ty_mara,
      wa_mara TYPE ty_mara.
 
FIELD-SYMBOLS: <fs> .
 
DATA: wc_sheets LIKE sy-index.  "no.of sheets
DATA: it_tabemp TYPE filetable,
      gd_subrcemp TYPE i.
 
CONSTANTS wl_c09(2) TYPE n VALUE 09.
 
CLEAR wc_sheets.
 
 
DEFINE ole_check_error.
  if &1 ne 0.
    message e001(zz) with &1.
    exit.
  endif.
END-OF-DEFINITION.
 
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
PARAMETERS: p_file   LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK block1.
 
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 
  REFRESH: it_tabemp.
 
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title         = 'Select File'
*      default_extension    = 'xls'
      default_file_name    = 'Material Details'
*      with_encoding        =
      file_filter          = '*.xls'
      initial_directory    = 'C:\'
      prompt_on_overwrite  = ' '
    CHANGING
      filename             = wf_file
      path                 = wf_path
      fullpath             = wf_fullpath
      user_action          = wf_action
*      file_encoding        =
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4
          .
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
  IF wf_action EQ 9.
    MESSAGE 'No File have been Selected' TYPE 'S'.
  ELSE.
    p_file = wf_fullpath.
    PERFORM create_excel.
  ENDIF.
 
*&---------------------------------------------------------------------*
*&      Form  create_excel
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_excel.
  LOOP AT it_tabemp INTO p_file.
  ENDLOOP.
* START THE EXCEL APPLICATION
  CREATE OBJECT wf_excel 'EXCEL.APPLICATION'.
  PERFORM err_hdl.
 
* PUT EXCEL IN FRONT
  SET PROPERTY OF wf_excel  'VISIBLE' = 1.
  PERFORM err_hdl.
 
* CREATE AN EXCEL WORKBOOK OBJECT
  CALL METHOD OF wf_excel 'WORKBOOKS' = wf_mapl.
  PERFORM err_hdl.
 
  SET PROPERTY OF wf_excel 'SheetsInNewWorkbook' = 3. "no of sheets
  PERFORM err_hdl.
 
  CALL METHOD OF wf_mapl 'ADD' = wf_map.
  PERFORM err_hdl.
 
 
*Assign the Delimiter to field  symbol.
  ASSIGN wf_deli TO <fs> TYPE 'X'.
  t_hex-l_tab = wl_c09.
  <fs> = t_hex-l_tab.
 
  CLEAR int_matl.
  REFRESH int_matl.
  SELECT matnr
       mtart
       matkl
       meins
      FROM mara
      INTO CORRESPONDING FIELDS OF TABLE int_mara.
*first the headings will be displayed  in the excel sheet
  CONCATENATE 'Material Number'
  'Material type'
  'Material Group'
  'Base Unit of Measure'
  INTO wa_matl
  SEPARATED BY wf_deli.
  APPEND wa_matl TO int_matl.
 
 
  LOOP AT int_mara INTO wa_mara.
    CONCATENATE wa_mara-matnr
                wa_mara-mtart
                wa_mara-matkl
                wa_mara-meins
                INTO wa_matl
                SEPARATED BY wf_deli.
    APPEND wa_matl TO int_matl.
    CLEAR wa_matl.
  ENDLOOP.
 
*Copyng thae same contents to another table to display in
*new sheet
  MOVE int_matl TO int_matl1.
  PERFORM f_material_details
  TABLES int_matl
  USING  1.
 
  PERFORM f_material_details
  TABLES int_matl
  USING  2.
 
 
  GET PROPERTY OF wf_excel 'ActiveSheet' = wf_map.
  GET PROPERTY OF wf_excel 'ActiveWorkbook' = wf_mapl.
 
  CALL FUNCTION 'FLUSH'
    EXCEPTIONS
      cntl_system_error = 1
      cntl_error        = 2
      OTHERS            = 3.
  IF sy-subrc = 0.
 
    CALL METHOD OF wf_map 'SAVEAS'
      EXPORTING #1 = p_file.
  ENDIF.
 
  CALL METHOD OF wf_mapl 'CLOSE'.
  CALL METHOD OF wf_excel 'QUIT'.
 
  FREE OBJECT wf_mapl.
  FREE OBJECT wf_map.
  FREE OBJECT wf_excel.
 
ENDFORM.                    "create_excel
*&---------------------------------------------------------------------*
*&      Form  ERR_HDL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM err_hdl.
 
  IF sy-subrc <> 0.
    WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
    STOP.
  ENDIF.
 
ENDFORM.                    "ERR_HDL
 
*-- End of Program
*&---------------------------------------------------------------------*
*&      Form  f_material_details
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_material_details
   TABLES lint_matl
  USING l_sheet_no TYPE i.
 
  DATA: lv_lines TYPE i,
        lv_sheet_name(50) TYPE c.
 
  wc_sheets = l_sheet_no.
  CASE l_sheet_no.
    WHEN 1.
      lv_sheet_name = 'Material_sheet1'.
    WHEN 2.
      lv_sheet_name = 'Material_sheet2'.
  ENDCASE.
 
 
*-- activating the worksheet and giving a  name to it
  CALL METHOD OF wf_excel 'WORKSHEETS' = wf_worksheet
    EXPORTING
    #1 = wc_sheets.
  CALL METHOD OF wf_worksheet 'ACTIVATE'.
 
 
 
  SET PROPERTY OF wf_worksheet 'NAME' = lv_sheet_name.
 
*--formatting the cells
  CALL METHOD OF wf_excel 'Cells' = wf_cell_from
    EXPORTING
    #1 = 1
    #2 = 1.
  DESCRIBE TABLE lint_matl LINES lv_lines.
  CALL METHOD OF wf_excel 'Cells' = wf_cell_to
    EXPORTING
    #1 = lv_lines
    #2 = 4.
*--range of cells to be formatted (in this case 1 to 4)
  CALL METHOD OF wf_excel 'Range' = wf_cell
    EXPORTING
    #1 = wf_cell_from
    #2 = wf_cell_to.
 
*--formatting the cells
  CALL METHOD OF wf_excel 'Cells' = wf_cell_from1
    EXPORTING
    #1 = 1
    #2 = 1.
  DESCRIBE TABLE lint_matl LINES lv_lines.
  CALL METHOD OF wf_excel 'Cells' = wf_cell_to1
    EXPORTING
    #1 = lv_lines
    #2 = 1.
  CALL METHOD OF wf_excel 'Range' = wf_cell1  " Cell range for first
 
                                              " column(Material)
    EXPORTING
    #1 = wf_cell_from1
    #2 = wf_cell_to1.
 
  SET PROPERTY OF wf_cell1 'NumberFormat' = '@' . "To disply zeros
  "in Material number
 
 
  DATA l_rc TYPE i.
*DATA download into excel first sheet
  CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
      data         = lint_matl[]
    CHANGING
      rc           = l_rc
    EXCEPTIONS
      cntl_error   = 1
      error_no_gui = 2
      OTHERS       = 4.
  CALL METHOD OF wf_worksheet 'Paste'.
 
  CALL METHOD OF wf_excel 'Columns' = wf_column1.
  CALL METHOD OF wf_column1 'Autofit'.
  FREE OBJECT wf_column1.
 
ENDFORM.                    " f_material_details

Reference link:
https://archive.sap.com/discussions/thread/1260102
https://blogs.sap.com/2012/03/29/using-ole2-objects-for-create-an-excel-file/

Monday, 25 February 2019

Parallel Processing using SPTA framework

Using SPTA framework, the parallel processing can be achieved in a more effective & efficient way as everything is handled by the standards. Performance wise also it is more optimized.

CONSTANTS: lc_e TYPE symsgty VALUE 'E'.

  IF gt_op_file[] IS INITIAL.
    RETURN.
  ENDIF.

  "Fetch the server group
  SELECT SINGLE classname
  INTO @DATA(lv_server_grp)
  FROM rzllitab
  WHERE grouptype = 'S'.
  IF sy-subrc NE 0.
    RETURN.
  ENDIF.


*---------------------------------------------------------------------*
*                P A R A L L E L   P R O C E S S I N G
*---------------------------------------------------------------------*
  "to invoke parallel processing framwork
  IF gv_parallel_process EQ abap_true.
    CALL FUNCTION 'SPTA_PARA_PROCESS_START_2'
      EXPORTING
        server_group             = lv_server_grp
        before_rfc_callback_form = 'BEFORE_RFC'
        in_rfc_callback_form     = 'IN_RFC'
        after_rfc_callback_form  = 'AFTER_RFC'
        callback_prog            = sy-repid
      CHANGING
        user_param               = gt_op_file
      EXCEPTIONS
        invalid_server_group     = 1
        no_resources_available   = 2
        OTHERS                   = 3.
    IF sy-subrc NE 0.
      "Populate the log
      PERFORM fill_msg_log USING lc_e
                                 TEXT-e01
                                 space space space
                        CHANGING gt_msg_log.
    ENDIF.
  ELSE.
    "Post the data
    PERFORM post_data CHANGING gt_op_file.
  ENDIF.

*&---------------------------------------------------------------------*
*& Form BEFORE_RFC
*&---------------------------------------------------------------------*
*& Packets are prepared for parallel processing
*&---------------------------------------------------------------------*
FORM before_rfc USING ps_before_rfc_imp     TYPE spta_t_before_rfc_imp
             CHANGING cs_before_rfc_exp     TYPE spta_t_before_rfc_exp
                      ct_rfcdata            TYPE spta_t_indxtab
                      ct_failed_objects     TYPE spta_t_failed_objects
                      ct_objects_in_process TYPE spta_t_objects_in_process
                      ct_file_data          TYPE gtt_op_file.

  TYPES: lty_op_file TYPE TABLE OF gty_op_file WITH EMPTY KEY.
  DATA: lv_counter        TYPE i,
        lv_pck_size       TYPE i VALUE 5000, "One work packet size
        lt_final          TYPE gtt_op_file,
        lv_current_tranno TYPE string.

  IF ct_file_data[] IS INITIAL.
    CLEAR: cs_before_rfc_exp-start_rfc.
    RETURN.
  ENDIF.

** Create small work packets for parallel processing
  SORT ct_file_data BY tranno.
  LOOP AT ct_file_data ASSIGNING FIELD-SYMBOL(<lfs_file_data>).
    IF lv_current_tranno NE <lfs_file_data>-tranno.
      lv_current_tranno = <lfs_file_data>-tranno.
      "count the total records against particular transactions
      DATA(lv_rec_count) = REDUCE i( INIT x = 0 FOR ls_file_data IN ct_file_data
                                  WHERE ( tranno EQ <lfs_file_data>-tranno )
                                  NEXT x = x + 1 ).

      "if the total number of records can be accomodated in the current batch then accomodate it
      IF ( lv_rec_count + lines( lt_final ) ) LE lv_pck_size.
        APPEND <lfs_file_data> TO lt_final.

        "If the record count for particular transactions is more than the pack size
        "then assign the whole lot in a single batch
      ELSEIF lv_rec_count GT lv_pck_size.
        lt_final = VALUE lty_op_file( FOR ls_file_data2 IN ct_file_data
                                      WHERE ( tranno EQ <lfs_file_data>-tranno )
                                          ( ls_file_data2 ) ).
      ENDIF.
    ELSE.
      APPEND <lfs_file_data> TO lt_final.
    ENDIF.
  ENDLOOP.

  "Delete the records which has been grouped
  DELETE ct_file_data FROM 1 TO lv_pck_size.

* Convert the input data into the INDX structure that is needed for the RFC
  CALL FUNCTION 'SPTA_INDX_PACKAGE_ENCODE'
    EXPORTING
      data    = lt_final
    IMPORTING
      indxtab = ct_rfcdata.

* informing task manager that an rfc can be started from the data compiled
  IF lt_final IS NOT INITIAL.
    cs_before_rfc_exp-start_rfc = abap_true.
  ELSE.
    CLEAR cs_before_rfc_exp-start_rfc.
    RETURN.
  ENDIF.

ENDFORM.                    "BEFORE_RFC

*&---------------------------------------------------------------------*
*&      Form  IN_RFC
*&---------------------------------------------------------------------*
*  create own RFC enabled FM or write logic in this routine
*----------------------------------------------------------------------*
FORM in_rfc USING ps_in_rfc_imp TYPE spta_t_in_rfc_imp
         CHANGING cs_in_rfc_exp TYPE spta_t_in_rfc_exp
                  ct_rfcdata    TYPE spta_t_indxtab.


  DATA: lt_final TYPE gtt_op_file.

* Decode the data from the INDX Structure into the process work list
  CALL FUNCTION 'SPTA_INDX_PACKAGE_DECODE'
    EXPORTING
      indxtab = ct_rfcdata
    IMPORTING
      data    = lt_final.

* Simple logic to sort data
  SORT lt_final BY tranno.
  PERFORM post_data CHANGING lt_final.

* Again Encode output data for AFTER_RFC form
  CALL FUNCTION 'SPTA_INDX_PACKAGE_ENCODE'
    EXPORTING
      data    = lt_final
    IMPORTING
      indxtab = ct_rfcdata.

ENDFORM.                    "in_rfc

*&---------------------------------------------------------------------*
*&      Form  AFTER_RFC
*&---------------------------------------------------------------------*
* To collect date after parallel processing
*----------------------------------------------------------------------*
FORM after_rfc USING pt_rfcdata            TYPE spta_t_indxtab
                     pv_rfcsubrc           TYPE sy-subrc
                     pv_rfcmsg             TYPE spta_t_rfcmsg
                     pt_objects_in_process TYPE spta_t_objects_in_process
                     ps_after_rfc_imp      TYPE spta_t_after_rfc_imp
            CHANGING cs_after_rfc_exp      TYPE spta_t_after_rfc_exp
                     cs_user_param         TYPE gtt_op_file.

  DATA: lt_final TYPE gtt_op_file.

* Decode RFC output data and add RFC-results to global data
  IF gv_parallel_process EQ abap_true.
    CALL FUNCTION 'SPTA_INDX_PACKAGE_DECODE'
      EXPORTING
        indxtab = pt_rfcdata
      IMPORTING
        data    = lt_final.
  ENDIF.

* After parallel processing write the records in AL11
  IF lt_final[] IS NOT INITIAL.

  ENDIF.
ENDFORM.                    "AFTER_RFC

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