Application Development 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: 

Table control and ALV grid

Former Member
0 Kudos
1,656

Dear experts,

I want to make display the internal table datas to

Table control or ALVgrid for display.

Later i want to edit the datas in ALV or Tablecontrol and save the datas to sales table.

i want to know which control is most suitable for this requirement.

I fear few of ALV control methods are not released and its better to go for tablecontrol.

what do you think of from your side.

Pls suggest me.

Ambichan.

1 ACCEPTED SOLUTION

jayanthi_jayaraman
Active Contributor
0 Kudos
283

Hi,

If want to use table control,check this code sample.

In the flow logic of the screen 9000, write the following code.

PROCESS BEFORE OUTPUT.

MODULE set_status.

MODULE get_t_ctrl_lines.

LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.

  • Dynamic screen modifications

MODULE set_screen_fields.

ENDLOOP.

*

PROCESS AFTER INPUT.

LOOP AT i_makt.

FIELD i_makt-pick MODULE check.

FIELD i_makt-zmatnr MODULE zmatnr .

ENDLOOP.

MODULE user_command_9000.

In the program, write the following code.

PROGRAM SAPMZTC MESSAGE-ID zz.

TABLES: zzz_makt.

DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.

  • Table control Declaration

CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.

  • Variable Declaration

DATA : flg, "Flag to set the change mode

ln TYPE i. "No. of records

MODULE get_t_ctrl_lines OUTPUT.

SELECT zmatnr zmaktx

INTO CORRESPONDING FIELDS OF TABLE i_makt

FROM zzz_makt.

DESCRIBE TABLE i_makt LINES ln.

  • To make the vertical scroll bar to come on runtime

t_ctrl-lines = ln + 100.

ENDMODULE. " get_T_CTRL_lines OUTPUT

MODULE user_command_9000 INPUT.

DATA :lv_fcode LIKE sy-ucomm, "Function Code

lv_answer(1) type c. "Storing the answer

lv_fcode = sy-ucomm.

CASE lv_fcode.

WHEN 'CHANGE'.

  • Setting the flag to make the table control in editable mode[excluding

  • primary key].

flg = 'Y'.

WHEN 'DELETE'.

  • Setting the flag to make the table control in editable mode after

  • deleting the selected line

flg = 'Y'.

  • Confirmation of delete

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

TITLEBAR = 'Confirm'

text_question = 'Are you sure to delete from database?'

TEXT_BUTTON_1 = 'Yes'(001)

TEXT_BUTTON_2 = 'No'(002)

IMPORTING

ANSWER = lv_answer.

if lv_answer eq '1'.

  • Updating the database table from the internal table

UPDATE zzz_makt FROM TABLE i_makt.

  • Deleting the selected row from the internal table

DELETE i_makt WHERE pick = 'X'.

  • Deleting the selected row from the database table

DELETE FROM zzz_makt WHERE pick = 'X'.

MESSAGE s005 WITH 'Deleted Successfully'.

ENDIF.

WHEN 'SAVE'.

  • Inserting new record or updating existing record in database table

  • from the internal table

MODIFY zzz_makt FROM TABLE i_makt.

MESSAGE s005 WITH 'Saved Successfully'.

WHEN 'BACK'.

SET SCREEN '0'.

WHEN 'EXIT' OR 'CANCEL'.

  • Leaving the program

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_9000 INPUT

MODULE set_screen_fields OUTPUT.

LOOP AT SCREEN.

IF flg IS INITIAL.

screen-input = 0.

ELSEIF ( flg EQ 'Y' ).

IF ( ( screen-name = 'I_MAKT-ZMAKTX'

OR screen-name = 'I_MAKT-CHECK1' )

AND t_ctrl-current_line LE ln ) .

  • Making the screen fields as editable

screen-input = 1.

ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )

AND t_ctrl-current_line LE ln ).

  • Making the screen field as uneditable

screen-input = 0.

ENDIF.

ENDIF.

  • Modifying the screen after making changes

MODIFY SCREEN.

ENDLOOP.

ENDMODULE. " set_screen_fields OUTPUT

MODULE zmatnr INPUT.

MODIFY i_makt INDEX t_ctrl-current_line.

IF t_ctrl-current_line GT ln.

READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.

IF sy-subrc NE 0.

  • Inserting record if it does not exist in database

APPEND i_makt.

ELSE.

MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.

ENDIF.

ENDIF.

ENDMODULE. " zmatnr INPUT

MODULE set_status OUTPUT.

SET PF-STATUS 'ZSTATUS'.

SET TITLEBAR 'ZTITLE'.

ENDMODULE. " set_status OUTPUT

MODULE check INPUT.

MODIFY i_makt INDEX t_ctrl-current_line.

ENDMODULE. " CHECK INPUT

If you want to use editable alv,check this standard program.

BCALV_TEST_GRID_EDITABLE

Kindly reward points if it helps.

Message was edited by: Jayanthi Jayaraman

5 REPLIES 5

Former Member
0 Kudos
283

Hi,

U can use editable ALV grid.

U can capture the changes that u make easily.

If u handle those events properly it wont be a problem.

u can search this forum for results.

Former Member
0 Kudos
283

Hi,

You can very well go ahead with ALV.

While modifying the field catalogue:

  LOOP AT p_fieldcat ASSIGNING <lfs_fieldcat>.

    CASE <lfs_fieldcat>-fieldname.
      WHEN 'DATE'.
        <lfs_fieldcat>-coltext = 'DATE.
       <b> <lfs_fieldcat>-edit    = c_x.</b>
    ENDCASE.

  ENDLOOP.

Also,

  CALL METHOD o_alvgrid->register_edit_event
                    EXPORTING
                       i_event_id = cl_gui_alv_grid=>mc_evt_modified.

But, Ambi Chan,

<b>In release 4.6B there is no field EDIT in structure LVC_S_FCAT.</b>

Hence, if u r on 4.6B, its recommended to use Table control.

Regards,

Anjali

Former Member
0 Kudos
283

i suggest you go for table control, there u can use wizard also,

tables are easy to use, but alv has some other features inbuilt like sorting number of column.

so u decide.

regards

Former Member
0 Kudos
283

Both of these two can meet your requirement. Sure.

About which is more suitable to you, simplely to say, if you need a nice graphic and possible to extend many function very flexibly in the furture, you'd better choose ALV. ALV offer you many exist functionality, you can easily active them if you need. But Tab Control can't ,you must do most of them manually.

But flexiblity will pay its cost, the way to control the ALV is more complex than Tab Control. E.G. You should pay attention to unactive many default active functionality. If your requirement is very simple, Tab Control is also a good choose. You don't need too much functionality, so let the ALV away, you can achieve them easily.

That's my opinion, thanks

Message was edited by: zhenglin gu

jayanthi_jayaraman
Active Contributor
0 Kudos
284

Hi,

If want to use table control,check this code sample.

In the flow logic of the screen 9000, write the following code.

PROCESS BEFORE OUTPUT.

MODULE set_status.

MODULE get_t_ctrl_lines.

LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.

  • Dynamic screen modifications

MODULE set_screen_fields.

ENDLOOP.

*

PROCESS AFTER INPUT.

LOOP AT i_makt.

FIELD i_makt-pick MODULE check.

FIELD i_makt-zmatnr MODULE zmatnr .

ENDLOOP.

MODULE user_command_9000.

In the program, write the following code.

PROGRAM SAPMZTC MESSAGE-ID zz.

TABLES: zzz_makt.

DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.

  • Table control Declaration

CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.

  • Variable Declaration

DATA : flg, "Flag to set the change mode

ln TYPE i. "No. of records

MODULE get_t_ctrl_lines OUTPUT.

SELECT zmatnr zmaktx

INTO CORRESPONDING FIELDS OF TABLE i_makt

FROM zzz_makt.

DESCRIBE TABLE i_makt LINES ln.

  • To make the vertical scroll bar to come on runtime

t_ctrl-lines = ln + 100.

ENDMODULE. " get_T_CTRL_lines OUTPUT

MODULE user_command_9000 INPUT.

DATA :lv_fcode LIKE sy-ucomm, "Function Code

lv_answer(1) type c. "Storing the answer

lv_fcode = sy-ucomm.

CASE lv_fcode.

WHEN 'CHANGE'.

  • Setting the flag to make the table control in editable mode[excluding

  • primary key].

flg = 'Y'.

WHEN 'DELETE'.

  • Setting the flag to make the table control in editable mode after

  • deleting the selected line

flg = 'Y'.

  • Confirmation of delete

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

TITLEBAR = 'Confirm'

text_question = 'Are you sure to delete from database?'

TEXT_BUTTON_1 = 'Yes'(001)

TEXT_BUTTON_2 = 'No'(002)

IMPORTING

ANSWER = lv_answer.

if lv_answer eq '1'.

  • Updating the database table from the internal table

UPDATE zzz_makt FROM TABLE i_makt.

  • Deleting the selected row from the internal table

DELETE i_makt WHERE pick = 'X'.

  • Deleting the selected row from the database table

DELETE FROM zzz_makt WHERE pick = 'X'.

MESSAGE s005 WITH 'Deleted Successfully'.

ENDIF.

WHEN 'SAVE'.

  • Inserting new record or updating existing record in database table

  • from the internal table

MODIFY zzz_makt FROM TABLE i_makt.

MESSAGE s005 WITH 'Saved Successfully'.

WHEN 'BACK'.

SET SCREEN '0'.

WHEN 'EXIT' OR 'CANCEL'.

  • Leaving the program

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_9000 INPUT

MODULE set_screen_fields OUTPUT.

LOOP AT SCREEN.

IF flg IS INITIAL.

screen-input = 0.

ELSEIF ( flg EQ 'Y' ).

IF ( ( screen-name = 'I_MAKT-ZMAKTX'

OR screen-name = 'I_MAKT-CHECK1' )

AND t_ctrl-current_line LE ln ) .

  • Making the screen fields as editable

screen-input = 1.

ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )

AND t_ctrl-current_line LE ln ).

  • Making the screen field as uneditable

screen-input = 0.

ENDIF.

ENDIF.

  • Modifying the screen after making changes

MODIFY SCREEN.

ENDLOOP.

ENDMODULE. " set_screen_fields OUTPUT

MODULE zmatnr INPUT.

MODIFY i_makt INDEX t_ctrl-current_line.

IF t_ctrl-current_line GT ln.

READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.

IF sy-subrc NE 0.

  • Inserting record if it does not exist in database

APPEND i_makt.

ELSE.

MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.

ENDIF.

ENDIF.

ENDMODULE. " zmatnr INPUT

MODULE set_status OUTPUT.

SET PF-STATUS 'ZSTATUS'.

SET TITLEBAR 'ZTITLE'.

ENDMODULE. " set_status OUTPUT

MODULE check INPUT.

MODIFY i_makt INDEX t_ctrl-current_line.

ENDMODULE. " CHECK INPUT

If you want to use editable alv,check this standard program.

BCALV_TEST_GRID_EDITABLE

Kindly reward points if it helps.

Message was edited by: Jayanthi Jayaraman