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

module pool -- table control.

Former Member
0 Likes
718

how to update the table control entries along with some fields outside the table control into a ztable.

and also how to change and delete the entries from the ztable.

please help me out..

will be rewarded

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
664

Hi,

Here is the complete program for updating the data from Table Control and other fields of ur screen into a table.

MATERIAL is the name of the table control contians MATNR and ERNAM.

MODIFY is the Function code of the Update Button.

a is the text box created in SE41 for this program.

since a is created as predefined type in SE41, they must be declared in this pgm also.

If it refers the data dictionary in SE41, we need not declare that variables in this pgm.

&----


*& Report Y_DB_TABLECONTROL

*&

&----


*&

*&

&----


REPORT Y_DB_TABLECONTROL.

TABLES: MARA.

CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.

TYPES: BEGIN OF ST_MARA,

MATNR TYPE MARA-MATNR,

ERNAM TYPE MARA-ERNAM,

pstat type mara-pstat,

END OF ST_MARA.

DATA: IT_ST TYPE TABLE OF ST_MARA,

WA_ST TYPE ST_MARA,

IT_MARA TYPE MARA,

WA_MARA TYPE MARA,

MATNR TYPE MARA-MATNR,

ERNAM TYPE MARA-ERNAM,

pstat type mara-pstat,

a(15) type c.

CALL SCREEN 130.

MODULE V1 INPUT.

CASE sy-ucomm.

WHEN 'SAVE'.

WA_ST-MATNR = MATNR.

WA_ST-ERNAM = ERNAM.

wa_st-pstat = a.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

INSERT INTO MARA VALUES WA_MARA.

if sy-subrc = 0.

MESSAGE s001(ZKAAR).

endif.

WHEN 'DELETE'.

WA_ST-MATNR = MATNR.

WA_ST-ERNAM = ERNAM.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

DELETE MARA FROM WA_MARA.

WHEN 'MODIFY'.

WA_ST-MATNR = MATNR.

WA_ST-ERNAM = ERNAM.

wa_st-pstat = a.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

MODIFY MARA FROM WA_MARA.

ENDCASE.

ENDMODULE. " V1 INPUT

MODULE EXIT INPUT.

IF sy-ucomm = 'EXIT' or sy-ucomm = 'BACK'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE. " EXIT INPUT

&----


*& Module status OUTPUT

&----


  • text

----


module status output.

set pf-status 'STAT'.

endmodule. " status OUTPUT

FLOW logic: (Need to be written for Table control)

PROCESS BEFORE OUTPUT.

module status.

LOOP WITH CONTROL MATERIAL.

ENDLOOP.

PROCESS AFTER INPUT.

MODULE exit.

LOOP WITH CONTROL MATERIAL.

MODULE V1.

ENDLOOP.

Hope it helps u..

Kindly reward points if helpful

Regards,

Shanthi.

Edited by: Shanthi on Mar 3, 2008 8:22 AM

Edited by: Shanthi on Mar 3, 2008 8:24 AM

5 REPLIES 5
Read only

Former Member
0 Likes
664

u can use

move-corresponding wa_table to ztable.

update ztable set

test = 'X'

where belnr = wa_table-belnr..

Read only

Former Member
0 Likes
664

hi,

write this in the module of the PAI.

case sy-ucomm.

when 'MODIFY'.

flg1 = 1.

when 'SAVE'.

flag1 = 'X'.

when 'DELETE'.

delete1 = '1'.

endcase.

then check for the flags, and write the code which u want.

for delete.

check this condition,

if table1-current_line = line1.

and do the rest.

for changes,

i.e modify,

example:

loop at screen.

if flg1 is initial.

screen-input = 0.

modify screen.

endloop.

Hope this helps u,

Regards,

Arunsri

Read only

Former Member
0 Likes
664

Hi,

This is the sample code..

might be useful.

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 Declaration

***********************************************************************

TABLES: zzz_makt.

***********************************************************************

  • Internal table Declaration

***********************************************************************

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

&----


  • Populating data

----


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

&----


  • Triggering event according to the user command

----


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 Successfull

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

&----


  • Setting the screen fields

----


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

&----


  • Appending records to the internal table

----


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

&----


  • Setting the GUI status

----


MODULE set_status OUTPUT.

SET PF-STATUS 'ZSTATUS'.

SET TITLEBAR 'ZTITLE'.

ENDMODULE. " set_status OUTPUT

*&----


*& Module CHECK INPUT

*&----


  • Modify the internal table using the current line in table control

*----


MODULE check INPUT.

MODIFY i_makt INDEX t_ctrl-current_line.

ENDMODULE. " CHECK INPUT

Regards,

Priya.

Read only

Former Member
0 Likes
665

Hi,

Here is the complete program for updating the data from Table Control and other fields of ur screen into a table.

MATERIAL is the name of the table control contians MATNR and ERNAM.

MODIFY is the Function code of the Update Button.

a is the text box created in SE41 for this program.

since a is created as predefined type in SE41, they must be declared in this pgm also.

If it refers the data dictionary in SE41, we need not declare that variables in this pgm.

&----


*& Report Y_DB_TABLECONTROL

*&

&----


*&

*&

&----


REPORT Y_DB_TABLECONTROL.

TABLES: MARA.

CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.

TYPES: BEGIN OF ST_MARA,

MATNR TYPE MARA-MATNR,

ERNAM TYPE MARA-ERNAM,

pstat type mara-pstat,

END OF ST_MARA.

DATA: IT_ST TYPE TABLE OF ST_MARA,

WA_ST TYPE ST_MARA,

IT_MARA TYPE MARA,

WA_MARA TYPE MARA,

MATNR TYPE MARA-MATNR,

ERNAM TYPE MARA-ERNAM,

pstat type mara-pstat,

a(15) type c.

CALL SCREEN 130.

MODULE V1 INPUT.

CASE sy-ucomm.

WHEN 'SAVE'.

WA_ST-MATNR = MATNR.

WA_ST-ERNAM = ERNAM.

wa_st-pstat = a.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

INSERT INTO MARA VALUES WA_MARA.

if sy-subrc = 0.

MESSAGE s001(ZKAAR).

endif.

WHEN 'DELETE'.

WA_ST-MATNR = MATNR.

WA_ST-ERNAM = ERNAM.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

DELETE MARA FROM WA_MARA.

WHEN 'MODIFY'.

WA_ST-MATNR = MATNR.

WA_ST-ERNAM = ERNAM.

wa_st-pstat = a.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

MODIFY MARA FROM WA_MARA.

ENDCASE.

ENDMODULE. " V1 INPUT

MODULE EXIT INPUT.

IF sy-ucomm = 'EXIT' or sy-ucomm = 'BACK'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE. " EXIT INPUT

&----


*& Module status OUTPUT

&----


  • text

----


module status output.

set pf-status 'STAT'.

endmodule. " status OUTPUT

FLOW logic: (Need to be written for Table control)

PROCESS BEFORE OUTPUT.

module status.

LOOP WITH CONTROL MATERIAL.

ENDLOOP.

PROCESS AFTER INPUT.

MODULE exit.

LOOP WITH CONTROL MATERIAL.

MODULE V1.

ENDLOOP.

Hope it helps u..

Kindly reward points if helpful

Regards,

Shanthi.

Edited by: Shanthi on Mar 3, 2008 8:22 AM

Edited by: Shanthi on Mar 3, 2008 8:24 AM

Read only

0 Likes
664

hello shanthi,

y u declared 2 tables.. and also how r u passing fields outside the table control ???