ABAP to change, add and edit records in table
To all ABAP Gurus,
I am new in ABAP. I found that in my SAP system, there is a restriction to update, add and change records directly using tc SE16. Therefore, i need to write a program to handle this.
Do you have any sample program like this. Will appreciated if you can send me a copy for my reference. Thanks.
Basically, what this program need to do is just allow me to ADD records, CHANGE records and DELETE records.
_________________
Best regards,
SAP - IT - MAN
Hi,
if you plan to edit the contents of a SAP Standard table, try to find the appropriate BAPIs or FMs for that.
if you plan to change custom tables, you can use the SQL command insert, update and delete. for details, you can type that command in your ABAP Editor and press F1.
Note: DO NOT USE THOSE SQL COMMANDS TO DIRECTLY MODIFY SAP STANDARD TABLES
In SE11,You will see a check box named Tab.Maint.Allowed.
Hit the checkbox, then you can maintain your table directly in SE16.
Tks
Hi,
Thanks for your reply. I understand the SE11 check "table maintainance" will allow me to change the table data BUT this will only work in my Development Server. In Test and Production server, direct manipulation data record for customized table will not allow.
That is why i need a program to update the record.
_________________
Best regards,
SAP - IT - MAN
Don't you use the table maintenance generator in SE11 and then transport it.
now this is a program I would love to write.
Select-options -> table name
Radio-button -> add/delete/modify option
Parameter -> Filename containing list of records to be added/deleted/modified (optional)
now code it. Select the delete option for let us say, bseg, usr02, t000. Run the program and then run yourself. very quickly.
In SE11,You will see a check box named Tab.Maint.Allowed.
Hit the checkbox, then you can maintain your table directly in SE16.
Tks
That only works in an open system!!!
untrue - sort of. you can choose whether the table maintenance follows the standard recording routine (i.e. in accordance with SCC4 for the current client) or does not use a recording routine. In the latter case, you can edit it in a changeable system.
That is why i need a program to update the record.
So, let's summarize: You are new to ABAP, and you want to (or have to?) write a program to directly change the contents of SAP standard tables.
Did I get this right?
Please let me know which company you are working for, so that I can make sure I never have to work for this company.
I bet there must exist a lot of mess, cleaning it up isn't fun.
That is why i need a program to update the record.
So, let's summarize: You are new to ABAP, and you want to (or have to?) write a program to directly change the contents of SAP standard tables.
Did I get this right?
Please let me know which company you are working for, so that I can make sure I never have to work for this company.
I bet there must exist a lot of mess, cleaning it up isn't fun.
Hello...
Did i mentioned "Customized" table????
Of cause i will not edit or change the standard table in SAP...
Pls understand the question b4 u have a good answer for me...
_________________
Best regards,
SAP - IT - MAN
Hello Mr. Guest,
I forget to tell u that i have a solution for my problem already...
Just want to share with u here is the sample of change "customized" table program i need...
* =======================================================
* PROGRAM FOR APPENDING, DELETING OR CHANGING ENTRIES
* OF A TABLE CALLED ZNB_UNITS
* with Fields :
* ZZ_UNIT key field type NUMC 9
* ZZ_TEXT type CHAR 25
* -------------------------------------------------------
* The key of the record appended is the next integer of
* the maximum existing key
* =======================================================
REPORT ZNB_UNITS_APPEND_NEXT_RECORD NO STANDARD PAGE HEADING .
DATA : BEGIN of I_UNITS occurs 1000 ,
MCHECK .
INCLUDE STRUCTURE ZNB_UNITS .
DATA : END OF I_UNITS .
DATA : WA_UNITS LIKE ZNB_UNITS .
DATA : W_ANS .
DATA : SY_INDEX LIKE SY-INDEX .
DATA : MTEXT LIKE ZNB_UNITS-ZZ_TEXT .
* =======================================================
* Start of selection
* =======================================================
Start-of-selection .
PERFORM GET_DATA .
* =======================================================
* End of selection
* =======================================================
End-of-selection .
* -------------------------------------------------------
* The Following Status MSTAT has buttons for
* Appending with function code : APP_A_REC
* Deleting with function code : DEL_REC
* Saving with function code : SAVE
* -------------------------------------------------------
set pf-status 'MSTAT' .
perform print_simple_list .
*&------------------------------------------------------*
*& Form print_simple_list
*&------------------------------------------------------*
* text
*-------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------*
FORM print_simple_list.
ULINE .
WRITE : / 'LIST OF TABLE ZNB_UNITS ' .
ULINE .
LOOP AT I_UNITS .
WRITE : /
I_UNITS-MCHECK AS CHECKBOX ,
I_UNITS-ZZ_UNIT NO-ZERO COLOR COL_TOTAL ,
I_UNITS-ZZ_TEXT INPUT ON .
ENDLOOP .
ENDFORM. " print_simple_list
*&------------------------------------------------------*
*& Form GET_DATA
*&------------------------------------------------------*
* text
*-------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------*
FORM GET_DATA.
SELECT * FROM ZNB_UNITS
INTO CORRESPONDING FIELDS OF TABLE I_UNITS .
ENDFORM. " GET_DATA
* =======================================================
* AT USER-COMMAND
* =======================================================
AT USER-COMMAND .
* -----------> APPEND A RECORD <-------------------------
IF SY-UCOMM = 'APP_A_REC'.
CLEAR WA_UNITS .
CALL FUNCTION 'POPUP_TO_GET_VALUE'
EXPORTING
FIELDNAME = 'ZZ_TEXT'
TABNAME = 'ZNB_UNITS'
TITEL = 'GIVE TEXT OF NEW UNIT'
VALUEIN = ' '
IMPORTING
ANSWER = w_ans
VALUEOUT = WA_UNITS-ZZ_TEXT
EXCEPTIONS
FIELDNAME_NOT_FOUND = 1
OTHERS = 2.
IF W_ANS = 'C' OR SY-SUBRC <> 0.
EXIT.
ENDIF.
IF SY-SUBRC EQ 0.
IF NOT ( WA_UNITS-ZZ_TEXT IS INITIAL ) .
SELECT MAX( ZZ_UNIT ) INTO WA_UNITS-ZZ_UNIT FROM ZNB_UNITS .
WA_UNITS-ZZ_UNIT = WA_UNITS-ZZ_UNIT + 1 .
INSERT INTO ZNB_UNITS VALUES WA_UNITS .
PERFORM GET_DATA .
perform print_simple_list .
SY-LSIND = 0 .
ENDIF .
ENDIF.
ENDIF .
* -----------> DELETE SELECTED RECORDS <-----------------
IF SY-UCOMM = 'DEL_REC' .
DO .
READ LINE SY-INDEX FIELD VALUE I_UNITS-MCHECK .
READ LINE SY-INDEX FIELD VALUE I_UNITS-ZZ_UNIT .
READ LINE SY-INDEX FIELD VALUE I_UNITS-ZZ_TEXT .
IF I_UNITS-MCHECK = 'X' .
SY_INDEX = SY-INDEX - 3 .
MODIFY I_UNITS INDEX SY_INDEX .
ENDIF .
IF SY-SUBRC <> 0 . EXIT . ENDIF .
ENDDO .
LOOP AT I_UNITS WHERE MCHECK = 'X' .
DELETE FROM ZNB_UNITS WHERE ZZ_UNIT = I_UNITS-ZZ_UNIT .
ENDLOOP .
DELETE I_UNITS WHERE MCHECK = 'X' .
perform print_simple_list .
SY-LSIND = 0 .
ENDIF .
* -----------> SAVE CHANGED RECORDS <--------------------
IF SY-UCOMM = 'SAVE' .
DO .
SY_INDEX = SY-INDEX - 3 .
CHECK SY_INDEX GE 1 .
READ TABLE I_UNITS INDEX SY_INDEX .
MTEXT = I_UNITS-ZZ_TEXT .
READ LINE SY-INDEX FIELD VALUE I_UNITS-ZZ_UNIT .
READ LINE SY-INDEX FIELD VALUE I_UNITS-ZZ_TEXT .
IF MTEXT NE I_UNITS-ZZ_TEXT .
UPDATE ZNB_UNITS SET ZZ_TEXT = I_UNITS-ZZ_TEXT
WHERE ZZ_UNIT = I_UNITS-ZZ_UNIT .
MODIFY I_UNITS INDEX SY_INDEX .
ENDIF .
IF SY-SUBRC <> 0 . EXIT . ENDIF .
ENDDO .
perform print_simple_list .
SY-LSIND = 0 .
ENDIF .
DON'T WORRY... YOU WILL NEVER WORK WITH MY COMPANY... CAUSE MY COMPANY WILL ONLY HAVE PEOPLE UNDERSTAND PROBLEM WELL AND HAVE SOLUTION TO SOLVE IT.
WE NEVER RECURIT PEOPLE ONLY RAISE PROBLEM AND HAVE NO SOLUTION OR WHEN THERE IS SOLUTION THEY WILL RUN AWAY.
I AM NEW TO ABAB AND IT DIDN'T MEANT THAT I DON'T KNOW SAP OR PROGRAMMING.
_________________
Best regards,
SAP - IT - MAN
Umm.... What's wrong with generating a table maintenance dialog and using SM30 ??
_________________
Regards
R
Abap KC
SFMDR
Hello,
I want to do the same program because i want to do a selection of my key (not avaible with sm30), and i dont want to alow modfy table by multiple user in teh same time (not avaible with sm30 or se16).
how can i block just one row of my table?
I have the same question as R... Why not Maintenance Table ???
It is easy and using FM "VIEW_MAINTENANCE_CALL" to call it you can let only view, or block any action...
Have a good 2004 !
PabloX
because all the table is bloked with sm30 or FM VIEW_MAINTENANCE_CALL in update task!