Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

table control

Former Member
0 Likes
568

Hi Friends,

I have a reuirement.

on my screen i have a table control which contains 3 coloums.

KUNNR NAME CATRGORY

1000 JOHN 1

1001 JOJO 1

1002 ANDY 2

1003 EDDY 2

1004 KUTS 3

1005 HUTS 3.

Now my requiremnt is i have 3 push buttons on my screen.

Pushbuttons

CATG1 CATG2 CATG3

Now when i clcik on the CATG1 push button i need to add a line to manually add one more line of category 1

ie i need a blank line after

1001 JOJO 1

this record in my table control..

ie : i need to manualy add a line in my tbale control.

similary when i click on CATG2 pushbutton i need to add a line in my table contorl to add a category 2 type record.

simliarly for CATG3 push button also.

How can i do that.

Regards

Priyanka.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
538

Hi

U need to append an initial line after the last line of a certain category:

CASE OK_CODE(4).
   WHEN 'CATG'.
      LOOP AT ITAB WHERE CATRGORY = OK_CODE+4(1).
        NEW_RECORD = SY-TABIX.
      ENDLOOP.
      IF SY-SUBRC <> 0.
        NEW_RECORD = 0.
      ENDIF.
      NEW_RECORD = NEW_RECORD + 1.
      INSERT INITIAL LINE INTO ITAB INDEX NEW_RECORD.
   WHEN ...
ENDCASE.

Max

6 REPLIES 6
Read only

Former Member
0 Likes
539

Hi

U need to append an initial line after the last line of a certain category:

CASE OK_CODE(4).
   WHEN 'CATG'.
      LOOP AT ITAB WHERE CATRGORY = OK_CODE+4(1).
        NEW_RECORD = SY-TABIX.
      ENDLOOP.
      IF SY-SUBRC <> 0.
        NEW_RECORD = 0.
      ENDIF.
      NEW_RECORD = NEW_RECORD + 1.
      INSERT INITIAL LINE INTO ITAB INDEX NEW_RECORD.
   WHEN ...
ENDCASE.

Max

Read only

0 Likes
538

Hi Max,

Iam able to insert a line with your code.

but the problem is the table control is in display mode.

iam getting a blank line inbetween but as iam adding a manual entry in that line, i need that line in the changed mode.

how can i do that.

Thanks in advance,

Regards

Priyanka.

Read only

0 Likes
538

Hi

U need to change the screen attribute in PBO:

PROCESS PBO.
   LOOP AT ITAB WITH.......
       MODULE LOOP_SCREEN.
   ENDLOOP.

MODULE LOOP_SCREEN.
   IF ITAB IS INITIAL.
     LOOP AT SCREEN.
        SCREEN-INPUT = 0.
        MODIFY SCREEN.
     ENDLOOP.
   ENDIF.
ENDMODULE.

Max

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
538

Hi,

Follow code:-

it_kna1 is my internal table w/o header line,

wa_ln1 is work area.

Name of input/output fields on screen are:-

wa_kna1-kunnr,

wa_kna1-name1, and

wa_kna1-categ

You must take the field category in table control as ouput only, so that user cant edit when you add a new row for a category.

At screen logic:-


PROCESS BEFORE OUTPUT.
  MODULE status_8003.
 
  LOOP WITH CONTROL tab_ctrl.
    MODULE read_data.
  ENDLOOP.
 
PROCESS AFTER INPUT.
  MODULE user_command_8003.
 
  LOOP WITH CONTROL tab_ctrl.
    MODULE modify_data.
  ENDLOOP.

In the TOP module take a field:-


data : flag(1) type c value ' '.

In PBO:-


*&---------------------------------------------------------------------*
*&      Module  STATUS_8003  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_8003 OUTPUT.
  if flag = ' '.
  "select query from database table into internal table it_kna1
    flag = 'X'.
  endif.
  " so that the query is fired only when user executes the application
  "first time, else it will not read from db table
  
  data : line_count type i.
  describe table it_kna1
  lines line_count.

  tab_ctrl-lines = line_count.
  " fix the size of table control to line found in it_kna1
  
  sort it_kna1 by categ ascending.
  " to display records accodring to field category
ENDMODULE.                 " STATUS_8003  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  READ_DATA  OUTPUT
*&---------------------------------------------------------------------*
MODULE read_data OUTPUT.
  READ TABLE it_kna1 INTO wa_kna1 INDEX tab_ctrl-current_line. "tab_ctrl is table control name
ENDMODULE.                 " READ_DATA  OUTPUT

In PAI:-


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_8003  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_8003 INPUT.
  case sy-ucomm.
    when 'CATG1'.
      wa_kna1-categ = '1'.
      append wa_kna1 to it_kna1.
    when 'CATG2'.
      wa_kna1-categ = '2'.
      append wa_kna1 to it_kna1.
    when 'CATG3'.
      wa_kna1-categ = '1'.
      append wa_kna1 to it_kna1.
  endcase.

" this will append a new line for the corresponding category
" with rest details as blnak that can be filled by user
ENDMODULE.                 " USER_COMMAND_8003  INPUT

*&---------------------------------------------------------------------*
*&      Module  MODIFY_DATA  INPUT
*&---------------------------------------------------------------------*
MODULE MODIFY_DATA INPUT.
  MODIFY IT_KNA1 INDEX TAB_CTRL-CURRENT_LINE FROM WA_KNA1.
  "modify records from table control into the internal table
  "when user performs any action
ENDMODULE.                 " MODIFY_DATA  INPUT

When user click any button for category, a new record for the associated category will be appended to internal table and PBO will be fired.

This time query will not be fired. But internal table will be sorted on field category and records will be displayed in the table control.

Now you have the a line inserted for the category, you can edit the fields kunnr and name1.

Now when user performs any action, at PAI, all these changes will be reflected to the internal table, and PBO will read the modified internal table.

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

Former Member
0 Likes
538

Hi,

Try using ,

AT NEW KUNNR.
   INSERT INITIAL LINE INTO itab.

Hope this helps.

Regards,

Deepthi.

Read only

Former Member
0 Likes
538

Hi

Flow Logic:

PROCESS BEFORE OUTPUT.
 MODULE STATUS_1100.
 module getdata.
 loop at itab with control tab1.
   module populate.
 endloop.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_1100.
 loop at itab.
   module store_details.
 endloop.
code}

Code:

&----


*& Report YTABCAT *

*& *

&----


*& *

*& *

&----


REPORT YTABCAT .

tables: ycategory.

data: ok_code type ok_code,

itab type table of ycategory with header line,

itab2 type table of ycategory with header line,

v_line type i,

v_flag type i,

v_limit type i.

controls: tab1 type tableview using screen 1100.

call screen 1100.

&----


*& Module STATUS_1100 OUTPUT

&----


  • text

----


MODULE STATUS_1100 OUTPUT.

SET PF-STATUS 'BACK'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_1100 OUTPUT

&----


*& Module USER_COMMAND_1100 INPUT

&----


  • text

----


MODULE USER_COMMAND_1100 INPUT.

case ok_code.

when 'BACK'.

Leave Program.

when 'CAT1'.

"insert a line in tbl ctrl at end of category = 1

loop at itab where category = 1.

v_line = sy-tabix + 1.

endloop.

v_flag = 1.

  • insert initial line into itab index v_line.

when 'CAT2'.

"insert a line in tbl ctrl at end of category = 2

loop at itab where category = 2.

v_line = sy-tabix + 1.

endloop.

v_flag = 1.

endcase.

ENDMODULE. " USER_COMMAND_1100 INPUT

&----


*& Module getdata OUTPUT

&----


  • text

----


MODULE getdata OUTPUT.

if itab is initial or v_limit = 1.

select * from ycategory into table itab.

sort itab by category.

v_limit = 0.

elseif v_flag = 1.

v_limit = 1.

loop at itab.

if itab is initial.

delete itab.

endif.

endloop.

sort itab[].

delete adjacent duplicates from itab[].

sort itab by category.

insert initial line into itab index v_line.

v_flag = 0.

v_line = 0.

else.

select * from ycategory into table itab.

sort itab by category.

endif.

ENDMODULE. " getdata OUTPUT

&----


*& Module populate OUTPUT

&----


  • text

----


MODULE populate OUTPUT.

move itab to ycategory.

ENDMODULE. " populate OUTPUT

&----


*& Module store_details INPUT

&----


  • text

----


MODULE store_details INPUT.

itab-kunnr = ycategory-kunnr.

itab-name = ycategory-name.

itab-category = ycategory-category.

insert ycategory from itab.

append itab.

ENDMODULE. " store_details INPUT

It allowed to edit the line.

Hope this helps

Regards,

Jayanthi.K