Wednesday, 29 March 2017

Insert and Update of a Table

Scenario: Provide two radio button - Insert and Update in the selection screen. On selecting the insert button, Data will be inserted in the table and on selecting the update the data will be updated.

Expected Output:
When Insert is selected the New Employee ID should come automatically & it should be non editable

When Update is selected, the employee ID that needs to be updated will be displayed

On entering the Employee ID, the records has to be displayed in the selection screen for editing

Solution:
*&---------------------------------------------------------------------*
*&
*& INSERT AND UPDATE IN TABLE ZEMP
*&---------------------------------------------------------------------*

REPORT zdemo.
TABLES: zemp.

DATA: gs_zemp TYPE zemp,
      gv_last_id TYPE zdt_id.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.  "RADIO BUTTON FOR - INSERT OR UPDATE
PARAMETERS: rb_in RADIOBUTTON GROUP rb1 USER-COMMAND c1 DEFAULT 'X' MODIF ID b1,
            rb_up RADIOBUTTON GROUP rb1 MODIF ID b1.
SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002. "INSERT RECORD BLOCK
PARAMETERS: p_id    TYPE zdt_id MODIF ID b2i,
            p_name  TYPE zemp_n MODIF ID b2,
            p_des   TYPE zemp_d MODIF ID b2,
            p_yr    TYPE zemp_y MODIF ID b2,
            p_ph    TYPE zemp_p MODIF ID b2.
SELECTION-SCREEN: END OF BLOCK b2.

SELECTION-SCREEN: BEGIN OF BLOCK b3 WITH FRAME TITLE text-003. "UPDATE BLOCK: EMP ID
PARAMETERS: p_u_id TYPE zdt_id MODIF ID b3.
SELECTION-SCREEN: END OF BLOCK b3.

SELECTION-SCREEN: BEGIN OF BLOCK b4 WITH FRAME TITLE text-004. "UPDATE BLOCK
PARAMETERS: p_u_name  TYPE zemp_n MODIF ID b4,
            p_u_des   TYPE zemp_d MODIF ID b4,
            p_u_yr    TYPE zemp_y MODIF ID b4,
            p_u_ph    TYPE zemp_p MODIF ID b4.
SELECTION-SCREEN: END OF BLOCK b4.

INITIALIZATION.
  SELECT MAX( emp_id ) FROM zemp INTO gv_last_id .  "GETTING THE LAST EMPID FOR GENERATING THE NEW EMPID
  IF sy-subrc EQ 0.
    p_id = gv_last_id + 1.
  ELSE.
*    IMPLEMENT SUITABLE HANDLER
  ENDIF.

AT SELECTION-SCREEN OUTPUT.
  IF rb_in EQ 'X' .    "IF INSERT IS SELECTED
    CLEAR: p_u_id.
    LOOP AT SCREEN.
      IF screen-group1 = 'B3' OR screen-group1 = 'B4'.
        screen-active = 0.
      ELSEIF screen-group1 = 'B2I'.
        screen-input = 0.
      ELSE.
        screen-active = 1.
      ENDIF.
      MODIFY SCREEN.
    ENDLOOP.

  ELSEIF rb_up EQ 'X' AND p_u_id IS INITIAL.
    LOOP AT SCREEN.
      IF screen-group1 = 'B2' OR screen-group1 = 'B2I' OR screen-group1 = 'B4'.
        screen-active = 0.
      ELSE.
        screen-active = 1.
      ENDIF.
      MODIFY SCREEN.
    ENDLOOP.

  ELSEIF rb_up EQ 'X' AND p_u_id IS NOT INITIAL.
    SELECT SINGLE *
    FROM zemp
    INTO gs_zemp
    WHERE emp_id = p_u_id.

    IF sy-subrc EQ 0.
      LOOP AT SCREEN.
        IF screen-group1 = 'B2' OR screen-group1 = 'B2I'.
          screen-active = 0.
        ELSE.
          screen-active = 1.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.

      p_u_name = gs_zemp-emp_name.
      p_u_des = gs_zemp-designation.
      p_u_yr = gs_zemp-yr_of_exp.
      p_u_ph = gs_zemp-phone_no.
    ELSE.
      MESSAGE 'Invalid ID' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ENDIF.
  ENDIF.



START-OF-SELECTION.

  IF rb_up EQ 'X'.    "UPDATE
    gs_zemp-emp_name = p_u_name.
    gs_zemp-designation = p_u_des.
    gs_zemp-yr_of_exp = p_u_yr.
    gs_zemp-phone_no = p_u_ph.

    UPDATE zemp FROM gs_zemp .
    IF sy-subrc EQ 0.
      MESSAGE 'Record Updated' TYPE 'S'.
    ELSE.
      MESSAGE 'Record Not Updated' TYPE 'E'.
    ENDIF.
  ELSE.                "INSERT
    CLEAR: gs_zemp.
    gs_zemp-mandt       = sy-mandt. "'115'.
    gs_zemp-emp_id      = p_id.
    gs_zemp-emp_name    = p_name.
    gs_zemp-designation = p_des.
    gs_zemp-yr_of_exp   = p_yr.
    gs_zemp-phone_no    = p_ph.

    INSERT zemp FROM gs_zemp.
    IF sy-subrc EQ 0.
      MESSAGE 'Record Inserted' TYPE 'S'.
    ELSE.
      MESSAGE 'Record Not Inserted' TYPE 'E'.
    ENDIF.
    CLEAR: gs_zemp.
  ENDIF.

Sunday, 26 March 2017

Display ALV with Various Approach

Displaying ALV with the automatic fieldcatalog creation:

*&---------------------------------------------------------------------*
*&
*& SIMPLE ALV DISPLAY WITH VARIOUS METHODS
*&---------------------------------------------------------------------*

REPORT zdemo1.

START-OF-SELECTION.
**********************************************************************
*   DISPLAYING ALV WITH AUTOMATIC GENERATION OF FIELD CATALOG
**********************************************************************
  DATA: lt_tab TYPE TABLE OF ekko,
        lt_fcat   TYPE slis_t_fieldcat_alv,
        ls_fcat   TYPE slis_fieldcat_alv,
        ls_layout TYPE slis_layout_alv.

  CLEAR: ls_fcat, ls_layout.
  REFRESH: lt_tab, lt_fcat.

  SELECT *
    FROM ekko
    INTO TABLE lt_tab.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'    "AUTOMATIC CREATION OF FIELDCATALOG
    EXPORTING
      i_program_name         = sy-repid
      i_structure_name       = 'EKKO'
    CHANGING
      ct_fieldcat            = lt_fcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  ls_layout-colwidth_optimize = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'          "FM TO SHOW ALV
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = ls_layout
      it_fieldcat        = lt_fcat
    TABLES
      t_outtab           = lt_tab
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.


Displaying ALV with manual Fieldcatalog creation:

*&---------------------------------------------------------------------*
*&
*& SIMPLE ALV DISPLAY WITH VARIOUS METHODS
*&---------------------------------------------------------------------*

REPORT zdemo1.

START-OF-SELECTION.
**********************************************************************
*   DISPLAYING ALV WITH MANUAL FIELDCATALOG CREATION
**********************************************************************

  DATA: lt_fcat   TYPE slis_t_fieldcat_alv,
        ls_fcat   TYPE slis_fieldcat_alv,
        ls_layout TYPE slis_layout_alv,
        lv_count TYPE i VALUE 1,
        lt_tab TYPE TABLE OF ekko
           .
  CLEAR: ls_fcat,
         ls_layout.
  REFRESH: lt_fcat, lt_tab.

  SELECT ebeln
         bukrs
         bstyp
         bsart
         bsakz
    FROM ekko
    INTO TABLE lt_tab.

********************* MANUAL FIELDCATALOG CREATION *********************************

  ls_fcat-fieldname = 'EBELN'.                        "FIELDNAME THAT IS TO BE MAPPED
  ls_fcat-seltext_m = 'Purchasing Document Number'.   "FIELD DESCRIPTION IN THE ALV GRID
  ls_fcat-col_pos = lv_count.                         "COLUMN POSITION IN THE ALV GRID
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BUKRS'.
  ls_fcat-seltext_m = 'Company Code'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BSTYP'.
  ls_fcat-seltext_m = 'Purchasing Document Category'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BSART'.
  ls_fcat-seltext_m = 'Purchasing Document Type'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BSAKZ'.
  ls_fcat-seltext_m = 'Control indicator for purchasing document type'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

********************* #END MANUAL FIELDCATALOG CREATION *********************************

  ls_layout-colwidth_optimize = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = ls_layout
      it_fieldcat        = lt_fcat
    TABLES
      t_outtab           = lt_tab
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
*  Implement suitable error handling here
  ENDIF.


Displaying ALV with OO approach:
For displaying ALV with OO approach:
1. A new screen has to be created first
2. Activate the PAI and PBO include of the screen
3. Copy the standard ALV status (how to?)

Then refer to the below program:
*&---------------------------------------------------------------------*
*&
*& SIMPLE ALV DISPLAY WITH VARIOUS METHODS
*&---------------------------------------------------------------------*

REPORT zdemo1.

START-OF-SELECTION.
**********************************************************************
*     DISPLAY ALV WTIH OO APPROACH
**********************************************************************

  DATA: lo_grid TYPE REF TO cl_gui_alv_grid,
        lo_container TYPE REF TO cl_gui_docking_container,
        lt_fcat TYPE lvc_t_fcat,
        ls_fcat TYPE lvc_s_fcat,
        lv_count TYPE i VALUE 1,
        lt_tab TYPE TABLE OF ekko.

  CLEAR: ls_fcat.
  REFRESH: lt_fcat, lt_tab.

  SELECT ebeln
         bukrs
         bstyp
         bsart
         bsakz
    FROM ekko
    INTO TABLE lt_tab.

  CALL SCREEN 0100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       PBO EVENT
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'PF_STATUS'.

*********************** FIELDCATALOG CREATION ************************
  ls_fcat-fieldname = 'EBELN'.                        "FIELDNAME THAT IS TO BE MAPPED
  ls_fcat-scrtext_m = 'Purchasing Document Number'.   "FIELD DESCRIPTION IN THE ALV GRID
  ls_fcat-col_pos = lv_count.                         "COLUMN POSITION IN THE ALV GRID
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BUKRS'.
  ls_fcat-scrtext_m = 'Company Code'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BSTYP'.
  ls_fcat-scrtext_m = 'Purchasing Document Category'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BSART'.
  ls_fcat-scrtext_m = 'Purchasing Document Type'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

  ls_fcat-fieldname = 'BSAKZ'.
  ls_fcat-scrtext_m = 'Control indicator for purchasing document type'.
  ls_fcat-col_pos = lv_count.
  APPEND ls_fcat TO lt_fcat.
  lv_count = lv_count + 1.
  CLEAR: ls_fcat.

********************** #FIELDCATALOG CREATION ************************

  CREATE OBJECT lo_container
    EXPORTING
      ratio = '95'.

  CREATE OBJECT lo_grid
    EXPORTING
      i_parent = lo_container.

  CALL METHOD lo_grid->set_table_for_first_display
    CHANGING
      it_outtab                     = lt_tab
      it_fieldcatalog               = lt_fcat
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       PAI EVENT - USER COMMAND HANDLER
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN '&F03' OR '&F15' OR '&F12'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

Thursday, 23 March 2017

Copy Standard GUI Status

Step 1: Goto Transaction: SE41

Step 2: Click on Status or press CTRL+F6

Step 3: Fill up the dialog box as below:
Frm
Program: SAPLSALV
Status: STANDARD
To
Program: <Name of the program>

Status:     <Name of the status>

Step 4: Click on Copy

The standard status will get copied to the newly created status. Activate the status from SE80.

Refer to the screenshots:
The status will get copied from the Standard to the Program ZDEMO with the Status name PF_STATUS

Permutation of Numbers - Simple Report

Permutation of Numbers - A simple ABAP Report
INITIALIZATION.
  TYPES: BEGIN OF lty_tab,
      i_field TYPE i,
      c_field TYPE c,
      c_field2 TYPE c,
    END OF lty_tab.

  DATA: it_tab TYPE STANDARD TABLE OF lty_tab WITH HEADER LINE.

START-OF-SELECTION.
  it_tab-i_field = 1.
  it_tab-c_field = 'A'.
  it_tab-c_field2 = 'X'.
  APPEND it_tab.
  it_tab-i_field = 2.
  it_tab-c_field = 'B'.
  it_tab-c_field2 = 'Y'.
  APPEND it_tab.
  it_tab-i_field = 3.
  it_tab-c_field = 'C'.
  it_tab-c_field2 = 'Z'.
  APPEND it_tab.
  PERFORM permutation TABLES it_tab.
*&---------------------------------------------------------------------*
*&      Form  Permutation
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM permutation TABLES f_itab LIKE it_tab[].
  DATA:
        f_line LIKE LINE OF f_itab,
        f_line2 LIKE LINE OF f_itab
        .

  LOOP AT f_itab INTO f_line.
    LOOP AT f_itab INTO f_line2.
      WRITE: / f_line-i_field, f_line2-c_field, f_line2-c_field2.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    "permutation

Displaying Two ALV Container Side by Side

Scenario:
There will be two ALV side by side. The left ALV will have the header data and the right ALV will contain the item data. On selecting a particular header data from the left side, the corresponding item data should be displayed in the right side.


Consideration:
1. For demo purpose we have used EKKO (Header Table) and EKPO (Item Table) & we have used only 20 records from EKKO table.

2. We have used Custom Container for the purpose and that's why the container has been created in the Screen Painter


Solution:
First, create a program in SE38 and then create a screen in SE80 and then open Screen Painter.

Step 1: From the screen painter, add two containers by selecting the custom control button. Name them as CUST_CONT_1 and CUST_CONT_2 respectively. Refer the below screenshots:
Screen Painter - The Two Containers



Step 2: Now copy the status from standard ALV. (How to?)

Step 3: Now refer to the following code:
*&---------------------------------------------------------------------*
*& Two ALVs in a single screen EKKO & EKPO
*& The custom container has been created from the layout
*& On selecting the header record from left will give the corresponding item record
*&---------------------------------------------------------------------*

CLASS lcl_event_receiver DEFINITION DEFERRED.

TYPES: BEGIN OF gty_ekko,
        ebeln TYPE ebeln,
        bukrs TYPE bukrs,
        bstyp TYPE ebstyp,
        bsart TYPE esart,
        bsakz TYPE bsakz,
       END OF gty_ekko.

TYPES: BEGIN OF gty_ekpo,
        ebeln TYPE ebeln,
        ebelp TYPE ebelp,
        loekz TYPE eloek,
        statu TYPE astat,
        aedat TYPE paedt,
       END OF gty_ekpo.

DATA: go_grid_1 TYPE REF TO cl_gui_alv_grid,
      go_grid_2 TYPE REF TO cl_gui_alv_grid,
      go_cont_1 TYPE REF TO cl_gui_custom_container,
      go_cont_2 TYPE REF TO cl_gui_custom_container,
      gt_ekko TYPE TABLE OF gty_ekko,
      gs_ekko TYPE gty_ekko,
      gt_ekpo TYPE TABLE OF gty_ekpo,
      gs_ekpo TYPE gty_ekpo,
      go_event_receiver TYPE REF TO lcl_event_receiver.
.

START-OF-SELECTION.
  CALL SCREEN 0100.

*&---------------------------------------------------------------------*
*&      Form  CREATE_GRID
*&---------------------------------------------------------------------*
*       CREATE TWO CONTAINERS & THEIR CORRESPONDING GRIDS
*----------------------------------------------------------------------*
FORM create_grid.

  CREATE OBJECT go_cont_1   "CONTAINER 1
    EXPORTING
      container_name = 'CUST_CONT_1'.

  CREATE OBJECT go_grid_1   "GRID 1
    EXPORTING
      i_parent = go_cont_1.

  CREATE OBJECT go_cont_2   "CONTAINER 2
    EXPORTING
      container_name = 'CUST_CONT_2'.

  CREATE OBJECT go_grid_2   "GRID 2
    EXPORTING
      i_parent = go_cont_2.

ENDFORM.                    " CREATE_GRID

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_GRID
*&---------------------------------------------------------------------*
*       DISPLAY GRID 1 - LEFT GRID
*----------------------------------------------------------------------*
FORM display_grid1 .
  CALL METHOD go_grid_1->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'EKKO'
    CHANGING
      it_outtab                     = gt_ekko
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
ENDFORM.                    " DISPLAY_GRID

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_GRID
*&---------------------------------------------------------------------*
*       DISPLAY GRID 2 - RIGHT GRID
*----------------------------------------------------------------------*
FORM display_grid2 .
  CALL METHOD go_grid_2->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'EKPO'
    CHANGING
      it_outtab                     = gt_ekpo
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
ENDFORM.                    " DISPLAY_GRID
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       FETCH DATA FROM THE HEADER TABLE 'EKKO'
*----------------------------------------------------------------------*
FORM get_data_ekko .
  SELECT ebeln
         bukrs
         bstyp
         bsart
         bsakz
  FROM ekko
  INTO TABLE gt_ekko
  UP TO 20 ROWS
  .
ENDFORM.                    " GET_DATA

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*       CLASS DEFINITION FOR HANDLING THE ALV EVENT - DOUBLE CLICK
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
    handle_double_click
    FOR EVENT double_click OF cl_gui_alv_grid
    IMPORTING e_row
    e_column.
ENDCLASS.                    "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*       CLASS IMPLEMENTATION FOR HANDLING THE ALV EVENT - DOUBLE CLICK
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_double_click.

*   FETCHING THE PARTICULAR RECORD THAT HAS BEEN SELECTED IN THE ALV
    READ TABLE gt_ekko INTO gs_ekko INDEX e_row-index.
    IF sy-subrc EQ 0.
      SELECT    ebeln
                ebelp
                loekz
                statu
                aedat
           FROM ekpo
           INTO TABLE gt_ekpo
           WHERE ebeln = gs_ekko-ebeln.
      IF sy-subrc EQ 0.
        PERFORM display_grid2.
      ENDIF.
    ENDIF.
  ENDMETHOD.                    "handle_double_click
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       PBO EVENT OF THE SCREEN
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'PF_STATUS'.
  IF go_cont_1 IS INITIAL AND go_cont_2 IS INITIAL.
    PERFORM get_data_ekko.
    PERFORM create_grid.
    CREATE OBJECT go_event_receiver.
    SET HANDLER go_event_receiver->handle_double_click FOR go_grid_1.
    PERFORM display_grid1.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       PAI EVENT OF THE SCREEN
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN '&F03' OR 'BACK' OR 'BCK' OR '&F15' OR '&F12' .
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

AT SELECTION-SCREEN OUTPUT Example

AT SELECTION-SCREEN OUTPUT event gets triggered before generating the Selection Screen. Thus, it can be used to manipulate the elements of the selection screens. It can also be used to generate dynamic selection screens. Below is a simple example to show how AT SELECTION-SCREEN OUTPUT can be used.

The following program accepts an employee id  and displays the corresponding name and designation in the selection screen.

TABLES: zemp_mstr.
DATA: ls_mstr TYPE zemp_mstr.

SELECTION-SCREEN: BEGIN OF BLOCK b1.
PARAMETERS: p_eid TYPE zemp_i.
SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b2.
PARAMETERS: p_ename TYPE zemp_n MODIF ID m1.
PARAMETERS: p_des TYPE zemp_d MODIF ID m1.
SELECTION-SCREEN: END OF BLOCK b2.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF p_eid IS NOT INITIAL.
      IF screen-group1 = 'M1'.
        screen-active = 1.
        screen-input = 0.   "for input disable
        CLEAR: ls_mstr.
        SELECT SINGLE * FROM zemp_mstr INTO ls_mstr WHERE emp_id = p_eid.
        p_ename = ls_mstr-emp_name.
        p_des = ls_mstr-designation.
        CLEAR: ls_mstr.
        MODIFY SCREEN.
      ENDIF.
    ELSE.
      IF screen-group1 = 'M1'.
        screen-active = 0.
        MODIFY SCREEN.
      ENDIF.
    ENDIF.
  ENDLOOP.

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