Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
krish469
Contributor


Hi Guys I just want to share my experience here, few days back I was searching for a way to access data browser without using SE16. I have landed at Function Modules  "RS_TOOL_ACCESS" ; "RS_TABLE_LIST_CREATE" and later I have realized that SAP uses a program "/1BCDWB/DBTABLE"  ( where TABLE is replaced with any name of any Table e.g,  "/1BCDWB/DBKNA1" ; "/1BCDWB/DBLFA1"  ).

                              Later I have realized that all the above ways need authorization to t-code SE16. But my requirement was I need to build SE16 kind of thing without having authorization to SE16.

                            I have used SE16 kind of layout via dynamic programing to acheive my requirement. I would like to share my experience here.

I have create a program "Y_VENDOR_TBLS" which uses SE16 kind of layout program "YSE16_LAYOUT" to generate required dynamic program.

              I have create a FM "Y_DYM_FIELD_SELECTION" to achieve dynamic input fields for selection.[ Copy GUI STATUS 'SELECTIO' from Program 'SAPLSETB' to main program of Function group; Create a screen 100 with model dailog box and reduce the screen to a box size ]

Testing with code -

Press on LFA1 -> It should display data browser of LFA1

For dynamic input fields -> Settings ->Fields for Selection

It displays below pop up as in SE16

Select few more input fields and select enter

->Displays new input screen

-> One can try with code provided , you can feel SE16 kind of thing. Though my code deosn't support Settings->User paramters; Settings->Format list

Program - YSE16_LAYOUT

*&---------------------------------------------------------------------*
*& This Report is a layout to access SE16 by report Y_VENDOR_TBLS     *&
*& Please do not modify this, instead make of copy of it and use it   *&
*&---------------------------------------------------------------------*


REPORT  YSE16_LAYOUT.

TABLES: sscrfields.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE t1.

SELECTION-SCREEN SKIP 1.
PARAMETERS list_bre  TYPE rseumod-tblistbr DEFAULT '250'.
PARAMETERS max_sel   TYPE rseumod-tbmaxsel DEFAULT '500'.
SELECTION-SCREEN: END OF BLOCK b1.

PARAMETERS: p_table  TYPE dd02l-tabname DEFAULT 'XXXX' NO-DISPLAY.

DATA: i_selc_texts   TYPE STANDARD TABLE OF rsseltexts,
      prog           TYPE sy-repid VALUE sy-repid,
      list           TYPE STANDARD TABLE OF string,
      where          TYPE STANDARD TABLE OF string,
      it_fieldcat    TYPE lvc_t_fcat,
      tref           TYPE REF TO data,
      struct_type    TYPE REF TO cl_abap_structdescr,
      table_type     TYPE REF TO cl_abap_tabledescr,
      comp_tab1      TYPE cl_abap_structdescr=>component_table.


FIELD-SYMBOLS:
      <i_selc_texts> LIKE LINE OF i_selc_texts,
      <table>        TYPE STANDARD TABLE.


INITIALIZATION.


  APPEND INITIAL LINE TO i_selc_texts ASSIGNING <i_selc_texts>.
  <i_selc_texts>-name = 'LIST_BRE'.
  <i_selc_texts>-kind = 'P'.
  <i_selc_texts>-text = 'Width of Output List'(001).

  APPEND INITIAL LINE TO i_selc_texts ASSIGNING <i_selc_texts>.
  <i_selc_texts>-name = 'MAX_SEL'.
  <i_selc_texts>-kind = 'P'.
  <i_selc_texts>-text = 'Maximum No. of Hits'(002).


**--Set the Title
  PERFORM set_title_selection(saplsetb) USING p_table.

**--Set the PF Status same as SE16
  CALL FUNCTION 'RS_EXTERNAL_SELSCREEN_STATUS'
    EXPORTING
      p_fb = 'RS_DATABROWSE_STATUS_SET'.


**--Create texts for Select options and Paramerters at run time.
  CALL FUNCTION 'SELECTION_TEXTS_MODIFY'
    EXPORTING
      program  = prog
    TABLES
      seltexts = i_selc_texts.


AT SELECTION-SCREEN.

**--Copy GUI STATUS 'SELECTIO' from Program 'SAPLSETB'.

  CASE sscrfields-ucomm.
    WHEN 'ONLI'.
**--Select query on select options
      PERFORM select_query.
    WHEN 'AEIN'.
**--Lists of no.of Entries
      PERFORM select_no_entries.
    WHEN 'SEOP'.
**--Select Fields of repective table for select options
      PERFORM select_input_fields.
    WHEN OTHERS.
  ENDCASE.


END-OF-SELECTION.

  IF <table> IS ASSIGNED.

**--Fetch the field catlouge by passing table as structure
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        i_structure_name = p_table
      CHANGING
        ct_fieldcat      = it_fieldcat.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

**--Display the table as in GRID display
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
      EXPORTING
        it_fieldcat_lvc = it_fieldcat
      TABLES
        t_outtab        = <table>.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

  ENDIF.  "IF <table> IS ASSIGNED.

*&---------------------------------------------------------------------*
*&      Form  SELECT_QUERY
*&---------------------------------------------------------------------*
* Select query on selected table with slected select options
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM select_query .

  FIELD-SYMBOLS: <fs> LIKE LINE OF comp_tab1.

  struct_type ?=
     cl_abap_typedescr=>describe_by_name( p_table ).
  comp_tab1 = struct_type->get_components( ).


  struct_type = cl_abap_structdescr=>create( comp_tab1 ).
  table_type = cl_abap_tabledescr=>create( struct_type ).
  CREATE DATA tref TYPE HANDLE table_type.
  ASSIGN tref->* TO <table>.

  LOOP AT comp_tab1 ASSIGNING <fs>.
    APPEND <fs>-name TO list.
  ENDLOOP.  " LOOP AT comp_tab1 ASSIGNING <fs>.

**--Import where conditions from Program - ZFI_VENDOR_TBLS to Dyanmic program
  IMPORT where TO where FROM MEMORY ID 'DYNMIC_PROG1'.

  IF max_sel IS INITIAL.

**--Dynamic Select query
    SELECT (list) FROM (p_table) INTO TABLE <table>
                  WHERE (where).

  ELSE.

**--Dynamic Select query
    SELECT (list) FROM (p_table) INTO TABLE <table>
                  UP TO max_sel ROWS
                  WHERE (where).

  ENDIF.


ENDFORM.                    " SELECT_QUERY
*&---------------------------------------------------------------------*
*&      Form  SELECT_NO_ENTRIES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM select_no_entries .

  DATA: isscr     TYPE STANDARD TABLE OF  rsscr,
        v_string  TYPE string.

  FIELD-SYMBOLS:
        <isscr> LIKE LINE OF isscr.

  REFRESH : where.
  LOAD REPORT prog PART 'SSCR' INTO isscr.

  DELETE isscr WHERE kind NE 'S'.

  IF NOT isscr[] IS INITIAL.

    LOOP AT isscr ASSIGNING <isscr> .
      IF sy-tabix = 1.

        CLEAR:v_string.
        CONCATENATE  <isscr>-name  'in'   <isscr>-name  INTO v_string SEPARATED BY space.
        APPEND v_string TO where.

      ELSE.

        CLEAR:v_string.
        CONCATENATE 'AND'  <isscr>-name  'in'   <isscr>-name  INTO v_string SEPARATED BY space.
        APPEND v_string TO where.

      ENDIF.

    ENDLOOP.  "LOOP AT isscr ASSIGNING <isscr>.

  ENDIF. "IF not isccr IS INITIAL.


**--Check the no.of entries
  SELECT COUNT(*) FROM (p_table) WHERE (where).
  IF sy-subrc = 0.
    MESSAGE i398(00) WITH 'Number of entries which meet' 'the selection criteria:' sy-dbcnt.
  else.
     MESSAGE i398(00) WITH 'Number of entries which meet' 'the selection criteria:' sy-dbcnt.
  ENDIF.


ENDFORM.                    " SELECT_NO_ENTRIES
*&---------------------------------------------------------------------*
*&      Form  SELECT_INPUT_FIELDS
*&---------------------------------------------------------------------*
* Dynamically select input fields for the given table
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM select_input_fields .

**--select input fields dynamically
  CALL FUNCTION 'Y_DYM_FIELD_SELECTION'
    EXPORTING
      p_table = p_table.

  LEAVE PROGRAM.

ENDFORM.                    " SELECT_INPUT_FIELDS

_____________________________________________________________________________________________

Program - Y_VENDOR_TBLS

*&---------------------------------------------------------------------*
*& Report  Y_VENDOR_TBLS
*&---------------------------------------------------------------------*
*& Display Vendor tables - LFA1,LFAS,LFB1
*&---------------------------------------------------------------------*


REPORT  Y_vendor_tbls.

*----------------------------------------------------------------------*
* Tables                                                               *
*----------------------------------------------------------------------*
TABLES:  sscrfields.

*----------------------------------------------------------------------*
* Data Declarations                                                    *
*----------------------------------------------------------------------*
DATA:    buttonis      TYPE dd02l-tabname,
         prog          TYPE c LENGTH 30 VALUE 'YSE16_LAYOUT',
         prog1         TYPE c LENGTH 30 VALUE 'YDYM_SE16',
         itab          TYPE TABLE OF string,
         where         TYPE TABLE OF string,
         v_line        TYPE i,
         v_string      TYPE string.


*----------------------------------------------------------------------*
* Field - Symbols                                                      *
*----------------------------------------------------------------------*
FIELD-SYMBOLS:
         <fs>          TYPE ANY,
        <itab>         LIKE LINE OF itab.

*----------------------------------------------------------------------*
* Selection Screen                                                     *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-100.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (15) w_bt101 USER-COMMAND bt101.
SELECTION-SCREEN PUSHBUTTON (15) w_bt102 USER-COMMAND bt102.
SELECTION-SCREEN PUSHBUTTON (15) w_bt103 USER-COMMAND bt103.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

*----------------------------------------------------------------------*
* Initialization                                                       *
*----------------------------------------------------------------------*
INITIALIZATION.

**--Declare Tables as buttons
  w_bt101 = 'LFA1'.
  w_bt102 = 'LFAS'.
  w_bt103 = 'LFB1'.


*----------------------------------------------------------------------*
* At Selection Screen                                                  *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN.

*------- Fetch the Table which need to be display
  LOOP AT SCREEN.
    IF screen-name CS sscrfields-ucomm.
      buttonis = screen-name.
      EXIT.
    ENDIF.  " IF screen-name CS sscrfields-ucomm.
  ENDLOOP.  "LOOP AT SCREEN.

  IF NOT buttonis IS INITIAL.

**--Fetch the table named assiociated with the button name
    ASSIGN (buttonis) TO <fs>.

**--Display the table selected via pushbutton
    PERFORM se16_program USING <fs>.

  ENDIF.   "IF NOT buttonis IS INITIAL.

*----------------------------------------------------------------------*
* End -of -Selection                                                   *
*----------------------------------------------------------------------*
END-OF-SELECTION.

*---------------------------------------------------------------------*
* Display the selected table in se16
*---------------------------------------------------------------------*
FORM se16_program USING table TYPE any.

  DATA: table1 TYPE dd02l-tabname.

  table1 = table.

*  CALL FUNCTION 'RS_TOOL_ACCESS'
*    EXPORTING
*      operation          = 'TAB_CONT'
*      object_name        = table1
*      object_type        = 'VIEW'
*      monitor_activation = space
*    EXCEPTIONS
*      not_executed       = 0.


* submit /1BCDWB/DBLFA1 via selection-screen and return.

  PERFORM call_se16_table USING table1.

ENDFORM.                    " FORM se16_program USING table1 TYPE any.
*&---------------------------------------------------------------------*
*&      Form  CALL_SE16_TABLE
*&---------------------------------------------------------------------*
*  Create a program dynamically with selected Select options
*----------------------------------------------------------------------*
*   Input -> Table
*----------------------------------------------------------------------*
FORM call_se16_table  USING   table TYPE dd02l-tabname.

**--Define structure for Field selection table
  TYPES: BEGIN OF st_final,
             tabname      TYPE tabname,
             fieldname    TYPE fieldname,
             datatype     TYPE datatype,
             scrtext_m    TYPE scrtext_m,
             flag         TYPE c LENGTH 1,
           END OF st_final.


  DATA:      i_tab        TYPE STANDARD TABLE OF st_final,
             v_string     TYPE string,
             x030l        TYPE x030l,
             l_dfies      TYPE STANDARD TABLE OF dfies.

  FIELD-SYMBOLS:
             <i_tab>      LIKE LINE OF i_tab,
             <l_dfies>    LIKE LINE OF l_dfies.


**--refresh all internal tables used
  REFRESH: itab,i_tab,l_dfies,where.

**-- Read the layout code of program designed for SE16 approach
  READ REPORT prog INTO itab .
  IF sy-subrc = 0.


**--Insert Tables line w.rt. table selected on selection screen into dynamic program
    LOOP AT itab ASSIGNING <itab> WHERE table_line CS 'REPORT  Yse16_layout'.
      v_line = sy-tabix.
      v_line = v_line + 1.

      CLEAR:v_string.
      CONCATENATE 'TABLES:'  table  '.' INTO v_string SEPARATED BY space.
      INSERT v_string INTO itab INDEX v_line.
      EXIT.
    ENDLOOP. " LOOP AT itab ASSIGNING <itab> WHERE table_line CS 'REPORT  Yse16_layout'.


**--Insert Selection Options into dynamic program
    LOOP AT itab ASSIGNING <itab> WHERE table_line CS 'SELECTION-SCREEN SKIP 1'.
      v_line = sy-tabix.
      v_line = v_line - 1.

**--Import Field selection list from Function group - YFI_DYNAMIC - Main program - LYFI_DYNAMICO01
      IMPORT i_tab TO i_tab FROM MEMORY ID  'SAPLYFI_DYNAMIC'.
      IF NOT i_tab IS INITIAL.

**--Delete entries where fieldname is MANDT
        DELETE i_tab  WHERE fieldname = 'MANDT'.

**--Insert Select options for only selected entries
        LOOP AT i_tab ASSIGNING <i_tab> WHERE flag = 'X'.

          CLEAR:v_string.
          CONCATENATE 'SELECT-OPTIONS: '  <i_tab>-fieldname  'for '  INTO v_string SEPARATED BY space.
          CONCATENATE v_string            <i_tab>-tabname            INTO v_string SEPARATED BY space.
          CONCATENATE v_string  '-'       <i_tab>-fieldname  '.'     INTO v_string.
          INSERT v_string INTO itab INDEX v_line.

          v_line = v_line + 1.
        ENDLOOP.  "LOOP AT i_tab ASSIGNING <i_tab> WHERE flag = 'X'.

        CLEAR: v_string.
        INSERT v_string INTO itab INDEX v_line.

**--Delete the field list from Memory Function group - YFI_DYNAMIC - Main program - LYFI_DYNAMICO01
        DELETE FROM MEMORY ID 'SAPLYFI_DYNAMIC'.

      ELSE.
**---Get initial settings of field selection from Key fields of Table

**--Fetch all fields of table
        CALL FUNCTION 'DDIF_FIELDINFO_GET'
          EXPORTING
            tabname   = table
          IMPORTING
            x030l_wa  = x030l
          TABLES
            dfies_tab = l_dfies
          EXCEPTIONS
            OTHERS    = 0.

**--Delete entry with field name MANDT
        DELETE l_dfies WHERE fieldname = 'MANDT'.

**--Insert Select options for Key fields - Initially
        LOOP AT l_dfies ASSIGNING <l_dfies> WHERE keyflag = 'X'.

          CLEAR:v_string.
          CONCATENATE 'SELECT-OPTIONS:' <l_dfies>-fieldname  'for' INTO v_string SEPARATED BY space.
          CONCATENATE v_string          <l_dfies>-tabname          INTO v_string SEPARATED BY space.
          CONCATENATE v_string  '-'     <l_dfies>-fieldname '.'    INTO v_string.
          INSERT v_string INTO itab INDEX v_line.

          v_line = v_line + 1.

        ENDLOOP.   " LOOP AT L_DFIES ASSIGNING <L_DFIES> WHERE KEYFLAG = 'X'.

        CLEAR: v_string.
        INSERT v_string INTO itab INDEX v_line.

      ENDIF.  "IF NOT i_tab IS INITIAL.

      EXIT.
    ENDLOOP. "LOOP AT itab ASSIGNING <itab> WHERE table_line CS 'SELECTION-SCREEN SKIP 1'.


**--Insert texts for Selection Options.
    LOOP AT itab ASSIGNING <itab> WHERE table_line CS 'INITIALIZATION'.
      v_line = sy-tabix.
      v_line = v_line + 2.

      IF NOT i_tab[] IS INITIAL.

        LOOP AT i_tab ASSIGNING <i_tab> WHERE flag = 'X'.

          INSERT ' APPEND INITIAL LINE TO I_SELC_TEXTS ASSIGNING <I_SELC_TEXTS>.' INTO itab INDEX v_line.
          v_line = v_line + 1.

          CLEAR:v_string.
          CONCATENATE '<I_SELC_TEXTS>-NAME = '   ''''       INTO v_string SEPARATED BY space.
          CONCATENATE v_string  <i_tab>-fieldname ''''  '.' INTO v_string.
          INSERT v_string INTO itab INDEX v_line.
          v_line = v_line + 1.

          INSERT '<I_SELC_TEXTS>-KIND = ''S''.'             INTO itab INDEX v_line.
          v_line = v_line + 1.

          CLEAR:v_string.
          CONCATENATE '<I_SELC_TEXTS>-TEXT = '   ''''       INTO v_string SEPARATED BY space.
          CONCATENATE v_string <i_tab>-scrtext_m ''''  '.'  INTO v_string.
          INSERT v_string INTO itab INDEX v_line.
          v_line = v_line + 1.

          CLEAR:v_string.
          INSERT v_string INTO itab INDEX v_line.
          v_line = v_line + 1.

        ENDLOOP.  "LOOP AT I_TAB ASSIGNING <I_TAB> WHERE FLAG = 'X'.


      ELSEIF NOT l_dfies[] IS INITIAL.


        LOOP AT l_dfies ASSIGNING <l_dfies> WHERE keyflag = 'X'.

          INSERT ' APPEND INITIAL LINE TO I_SELC_TEXTS ASSIGNING <I_SELC_TEXTS>.' INTO itab INDEX v_line.
          v_line = v_line + 1.

          CLEAR:v_string.
          CONCATENATE '<I_SELC_TEXTS>-NAME = '  ''''         INTO v_string SEPARATED BY space.
          CONCATENATE v_string <l_dfies>-fieldname ''''  '.' INTO v_string.
          INSERT v_string INTO itab INDEX v_line.
          v_line = v_line + 1.

          INSERT '<I_SELC_TEXTS>-KIND = ''S''.'              INTO itab INDEX v_line.
          v_line = v_line + 1.

          CLEAR:v_string.
          CONCATENATE '<I_SELC_TEXTS>-TEXT = '  ''''         INTO v_string SEPARATED BY space.
          CONCATENATE v_string <l_dfies>-scrtext_l ''''  '.' INTO v_string.
          INSERT v_string INTO itab INDEX v_line.
          v_line = v_line + 1.


          CLEAR:v_string.
          INSERT v_string INTO itab INDEX v_line.
          v_line = v_line + 1.

        ENDLOOP.  "LOOP AT L_DFIES ASSIGNING <L_DFIES> WHERE FLAG = 'X'.

      ENDIF.  "IF NOT i_tab[] IS INITIAL. ; ELSEIF NOT l_dfies[] IS INITIAL.

      EXIT.
    ENDLOOP.  " LOOP AT ITAB ASSIGNING <ITAB> WHERE TABLE_LINE CS 'INITIALIZATION'.

**--Replace XXXX with table name
    LOOP AT itab ASSIGNING <itab> WHERE table_line CS 'PARAMETERS: P_TABLE'.
      REPLACE 'XXXX' IN <itab> WITH table.
    ENDLOOP.

**--Delete existing program PROG1
    DELETE REPORT prog1.

**--Insert code from ITAB into Program PROG1
    INSERT REPORT prog1 FROM itab.

**--Generate the created report PROG1
    GENERATE REPORT prog1.


**--Export the where condition.

    IF NOT i_tab[] IS INITIAL.

      LOOP AT i_tab ASSIGNING <i_tab> WHERE flag = 'X'.

        IF sy-tabix = 1.

          CLEAR:v_string.
          CONCATENATE <i_tab>-fieldname  'in'  <i_tab>-fieldname INTO v_string SEPARATED BY space.
          APPEND v_string TO where.

        ELSE.

          CLEAR:v_string.
          CONCATENATE 'AND'  <i_tab>-fieldname  'in'  <i_tab>-fieldname INTO v_string SEPARATED BY space.
          APPEND v_string TO where.

        ENDIF.

      ENDLOOP.  "LOOP AT I_TAB ASSIGNING <I_TAB> WHERE FLAG = 'X'.


    ELSEIF NOT l_dfies[] IS INITIAL.


      LOOP AT l_dfies ASSIGNING <l_dfies> WHERE keyflag = 'X'.

        IF sy-tabix = 1.

          CLEAR:v_string.
          CONCATENATE  <l_dfies>-fieldname  'in'   <l_dfies>-fieldname  INTO v_string SEPARATED BY space.
          APPEND v_string TO where.

        ELSE.

          CLEAR:v_string.
          CONCATENATE 'AND'  <l_dfies>-fieldname   'in'  <l_dfies>-fieldname INTO v_string SEPARATED BY space.
          APPEND v_string TO where.

        ENDIF.

      ENDLOOP.  "LOOP AT L_DFIES ASSIGNING <L_DFIES> WHERE KEYFLAG = 'X'.

    ENDIF. "IF NOT i_tab[] IS INITIAL. ; ELSEIF NOT l_dfies[] IS INITIAL.

**--Export where conditions to the dynamic program.
    DELETE FROM MEMORY ID  'DYNMIC_PROG1'.
    EXPORT where FROM where TO MEMORY ID 'DYNMIC_PROG1'.

**--Submit the program to display
    SUBMIT (prog1) VIA SELECTION-SCREEN AND RETURN.

**--Delete existing program PROG1
    DELETE REPORT prog1.

  ENDIF.  "  READ REPORT PROG INTO ITAB .

ENDFORM.                    " CALL_SE16_TABLE

______________________________________________________________________________

Attached are the files to create Function module  - Y_DYM_FIELD_SELECTION ; its top include; Include program

39 Comments