‎2006 Aug 11 2:32 PM
Hello all,
can any one give one simple program for Insert Update Delete
i have taken 9 fields and in a simple screen.
and have 3 button. through this i want to Insert Update and Delete Data in customize table.
Thaks.
Rajesh.
‎2006 Aug 11 2:37 PM
‎2006 Aug 11 2:43 PM
Hi Rajesh ,
I think Rich has suggested the best solution for your problem . For more help on that click <a href="http://help.sap.com/saphelp_erp2005/helpdata/en/a1/e45217a2f511d1a5630000e82deaaa/content.htm">Table maintenance</a>
Hope this helps .
Regards ,
Shounak M.
‎2006 Aug 11 2:43 PM
Hello Rich Heilmen,
I am new for module pool program. i want to know how to create MP Program and in that i want to use 4 buttons to do operations of Insert Update and delete.
Rajesh
‎2006 Aug 11 2:40 PM
‎2006 Aug 11 2:46 PM
HI,
See the below link, open that link. Press next button for step by step
http://sap.mis.cmich.edu/sap-abap/abap09/sld011.htm
you will find Example programs in the SAP itself, T.code <b>ABAPDOCU</b> , or goto SE80, then Utilities --> Examples --> ABAP Examples
here, Press ABAP User Dialogs --> Screens, you will find all the example programs for Module pool
Thanks
Sudheer
‎2006 Aug 11 3:41 PM
Hi Rajesh,
in module pool program generally there will be 2 processes
<b>PBO and PAI</b>
<b>PBO(Process before output)</b>
this is trigerred before displaying the output screen
generally in PBO
we set the PF status
<b>PAI(Process after input )</b>
this is trigerred when the user gives any input
here write the code for handling sy-ucomm.
********simple program as you reqd***************
data:itab1 type standard table of sflight,
ucomm like sy-ucomm.
call screen 100.
&----
*& Module pbo OUTPUT
&----
text
----
module pbo output.
set pf-status 'SCN100'.
select * from sflight into table itab1.
endmodule. " pbo OUTPUT
&----
*& Module pai INPUT
&----
text
----
module pai input.
ucomm = sy-ucomm.
case ucomm.
when 'EXIT'.
leave program.
when 'INSERT'.
write the code for insert
when 'UPDATE'.
write the code for update
*when 'DELETE'.
write the code for delete
endcase.
endmodule. " pai INPUT
********end of program***************
*****doc contd...
after writing the call screen stmt
dblclk on screen no(100)
it will take you to screen painter
define the attributes and click on flow logic tab
replace the first commented stmt with
module pbo.
dblck on pbo.
it will take back you to se38 with that module created
write the code in
similarly replace the next commented code with
module pai.
again dblck on pai.
it will take back you to se38 with that module created
write the code in
again go back to screen painter screen, click on layout tab,
click on dictionary/program fields window tab
it will take you to another screen
from there select the reqd fields you want to display
and create 3 push buttons
dblcl on them give text and fctcode and activate the screen
similarly in se38 dblck on the name given for the pf status to set the same
it will take you to the maintain status screen
i hope you know how to set the pf status
activate all the screens
of PF status, screen painter and se38
then execute
even you can create one more button for DISPLAY
to display the data
I hope this is very much clear to you
Please reward points if you feel it so
Regards,
Sowjanya
‎2006 Aug 11 3:48 PM
************************************************************************
* MODULE POOL *
PROGRAM YP_BOOKMASTER_MAINTENANCE MESSAGE-ID ZZ.
************************************************************************
* TABLES *
************************************************************************
TABLES ZBKMA. "book master table
************************************************************************
* VARIABLES *
************************************************************************
DATA : V_NUMBER(5) TYPE N, "variable to store random number
V_LINE TYPE I, "variable to get total no of lines
V_FLAG LIKE SY-TABIX. "variable for checking
************************************************************************
* INTERNAL TABLE *
************************************************************************
* internal table to store book numbers (i.e random numbers)
DATA : BEGIN OF IT_RANDOMNUMBERS OCCURS 0,
BKNUM LIKE ZBKMA-BKNUM, "book number
END OF IT_RANDOMNUMBERS.
* internal table to store only numeric part of book number
* eg : if book no is HUM00100 ,this table will only store 00100
DATA : BEGIN OF IT_NUMBERS OCCURS 0,
NUMBER(5) TYPE N, " a number
END OF IT_NUMBERS.
*internal table to store book details
DATA : BEGIN OF IT_BOOKMASTER OCCURS 0,
BKNUM LIKE ZBKMA-BKNUM, "BOOK NUMBER
BKNAM LIKE ZBKMA-BKNAM, "BOOK NAME
AUTHR LIKE ZBKMA-AUTHR, "AUTHOR
SRCHT LIKE ZBKMA-SRCHT, "SEARCH TERM
PUBSH LIKE ZBKMA-PUBSH, "PUBLISHER
YRPUB LIKE ZBKMA-YRPUB, "YEAR OF PUBLISHING
VERNO LIKE ZBKMA-VERNO, "VERSION NUMBER
DATPR LIKE ZBKMA-DATPR, "DATE OF PURCHASE
BKCOD LIKE ZBKMA-BKCOD, "BOOKCODE
END OF IT_BOOKMASTER .
*&---------------------------------------------------------------------*
*& Module STATUS_0090 OUTPUT
*&---------------------------------------------------------------------*
* PBO OF SCREEN 090(screen contains three buttons ADD , DELETE , MODIFY)
*----------------------------------------------------------------------*
MODULE STATUS_0090 OUTPUT.
SET PF-STATUS 'BOOKMASTER_FIRST'.
SET TITLEBAR 'BOOKMASTER'.
ENDMODULE. " STATUS_0090 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0090 INPUT
*&---------------------------------------------------------------------*
* PAI OF SCREEN 90
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0090 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN '0'. "go back
WHEN 'EXIT'.
LEAVE PROGRAM. "exit the program
WHEN 'CANCEL'.
leave to screen '0'. "cancel the screen
WHEN 'ADD'.
CLEAR IT_BOOKMASTER. "clears the contents of the fields.
CALL SCREEN '0100'.
WHEN 'DELETE'.
CLEAR IT_BOOKMASTER. "clears the contents of the fields.
CALL SCREEN '0200'.
WHEN 'MODIFY'.
CLEAR IT_BOOKMASTER. "clears the contents of the fields.
CALL SCREEN '0300'.
ENDCASE. "end sy-ucomm
ENDMODULE. " USER_COMMAND_0090 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* PBO OF 100 ( ADD THE BOOKS )
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'BOOKMASTER'.
SET TITLEBAR 'UPDATE BOOKMASTER'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* PAI OF 100 ( ADD THE BOOKS )
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM. "check the screen 100 actions
WHEN 'BACK'.
LEAVE TO SCREEN '0'. "go back
WHEN 'EXIT'.
LEAVE PROGRAM. "exit the program
WHEN 'CANCEL'.
LEAVE to screen '0' . "cancel the screen 100
WHEN 'ADD'.
* add the books to the master records
PERFORM FORM_ADDBOOK. " add the
WHEN 'RESET'.
CLEAR IT_BOOKMASTER. "reset the screen
SET SCREEN '0100'.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form FORM_ADDBOOK
*&---------------------------------------------------------------------*
* ADDING THE BOOKS
*----------------------------------------------------------------------*
FORM FORM_ADDBOOK .
*TO ASSIGN BOOK NUMBER
PERFORM FORM_ASSIGN_BOOKNO.
* INSERTING THE BOOKS
ZBKMA-BKNAM = IT_BOOKMASTER-BKNAM.
ZBKMA-AUTHR = IT_BOOKMASTER-AUTHR.
ZBKMA-SRCHT = IT_BOOKMASTER-SRCHT.
ZBKMA-PUBSH = IT_BOOKMASTER-PUBSH.
ZBKMA-YRPUB = IT_BOOKMASTER-YRPUB.
ZBKMA-VERNO = IT_BOOKMASTER-VERNO.
ZBKMA-DATPR = IT_BOOKMASTER-DATPR.
ZBKMA-BKCOD = IT_BOOKMASTER-BKCOD.
IF NOT IT_BOOKMASTER-BKNAM IS INITIAL. "if the book number is not initial
INSERT ZBKMA.
ENDIF. "endif check initial
IF SY-SUBRC = 0.
MESSAGE S003(ZCHA) WITH IT_BOOKMASTER-BKNUM.
ENDIF. "endif success
ENDFORM. " FORM_ADDBOOK
*&---------------------------------------------------------------------*
*& Form FORM_DELETEBOOK
*&---------------------------------------------------------------------*
* delete books from the master data
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FORM_DELETEBOOK .
* check the it is initial
IF NOT IT_BOOKMASTER-BKNUM IS INITIAL.
*get the book numbers present already
SELECT SINGLE BKNUM
FROM ZBKMA
INTO ZBKMA-BKNUM
WHERE BKNUM = IT_BOOKMASTER-BKNUM.
*check if select is successful
IF SY-SUBRC = 0.
DELETE FROM ZBKMA WHERE BKNUM = IT_BOOKMASTER-BKNUM.
MESSAGE S004(ZCHA) WITH IT_BOOKMASTER-BKNUM. "if book deleted
ELSE.
MESSAGE S005(ZCHA) WITH IT_BOOKMASTER-BKNUM. "if book not found
ENDIF.
ENDIF.
ENDFORM. " FORM_DELETEBOOK
*&---------------------------------------------------------------------*
*& Form FORM_MODIFYBOOK
*&---------------------------------------------------------------------*
* MODIFING THE BOOK
*----------------------------------------------------------------------*
FORM FORM_MODIFYBOOK.
*validiate the book number
SELECT SINGLE BKNUM
FROM ZBKMA
INTO ZBKMA-BKNUM
WHERE BKNUM = IT_BOOKMASTER-BKNUM.
*check for the success
IF SY-SUBRC NE 0.
MESSAGE S005(ZCHA) WITH IT_BOOKMASTER-BKNUM.
ENDIF.
ZBKMA-BKNUM = IT_BOOKMASTER-BKNUM.
ZBKMA-BKNAM = IT_BOOKMASTER-BKNAM.
ZBKMA-AUTHR = IT_BOOKMASTER-AUTHR.
ZBKMA-SRCHT = IT_BOOKMASTER-SRCHT.
ZBKMA-PUBSH = IT_BOOKMASTER-PUBSH.
ZBKMA-YRPUB = IT_BOOKMASTER-YRPUB.
ZBKMA-VERNO = IT_BOOKMASTER-VERNO.
ZBKMA-DATPR = IT_BOOKMASTER-DATPR.
UPDATE ZBKMA. "update the book master table
IF SY-SUBRC = 0.
MESSAGE S006(ZCHA) WITH IT_BOOKMASTER-BKNUM.
ENDIF.
ENDFORM. " FORM_MODIFYBOOK
*&---------------------------------------------------------------------*
*& Form FORM_ASSIGN_BOOKNO
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM FORM_ASSIGN_BOOKNO .
*select the books already there from bookmaster
SELECT BKNUM
FROM ZBKMA
INTO TABLE IT_RANDOMNUMBERS
WHERE BKCOD = IT_BOOKMASTER-BKCOD.
*if the book is first book i.e. first entry
IF IT_RANDOMNUMBERS[] IS INITIAL.
V_NUMBER = 1. "start with 1
CONCATENATE IT_BOOKMASTER-BKCOD V_NUMBER INTO IT_BOOKMASTER-BKNUM.
ZBKMA-BKNUM = IT_BOOKMASTER-BKNUM. "assign booknumber
EXIT.
ENDIF. "check for initial
CLEAR IT_NUMBERS[]. "clear the temporary table
CLEAR IT_NUMBERS.
* check for the book numbers if there is no book start from first in other
* cases look for first gap and assign that number
LOOP AT IT_RANDOMNUMBERS.
IT_NUMBERS-NUMBER = IT_RANDOMNUMBERS-BKNUM+3(5). "get the last 5 digits
"and store it in it_number
APPEND IT_NUMBERS.
ENDLOOP.
SORT IT_NUMBERS BY NUMBER. "sort
DESCRIBE TABLE IT_NUMBERS LINES V_LINE. "get no. of lines in table
*check for book number gap
LOOP AT IT_NUMBERS.
V_FLAG = SY-TABIX.
* if the book number is not equal to the index of table i.e. some gap in book number
* or only one record
IF IT_NUMBERS-NUMBER NE SY-TABIX OR V_LINE = 1.
V_NUMBER = SY-TABIX. "fill the gap
if v_line = 1. "if only one record
v_number = v_line + 1. "increment the book number
endif. "only one record check
CONCATENATE IT_BOOKMASTER-BKCOD V_NUMBER INTO IT_BOOKMASTER-BKNUM.
ZBKMA-BKNUM = IT_BOOKMASTER-BKNUM. "assign
EXIT.
ENDIF. "check for gap
*if no gap in book number assign next number
IF V_FLAG = V_LINE.
V_NUMBER = IT_NUMBERS-NUMBER + 1.
CONCATENATE IT_BOOKMASTER-BKCOD V_NUMBER INTO IT_BOOKMASTER-BKNUM.
ZBKMA-BKNUM = IT_BOOKMASTER-BKNUM.
EXIT.
ENDIF. "book number increment
ENDLOOP. "check number gap
ENDFORM. " FORM_ASSIGN_BOOKNO
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
* PBO OF SCREEN 200 ( DELETE BOOKS)
*----------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'DELETE'.
SET TITLEBAR 'DELETE'.
ENDMODULE. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* PAI OF SCREEN 200 (DELETE BOOKS)
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
CASE SY-UCOMM. "check for screen 200 actions
WHEN 'BACK'.
LEAVE TO SCREEN '0'. "go back
WHEN 'EXIT'.
LEAVE PROGRAM. "leave program
WHEN 'CANCEL'.
LEAVE to screen '0'. "cancel screen
WHEN 'DELETE'.
* delete the book from master data
PERFORM FORM_DELETEBOOK.
WHEN 'RESET'. "reset the screen
CLEAR IT_BOOKMASTER.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0300 OUTPUT
*&---------------------------------------------------------------------*
* PBO OF SCREEN 300 ( FOR MODIFYING )
*----------------------------------------------------------------------*
MODULE STATUS_0300 OUTPUT.
SET PF-STATUS 'MODIFY'.
SET TITLEBAR 'MODIFY'.
ENDMODULE. " STATUS_0300 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0300 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0300 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN '0'.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE TO SCREEN '0'.
WHEN 'MODIFY'.
PERFORM FORM_MODIFYBOOK. "update the record
WHEN 'RESET'.
CLEAR IT_BOOKMASTER. "screen reset
ENDCASE.
ENDMODULE. " USER_COMMAND_0300 INPUT
*&---------------------------------------------------------------------*
*& Module MODULE_CANCEL INPUT
*&---------------------------------------------------------------------*
* ACTIONS AT EXIT COMMAND
*----------------------------------------------------------------------*
MODULE MODULE_CANCEL INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN '0'.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " MODULE_CANCEL INPUTMessage was edited by: Chandrasekhar Jagarlamudi