Wednesday, April 13, 2016

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.

TYPES: BEGIN OF ty_vbak,
        vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
        ernam TYPE vbak-ernam,
        vkorg TYPE vbak-vkorg,
      END OF ty_vbak.

TYPES: BEGIN 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.

9 comments:

Rahul said...

Well explained. Got to learn new things from your Blog on Appium.
Appium training in chennai

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shalini said...


Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

http://thecreatingexperts.com/sap-mm-training-in-chennai/

sushma said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882
http://thecreatingexperts.com/category/sap-hana-training-in-chennai/

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD

SieveSoftware said...

Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
SAP ABAP TRAINING IN HYDERABAD