Tuesday, 6 May 2014

Simple Table control in SAP ABAP

Create a program in SE80.



We are going to create a very simple program to display the selected row value in the output.
For that we have created a main program, there we have a select-option for customer.
After executing the program there will be another screen where the customers sales area details will be displayed.
After selecting the particular row and pressing OK button the single selected customer sales area data will be displayed in the screen.

This is just a demo program; we can take leverage of the program to make changes in the SAP tables for some particular record or we can
select the particular record and process further with the record.


*&---------------------------------------------------------------------*
*& Report  Z_TEST_MODULE_POOL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_TEST_MODULE_POOL.

INCLUDE Z_TEST_MODULE_POOL_TOP.

TABLESkna1.
SELECT-OPTIONSs_kunnr FOR kna1-kunnr.
INITIALIZATION.
AT SELECTION-SCREEN.

START-OF-SELECTION.
  CALL SCREEN '9000'.

  CLEAR k_knvv.
  READ TABLE i_knvv INTO k_knvv WITH KEY sel 'X'.
  WRITE:'You have selected : ',
          'Kunnr = 'k_knvv-kunnr,
          'VKORG = 'k_knvv-vkorg,
          'VTWEG = 'k_knvv-vtweg,
          'SPART = 'k_knvv-spart.

INCLUDE Z_TEST_MODULE_POOL_STATUS_9O01.
INCLUDE Z_TEST_MODULE_POOL_USER_COMI01.
*&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE!
INCLUDE Z_TEST_MODULE_POOL_SUB .


Create a screen.




Lets create a standard table and work area in the TOP include.
Like below:
TYPESBEGIN OF t_knvv,
        sel   TYPE char1,
        kunnr TYPE kunnr,
        vkorg TYPE vkorg,
        vtweg TYPE vtweg,
        spart TYPE spart,
       END OF t_knvv.

DATAi_knvv TYPE STANDARD TABLE OF t_knvv INITIAL SIZE 0,
      k_knvv TYPE t_knvv,
      mark   TYPE c.















The below step is important for selecting records in table control.


All the code will be generated automatically. We just need to add the highlighted code for our own purpose.




Code:
*&---------------------------------------------------------------------*
*&      Module  POPULATE_TABLE  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE populate_table OUTPUT.

  SELECT kunnr
         vkorg
         vtweg
         spart
    FROM knvv
    INTO CORRESPONDING FIELDS OF TABLE i_knvv
    WHERE kunnr IN s_kunnr.

ENDMODULE.                 " POPULATE_TABLE  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
  SET PF-STATUS 'GUI9000'.
  SET TITLEBAR 'This is Test Program'.

ENDMODULE.                 " STATUS_9000  OUTPUT



The below code is VERY VERY.. important for selecting record in table control and process with the record.
*&---------------------------------------------------------------------*
*&      Module  UPDATE_TABLE  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE update_table INPUT.
  READ TABLE i_knvv INTO k_knvv INDEX TABLE_CON-CURRENT_LINE.
  IF NOT mark IS INITIAL.
    k_knvv-sel 'X'.
    MODIFY i_knvv FROM k_knvv INDEX TABLE_CON-CURRENT_LINE.
  ENDIF.
ENDMODULE.                 " UPDATE_TABLE  INPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.

  CASE  sy-ucomm.
    WHEN 'BACK'.
      CLEAR:sy-ucomm.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      CLEAR:sy-ucomm.
      LEAVE TO SCREEN 0.
    WHEN 'CANC'.
      CLEAR:sy-ucomm.
      LEAVE TO SCREEN 0.
    WHEN 'OK'.
      CLEAR:sy-ucomm.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT



Input / Output:   


Now select one record and press ‘OK’.


The values will come in the o/p screen.






1 comment: