Tuesday, September 15, 2015

Multiple Table Controls

Here we are creating multiple table controls by using different screens. At first we shall have a selection screen where we are using select option (selection range) to enter the input of airline code. Since select option can only be used under a selection screen, we have declared a sub screen while creating the first screen 9001. 



The first screen 9001 contains two push buttons ‘DISPLAY’ and ‘CLEAR’. After entering the selection range if DISPLAY button is clicked then the program will continue with second screen.



On the second screen 9002 we shall have the airline details with table control. In this table control we have declared a selection mark by which we can mark a specific row. We have a push button ‘FLIGHT NUMBER’ in this screen 9002. Now after selecting a row we can see flight number details by clicking that button.



Step – 1:
At first we need to create all the include programs.

INCLUDE mz_testtop                              .  " global Data
INCLUDE mz_testo01                              .  " PBO-Modules
INCLUDE mz_testi01                              .  " PAI-Modules
INCLUDE mz_testf01                              .  " FORM-Routines

Step – 2:
Next we are declaring the top include for global declaration.

*&---------------------------------------------------------------------*
*& Include MZ_TESTTOP                        Module Pool      SAPMZ_TEST
*&
*&---------------------------------------------------------------------*

PROGRAM  sapmz_test.

*-------Decalring the database tables for screen fields----------------*
TABLES: scarr, spfli, sflight.

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

*------Airline structure for screen output-----------------------------*
       BEGIN OF ty_out_scarr,
         mark     TYPE char1,         "Selection box
         carrid   TYPE scarr-carrid,
         carrname TYPE scarr-carrname,
         currcode TYPE scarr-currcode,
       END OF ty_out_scarr,

*------Flight schedule structure---------------------------------------*
       BEGIN OF ty_spfli,
         carrid     TYPE spfli-carrid,
         connid     TYPE spfli-connid,
         countryfr  TYPE spfli-countryfr,
         cityfrom   TYPE spfli-cityfrom,
         airpfrom   TYPE spfli-airpfrom,
         cityto     TYPE spfli-cityto,
         airpto     TYPE spfli-airpto,
       END OF ty_spfli,

*------Flight schedule structure for screen output---------------------*
       BEGIN OF ty_out_spfli,
         mark       TYPE char1,
         carrid     TYPE spfli-carrid,
         connid     TYPE spfli-connid,
         countryfr  TYPE spfli-countryfr,
         cityfrom   TYPE spfli-cityfrom,
         airpfrom   TYPE spfli-airpfrom,
         cityto     TYPE spfli-cityto,
         airpto     TYPE spfli-airpto,
       END OF ty_out_spfli.

DATA:
*-----Airline work areas & internal tables-----------------------------*
      lw_scarr TYPE          ty_scarr,
      wa_scarr TYPE          ty_out_scarr,
      lt_scarr TYPE TABLE OF ty_scarr,
      it_scarr TYPE TABLE OF ty_out_scarr,

*-----Temporary internal table to store data for reusing---------------*
      it_temp_scarr TYPE TABLE OF ty_out_scarr,

*-----To capture the Airline code for different use--------------------*
      v_carrid TYPE scarr-carrid,

*-----Flight schedule work areas & internal tables---------------------*
      lw_spfli TYPE          ty_spfli,
      wa_spfli TYPE          ty_out_spfli,
      lt_spfli TYPE TABLE OF ty_spfli,
      it_spfli TYPE TABLE OF ty_out_spfli.

DATA: ok_code1 TYPE sy-ucomm, "User command for screen 9001
      ok_code2 TYPE sy-ucomm, "User command for screen 9002
      ok_code3 TYPE sy-ucomm. "User command for screen 9003

*---------Declaring the selection screen as a subscreen of 100---------*
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECT-OPTIONS:  s_carrid FOR scarr-carrid.       "Select option
SELECTION-SCREEN END OF SCREEN 100.

*---------Declaring the table controls for different screen------------*
CONTROLS: tab_ctrl_scarr TYPE TABLEVIEW USING SCREEN 9002,
          tab_ctrl_spfli TYPE TABLEVIEW USING SCREEN 9003.

Here we have declared the selection screen as a sub screen of 100. Select option can only be called from a selection screen in module pool program. We need to create this sub screen at 9001 layout. We must not create the sub screen manually. In the layout there is an option of creating a sub screen.



Step – 3:
Next we have to create the screen 9001.

PROCESS BEFORE OUTPUT.

  "PBO for PF status & Title bar
  MODULE status_9001.

  "Calling the subscreen which is selection screen
  CALL SUBSCREEN sel INCLUDING sy-repid '100'.

PROCESS AFTER INPUT.

  "Subscreen needs to be called at PAI level
  CALL SUBSCREEN sel.

  "PAI for different button functionality
  MODULE user_command_9001.

Step – 4:
Then we need to create the PBO & PAI modules.

MODULE status_9001 OUTPUT.

  SET PF-STATUS 'PF_SEL'.
  SET TITLEBAR 'TI_SEL'.

ENDMODULE.                 " status_9001  OUTPUT

MODULE user_command_9001 INPUT.

  CASE ok_code1. "User command for 9001
    WHEN 'DISP'.
      PERFORM get_airline.
    WHEN 'CLR'.
      REFRESH s_carrid.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.                 " user_command_9001  INPUT

Step – 5:
After this we have to create the subroutine called in PAI.

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

  IF s_carrid[] IS NOT INITIAL.

    "It will refresh previous data when program moves with BACK
    REFRESH: lt_scarr.

    SELECT carrid carrname currcode
      FROM scarr INTO TABLE lt_scarr
      WHERE carrid IN s_carrid.

    IF sy-subrc = 0.
      REFRESH it_scarr.

      "Preparing the output table for screen fields
      LOOP AT lt_scarr INTO lw_scarr.
        wa_scarr-carrid   = lw_scarr-carrid.
        wa_scarr-carrname = lw_scarr-carrname.
        wa_scarr-currcode = lw_scarr-currcode.
        APPEND wa_scarr TO it_scarr.
        CLEAR: wa_scarr, lw_scarr.
      ENDLOOP.

      IF it_scarr IS NOT INITIAL.
        SORT it_scarr.

        "Storing the data to a temp table for reusing
        it_temp_scarr = it_scarr.

        "Refreshing the table control to display new records
        REFRESH CONTROL 'TAB_CTRL_SCARR' FROM SCREEN 9002.

        "Calling the next screen
        CALL SCREEN 9002.
      ENDIF.

    ELSE.
      MESSAGE 'Airline code doesn''t exist' TYPE 'S'.
      LEAVE LIST-PROCESSING.
    ENDIF.

  ELSE.
    MESSAGE 'Enter a valid Airline Code' TYPE 'I'.
  ENDIF.

ENDFORM.                    " get_airline

Step – 6:
After that we have to create the next screen 9002.

PROCESS BEFORE OUTPUT.

  "PBO for PF status & Title bar
  MODULE status_9002.

  "Populating the output table data in table control
  LOOP AT it_scarr INTO wa_scarr WITH CONTROL tab_ctrl_scarr.
    MODULE table_control_scarr.
  ENDLOOP.

PROCESS AFTER INPUT.

  "Reseting the output table after it gets modified
  MODULE reset_scarr.

  "Modifying the output table with current line operation
  LOOP AT it_scarr.
    MODULE modify_scarr.
  ENDLOOP.

  "PAI for different button functionality
  MODULE user_command_9002.

Here we have prepared the table control’s MARK field with work area WA_SCARR-MARK.



Step – 7:
Now we have to create the PBO and PAI modules.

MODULE status_9002 OUTPUT.

  SET PF-STATUS 'PF_SEL'.
  SET TITLEBAR 'TI_AIR'.

  "The internal table needs to be reset with its previous data
  "The table has been modified with MARK
  "So it needs to be reset to use it again


  it_scarr = it_temp_scarr.

ENDMODULE.                 " status_9002  OUTPUT

Now we are putting the data from work area to screen fields of table control.

MODULE table_control_scarr OUTPUT.

  CLEAR scarr.

  scarr-carrid   = wa_scarr-carrid.
  scarr-carrname = wa_scarr-carrname.
  scarr-currcode = wa_scarr-currcode.

ENDMODULE.                 " table_control_scarr  OUTPUT

Now we need to reset the output internal table to its previous value. This is because the table will be reused for different sort of commands.

MODULE reset_scarr INPUT.

  "Resetting the internal table to its previous data
  "It is needed to remove the modification with MARKs


  it_scarr = it_temp_scarr.

ENDMODULE.                 " reset_scarr  INPUT

Now we have to modify the internal table with its MARK fields for different sort of commands.

MODULE modify_scarr INPUT.

  "When one row is selected the internal table is modified
  "with the MARK fields x coming from wa_scarr-mark
  IF wa_scarr-mark = 'X'.
    MODIFY it_scarr INDEX tab_ctrl_scarr-current_line FROM wa_scarr.
  ENDIF.

  "When the table control is scralled
  READ TABLE it_scarr INTO wa_scarr
  INDEX tab_ctrl_scarr-current_line.

  IF sy-subrc = 0.
    MODIFY it_scarr INDEX tab_ctrl_scarr-current_line FROM wa_scarr.
  ENDIF.

ENDMODULE.                 " modify_scarr  INPUT

Now we need to create the user commands for different buttons functionality.

MODULE user_command_9002 INPUT.

  CASE ok_code2. "User command of screen 9002
    WHEN 'FLNM'.
      PERFORM capture_carrid.
      PERFORM get_flight_number.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.

      "Previous user command needs to be cleared for further operation
      CLEAR ok_code1.
      LEAVE LIST-PROCESSING.
      LEAVE TO SCREEN 9001.
  ENDCASE.

ENDMODULE.                 " user_command_9002  INPUT

Step – 8:
After this we have to create all the subroutines defined at user command. Here we need to capture the selected row data into a variable.

*&---------------------------------------------------------------------*
*&      Form  capture_carrid
*&---------------------------------------------------------------------*
*       Capturing the selected rows into a table
*----------------------------------------------------------------------*
FORM capture_carrid .

  IF it_scarr IS NOT INITIAL.

    LOOP AT it_scarr INTO wa_scarr WHERE mark = 'X'.
      v_carrid = wa_scarr-carrid.
      CLEAR: wa_scarr.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " capture_carrid

Now we have to get data from flight table based on the selected row data.
*&---------------------------------------------------------------------*
*&      Form  get_flight_number
*&---------------------------------------------------------------------*
*       Get data from Flight schedule table
*----------------------------------------------------------------------*
FORM get_flight_number .

  IF v_carrid IS NOT INITIAL.

    "It will refresh previous data when program moves with BACK
    REFRESH: lt_spfli, it_spfli.

    SELECT carrid connid countryfr cityfrom airpfrom cityto airpto
      FROM spfli INTO TABLE lt_spfli
      WHERE carrid = v_carrid.

    "Preparing the output table for screen fields
    IF sy-subrc = 0.
      CLEAR v_carrid. "Clearing v_carrid for UAT - BUGs

      LOOP AT lt_spfli INTO lw_spfli.
        wa_spfli-carrid    = lw_spfli-carrid.
        wa_spfli-connid    = lw_spfli-connid.
        wa_spfli-countryfr = lw_spfli-countryfr.
        wa_spfli-cityfrom  = lw_spfli-cityfrom.
        wa_spfli-airpfrom  = lw_spfli-airpfrom.
        wa_spfli-cityto    = lw_spfli-cityto.
        wa_spfli-airpto    = lw_spfli-airpto.
        APPEND wa_spfli TO it_spfli.
        CLEAR: wa_spfli, lw_spfli.
      ENDLOOP.

      IF it_spfli IS NOT INITIAL.
        SORT it_spfli.

        "Refreshing the table control to display new records
        REFRESH CONTROL 'TAB_CTRL_SPFLI' FROM SCREEN 9003.

        "Calling the next screen
        CALL SCREEN 9003.
      ENDIF.

    ELSE.
      CLEAR ok_code2. "Clearing OK_CODE2 for UAT - BUGs
      MESSAGE 'Flight doesn''t exist' TYPE 'I'.
    ENDIF.

  ELSE.
    CLEAR ok_code2. "Clearing OK_CODE2 for UAT - BUGs
    MESSAGE 'Select an Airline' TYPE 'I'.
  ENDIF.

ENDFORM.                    " get_flight_number

Step – 9:
After this we need to create the screen 9003 (last screen).

PROCESS BEFORE OUTPUT.

  "PBO for PF status & Title bar
  MODULE status_9003.

  "Populating the output table data in table control
  LOOP AT it_spfli INTO wa_spfli WITH CONTROL tab_ctrl_spfli.
    MODULE table_control_spfli.
  ENDLOOP.

PROCESS AFTER INPUT.

  "Modifying the output table with current line operation
  LOOP AT it_spfli.
    MODULE modify_spfli.
  ENDLOOP.

  "PAI for different button functionality
  MODULE user_command_9003.



Step – 10:
Then similarly we have to create all these modules.

MODULE status_9003 OUTPUT.

  SET PF-STATUS 'PF_SEL'.
  SET TITLEBAR 'TI_SPFLI'.

ENDMODULE.                 " status_9003  OUTPUT

Here we are populating the screen fields of table control for flight number details.

MODULE table_control_spfli OUTPUT.

  CLEAR spfli.

  spfli-carrid    = wa_spfli-carrid.
  spfli-connid    = wa_spfli-connid.
  spfli-countryfr = wa_spfli-countryfr.
  spfli-cityfrom  = wa_spfli-cityfrom.
  spfli-airpfrom  = wa_spfli-airpfrom.
  spfli-cityto    = wa_spfli-cityto.
  spfli-airpto    = wa_spfli-airpto.

ENDMODULE.                 " table_control_spfli  OUTPUT

Now we are again modifying the output table. Since this is the last screen of table control, there is no option to get marked row.

MODULE modify_spfli INPUT.

  "When the table control is scralled
  READ TABLE it_spfli INTO wa_spfli
  INDEX tab_ctrl_spfli-current_line.

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

ENDMODULE.                 " modify_spfli  INPUT

Now we are preparing the buttons at user command for screen 9003.

MODULE user_command_9003 INPUT.

  CASE ok_code3.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      "Previous user command needs to be cleared for further operation
      CLEAR: ok_code1, ok_code2.
      LEAVE LIST-PROCESSING.
      LEAVE TO SCREEN 9002.
  ENDCASE.

ENDMODULE.                 " user_command_9003  INPUT

The output screen 9001 is as follows:


Click on the Display after setting the selection range and the output is as follows:


We can scroll the table control and the output will be like follows:


Next we select a particular row like follows:


After that we want to see the Flight number details by clicking the Flight number button.


8 comments:

Rahul said...

It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

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/

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

sanayamohit 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

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/