Skip to Content
author's profile photo Former Member
Former Member

Update a Z table

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 10, 2009 at 12: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2009 at 04: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.