banner ads

Disable Table Control Input

Disable Table Control Input



Table control can be disabled in various ways. In the following example we have demonstrated a module pool program where we have mentioned a button which can disable table control to take an input. The table control output will be like following.


If we click the “Disable Table Control” button then the system will disable two fields – sales doc & item.


Next if we click the “Enable Table Control” button then it will be enabled again.


Now we shall discuss it step by step.

Step – 1:
Create a module pool program named SAPMZ_SR (as per naming convention it starts with SAPMZ). Create all the include programs as follows.

INCLUDE mz_sr_top                               .  " global Data
INCLUDE mz_sr_o01                               .  " PBO-Modules
INCLUDE mz_sr_i01                               .  " PAI-Modules
INCLUDE mz_sr_f01                               .  " FORM-Routines

Step – 2:
Now create the TOP include where we need to declare every data members.

PROGRAM  sapmz_sr.

TABLES: vbak, vbap.
CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN 9001.

TYPESBEGIN OF ty_vbak,
        vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
        ernam TYPE vbak-ernam,
        vkorg TYPE vbak-vkorg,
      END OF ty_vbak.

TYPESBEGIN OF ty_vbap,
        vbeln TYPE vbap-vbeln,
        posnr TYPE vbap-posnr,
        matnr TYPE vbap-matnr,
        matkl TYPE vbap-matkl,
       END OF ty_vbap.

DATA: wa_vbak TYPE ty_vbak,
      wa_vbap TYPE ty_vbap,
      it_vbap TYPE TABLE OF ty_vbap.

DATA: ok_code TYPE sy-ucomm,
      disable TYPE c.

Step – 3:
Now create the screen 9001 and mention all details for the table control.

PROCESS BEFORE OUTPUT.  MODULE status_9001.

  LOOP AT it_vbap INTO wa_vbap WITH CONTROL tab_ctrl.
    MODULE prepare_table_control.
  ENDLOOP.

PROCESS AFTER INPUT.  LOOP AT it_vbap.
    MODULE modify_table_control.
  ENDLOOP.

  MODULE user_command_9001.

Step – 4:
Now create the layout for screen 9001. Here we have created one single screen where we have put the table control.




Step – 5:
Mention the OK_CODE under Element List tab.


Step – 6:
Now in PBO create the Module status 9001.

MODULE status_9001 OUTPUT.

  "Setting PF status and Title
  SET PF-STATUS 'PF_9001'.
  SET TITLEBAR  'TI_9001'.

  "Preparing the Sales Header information
  vbak-erdat = wa_vbak-erdat.
  vbak-ernam = wa_vbak-ernam.
  vbak-vkorg = wa_vbak-vkorg.

ENDMODULE.                 " status_9001  OUTPUT
Step – 7:
Next we create Module prepare table control.

MODULE prepare_table_control OUTPUT.

  "Describing table to generate sy-dbcnt
  DESCRIBE TABLE it_vbap LINES sy-dbcnt.
  tab_ctrl-current_line = sy-loopc.
  tab_ctrl-lines        = sy-dbcnt.

  "Preparing the Table Control data of Sales Doc Items
  vbap-vbeln = wa_vbap-vbeln.
  vbap-posnr = wa_vbap-posnr.
  vbap-matnr = wa_vbap-matnr.
  vbap-matkl = wa_vbap-matkl.
  CLEAR wa_vbap.

  "If user clicks on the DISABLE button
  IF disable IS NOT INITIAL.
    LOOP AT SCREEN.
      CASE screen-name.
        WHEN 'VBAP-VBELN'.
          screen-input = '0'"Input Disabled for VBELN
          MODIFY SCREEN.
        WHEN 'VBAP-POSNR'.
          screen-input = '0'"Input Disabled for POSNR
          MODIFY SCREEN.
      ENDCASE.
    ENDLOOP.
  ENDIF.

ENDMODULE.                 " prepare_table_control  OUTPUT

Here we need to call the screen to disable the input of VBELN & POSNR and then modify the screen.

Step – 8:
Now we create the PAI module modify table control.

MODULE modify_table_control INPUT.

  "Reading output table with current line to modify
  "when user scrolls down the table control
  READ TABLE it_vbap INTO wa_vbap INDEX tab_ctrl-current_line.

  IF sy-subrc = 0.
    MODIFY it_vbap FROM wa_vbap INDEX tab_ctrl-current_line.
  ENDIF.

ENDMODULE.                 " modify_table_control  INPUT

Step – 9:
Next create the module of user command 9001.

MODULE user_command_9001 INPUT.

  CASE ok_code.
    WHEN 'DISP'"Display Button
      PERFORM get_sales_data.
    WHEN 'REF'.  "Refresh Button
      PERFORM refresh_sales_data.
    WHEN 'DISA'"Disable Button
      disable = 'X'.
    WHEN 'ENA'.  "Enable Button
      CLEAR disable.
    WHEN 'BACK'"Back Button
      LEAVE LIST-PROCESSING.      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.                 " user_command_9001  INPUT
Step – 10:
Now we create the subroutines (performs) one by one. Firstly get sales data.

FORM get_sales_data .

  IF vbak-vbeln IS NOT INITIAL.
    SELECT SINGLE vbeln erdat ernam vkorg
      FROM vbak INTO wa_vbak
      WHERE vbeln = vbak-vbeln.

    IF sy-subrc = 0.
      SELECT vbeln posnr matnr matkl
        FROM vbap INTO TABLE it_vbap
        WHERE vbeln = vbak-vbeln.

      IF sy-subrc = 0.
        SORT it_vbap.
        REFRESH CONTROL 'TAB_CTRL' FROM SCREEN 9001.
        CALL SCREEN 9001.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_sales_data
Step – 11:
Then refresh sales data.

FORM refresh_sales_data .

  CLEAR: wa_vbak, vbak, vbap, ok_code.
  REFRESH it_vbap.

ENDFORM.                    " refresh_sales_data

Step – 12:
Finally create a transaction code for that. In this case it is ZSR_TRAN.


Step – 13:
Now we enter the transaction and get the following output.

No comments