Wednesday, June 5, 2013

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 table control will look like as follows from the layout. It is created from layout palate.


Here we have created a simple table control where we have two screens. First screen in the selection screen where we need to select a purchase order number and click on the display button. After that second screen will open and it contains the item wise detailed information.

Following is the Steps for Table Control:

Step 1:
At first we are creating a module pool program with proper naming convention and 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:
Next declare all the variables, structures, tables etc at top include.

PROGRAM  sapmz_sr.

*-------Declaration of tables for screen fields------------------------*
TABLES: ekko, ekpo.

*------Declaration of required structures------------------------------*
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.

*-----Declaration of user command variables----------------------------*
DATA: ok_code1 TYPE sy-ucomm,
      ok_code2 TYPE sy-ucomm.

*-----Declaration of work area & table---------------------------------*
DATA: wa_ekko TYPE          ty_ekko,
      wa_ekpo TYPE          ty_ekpo,
      it_ekpo TYPE TABLE OF ty_ekpo.

*---------Declaration of Table Control---------------------------------*
CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN 9002.

Step 3:
Now create a screen 9001 which is the selection screen of purchase order.


In the elementary list we declare the sy-ucomm (ok_code).


Step 4:
Write the flow logic as follows.

PROCESS BEFORE OUTPUT.
  MODULE status_9001.

PROCESS AFTER INPUT.
  MODULE user_command_9001.

Step 5:
Create the layout with required buttons and input fields.


Step 6:
Create PBO and PAI module of screen 9001 as follows.

MODULE status_9001 OUTPUT.

  SET PF-STATUS 'PF_PO_INP'.
  SET TITLEBAR 'PO_TITLE'.

ENDMODULE.                 " status_9001  OUTPUT

MODULE user_command_9001 INPUT.

  CASE ok_code1.
    WHEN 'DISP'.     "Display button
      PERFORM get_po.

    WHEN 'CLR'.      "Clear button
      CLEAR ekko-ebeln.

    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.

  ENDCASE.

ENDMODULE.                 " user_command_9001  INPUT

Step 7:
Now we are going to create the functionality of Display button in the subroutine as follows.

FORM get_po .

  IF ekko-ebeln IS NOT INITIAL.
    REFRESH: it_ekpo.

    SELECT SINGLE ebeln bukrs ernam lifnr
      FROM ekko INTO wa_ekko
      WHERE ebeln = ekko-ebeln.

    IF sy-subrc = 0.
      SELECT ebeln ebelp matnr werks lgort
        FROM ekpo INTO TABLE it_ekpo
        WHERE ebeln = wa_ekko-ebeln.

      IF sy-subrc = 0.
        SORT it_ekpo.

        "Refreshing the table control to have updated data
        REFRESH CONTROL 'TAB_CTRL' FROM SCREEN 9002.
        CALL SCREEN 9002.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                    " get_po

Step 8:
After that create the screen 9002 which is the table control screen of PO item wise details.



Step 9:
Write the flow logic of table control in PBO & PAI.

PROCESS BEFORE OUTPUT.
  MODULE status_9002.

  LOOP AT it_ekpo INTO wa_ekpo WITH CONTROL tab_ctrl.
    MODULE table_control.
  ENDLOOP.

PROCESS AFTER INPUT.

  LOOP AT it_ekpo.
    MODULE modify_table_control.
  ENDLOOP.

  MODULE user_command_9002.

Step 10:
Now go to layout and create the table control from palate. The name must be TAB_CTRL.


Step 11:
Click on the dictionary button and select the required fields which need to be displayed in the table control.


Step 12:
After that the table control will look like this.


We can modify the visibility length also.


Step 13:
Now we have to create the PBO module of table control as follows.

MODULE status_9002 OUTPUT.

  SET PF-STATUS 'PF_PO_INP'.
  SET TITLEBAR 'PO_TITLE'.

ENDMODULE.                 " status_9002  OUTPUT

MODULE table_control OUTPUT.

  "Describing table to populate sy-dbcnt
  DESCRIBE TABLE it_ekpo LINES sy-dbcnt.

  "Current line populates the loop information in table control
  tab_ctrl-current_line = sy-loopc.

  "Lines are populated with number of table lines
  tab_ctrl-lines        = sy-dbcnt.

  "Moving data from work area to screen fields
  ekpo-ebeln = wa_ekpo-ebeln.
  ekpo-ebelp = wa_ekpo-ebelp.
  ekpo-matnr = wa_ekpo-matnr.
  ekpo-werks = wa_ekpo-werks.
  ekpo-lgort = wa_ekpo-lgort.

  CLEAR wa_ekpo.

ENDMODULE.                 " table_control  OUTPUT

Step 14:
Now create the PAI module as follows.

MODULE user_command_9002 INPUT.

  CASE ok_code2.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.

      "Due to multiple clicks user command needs to be updated
      CLEAR ok_code2.

      LEAVE LIST-PROCESSING.
      LEAVE TO SCREEN 9001.

  ENDCASE.

ENDMODULE.                 " user_command_9002  INPUT

MODULE modify_table_control INPUT.

  "Readin the table with current line
  READ TABLE it_ekpo INTO wa_ekpo INDEX tab_ctrl-current_line.

  IF sy-subrc = 0.

    "Modifying the current line in table control
    MODIFY it_ekpo FROM wa_ekpo INDEX tab_ctrl-current_line.
  ENDIF.

ENDMODULE.                 " modify_table_control  INPUT

Step 15:
Finally create a Transaction code and run it from SAP system. The selection screen which is the first screen will come and enter a PO number there.



Step 14:
Click on Display button and we see the item wise details in table control.


Now we can scroll down like this.

13 comments:

Anonymous said...

awesome tutorial.

yektek training said...

Thanks for sharing this post thank you

r2b2 said...

Hi I would just like to ask something, i am new to table controls, how do you know which screen displays first?

Sandip Roy said...

It's very simple. To run module pool program you always need a Transaction Code. After entering the T-code a screen will come and that will be the 1st screen. After entering some input the second screen will come.

There may be plenty of screens. So whenever you are making a screen give the numbers sequentially (like 9000, 9001, 9002) and maintain proper description of the screen.

r2b2 said...

Thanks Sandip.

Unknown said...

It's really good

Anonymous said...

How to save data from table control to ztable.

Anonymous said...

Awesome tutorial! Thanks for sharing.

Unknown said...

sir how to create table control for taking input from user & save to database?

Anonymous 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!!!!!!

Unknown said...



Best SAP Success Factors Training Institute in Chennai
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
Best SAP MM Training in Chennai
http://thecreatingexperts.com/sap-mm-training-in-chennai/
Best SAP SD Training in Chennai
http://thecreatingexperts.com/sap-sd-training-in-chennai/
http://thecreatingexperts.com/sap-hr-training-in-chennai/
Best SAP FICO Training in Chennai
http://thecreatingexperts.com/sap-fico-training-in-chennai/
Best SAP ABAP Training in Chennai
http://thecreatingexperts.com/sap-abap-training-in-chennai/
Best SAP BASIS Training in Chennai
http://thecreatingexperts.com/sap-basis-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!!!!!!

Anonymous said...

Hi, I learned SAP Training in Chennai from THE CREATING EXPERTS. The training was good and i got selected in leading MNC company as SAP Consultant.

contact 8122241286

www.thecreatingexperts.com

Business World said...

Informative article. Thank you for sharing the great blog. You have done great explanation and visualization. Keep up the good work.
BEST SAP ABAP TRAINING IN HYDERABAD