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.

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