Skip to Content
-2

ABAP - update table vbap

Hi,

I have the following code to update the table VBAP based on gt_record1 entries, which I got from file upload. Gt_record1 has ordnum, item, plant, item category data. I have to update table VBAP with plant and item cat for provided ordnum and item.

I am doing something wrong with my loops. Can you please help.

Form get_data.

If gt_record1 is not initial.

sort gt_record1.

select * from vbap into table @data(lt_vbap)

for all entries in @gt_record1

where vbeln = @gt_record1-ordnum

and posnr = @gt_record1-item.

Loop at gt_record1 assigning field-symbol(<fs_record1>).

If sy-subrc = 0.

Loop at lt_vbap assigning field-symbol(<fs_vbap>).

<fs_vbap>-werks = <fs_record1>-plant.

<fs_vbap>-pstyv = <fs_record1>-itemcat.

ENDLOOP.

MODIFY vbap FROM TABLE lt_vbap.

If sy-subrc = 0.

COMMIT WORK.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM.

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Posted on Oct 17, 2019 at 06:10 AM

    The solution is very simple

    YOU MUST NEVER MODIFY THE STANDARD TABLE CONTENT

    or you will loose SAP support

    so please, do not ask forbidden solution in an official SAP forum

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 17, 2019 at 06:46 AM

    I agree completely with Frederic Girod you should not do this, the person who requested this probably has no idea what can be the consequences of such approach. I am a SD consultant and please, believe me when I say that this can easily mess up your whole order-to-cash process.

    As a developer you also have a say in the solution development.

    What is more - there is no need for a custom program to update the [plant and the item category of sales order items; this can be done via transaction MASS and even with LSMW. If you really need to update sales orders via a custom program then at least you can use safer ways - like BAPI_SALESORDER_CHANGE.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 17, 2019 at 07:50 AM

    This is NOT your requirement.

    Your requirement is to update sales orders. If you don't use Bapi's or even bdc to fulfill that requirement then SAP has no commitment to support your client in case something goes wrong with direct table updates.

    Think of corrupt data, incorrect information which leads to failing audits, etc

    If the functional/business requirement details the specific direct manipulation of SAP tables then it is your responsibility to reject that requirement.

    Kind regards, Rob Dielemans

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 17, 2019 at 02:53 PM

    Thank you all for your explanations. I understood the consequences. I will go and talk to the functional people about it.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 17, 2019 at 06:26 AM
    -4

    Thank you for your reply but that is my requirement.

    Add a comment
    10|10000 characters needed characters exceeded

    • You can choose: be a crappy developer doing things without thinking about the consequences nor offering an alternative OR be a valuable resource, documenting your choices and explaining why something is wrong and should be done that way.

      I bet your request is "update those 2 fields": now you have to ask yourself "what does SAP say on updating standard tables?".