Skip to Content

This video explains how to create Tablecontrols in ABAP and Work with the lock objects .

The Output of the Above Program will look like this :

/wp-content/uploads/2013/04/untitled_203244.jpg

After Pressing the edit Button , the output will look like as follows . Notice that the employee no. column is uneditable and the designation is MNGR then the cell of the tablecontrol is not ready for input . These attributes have been set on runtime .

/wp-content/uploads/2013/04/untitled2_203245.jpg

Now to create the table control in the layout section Press the tablecontrol Botton.

Untitled3.jpg

The Following Screen will appear . Press the dictionary/programs fields button (f6)

Untitled.jpg

Enter the name of the structure or the work area which you want to include in the table control . then select the structure , press ok and then drag the structure to the table control area .

Untitled.jpg

This way we can create the tablecontrol .

FLOW LOGIC :

Untitled.jpg


SOURCE CODE :

PROGRAM  ysuv_tabctrl_001.

TABLES : ysuv_employee1 .

TYPES : BEGIN OF ty_empno ,

        empno TYPE zdeempno ,

        name  TYPE zdeempname ,

        END OF ty_empno .

TYPES : BEGIN OF ty_empname ,

        empname TYPE zdeempname ,

        END OF ty_empname .

DATA : it_emp1 TYPE STANDARD TABLE OF ysuv_employee1 ,

       wa_emp1 TYPE ysuv_employee1 ,

       it_empno TYPE STANDARD TABLE OF ty_empno ,

       wa_empno TYPE ty_empno ,

       it_empname TYPE STANDARD TABLE OF ty_empname ,

       wa_empname TYPE ty_empname ,

       it_dynpread TYPE STANDARD TABLE OF dynpread ,

       wa_dynpread TYPE dynpread .

DATA : wa_stepl TYPE sy-stepl .

CONTROLS : tabctrl1 TYPE TABLEVIEW USING SCREEN 0001 .

DATA : mark1 TYPE c ,

       get_cursor TYPE sy-tabix VALUE 1 ,

       wa_lines TYPE i .

DATA: wa_cols TYPE cxtab_column ,

      tabix_emp TYPE sy-tabix .

DATA : counter TYPE i VALUE 1 ,

       p TYPE i VALUE 1 ,

       n TYPE i .

*&———————————————————————*

*&      Module  STATUS_0001  OUTPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE status_0001 OUTPUT.

  SET CURSOR FIELD ‘WA_EMP1-EMPADD’ LINE 4 . ” To set the Cursor on field Empadd at line 4 .

  SET PF-STATUS ‘STATUS001’.

*  SET TITLEBAR ‘xxx’.

ENDMODULE.                 ” STATUS_0001  OUTPUT

*&———————————————————————*

*&      Module  user_command_0001  INPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE user_command_0001 INPUT.

  CASE sy-ucomm .

    WHEN ‘BACK’ .

      LEAVE PROGRAM .

    WHEN ‘SAVE’ .

      IF mark1 = ‘X’ .

        UPDATE ysuv_employee1 FROM wa_emp1 .

      ENDIF.

    WHEN ‘DELETE’ .

      IF mark1 = ‘X’ .

        DELETE ysuv_employee1 FROM wa_emp1 .

      ENDIF.

    WHEN ‘EDIT’.

      CALL FUNCTION ‘ENQUEUE_EYSUV_EMPLOYEE1’

        EXPORTING

          mode_ysuv_employee1 = ‘E’

          mandt               = sy-mandt

          empno               = wa_emp1-empno

          x_empno             = ‘ ‘

          _scope              = ‘2’

          _wait               = ‘ ‘

          _collect            = ‘ ‘

        EXCEPTIONS

          foreign_lock        = 1

          system_failure      = 2

          OTHERS              = 3.

      IF sy-subrc <> 0.

        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

      ENDIF.

    WHEN ‘DISPLAY’ OR ‘REFRESH’ .

      CALL FUNCTION ‘DEQUEUE_EYSUV_EMPLOYEE1’

        EXPORTING

          mode_ysuv_employee1 = ‘E’

          mandt               = sy-mandt

          empno               = wa_emp1-empno

          x_empno             = ‘ ‘

          _scope              = ‘3’

          _synchron           = ‘ ‘

          _collect            = ‘ ‘.

  ENDCASE.

ENDMODULE.                 ” user_command_0001  INPUT

*&———————————————————————*

*&      Module  value_check  INPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE value_check INPUT.

  SELECT empno

         empname

    FROM ysuv_employee1

    INTO TABLE it_empno .

  CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’

    EXPORTING

      retfield        = ‘EMPNO’

      dynpprog        = sy-repid

      dynpnr          = sy-dynnr

      dynprofield     = ‘Employee Number’

      value_org       = ‘S’

    TABLES

      value_tab       = it_empno

    EXCEPTIONS

      parameter_error = 1

      no_values_found = 2

      OTHERS          = 3.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

ENDMODULE.                 ” value_check  INPUT

*&———————————————————————*

*&      Module  value_check_empname  INPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE value_check_empname INPUT.

*  DATA : wa_stepl TYPE systepl .

  CALL FUNCTION ‘DYNP_GET_STEPL’

    IMPORTING

      povstepl        = wa_stepl

    EXCEPTIONS

      stepl_not_found = 1

      OTHERS          = 2.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

  wa_dynpread-fieldname = ‘WA_EMP1-EMPNO’ .

  wa_dynpread-stepl     = wa_stepl .

  APPEND wa_dynpread TO it_dynpread .

  wa_dynpread-fieldname = ‘WA_EMP1-EMPNAME’ .

  wa_dynpread-stepl     = wa_stepl .

  APPEND wa_dynpread TO it_dynpread .

  CALL FUNCTION ‘DYNP_VALUES_READ’

    EXPORTING

      dyname               = sy-repid

      dynumb               = sy-dynnr

    TABLES

      dynpfields           = it_dynpread

    EXCEPTIONS

      invalid_abapworkarea = 1

      invalid_dynprofield  = 2

      invalid_dynproname   = 3

      invalid_dynpronummer = 4

      invalid_request      = 5

      no_fielddescription  = 6

      invalid_parameter    = 7

      undefind_error       = 8

      double_conversion    = 9

      stepl_not_found      = 10

      OTHERS               = 11.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

  READ TABLE it_dynpread INTO wa_dynpread INDEX 1 .”WITH  KEY fieldname = wa_emp1-empno .

  SELECT SINGLE empname

    FROM ysuv_employee1

    INTO  wa_empname

    WHERE empno = wa_dynpread-fieldvalue .

  APPEND wa_empname TO it_empname .

  CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’

    EXPORTING

      retfield        = ‘EMPNAME’

      dynpprog        = sy-repid

      dynpnr          = sy-dynnr

      dynprofield     = ‘Employee Name’

      value_org       = ‘S’

    TABLES

      value_tab       = it_empname

    EXCEPTIONS

      parameter_error = 1

      no_values_found = 2

      OTHERS          = 3.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

  CLEAR it_empname .

  CLEAR it_dynpread .

ENDMODULE.                 ” value_check_empname  INPUT

*&———————————————————————*

*&      Module  fill_table_control  OUTPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE fill_table_control OUTPUT.

  ” To Get the vertical scroll bar the no. of lines of table control is

  ” set to 100 + the no. of lines in internal table.

  DESCRIBE TABLE it_emp1 LINES wa_lines .

  tabctrl1-lines = wa_lines + 100 .

  IF it_emp1 IS NOT INITIAL .

    ” Read the value of the internal table into table control one by one.

    READ TABLE it_emp1 INTO wa_emp1 INDEX tabctrl1-current_line .

    ” Modifying the attributes of the Table-control .

    IF sy-ucomm NE ‘EDIT’ .

      LOOP AT SCREEN .

        IF screen-name NE ‘MARK1’ .

          screen-input = 0 .

          MODIFY SCREEN.

        ENDIF.

      ENDLOOP.

    ENDIF.

    CASE sy-ucomm .

      WHEN ‘EDIT’ .

        LOOP AT SCREEN .

          IF screen-name = ‘WA_EMP1-EMPNAME’ .

            IF screen-input = 0 .”1

              LOOP AT SCREEN.

                screen-input = 1 .

                MODIFY SCREEN.

              ENDLOOP.

            ENDIF.”1

          ENDIF.

        ENDLOOP.

        IF sy-ucomm = ‘EDIT’ .

          LOOP AT SCREEN .

            IF screen-name = ‘WA_EMP1-EMPDESIG’ .

              IF wa_emp1-empdesig = ‘MNGR’ .

                screen-input = 0 .

                screen-intensified = 1 . ” This will change the colour of the Text.

                MODIFY SCREEN.

              ENDIF.

            ENDIF.

            IF screen-name = ‘WA_EMP1-EMPNO’ .

              IF wa_emp1-empno IS NOT INITIAL .

                screen-input = 0.

                MODIFY SCREEN .

              ENDIF.

            ENDIF.

          ENDLOOP.

        ENDIF.

    ENDCASE.

  ENDIF.

ENDMODULE.                 ” fill_table_control  OUTPUT

*&———————————————————————*

*&      Module  get_data  OUTPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE get_data OUTPUT.

  SELECT * FROM ysuv_employee1 INTO TABLE it_emp1.

ENDMODULE.                 ” get_data  OUTPUT


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply