Thursday, June 20, 2013

Table Controls in Tab Strip

Tab strip is a screen container where we can have multiple screen fields from different tables or same table. Tab contains two parts – tab title and page area. Here the tab title works like a push button. In the page area of tab we need to design a sub screen. Each tab is a container of each sub screen where we can show different fields. We can have table control also in that sub screen. We have to looping the internal table with the table control to create a table control in a tab strip.

In the following example we have created a main screen where an input field of Airline code is there. Based on that input the program will fetch data from Airline, Flight schedule and Flight database table. After that the program will display the details inside the three tabs. Here at the first tab we are declaring the details of Airline. This is a normal display because we are selecting only one input of airline code. Now according to the function one airline can contain one or more flight schedule and flight details. So we are displaying those multiple data by using a table control created in different tabs.

Step – 1:
At first we need to create the different includes of the module pool.

INCLUDE mz_test_top                             .  " global Data
INCLUDE mz_test_o01                             .  " PBO-Modules
INCLUDE mz_test_i01                             .  " PAI-Modules
INCLUDE mz_test_f01                             .  " FORM-Routines

Step – 2:
Next we are declaring the variables, structures and tables at the top include.

*-------Declaring tables for screen fields-----------------------------*
TABLES: scarr, spfli, sflight.

TYPES:
*------Airline internal structure--------------------------------------*
       BEGIN OF ty_scarr,
        carrid   TYPE scarr-carrid,
        carrname TYPE scarr-carrname,
        currcode TYPE scarr-currcode,
       END OF ty_scarr,

*------Flight schedule internal structure------------------------------*
       BEGIN OF ty_spfli,
        carrid   TYPE spfli-carrid,
        connid   TYPE spfli-connid,
        cityfrom TYPE spfli-cityfrom,
        airpfrom TYPE spfli-airpfrom,
        cityto   TYPE spfli-cityto,
        airpto   TYPE spfli-airpto,
        deptime  TYPE spfli-deptime,
        arrtime  TYPE spfli-arrtime,
        distance TYPE spfli-distance,
       END OF ty_spfli,

*------Flight internal structure---------------------------------------*
       BEGIN OF ty_sflight,
        carrid   TYPE sflight-carrid,
        connid   TYPE sflight-connid,
        fldate   TYPE sflight-fldate,
        price    TYPE sflight-price,
        currency TYPE sflight-currency,
        seatsmax TYPE sflight-seatsmax,
        seatsocc TYPE sflight-seatsocc,
       END OF ty_sflight.

*-----Work area & internal table declaration---------------------------*
DATA: wa_scarr   TYPE ty_scarr,
      wa_spfli   TYPE ty_spfli,
      it_spfli   TYPE TABLE OF ty_spfli,
      wa_sflight TYPE ty_sflight,
      it_sflight TYPE TABLE OF ty_sflight.

DATA: ok_code  TYPE sy-ucomm,     "User command capturing variable
      v_carrid TYPE scarr-carrid. "Screen field variable

CONTROLS:
*---------Declaring the tab strip--------------------------------------*
          ts_air     TYPE TABSTRIP,

*---------Declaring the table controls---------------------------------*
          tc_spfli   TYPE TABLEVIEW USING SCREEN 9003,
          tc_sflight TYPE TABLEVIEW USING SCREEN 9004.

Step – 3:
Now we are creating the main screen 9001. We shall have one single main screen which contains the tab strip. Several other tabs will contain several other sub screens.

PROCESS BEFORE OUTPUT.

*--------Calling the module for GUI status of PBO----------------------*
  MODULE status_9001.

*------Calling the sub screens which contains the table control--------*
  CALL SUBSCREEN sub1 INCLUDING sy-repid '9002'.
  CALL SUBSCREEN sub2 INCLUDING sy-repid '9003'.
  CALL SUBSCREEN sub3 INCLUDING sy-repid '9004'.

PROCESS AFTER INPUT.
*------Calling the sub screens which contains the table control--------*
  CALL SUBSCREEN sub1.
  CALL SUBSCREEN sub2.
  CALL SUBSCREEN sub3.

*--------Calling the module to capture the sy-ucomm--------------------*
  MODULE user_command_9001.



Here we have call other sub screens which belong to different tabs. The sub screens are 9002, 9003 & 9004.

Step – 4:
Now we are creating the GUI status for the main screen.

MODULE status_9001 OUTPUT.

  SET PF-STATUS 'PF_MAIN_9001'. "GUI status
  SET TITLEBAR 'TI_MAIN_9001'"GUI title

ENDMODULE.                 " status_9001  OUTPUT

Step – 5:
After that we have to create the user command functionality (push button) in PAI.

MODULE user_command_9001 INPUT.

  CASE ok_code.
    WHEN 'TAB1'. "TAB1 tab title works like a push button
      ts_air-activetab = 'TAB1'.
    WHEN 'TAB2'. "TAB2 tab title works like a push button
      ts_air-activetab = 'TAB2'.
    WHEN 'TAB3'. "TAB3 tab title works like a push button
      ts_air-activetab = 'TAB3'.

    WHEN 'DISP'. "Display push button
      PERFORM get_airline.
      PERFORM get_flight_schedule.
      PERFORM get_flight.
    WHEN 'CLR'"Clear push button
      PERFORM clear_program.

    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'. "GUI buttons
      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.                 " user_command_9001  INPUT

Since tab titles work as push buttons we have activated the tab strip with the tab name. Now for display command we have created three sub routines to fetch data from database tables.

Step – 6:
Now we are fetching data from database tables by using the sub routines.

*&---------------------------------------------------------------------*
*&      Form  get_airline
*&---------------------------------------------------------------------*
*       Get data from Airline
*----------------------------------------------------------------------*
FORM get_airline .

  IF scarr-carrid IS NOT INITIAL.
    SELECT SINGLE carrid carrname currcode
      FROM scarr INTO wa_scarr
      WHERE carrid = scarr-carrid.

    IF sy-subrc = 0.

      "To avoid the selection screen field and display field
      "we are using different name for carrid
      v_carrid       = wa_scarr-carrid.
      scarr-carrname = wa_scarr-carrname.
      scarr-currcode = wa_scarr-currcode.
      CLEAR wa_scarr.
    ENDIF.
  ELSE.
    MESSAGE 'Please enter a valid Airline code' TYPE 'I'.
  ENDIF.

ENDFORM.                    " get_airline
*&---------------------------------------------------------------------*
*&      Form  get_flight_schedule
*&---------------------------------------------------------------------*
*       Get data from Flight schedule table
*----------------------------------------------------------------------*
FORM get_flight_schedule .

  IF scarr-carrid IS NOT INITIAL.
    SELECT carrid connid cityfrom airpfrom
           cityto airpto deptime arrtime distance
      FROM spfli INTO TABLE it_spfli
      WHERE carrid = scarr-carrid.
  ENDIF.

ENDFORM.                    " get_flight_schedule
*&---------------------------------------------------------------------*
*&      Form  get_flight
*&---------------------------------------------------------------------*
*       Get data from Flight table
*----------------------------------------------------------------------*
FORM get_flight .

  IF scarr-carrid IS NOT INITIAL.
    SELECT carrid connid fldate price
           currency seatsmax seatsocc
      FROM sflight INTO TABLE it_sflight
      WHERE carrid = scarr-carrid.
  ENDIF.

ENDFORM.                    " get_flight

Since we are selecting one single airline code to fetch details on tab 1 we have selected single record from airline table into work area. Rest of the selection has been done by using the internal tables which will be displayed on the table controls.

Step – 7:
After that we have created the CLEAR button functionality.

*&---------------------------------------------------------------------*
*&      Form  clear_program
*&---------------------------------------------------------------------*
*       Clearing & refreshing all screen fields and tables
*----------------------------------------------------------------------*
FORM clear_program .

  CLEAR: scarr, spfli, sflight, v_carrid,
         wa_scarr, wa_spfli, wa_sflight.
  REFRESH: it_spfli, it_sflight.

ENDFORM.                    " clear_program

Step – 8:
Since tab1 does not contain any user command functionality we haven’t created any PBO and PAI on that sub screen.



Here at tab2 (9003 sub screen) we are declaring the table control for flight schedule. Hence we have to loop internal table with table control at PBO and PAI.

PROCESS BEFORE OUTPUT.
* MODULE STATUS_9003.

*------Applying the table control with the internal table--------------*
  LOOP AT it_spfli INTO wa_spfli WITH CONTROL tc_spfli.

    "Populating the table control with table data
    MODULE display_tc_spfli.
  ENDLOOP.

PROCESS AFTER INPUT.

*------Looping the output table for next lines at scrolling------------*
  LOOP AT it_spfli.

    "Modify the output table with current line
    MODULE modify_tc_spfli.
  ENDLOOP.

* MODULE USER_COMMAND_9003.



Here we are not declaring any GUI status and button functionality since we don’t need that.

Step – 9:
Now we are creating the PBO module to populate the records at the table control.

MODULE display_tc_spfli OUTPUT.

*---------To activate the scrolling option of table control------------*
  PERFORM current_line_spfli.

*-------Moving data from work area to screen fields--------------------*
  spfli-carrid   = wa_spfli-carrid.
  spfli-connid   = wa_spfli-connid.
  spfli-cityfrom = wa_spfli-cityfrom.
  spfli-airpfrom = wa_spfli-airpfrom.
  spfli-cityto   = wa_spfli-cityto.
  spfli-airpto   = wa_spfli-airpto.
  spfli-deptime  = wa_spfli-deptime.
  spfli-arrtime  = wa_spfli-arrtime.
  spfli-distance = wa_spfli-distance.

ENDMODULE.                 " display_tc_spfli  OUTPUT

Step – 10:
Here we have declared a sub routine to activate the scrolling option in the table control.

*&---------------------------------------------------------------------*
*&      Form  current_line_spfli
*&---------------------------------------------------------------------*
*       Scrolling operation in flight schedule table control
*----------------------------------------------------------------------*
FORM current_line_spfli .

  "Describing the internal table to populate the sy-dbcnt
  DESCRIBE TABLE it_spfli LINES sy-dbcnt.

  "Field current line of table control needs to be populated
  "with sy-loopc - loop information in table control
  tc_spfli-current_line = sy-loopc.

  "Field lines is populated with the number of table lines
  "which has been processed yet
  tc_spfli-lines = sy-dbcnt.

ENDFORM.                    " current_line_spfli

Step – 11:
Now we have to modify the internal table in table control at PAI. The scrolling function always works at PAI.

MODULE modify_tc_spfli INPUT.

  READ TABLE it_spfli INTO wa_spfli
  INDEX tc_spfli-current_line.

  IF sy-subrc = 0.
    MODIFY it_spfli FROM wa_spfli INDEX tc_spfli-current_line.
  ENDIF.

ENDMODULE.                 " modify_tc_spfli  INPUT

Step – 12:
Similarly we are creating another sub screen for another tab. The screen flow logic will be similar as follows.

PROCESS BEFORE OUTPUT.
* MODULE STATUS_9004.

*------Applying the table control with the internal table--------------*
  LOOP AT it_sflight INTO wa_sflight WITH CONTROL tc_sflight.

    "Populating the table control with table data
    MODULE display_tc_sflight.
  ENDLOOP.

PROCESS AFTER INPUT.

*------Looping the output table for next lines at scrolling------------*
  LOOP AT it_sflight.

    "Modify the output table with current line
    MODULE modify_tc_sflight.
  ENDLOOP.
* MODULE USER_COMMAND_9004.



Step – 13:
Now the PBO module is as following.

MODULE display_tc_sflight OUTPUT.

*---------To activate the scrolling option of table control------------*
  PERFORM current_line_sflight.

*-------Moving data from work area to screen fields--------------------*
  sflight-carrid   = wa_sflight-carrid.
  sflight-connid   = wa_sflight-connid.
  sflight-fldate   = wa_sflight-fldate.
  sflight-price    = wa_sflight-price.
  sflight-currency = wa_sflight-currency.
  sflight-seatsmax = wa_sflight-seatsmax.
  sflight-seatsocc = wa_sflight-seatsocc.

ENDMODULE.                 " display_tc_sflight  OUTPUT

Step – 14:
Similarly we are creating the sub routine for scrolling option of table control.

FORM current_line_sflight .

  "Describing the internal table to populate the sy-dbcnt
  DESCRIBE TABLE it_sflight LINES sy-dbcnt.

  "Field current line of table control needs to be populated
  "with sy-loopc - loop information in table control
  tc_sflight-current_line = sy-loopc.

  "Field lines is populated with the number of table lines
  "which has been processed yet
  tc_sflight-lines = sy-dbcnt.

ENDFORM.                    " current_line_sflight

Step – 15:
Similarly we are modifying the internal table with current line of table control.

MODULE modify_tc_sflight INPUT.

  READ TABLE it_sflight INTO wa_sflight
  INDEX tc_sflight-current_line.

  IF sy-subrc = 0.
    MODIFY it_sflight FROM wa_sflight INDEX tc_sflight-current_line.
  ENDIF.

ENDMODULE.                 " modify_tc_sflight  INPUT

Step – 16:
Finally we create a transaction code to run the module pool from the system.

Now we have the output of this.


After giving the proper Airline code click the Display button.


Now click on the Flight Schedule tab.


After that click on the Flight Information tab.


Now we are scrolling down to the last row of this table.


Finally we click on the Clear button and all those screens will be cleared.

12 comments:

yektek training said...

thanks for this information siri

Gen4 said...

Thanks for the tutorial.Very helpful.
I would like to connect with you in Google hangout.

Gen4 said...

please provide your mail id or Google Hangout Profile id.

Anonymous said...

Thanks alot , Sir

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/

abid ali said...

Can anyone explain me the Step 8 of this blog? where to write PBO code

gilledashivani said...

Thanks for sharing valuable information through your post. The information provided is of great use.
SAP ABAP TRAINING IN HYDERABAD