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: 

how to update field values in a database table using module pool prg?

Former Member
0 Kudos

hi

how to update field values in a database table using module pool prg?

we created a customized table, and we put 2 push buttons in screen painter update and display.

but update is not working?

data is enter into screen fields and to internal table, but it is not updated in database table.

thanks in adv

vidya

11 REPLIES 11

Former Member
0 Kudos

Hi

Go to following link

http://sapmaterial.com/files/database_update.pdf

Reward points if helpful

Regards

Srikanta Gope

Former Member
0 Kudos

Hi,

look at this code

when u click on save button write this code

here i am modifying some of fields of ekpo.

LOOP AT itab.

UPDATE ekpo SET matnr = itab-matnr

werks = itab-werks

menge = itab-menge

meins = itab-meins

netwr = itab-netwr

WHERE ebeln = itab-ebeln AND

ebelp = itab-ebelp.

ENDLOOP.

regards

suman

Former Member
0 Kudos

in PAI event, wite update table <tablename>.

regards,

srinivas

<b>*reward for useful answers*</b>

Former Member
0 Kudos

Update or modify statement should solve your purpose. Need to check your code to rectify why it is not working. So sill if u getting the problem, you can pest your code.

0 Kudos

HI,

we already used the update statement. but its not working.

plz check this.

&----


*& Module Pool ZCUST_CALL_REC

*&

&----


*&

*&

&----


PROGRAM ZCUST_CALL_REC.

TABLES: ZCUST_CALL_REC,ZREMARKS.

data: v_kun_low like ZCUST_CALL_REC-kunnr ,

v_kun_high like ZCUST_CALL_REC-kunnr,

v_bud_low like ZCUST_CALL_REC-budat,

v_bud_high like ZCUST_CALL_REC-budat.

ranges r_kunnr for ZCUST_CALL_REC-kunnr .

ranges r_budat for zcust_call_rec-budat.

DATA: ITAB TYPE STANDARD TABLE OF ZCUST_CALL_REC WITH HEADER LINE,

JTAB TYPE STANDARD TABLE OF ZREMARKS WITH HEADER LINE.

*data:begin of itab occurs 0,

  • MANDT LIKE ZCUST_CALL_REC-MANDT,

  • kunnr like ZCUST_CALL_REC-kunnr,

  • budat like ZCUST_CALL_REC-budat,

  • code like ZCUST_CALL_REC-code,

  • remarks like ZCUST_CALL_REC-remarks,

  • end of itab.

*data:begin of Jtab occurs 0,

  • MANDT LIKE ZCUST_CALL_REC-MANDT,

  • kunnr like ZCUST_CALL_REC-kunnr,

  • budat like ZCUST_CALL_REC-budat,

  • code like ZCUST_CALL_REC-code,

  • remarks like ZCUST_CALL_REC-remarks,

  • end of Jtab.

*

CONTROLS:vcontrol TYPE TABLEVIEW USING SCREEN '9001'.

CONTROLS:vcontrol1 TYPE TABLEVIEW USING SCREEN '9002'.

*start-of-selection.

&----


*& Module USER_COMMAND_9000 INPUT

&----


  • text

----


MODULE USER_COMMAND_9000 INPUT.

CASE sy-ucomm.

WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.

SET SCREEN 0.

LEAVE SCREEN.

CLEAR sy-ucomm.

WHEN 'ENQUIRY'.

  • perform multiple_selection.

perform append_CUSTOMER_code.

PERFORM SELECT_DATA.

call screen '9001'.

WHEN 'UPDATE'.

perform append_CUSTOMER_code.

PERFORM SELECT_DATA.

call screen '9002'.

perform update on commit.

WHEN 'DELETE'.

perform append_CUSTOMER_code.

PERFORM SELECT_DATA.

call screen '9002'.

ENDCASE.

ENDMODULE. " USER_COMMAND_9000 INPUT

&----


*& Module STATUS_9000 OUTPUT

&----


  • text

----


MODULE STATUS_9000 OUTPUT.

SET PF-STATUS 'ZCUSTOMER'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_9000 OUTPUT

&----


*& Module USER_COMMAND_9001 INPUT

&----


  • text

----


MODULE USER_COMMAND_9001 INPUT.

CASE sy-ucomm.

WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.

SET SCREEN 0.

LEAVE SCREEN.

CLEAR sy-ucomm.

endcase.

ENDMODULE. " USER_COMMAND_9001 INPUT

&----


*& Module STATUS_9001 OUTPUT

&----


  • text

----


MODULE STATUS_9001 OUTPUT.

SET PF-STATUS 'ZCUSTOMER'.

  • SET TITLEBAR 'xxx'.

move itab-MANDT to zcust_call_rec-MANDT.

move itab-kunnr to zcust_call_rec-kunnr.

move itab-budat to zcust_call_rec-budat.

move itab-code to zcust_call_rec-code.

move itab-remarks to zcust_call_rec-remarks.

vcontrol-lines = sy-dbcnt.

ENDMODULE. " STATUS_9001 OUTPUT

&----


*& Module USER_COMMAND_9002 INPUT

&----


  • text

----


module USER_COMMAND_9002 input.

CASE sy-ucomm.

WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.

SET SCREEN 0.

LEAVE SCREEN.

CLEAR sy-ucomm.

WHEN 'UPDATE'.

perform move_data.

UPDATE ZCUST_CALL_REC FROM TABLE ITAB.

IF SY-SUBRC = 0.

MESSAGE I000(0) WITH 'RECORDS ARE UPDATED'.

ELSE.

MESSAGE E001(0) WITH 'RECORDS ARE NOT UPDATED'.

ENDIF.

WHEN 'DELETE'.

perform move_data.

DELETE ZCUST_CALL_REC FROM TABLE ITAB.

IF SY-SUBRC = 0.

MESSAGE I000(0) WITH 'RECORDS ARE DELETED'.

ELSE.

MESSAGE E001(0) WITH 'RECORDS ARE NOT DELETED'.

ENDIF.

endcase.

endmodule. " USER_COMMAND_9002 INPUT

&----


*& Module STATUS_9002 OUTPUT

&----


  • text

----


module STATUS_9002 output.

SET PF-STATUS 'ZCUSTOMER1'.

  • SET TITLEBAR 'xxx'.

endmodule. " STATUS_9002 OUTPUT

&----


*& Module update_table OUTPUT

&----


  • text

----


module update_table output.

move itab-MANDT to zcust_call_rec-MANDT.

move itab-kunnr to zcust_call_rec-kunnr.

move itab-budat to zcust_call_rec-budat.

move itab-code to zcust_call_rec-code.

move itab-remarks to zcust_call_rec-remarks.

vcontrol-lines = sy-dbcnt.

endmodule. " update_table OUTPUT

*&----


&

***Selection Data

*&----


&

FORM SELECT_DATA.

SELECT mandt kunnr budat code remarks FROM zcust_call_rec INTO

table itab

WHERE kunnr IN r_kunnr AND BUDAT IN R_BUDAT.

ENDFORM.

**&----


&

****append vendor code

**&----


&

FORM APPEND_CUSTOMER_CODE.

clear r_kunnr.

clear itab.

clear r_budat.

refresh r_kunnr.

refresh itab.

refresh r_kunnr.

IF r_kunnr IS INITIAL

AND NOT v_kun_low IS INITIAL

AND NOT v_kun_high IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_kun_low

IMPORTING

OUTPUT = r_kunnr-low.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_kun_high

IMPORTING

OUTPUT = r_kunnr-high.

r_kunnr-option = 'BT'.

r_kunnr-sign = 'I'.

append r_kunnr.

PERFORM V_BUDAT.

ELSEIF r_kunnr IS INITIAL

AND NOT v_kun_low IS INITIAL

AND v_kun_high IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_kun_low

IMPORTING

OUTPUT = r_kunnr-low.

r_kunnr-SIGN = 'I'.

r_kunnr-OPTION = 'EQ'.

APPEND r_kunnr.

PERFORM V_BUDAT.

ELSEIF r_kunnr IS INITIAL

AND v_kun_low IS INITIAL

AND NOT v_kun_high IS INITIAL.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_kun_low

IMPORTING

OUTPUT = r_kunnr-low.

r_kunnr-SIGN = 'I'.

r_kunnr-OPTION = 'EQ'.

APPEND r_kunnr.

PERFORM V_BUDAT.

ELSEIF r_kunnr IS INITIAL

AND v_kun_low IS INITIAL

AND v_kun_high IS INITIAL.

IF SY-SUBRC = 0.

MESSAGE I003(0) WITH 'ENTER CUSTOMER NUMBER'.

CALL SCREEN '9000'.

ENDIF.

PERFORM V_BUDAT.

ENDIF.

ENDFORM.

FORM V_BUDAT.

IF R_BUDAT IS INITIAL

AND NOT v_BUD_low IS INITIAL

AND NOT v_BUD_high IS INITIAL.

r_budat-low = v_bud_low.

r_budat-high = v_bud_high.

r_budat-option = 'BT'.

r_budat-sign = 'I'.

append r_budat.

ELSEIF R_BUDAT IS INITIAL

AND NOT v_BUD_low IS INITIAL

AND v_BUD_high IS INITIAL.

r_budat-low = v_bud_low.

r_budat-high = v_bud_high.

r_budat-option = 'EQ'.

r_budat-sign = 'I'.

append r_budat.

ELSEIF R_BUDAT IS INITIAL

AND v_BUD_low IS INITIAL

AND NOT v_BUD_high IS INITIAL.

r_budat-HIGH = v_bud_HIGH.

r_budat-option = 'EQ'.

r_budat-sign = 'I'.

append r_budat.

ELSEIF R_BUDAT IS INITIAL

AND v_BUD_low IS INITIAL

AND v_BUD_high IS INITIAL.

IF SY-SUBRC = 0.

MESSAGE I002(0) WITH 'ENTER POSTING DATE'.

CALL SCREEN '9000'.

  • r_budat-low = ''.

  • r_budat-option = ''.

  • r_budat-sign = ''.

ENDIF.

ENDIF.

ENDFORM.

&----


*& Form update

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form update .

commit work.

endform. " update

&----


*& Form move_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form move_data .

clear itab.

  • refresh itab.

  • move-corresponding zcust_call_rec to itab.

MOVE ZCUST_CALL_REC-MANDT TO ITAB-MANDT.

MOVE ZCUST_CALL_REC-KUNNR TO ITAB-KUNNR.

MOVE ZCUST_CALL_REC-BUDAT TO ITAB-BUDAT.

MOVE ZCUST_CALL_REC-CODE TO ITAB-CODE.

MOVE ZCUST_CALL_REC-REMARKS TO ITAB-REMARKS.

APPEND ITAB.

delete itab where kunnr is initial.

endform. " move_data

thanks in adv

vidya

Former Member
0 Kudos

we solved the problem

Former Member
0 Kudos

we solved the problem

Former Member
0 Kudos

DATA: LT_BACKLOG_IND TYPE STANDARD TABLE OF ZABACKLOG.

SELECT ZALOS_VALUE INTO TABLE LT_BACKLOG_IND

FROM ZABACKLOG

WHERE ZALOS_VALUE = AFVGD_IMP-USR06.

IF SY-SUBRC <> 0.

MESSAGE E075(ZAN) WITH AFVGD_IMP-USR06.

ENDIF.

0 Kudos

i m using zabacklog table have three field i just want match numeric field to that output field

Former Member
0 Kudos

tell me any one how to write the code for validate the field ?????????

0 Kudos

hi

using chain and endchain u can validate the field

regards

vidya