Sunday, 16 February 2014

Field selection operation with two Table Controls in Module Pool Program


Scenario: Usually in standard ALV the filter criteria provides the option of selecting some fields based on which the ALV output is determined. This post creates the same with the help of Module pool screen table control option.




























Step1. Create a module pool program and only declare the required variables and activate it.
















Step2. Create a Normal screen with screen number '9999' and designed as per below.

















Step3. Details of Table control one.





















Step4.  Details of Table control two





















Step5. Declare some modules in the flow logic.





















Step6. Set the program PF status as mentioned below.











Step7. The detailed program code is given below. At last create a tcode for the Module pool program and activate all.
________________________________________________________________________________

PROGRAM  zsapmtest2.

DATA : tab_name TYPE dd02l-tabname,
              ls TYPE dd02l,
              lt TYPE TABLE OF dd03l,
              wa TYPE dd03l,
              focde1 TYPE sy-ucomm,
             fcode2 TYPE sy-ucomm,
             indx1 TYPE i,
             indx2 TYPE i.

TYPES: BEGIN OF ty_blk1,
              ch1,
              fieldname TYPE dd03l-fieldname,
             END OF ty_blk1.

TYPES: BEGIN OF ty_blk2,
              ch2,
              fieldname TYPE dd03l-fieldname,
             END OF ty_blk2.
DATA : lt1 TYPE TABLE OF ty_blk1,
              ls1 TYPE ty_blk1,
              ls11 TYPE ty_blk1,
              lt2 TYPE TABLE OF ty_blk2,
              ls2 TYPE ty_blk2,
              ls22 TYPE ty_blk2.

CONTROLS: tc1 TYPE TABLEVIEW USING SCREEN 9999,
                      tc2 TYPE TABLEVIEW USING SCREEN 9999.
*&---------------------------------------------------------------------*
*&      Module  status_9999  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9999 OUTPUT.
  SET PF-STATUS 'STATUS'.
ENDMODULE.                 " status_9999  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  fill_lt1  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE fill_lt1 OUTPUT.

ENDMODULE.                 " fill_lt1  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  fill_lt2  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE fill_lt2 OUTPUT.

ENDMODULE.                 " fill_lt2  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  pick_lt1  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

MODULE pick_lt1 INPUT.
  IF ls1-ch1 = 'X'.
    indx1 = tc1-current_line.
    ls22-fieldname = ls1-fieldname.
  ENDIF.
ENDMODULE.                 " pick_lt1  INPUT

*&---------------------------------------------------------------------*
*&      Module  pick_lt2  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

MODULE pick_lt2 INPUT.
  IF ls2-ch2 EQ 'X'.
    indx2 = tc2-current_line.
    ls11-fieldname = ls2-fieldname.
  ENDIF.
ENDMODULE.                 " pick_lt2  INPUT

*&---------------------------------------------------------------------*
*&      Module  user_command_9999  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

MODULE user_command_9999 INPUT.
  CASE sy-ucomm .

    WHEN 'ENTER'.
      REFRESH : lt[], lt2[].
      SELECT * FROM dd03l INTO TABLE lt WHERE tabname = ls-tabname AND rollname <> ' '.
      LOOP AT lt INTO wa .
        IF wa-fieldname <> 'MANDT'.
          ls2-fieldname = wa-fieldname.
          APPEND ls2 TO lt2.
          CLEAR:  ls2, wa.
        ENDIF.
      ENDLOOP.
      IF lt2 IS NOT INITIAL.
        SORT lt2 BY fieldname.
      ENDIF.

    WHEN 'SEL'.
      IF indx2 IS NOT INITIAL.
        IF ls11-fieldname IS NOT INITIAL.
          APPEND ls11 TO lt1.
          SORT lt1 BY fieldname.
          DELETE lt2 INDEX indx2.
          CLEAR : ls11, indx2.
        ENDIF.
      ENDIF.

    WHEN 'DESEL'.
      IF indx1 IS NOT INITIAL.
        IF ls22-fieldname IS NOT INITIAL.
          APPEND ls22 TO lt2.
          SORT lt2 BY fieldname.
          DELETE lt1 INDEX indx1.
          CLEAR : ls22, indx1.
        ENDIF.
      ENDIF.

    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " user_command_9999  INPUT

*&---------------------------------------------------------------------*
*&      Module  validate_table_name  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE validate_table_name INPUT.
  CASE sy-ucomm .

    WHEN 'ENTER'.
      SELECT SINGLE * FROM dd02l INTO ls WHERE tabname = tab_name.
      IF sy-subrc <> 0.
        MESSAGE 'Table Name doesnot Exists in Repository' TYPE 'E'.
      ENDIF.
      REFRESH : lt2[], lt1[].

    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " validate_table_name  INPUT

*&---------------------------------------------------------------------*
*&      Module  no_input_exit  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

MODULE no_input_exit INPUT.
  CASE sy-ucomm.
    WHEN 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 " no_input_exit  INPUT
_________________________________________________________________________________

Step8. Execute the program and the below screen comes up.





















Step9. Provide any table name and hit Enter Key from keyboard. Pls check that in the PF status of the program the ENTER menu is activated. The Table fields appears in the right hand side table control. Here the user can select any field and click on the LEFT arrow button , so that the selected field added to the Left hand side table control.

















Step10. If the field is wrongly selected then, user can selected the field from the left table control and click on the Right arrow button to take it to the Right hand side table control.


















Step11. If the user at this point decides to provide another table name to select that fields of the table.




















Step12. Provide the new table name and hit enter key from key board. So the new set of fields appear in the right hand side table control and the user can perform the select and deselect operation.






















________________________________________________________________________________



No comments:

Comments system

Disqus Shortname