2009 Aug 10 1:41 PM
Hi,
I have to update\insert values in a Z table from a Z BAPI and with the OO Concept.
Please suggest how i can proceed. ECC version 5.0.
Till now i have created a Persistent class with Instantiation as 'Protected'.
I checked in SDN that (IF_OS_STATE~SET) method is used to update the database table, but couldn't find any sample code.
I am new to ABAP Object, so a sample code would be of great help.
Thanks,
James
Hi,
I have to update\insert values in a Z table from a Z BAPI and with the OO Concept.
Please suggest how i can proceed. ECC version 5.0.
Till now i have created a Persistent class with Instantiation as 'Protected'.
I checked in SDN that (IF_OS_STATE~SET) method is used to update the database table, but couldn't find any sample code.
I am new to ABAP Object, so a sample code would be of great help.
Thanks,
James
2009 Aug 10 1:45 PM
Hi James
It's not easy to help you, u should say us how you need to implement your code in OOA, i.e. the logic of your program.
Before creating a class it needs to know the logic of the program in order to decide the charateristics, attributes,...of the class.
Max
2009 Aug 10 1:52 PM
Hi Max,
I need to update a z table whenever my BAPI is called. If the parameter (mode ) coming in BAPI is Create then i have to insert the record in my Z table. and if the Parameter(Mode) is Update then i have to update my Z table record.
I have to do this updation\insertion using OO concept.
Please suggest.
Thanks,
James.
2009 Aug 10 3:53 PM
You can create an persistent class for your Z table. Check this help on creating the Persistent Class:
http://help.sap.com/saphelp_nw04/Helpdata/EN/b1/82309cd26611d4b2e90050dadfb92b/frameset.htm
You can use the method from this persistent class to create or Update your Z table.
Check the demo program DEMO_CREATE_PERSISTENT on how to create data using the persistent class.
To Update the data, once you get the Persistent object, you can use the SET_ methods to update the data.
You may like to check this example to read / create the data:
http://help-abap.blogspot.com/2009/04/persistent-object-service-example.html
Regards
Naimesh Patel
2009 Aug 10 4:12 PM
Thanks Naimesh,
I will try this and let you know.
Thanks,
James
2009 Aug 11 5:24 AM
Hi,
If you are updating the ZTABLE from getting values from different SAP tables used in the report then it can be done using the INSERT/MODIFY statement.
Or else You can try either of these SAMPLE codes:
SAMPLE 1:
DATA: it_ztable TYPE STANDARD TABLE OF ztable.
DATA: wa_ztable TYPE ztable.
DATA: it_bkpf TYPE STANDARD TABLE OF bkpf.
DATA: wa_bkpf TYPE bkpf.
SELECT * FROM bkpf INTO TABLE it_bkpf WHERE ... "some conditions
LOOP AT it_bkpf INTO wa_bkpf.
CLEAR wa_ztable.
SELECT SINGLE * FROM ztable INTO wa_ztable
WHERE field1 = wa_bkpf-field1
AND field2 = wa_bkpf-field2.
IF sy-subrc EQ 0.
UPDATE ztable SET field3 = wa_bkpf-field3
WHERE field1 = wa_bkpf-field1
AND field2 = wa_bkpf-field2.
ELSE.
MOVE-CORRESPONDING wa_bkpf TO wa_ztable.
INSERT ztable FROM wa_ztable.
ENDIF.
ENDIF.
OR
SAMPLE 2:
*Lock Table ZHPA_CON_INF
PERFORM sub_lock_db.
*Update the table with this work area having current date and time
MODIFY zhpa_con_inf FROM wa_zhpa_con_inf.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
*Unloak Table ZHPA_CON_INF
PERFORM sub_unlock_db.
**************************************
&----
*& Form sub_lock_db
&----
Lock Database
-
No Parameters
-
FORM sub_lock_db.
Declare the local variable for varkey
DATA : l_varkey TYPE vim_enqkey. "Varkey
Move the value of client to local variable
CONCATENATE sy-mandt c_intid INTO l_varkey.
Lock the table before update
CALL FUNCTION 'ENQUEUE_E_TABLEE'
EXPORTING
tabname = c_tabname "ZHPA_CON_INF
varkey = l_varkey
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc 0.
MESSAGE i000 WITH 'Error while locking table:'(002) c_tabname.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_lock_db
&----
*& Form sub_unlock_db
&----
Unlock Database
-
No Parameters
-
FORM sub_unlock_db .
Declare the local variable for varkey
DATA : l_varkey TYPE vim_enqkey. "Varkey
Move the value of client to local variable
CONCATENATE sy-mandt c_intid INTO l_varkey.
*Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLEE'
EXPORTING
tabname = c_tabname "ZHPA_CON_INF
varkey = l_varkey.
ENDFORM. " sub_unlock_db
Hope this will be useful.
Regards,
Dhanalakshmi L
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |