Thursday, May 7, 2020

Table control using module programming (Dialog Programming)

Table Control:
Table control is a very useful tool when it comes to creating applications with user interactions.The program show how table control can be used to display and manipulate data. It will display sales order number, sales order line item and material number.

User is able to change material number, sort up, sort down or delete entries.


Table control can be created in two methods,

1. Using table control wizard

2. Manually creating the table control

In this example, table control is created manually (method 2) without using the wizard.

Steps to follow:

1. Go to transaction SE80 and create a program as 'ZSAPMVZTEST_MM_DS1'. Then create the screen, GUI Status (PF Status), GUI Title .

Screen Layout - 9001













Screen Layout - 9002












GUI Status (PF Status)

















Program:

*&---------------------------------------------------------------------*
*& Module Pool      ZSAPMVZTEST_MM_DS1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*

 INCLUDE ZSAPMVZTEST_MM_DS1_TOP                  .    " Global Data
 INCLUDE ZSAPMVZTEST_MM_DS1_O01                  .  " PBO-Modules
 INCLUDE ZSAPMVZTEST_MM_DS1_I01                  .  " PAI-Modules
 INCLUDE ZSAPMVZTEST_MM_DS1_F01                  .  " FORM-Routines


-------------------------------------------------------------------------

*&---------------------------------------------------------------------*
*& Include ZSAPMVZTEST_MM_DS1_TOP                   - Module Pool      ZSAPMVZTEST_MM_DS1
*&---------------------------------------------------------------------*
PROGRAM zsapmvztest_mm_ds1.

TABLES vbak .
DATAok_code TYPE sy-ucomm .
DATA v_vbeln TYPE vbeln .
DATA v_line TYPE .
CONTROLS tc_vbap TYPE TABLEVIEW USING SCREEN 9002,
           tc_cols TYPE TABLEVIEW USING SCREEN 9002.
DATA col TYPE cxtab_column.
DATA fld_list LIKE tc_vbap-cols.
DATA fldname(100TYPE .

TYPES  BEGIN OF ty_vbap ,
           mark  TYPE ce_mark,
           vbeln TYPE vbap-vbeln,
           posnr TYPE posnr_va,
           matnr TYPE matnr,
           matwa TYPE matwa,
           pmatn TYPE pmatn,
           charg TYPE charg_d,
           matkl TYPE matkl,
           arktx TYPE arktx,
           pstyv TYPE pstyv,
           posar TYPE posar,
         END OF ty_vbap .

DATAit_vbap TYPE TABLE OF ty_vbap,
      wa_vbap TYPE          ty_vbap.

------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include          ZSAPMVZTEST_MM_DS1_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
 SET PF-STATUS 'ZGUIS01'.
 SET TITLEBAR 'ZGUI01'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9002 OUTPUT.
 SET PF-STATUS 'ZGUIS01'.
 SET TITLEBAR 'ZGUI01'.
 DESCRIBE TABLE it_vbap LINES v_line.
 tc_vbap-lines v_line.
ENDMODULE.
--------------------------------------------------------------------------------

*&---------------------------------------------------------------------*
*& Include          ZSAPMVZTEST_MM_DS1_I01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.

  CLEAR v_vbeln .

  CASE ok_code .
    WHEN 'SAVE' OR 'CANCEL' OR 'BACK' OR 'EXIT' .
      LEAVE PROGRAM .
    WHEN 'NEXT' .
*      BREAK-POINT .
      IF vbak-vbeln IS INITIAL .
        MESSAGE 'Please enter a value' TYPE 'E' .
      ELSE .
        SELECT SINGLE vbeln FROM vbak INTO v_vbeln
          WHERE vbeln vbak-vbeln .
*        IF NOT sy-subrc IS INITIAL
        IF v_vbeln IS INITIAL .
          MESSAGE 'SALES DOC. NOT VALID' TYPE 'E' .
        ELSE .
          PERFORM fetch_data .
          CALL SCREEN '9002' .
        ENDIF.
      ENDIF.

  ENDCASE .

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  MODIFY_IT_VBAP  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE modify_it_vbap INPUT.

  MODIFY it_vbap FROM wa_vbap INDEX tc_vbap-current_line .

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9002  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9002 INPUT.

  CASE ok_code .
    WHEN 'SAVE' OR 'CANCEL' OR 'EXIT' .
      LEAVE PROGRAM .
    WHEN 'BACK' .
      SET SCREEN .
      LEAVE TO SCREEN .
    WHEN 'INSR' .
      APPEND INITIAL LINE TO it_vbap .
    WHEN 'DELE' .
      DELETE it_vbap WHERE mark 'X'  .
    WHEN 'SORT' .
      REFRESH fld_list .
      LOOP AT tc_vbap-cols INTO col .
        IF col-selected 'X' .
          APPEND col TO fld_list .
        ENDIF.
      ENDLOOP .
      SORT fld_list BY index .
      CLEAR fldname .
      READ TABLE fld_list INDEX INTO col .
      fldname col-screen-name+8 .
      SORT it_vbap BY (fldname.
  ENDCASE.

ENDMODULE.

---------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Include          ZSAPMVZTEST_MM_DS1_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM fetch_data .

  SELECT
           vbeln
           posnr
           matnr
           matwa
           pmatn
           charg
           matkl
           arktx
           pstyv
           posar
      FROM vbap
*      INTO TABLE it_vbap
      INTO CORRESPONDING FIELDS OF TABLE it_vbap
      WHERE vbeln vbak-vbeln.

ENDFORM.

--------------------------------------------------------------------------------
Creating Transaction:


















Output as Follows:
















No comments:

Post a Comment