Wednesday, March 18, 2015



Table control examples

*&---------------------------------------------------------------------*
*& Report  Z_DB_TABLECONTROL                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  Z_DB_TABLECONTROL.
TABLES: MARA.
CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.
TYPES: BEGIN OF ST_MARA,
       MATNR TYPE MARA-MATNR,
       ERSDA TYPE MARA-ERSDA,
       ERNAM TYPE MARA-ERNAM,
       LAEDA TYPE MARA-LAEDA,
       END OF ST_MARA.
DATA: IT_ST TYPE TABLE OF ST_MARA,
      WA_ST TYPE ST_MARA,
      IT_MARA TYPE MARA,
      WA_MARA TYPE MARA,
      OK_CODE LIKE SY-UCOMM.
CALL SCREEN 130.
*&---------------------------------------------------------------------*
*&      Module  V1  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE V1 INPUT.
CASE OK_CODE.
WHEN 'SAVE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
INSERT INTO MARA VALUES WA_MARA.
WHEN 'DELETE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING  WA_ST TO WA_MARA.
DELETE MARA FROM WA_MARA.
WHEN 'MODIFY'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING  WA_ST TO WA_MARA.
MODIFY MARA FROM WA_MARA.
ENDCASE.
ENDMODULE.                 " V1  INPUT
*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
IF OK_CODE = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.                 " EXIT  INPUT
Create a screen by number 130 and provide the following attributes: 
 
LAYOUT:
 
ELEMENT LIST:
 
FLOW LOGIC.
 
EXECUTE: 




http://scn.sap.com/thread/1067760




Simple Table Control

Table control is one of a ABAP displaying mechanisms. With the help of Table control we can see the output table in different visibility approach. Here we have developed a Module Pool program where a simple table control has been incorporated.

The output of the table control is like following:

1. Initial screen where we have to give the Transaction Code to run the Module Pool Program.


2. This is the first screen where we have to give the Purchase Order number in the input field. DISPLAY button will display the entered PO details at the second screen. CLEAR button will clear the entered data in the input field. Also we can see the title is coming for the first screen.


3. If nothing is give here then an Information message will come by clicking DISPLAY button.


4. Now we are giving a valid PO which has 22 items like follows.


5. By clicking on DISPLAY button we are going to the second screen where the Table Control is there to display the Item wise details as per Output table structure.


6. Now if we Scroll down by putting the mouse pointer on the Table Control then we shall go to the next slot of records as following.


7. By clicking on the BACK or EXIT or CANCEL button we shall come back to the first screen with a blank input field.

8. Now we are giving another PO and click on DISPLAY button.


9. New list will be coming with the same format but data are different. Here previous data will not be there. The entered PO contains 311 Items as follows.


10. By scroll down we can go to the last slot of data as follows.


11. By clicking BACK we shall come back to first screen like follows.


Following is the Coding for various Modules:

*&---------------------------------------------------------------------*
*& Module Pool       ZSR_MOD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*


INCLUDE zsr_top                                 .  " global Data
INCLUDE zsr_o01                                 .  " PBO-Modules
INCLUDE zsr_i01                                 .  " PAI-Modules
INCLUDE zsr_f01                                 .  " FORM-Routines


Top Include:

*&---------------------------------------------------------------------*
*& Include ZSR_TOP                                           Module Pool      ZSR_MOD
*&
*&---------------------------------------------------------------------*

PROGRAM  zsr_mod.

TABLES: ekko, ekpo.

TYPES: BEGIN OF ty_ekko,
        ebeln TYPE ekko-ebeln,
        bukrs TYPE ekko-bukrs,
        ernam TYPE ekko-ernam,
        lifnr TYPE ekko-lifnr,
       END OF ty_ekko,

       BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         lgort TYPE ekpo-lgort,
       END OF ty_ekpo,

       BEGIN OF ty_out,
        ebeln TYPE ekko-ebeln,
        ebelp TYPE ekpo-ebelp,
        ernam TYPE ekko-ernam,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        lgort TYPE ekpo-lgort,
        bukrs TYPE ekko-bukrs,
        lifnr TYPE ekko-lifnr,
       END OF ty_out.

DATA: ok_code1 TYPE sy-ucomm,
      ok_code2 TYPE sy-ucomm,
      editable TYPE i.

DATA: wa_ekko TYPE ty_ekko,
      wa_ekpo TYPE ty_ekpo,
      wa_out  TYPE ty_out,
      it_ekko TYPE STANDARD TABLE OF ty_ekko,
      it_ekpo TYPE STANDARD TABLE OF ty_ekpo,
      it_out  TYPE STANDARD TABLE OF ty_out WITH HEADER LINE.

CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN 9001.


Include for PBO:

*&---------------------------------------------------------------------*
*&  Include           ZSR_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.

  SET PF-STATUS 'GUI_9000'.
  SET TITLEBAR 'TITLE_9000'.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  TABLE_CTRL  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE table_ctrl OUTPUT.

  CLEAR: ekko, ekpo.
  ekko-ebeln = wa_out-ebeln.
  ekpo-ebelp = wa_out-ebelp.
  ekko-ernam = wa_out-ernam.
  ekpo-matnr = wa_out-matnr.
  ekpo-werks = wa_out-werks.
  ekpo-lgort = wa_out-lgort.
  ekko-bukrs = wa_out-bukrs.
  ekko-lifnr = wa_out-lifnr.
  CLEAR wa_out.

ENDMODULE.                 " TABLE_CTRL  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.

  SET PF-STATUS 'GUI_9001'.
  SET TITLEBAR 'TITLE_9001'.

ENDMODULE.                 " STATUS_9001  OUTPUT


Include for PAI:

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

  IF ok_code1 IS NOT INITIAL.
    CASE ok_code1.
      WHEN 'BACK'.
        PERFORM leave_program.
      WHEN 'EXIT'.
        PERFORM leave_program.
      WHEN 'CANCEL'.
        PERFORM leave_program.
      WHEN 'DISP'.
        PERFORM display_po_details.
      WHEN 'CLR'.
        PERFORM clear_screen.
    ENDCASE.
  ENDIF.

ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.

  IF ok_code1 IS NOT INITIAL.
    CASE ok_code2.
      WHEN 'BACK'.
        PERFORM leave_program.
      WHEN 'EXIT'.
        PERFORM leave_program.
      WHEN 'CANCEL'.
        PERFORM leave_program.
    ENDCASE.
  ENDIF.

ENDMODULE.                 " USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*&      Module  MODIFY_TABLE_CTRL  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE modify_table_ctrl INPUT.

  READ TABLE it_out INTO wa_out
  INDEX tab_ctrl-current_line.

  IF sy-subrc = 0.
    MODIFY it_out INDEX tab_ctrl-current_line FROM wa_out.
  ENDIF.

ENDMODULE.                 " MODIFY_TABLE_CTRL  INPUT


Include for Subroutine:

*&---------------------------------------------------------------------*
*&  Include           ZSR_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  LEAVE_PROGRAM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM leave_program .

  "Refreshing all Internal Tables
  REFRESH: it_out[], it_ekko, it_ekpo.

  "Clearing work area with Screen fields
  CLEAR: it_out, ekko, ekpo.

  "Clearing OK_CODE for new user command
  CLEAR: ok_code1, ok_code2.

  "Going back to initial screen
  LEAVE TO SCREEN 0.

ENDFORM.                    " LEAVE_PROGRAM
*&---------------------------------------------------------------------*
*&      Form  CLEAR_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM clear_screen .

  CLEAR ekko-ebeln.
  SET SCREEN 9000.

ENDFORM.                    " CLEAR_SCREEN
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_PO_DETAILS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_po_details .

  IF ekko-ebeln IS NOT INITIAL.
    "Selection of PO Header based Screen 1 PO
    SELECT ebeln bukrs ernam lifnr
      FROM ekko INTO TABLE it_ekko
      WHERE ebeln = ekko-ebeln.

    IF sy-subrc = 0.
      SORT it_ekko BY ebeln.

      "Selection of PO Item for all entries in header table
      SELECT ebeln ebelp matnr werks lgort
        FROM ekpo INTO TABLE it_ekpo
        FOR ALL ENTRIES IN it_ekko
        WHERE ebeln = it_ekko-ebeln.

      IF sy-subrc = 0.
        SORT it_ekpo BY ebeln.
      ELSE.
        MESSAGE 'Item not found' TYPE 'I'.
      ENDIF.

    ELSE.
      MESSAGE 'PO doesn''t exist' TYPE 'I'.
    ENDIF.

    IF it_ekpo IS NOT INITIAL.
      LOOP AT it_ekpo INTO wa_ekpo.
        READ TABLE it_ekko INTO wa_ekko
        WITH KEY ebeln = wa_ekpo-ebeln
        BINARY SEARCH.

        IF sy-subrc = 0.
          "Preparing Output table of Table Control
          wa_out-ebeln = wa_ekko-ebeln.
          wa_out-ebelp = wa_ekpo-ebelp.
          wa_out-ernam = wa_ekko-ernam.
          wa_out-matnr = wa_ekpo-matnr.
          wa_out-werks = wa_ekpo-werks.
          wa_out-lgort = wa_ekpo-lgort.
          wa_out-bukrs = wa_ekko-bukrs.
          wa_out-lifnr = wa_ekko-lifnr.
          APPEND wa_out TO it_out.
          CLEAR: wa_out, wa_ekko, wa_ekpo.
        ENDIF.
      ENDLOOP.
    ENDIF.

  ELSE.
    MESSAGE 'Please Select Valid PO' TYPE 'I'.
  ENDIF.

  IF it_out[] IS NOT INITIAL.

    "Output table is Sorted out by Item
    SORT it_out[] BY ebelp.

    "Table Control is refreshed before get into of this
    REFRESH CONTROL 'TAB_CTRL' FROM SCREEN 9001.

    "Calling Table control screen
    CALL SCREEN 9001.
  ENDIF.

ENDFORM.                    " DISPLAY_PO_DETAILS


Coding for Screen - 1:

PROCESS BEFORE OUTPUT.
  MODULE status_9000.

PROCESS AFTER INPUT.
  MODULE user_command_9000.


Coding for Screen - 2:

PROCESS BEFORE OUTPUT.

  "Module for PF Status & Title Bar of 2nd Screen
  MODULE status_9001.

  "Looping at Output table to pass value to Table Control
  LOOP AT it_out INTO wa_out WITH CONTROL tab_ctrl.

    "Module to pass the value to Screen Fields
    MODULE table_ctrl.
  ENDLOOP.


PROCESS AFTER INPUT.

  "Looping at Output table to fetch next set of values
  LOOP AT it_out.

    "Module to modify Output table with Current Line Index
    MODULE modify_table_ctrl.
  ENDLOOP.

  "Module for using Button on the screen - 2
  MODULE user_command_9001.

http://sapabap-4.blogspot.in/2013/06/simple-table-control.html

No comments:

Post a Comment