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

regarding the table control in module pool

Former Member
0 Likes
2,738

hi,

I have to populate the data from the internal table to the table control in the module pool when I clicks on one push button on the screen.

5 REPLIES 5
Read only

Former Member
0 Likes
1,159

hi there....

i hope u know about the PBO and PAI.

in order to accomplish what u want to do, first u need to know wat wil happen when u press the button on the screen. wen a button is presses, or any user action happens on the screen, the PAI is triggered. So in the PAI, first chk if the user action taken is button pressed or not. you can check this by checking the SY-UCOMM which should match the name of the user command. this can be done using if else loop. and in that loop, simply fetch the values using select-end select statements. i hope this should solve your query.

Do reward if helpful or ask for further assistance.

Read only

Former Member
0 Likes
1,159

Hi,

under PBO event call table control with loop.

you will write when 'display'.

ex: when 'display'.

retrieve records into internal table.

to place those records into table control using below code.

loop at itab with control tcontrol.

*pbo

endloop.

inside pbo module use move statement to move internal table to screen fields of table control.

And also you have have write loop and endloop under pai also.

outside of pai module to process record to work area.

it will solve you problem.

Edited by: jeevitha on May 6, 2008 10:39 AM

Read only

Former Member
0 Likes
1,159

Hi

go through this code.

tables: kna1,vbak,vbap.

controls tc1 type tableview using screen 200.

controls tc2 type tableview using screen 300.

&--


structure declaration for vbak--

types: begin of st_tab," OCCURS 0 with header line,

chk(2) type c,

vbeln type vbeln_va,

erdat type erdat,

erzet type erzet,

ernam type ernam,

kunnr type kunag,

end of st_tab.

&--


structure declaration for vbap--

types: begin of st_tab1," OCCURS 0 with header line,

vbeln type vbeln_va,

posnr type posnr_va,

charg type charg_d,

matkl type matkl,

posar type posar,

end of st_tab1.

&--


data declaration--

data: wa_tab type st_tab,

it_tab type standard table of st_tab,

wa_tab1 type st_tab1,

it_tab1 type standard table of st_tab1.

&----


*& Module USER_COMMAND_0100 INPUT

&----


module user_command_0100 input.

case sy-ucomm.

when 'DISPLAY'.

select *

from vbak

into corresponding fields of table it_tab

where kunnr = kna1-kunnr.

if sy-subrc eq 0.

leave to screen 200.

else.

message i015.

endif.

when 'BACK' or 'EXIT' or 'CANCEL'.

leave program.

clear sy-ucomm.

endcase.

endmodule. "USER_COMMAND_0100 INPUT

&----


*& Module VALIDATE_KUNNR INPUT

&----


module validate_kunnr input.

select single kunnr

from kna1 into wa_tab

where kunnr = kna1-kunnr.

endmodule. " VALIDATE_KUNNR INPUT

&----


*& Module STATUS_0100 OUTPUT

&----


module status_0100 output.

set pf-status 'S100'.

endmodule. "STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0200 INPUT

&----


module user_command_0200 input.

case sy-ucomm.

when 'ITEM-DETAILS'. "you select one record then you click on this push button then you will get item data of that header record.

read table it_tab into wa_tab with key chk = 'X'.

if sy-subrc = 0.

select vbeln

posnr

charg

matkl

posar

from vbap

into table it_tab1

where vbeln = wa_tab-vbeln.

if sy-subrc = 0.

vbak-vbeln = wa_tab-vbeln.

leave to screen 300.

else.

message i016.

endif.

message i017.

endif.

when 'BACK'.

leave to screen '100'.

when 'EXIT' or 'CANCEL'.

leave program.

endcase.

endmodule. " USER_COMMAND_0200 INPUT

&----


*& Module STATUS_0200 OUTPUT

&----


module status_0200 output.

set pf-status 'S200'.

endmodule. " STATUS_0200 OUTPUT

&----


*& Module MODIFY INPUT

&----


module modify input.

modify it_tab from wa_tab index tc1-current_line.

endmodule. " MODIFY INPUT

&----


*& Module populate_header OUTPUT

&----


module populate_header output.

vbak-vbeln = wa_tab-vbeln.

vbak-erdat = wa_tab-erdat.

vbak-erzet = wa_tab-erzet.

vbak-ernam = wa_tab-ernam.

vbak-kunnr = wa_tab-kunnr.

endmodule. " populate_header OUTPUT

&----


*& Module populate_items OUTPUT

&----


module populate_items output.

vbap-vbeln = wa_tab1-vbeln.

vbap-posnr = wa_tab1-posnr.

vbap-charg = wa_tab1-charg.

vbap-matkl = wa_tab1-matkl.

vbap-posar = wa_tab1-posar.

endmodule. " populate_items OUTPUT

&----


*& Module STATUS_0300 OUTPUT

&----


module status_0300 output.

set pf-status 'S300'.

endmodule. " STATUS_0300 OUTPUT

----


*& Module USER_COMMAND_0300 INPUT

----


module user_command_0300 input.

case sy-ucomm.

when 'BACK'.

leave to screen '200'.

when 'EXIT' or 'CANCEL' .

leave program.

endcase.

endmodule. " USER_COMMAND_0300 INPUT

in screen 100:

process before output.

module status_0100.

process after input.

field kna1-kunnr module validate_kunnr on input.

module user_command_0100.

in screen 200:

process before output.

module status_0200.

loop at it_tab into wa_tab with control tc1 cursor tc1-current_line.

module populate_header.

endloop.

process after input.

loop at it_tab.

module modify.

endloop.

module user_command_0200.

in screen 300:

process before output.

loop at it_tab1 into wa_tab1 with control tc2 cursor tc2-current_line.

module populate_items.

endloop.

module status_0300.

*

process after input.

module user_command_0300.

loop at it_tab1.

endloop.

Read only

Former Member
0 Likes
1,159

Hi,

In the flow logic u written for the screen in which u displayed the table control,give the code as follws

PROCESS BEFORE OUTPUT.

LOOP WITH CONTROL TCONTROL.

ENDLOOP.

MODULE STATUS_0200.

PROCESS AFTER INPUT.

LOOP WITH CONTROL TCONTROL.

MODULE USER_COMMAND_0200.

ENDLOOP.

TCONTROL is the name of the table control u have declared,

and also specify the table which the table control is using in the layout.ie., TCONTROL should be assigned with the internal table u have used,get it from dictionary/program and drop on the TCONTROL right corner.

In PAI write the relavent code, ie Move to the internal table.For example

MODULE USER_COMMAND_0200 INPUT.

CASE SY-UCOMM.

WHEN 'SAVE'.

MOVE T001 TO WA_T001.

APPEND WA_T001 TO IT_T001.

INSERT INTO T001 VALUES WA_T001.

ENDCASE.

I think this would help u,pls reply if it helps u.

Read only

Former Member
0 Likes
1,159

Hi,

Check the code below:

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 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

&----


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

Kannaiah