Skip to Content
-3

Table control that should be empty is prefilled with initial values

Mar 15, 2017 at 04:19 PM

120

avatar image

Hi everyone,

Here's another novice question. I've got a table control on a dynpro, an works fine as long a the underlying internal table contains lines. If it doesn't, instead of displaying an empty table control, I get an entire page where two columns are prefilled:

- Run ID

- Time

Take a look:

Why does it behave this way, and how do I suppress this behaviour so it comes up empty instead?

A hint:

Run_ID is selected from a database table where it is a key value and thus has an initial value. Not sure why that would lead to this beaviour though...

Here's literally the entire ABAP code, since there is not much there yet:

The table control was added via the wizard.

Thanks in advance for taking a look!

Martin

TABLES: /textform/stelog.


TYPES:
  BEGIN OF s_log_entries,
    run_id   TYPE lxe_id,
    run_date TYPE sydatum,
    run_time TYPE syuzeit,
    run_type TYPE /textform/ste_run_type,
    objtype  TYPE lxeobjtype,
    objname  TYPE lxeobjname,
    error    TYPE c LENGTH 73,
  END OF s_log_entries.


DATA:
  wa_stelog      type /textform/stelog,
  run_id type lxe_id,
  time_from      TYPE syuzeit,
  time_to        TYPE syuzeit,
  i_log_entries  TYPE TABLE OF s_log_entries,
  wa_log_entries TYPE s_log_entries,
  ok_code        LIKE sy-ucomm,
  condition      TYPE c LENGTH 72,
  i_conditions   LIKE TABLE OF condition,
  second_call type abap_bool.


CLEAR i_log_entries.


CALL SCREEN 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS '/TEXTFORM/LOGS'.
  SET TITLEBAR '/TEXTFORM/LOGS'.


MOVE-CORRESPONDING wa_stelog TO /textform/stelog.


"  IF i_log_entries IS INITIAL and second_call is initial.
"    SELECT * FROM /textform/stelog INTO CORRESPONDING FIELDS OF TABLE i_log_entries.
"    LEAVE SCREEN.
"    second_call = abap_true.
"  ENDIF.


ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  MOVE-CORRESPONDING /textform/stelog TO wa_stelog.




  CASE ok_code.
    WHEN 'EXECUTE'.


      CLEAR i_conditions.
      CLEAR i_log_entries.


*set select conditions
      IF ( time_from IS NOT INITIAL OR time_from = '' ) OR ( time_to IS NOT INITIAL OR time_to = '' ).
        IF time_from IS INITIAL OR time_from = ''.
          time_from = 000000.
        ENDIF.
        IF time_to IS INITIAL OR time_to = ''.
          time_to = 235959.
        ENDIF.
      ELSE.
        time_from = 000000.
        time_to = 235959.
      ENDIF.
      CONCATENATE 'run_time between time_from and time_to' ' ' INTO condition.
      APPEND condition TO i_conditions.


      IF run_id IS NOT INITIAL.
        CONCATENATE 'and run_id = run_id' ' ' INTO condition.
        APPEND condition TO i_conditions.
      ELSE.
        run_id = ''.
      ENDIF.
      IF wa_stelog-run_date IS NOT INITIAL.
        CONCATENATE 'and run_date = wa_stelog-run_date' ' ' INTO condition.
        APPEND condition TO i_conditions.
      ENDIF.
      IF wa_stelog-run_type IS NOT INITIAL.
        CONCATENATE 'and run_type = wa_stelog-run_type' ' ' INTO condition.
        APPEND condition TO i_conditions.
      ENDIF.


      SELECT * FROM /textform/stelog INTO CORRESPONDING FIELDS OF TABLE i_log_entries
        WHERE (i_conditions).


      IF run_id IS INITIAL.
      ENDIF.


    WHEN 'BACK'.
      LEAVE PROGRAM.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.


*&SPWIZARD: DECLARATION OF TABLECONTROL 'LOG_ENTRIES' ITSELF
CONTROLS: log_entries TYPE TABLEVIEW USING SCREEN 0100.


*&SPWIZARD: LINES OF TABLECONTROL 'LOG_ENTRIES'
DATA:     g_log_entries_lines  LIKE sy-loopc.




*&SPWIZARD: OUTPUT MODULE FOR TC 'LOG_ENTRIES'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE log_entries_change_tc_attr OUTPUT.
  DESCRIBE TABLE i_log_entries LINES log_entries-lines.
ENDMODULE.


*&SPWIZARD: OUTPUT MODULE FOR TC 'LOG_ENTRIES'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE log_entries_get_lines OUTPUT.
  g_log_entries_lines = sy-loopc.
ENDMODULE.


*&SPWIZARD: INPUT MODULE FOR TC 'LOG_ENTRIES'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE log_entries_user_command INPUT.
  ok_code = sy-ucomm.
  PERFORM user_ok_tc USING    'LOG_ENTRIES'
                              'I_LOG_ENTRIES'
                              ' '
                     CHANGING ok_code.
  sy-ucomm = ok_code.
ENDMODULE.


*----------------------------------------------------------------------*
*   INCLUDE TABLECONTROL_FORMS                                         *
*----------------------------------------------------------------------*


*&---------------------------------------------------------------------*
*&      Form  USER_OK_TC                                               *
*&---------------------------------------------------------------------*
FORM user_ok_tc USING    p_tc_name TYPE dynfnam
                         p_table_name
                         p_mark_name
                CHANGING p_ok      LIKE sy-ucomm.


*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
  DATA: l_ok     TYPE sy-ucomm,
        l_offset TYPE i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*


*&SPWIZARD: Table control specific operations                          *
*&SPWIZARD: evaluate TC name and operations                            *
  SEARCH p_ok FOR p_tc_name.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  l_offset = strlen( p_tc_name ) + 1.
  l_ok = p_ok+l_offset.
*&SPWIZARD: execute general and TC specific operations                 *
  CASE l_ok.
    WHEN 'INSR'.                      "insert row
      PERFORM fcode_insert_row USING    p_tc_name
                                        p_table_name.
      CLEAR p_ok.


    WHEN 'DELE'.                      "delete row
      PERFORM fcode_delete_row USING    p_tc_name
                                        p_table_name
                                        p_mark_name.
      CLEAR p_ok.


    WHEN 'P--' OR                     "top of list
         'P-'  OR                     "previous page
         'P+'  OR                     "next page
         'P++'.                       "bottom of list
      PERFORM compute_scrolling_in_tc USING p_tc_name
                                            l_ok.
      CLEAR p_ok.

    WHEN 'MARK'.                      "mark all filled lines
      PERFORM fcode_tc_mark_lines USING p_tc_name
                                        p_table_name
                                        p_mark_name   .
      CLEAR p_ok.


    WHEN 'DMRK'.                      "demark all filled lines
      PERFORM fcode_tc_demark_lines USING p_tc_name
                                          p_table_name
                                          p_mark_name .
      CLEAR p_ok.


  ENDCASE.


ENDFORM.                              " USER_OK_TC


*&---------------------------------------------------------------------*
*&      Form  FCODE_INSERT_ROW                                         *
*&---------------------------------------------------------------------*
FORM fcode_insert_row
              USING    p_tc_name           TYPE dynfnam
                       p_table_name             .


*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
  DATA l_lines_name       LIKE feld-name.
  DATA l_selline          LIKE sy-stepl.
  DATA l_lastline         TYPE i.
  DATA l_line             TYPE i.
  DATA l_table_name       LIKE feld-name.
  FIELD-SYMBOLS <tc>                 TYPE cxtab_control.
  FIELD-SYMBOLS <table>              TYPE STANDARD TABLE.
  FIELD-SYMBOLS <lines>              TYPE i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*


  ASSIGN (p_tc_name) TO <tc>.


*&SPWIZARD: get the table, which belongs to the tc                     *
  CONCATENATE p_table_name '[]' INTO l_table_name. "table body
  ASSIGN (l_table_name) TO <table>.                "not headerline


*&SPWIZARD: get looplines of TableControl                              *
  CONCATENATE 'G_' p_tc_name '_LINES' INTO l_lines_name.
  ASSIGN (l_lines_name) TO <lines>.


*&SPWIZARD: get current line                                           *
  GET CURSOR LINE l_selline.
  IF sy-subrc <> 0.                   " append line to table
    l_selline = <tc>-lines + 1.
*&SPWIZARD: set top line                                               *
    IF l_selline > <lines>.
      <tc>-top_line = l_selline - <lines> + 1 .
    ELSE.
      <tc>-top_line = 1.
    ENDIF.
  ELSE.                               " insert line into table
    l_selline = <tc>-top_line + l_selline - 1.
    l_lastline = <tc>-top_line + <lines> - 1.
  ENDIF.
*&SPWIZARD: set new cursor line                                        *
  l_line = l_selline - <tc>-top_line + 1.


*&SPWIZARD: insert initial line                                        *
  INSERT INITIAL LINE INTO <table> INDEX l_selline.
  <tc>-lines = <tc>-lines + 1.
*&SPWIZARD: set cursor                                                 *
  SET CURSOR LINE l_line.


ENDFORM.                              " FCODE_INSERT_ROW


*&---------------------------------------------------------------------*
*&      Form  FCODE_DELETE_ROW                                         *
*&---------------------------------------------------------------------*
FORM fcode_delete_row
              USING    p_tc_name           TYPE dynfnam
                       p_table_name
                       p_mark_name   .


*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
  DATA l_table_name       LIKE feld-name.


  FIELD-SYMBOLS <tc>         TYPE cxtab_control.
  FIELD-SYMBOLS <table>      TYPE STANDARD TABLE.
  FIELD-SYMBOLS <wa>.
  FIELD-SYMBOLS <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*


  ASSIGN (p_tc_name) TO <tc>.


*&SPWIZARD: get the table, which belongs to the tc                     *
  CONCATENATE p_table_name '[]' INTO l_table_name. "table body
  ASSIGN (l_table_name) TO <table>.                "not headerline


*&SPWIZARD: delete marked lines                                        *
  DESCRIBE TABLE <table> LINES <tc>-lines.


  LOOP AT <table> ASSIGNING <wa>.


*&SPWIZARD: access to the component 'FLAG' of the table header         *
    ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.


    IF <mark_field> = 'X'.
      DELETE <table> INDEX syst-tabix.
      IF sy-subrc = 0.
        <tc>-lines = <tc>-lines - 1.
      ENDIF.
    ENDIF.
  ENDLOOP.


ENDFORM.                              " FCODE_DELETE_ROW


*&---------------------------------------------------------------------*
*&      Form  COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*      -->P_OK       ok code
*----------------------------------------------------------------------*
FORM compute_scrolling_in_tc USING    p_tc_name
                                      p_ok.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
  DATA l_tc_new_top_line     TYPE i.
  DATA l_tc_name             LIKE feld-name.
  DATA l_tc_lines_name       LIKE feld-name.
  DATA l_tc_field_name       LIKE feld-name.


  FIELD-SYMBOLS <tc>         TYPE cxtab_control.
  FIELD-SYMBOLS <lines>      TYPE i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*


  ASSIGN (p_tc_name) TO <tc>.
*&SPWIZARD: get looplines of TableControl                              *
  CONCATENATE 'G_' p_tc_name '_LINES' INTO l_tc_lines_name.
  ASSIGN (l_tc_lines_name) TO <lines>.




*&SPWIZARD: is no line filled?                                         *
  IF <tc>-lines = 0.
*&SPWIZARD: yes, ...                                                   *
    l_tc_new_top_line = 1.
  ELSE.
*&SPWIZARD: no, ...                                                    *
    CALL FUNCTION 'SCROLLING_IN_TABLE'
      EXPORTING
        entry_act      = <tc>-top_line
        entry_from     = 1
        entry_to       = <tc>-lines
        last_page_full = 'X'
        loops          = <lines>
        ok_code        = p_ok
        overlapping    = 'X'
      IMPORTING
        entry_new      = l_tc_new_top_line
      EXCEPTIONS
*       NO_ENTRY_OR_PAGE_ACT  = 01
*       NO_ENTRY_TO    = 02
*       NO_OK_CODE_OR_PAGE_GO = 03
        OTHERS         = 0.
  ENDIF.


*&SPWIZARD: get actual tc and column                                   *
  GET CURSOR FIELD l_tc_field_name
             AREA  l_tc_name.


  IF syst-subrc = 0.
    IF l_tc_name = p_tc_name.
*&SPWIZARD: et actual column                                           *
      SET CURSOR FIELD l_tc_field_name LINE 1.
    ENDIF.
  ENDIF.


*&SPWIZARD: set the new top line                                       *
  <tc>-top_line = l_tc_new_top_line.




ENDFORM.                              " COMPUTE_SCROLLING_IN_TC


*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
*       marks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM fcode_tc_mark_lines USING p_tc_name
                               p_table_name
                               p_mark_name.
*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------*
  DATA l_table_name       LIKE feld-name.


  FIELD-SYMBOLS <tc>         TYPE cxtab_control.
  FIELD-SYMBOLS <table>      TYPE STANDARD TABLE.
  FIELD-SYMBOLS <wa>.
  FIELD-SYMBOLS <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*


  ASSIGN (p_tc_name) TO <tc>.


*&SPWIZARD: get the table, which belongs to the tc                     *
  CONCATENATE p_table_name '[]' INTO l_table_name. "table body
  ASSIGN (l_table_name) TO <table>.                "not headerline


*&SPWIZARD: mark all filled lines                                      *
  LOOP AT <table> ASSIGNING <wa>.


*&SPWIZARD: access to the component 'FLAG' of the table header         *
    ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.


    <mark_field> = 'X'.
  ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines


*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
*       demarks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM fcode_tc_demark_lines USING p_tc_name
                                 p_table_name
                                 p_mark_name .
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
  DATA l_table_name       LIKE feld-name.


  FIELD-SYMBOLS <tc>         TYPE cxtab_control.
  FIELD-SYMBOLS <table>      TYPE STANDARD TABLE.
  FIELD-SYMBOLS <wa>.
  FIELD-SYMBOLS <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*


  ASSIGN (p_tc_name) TO <tc>.


*&SPWIZARD: get the table, which belongs to the tc                     *
  CONCATENATE p_table_name '[]' INTO l_table_name. "table body
  ASSIGN (l_table_name) TO <table>.                "not headerline


*&SPWIZARD: demark all filled lines                                    *
  LOOP AT <table> ASSIGNING <wa>.


*&SPWIZARD: access to the component 'FLAG' of the table header         *
    ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.


    <mark_field> = space.
  ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Pablo Casamayor Mar 15, 2017 at 04:54 PM
1

Hi,

Read Rich Heilman ' s answer in the following thread:

Initial values for time field

Best regards,

Pablo

Share
10 |10000 characters needed characters left characters exceeded
Sandra Rossi Mar 17, 2017 at 07:34 AM
1

If your internal table is empty, and you want nothing to appear, you may either set the INVISIBLE attribute of your table control (but even the column headings will be hidden), or display just one line by defining the LINES attribute to 1 (line counter) which has the drawback of having only one line with initial values. Changing all the types of screen fields to "characters" is not a good practice in my opinion.

Share
10 |10000 characters needed characters left characters exceeded
Martin Luedecke Mar 16, 2017 at 01:01 PM
0

Thanks! That was it. Added this code (plus changed DATA statement), and it worked:

      LOOP AT i_log_entries INTO wa_log_entries.
        WRITE wa_log_entries-run_time TO wa_log_entries-time.
        MODIFY i_log_entries FROM wa_log_entries.
      ENDLOOP.

Share
10 |10000 characters needed characters left characters exceeded