SAP Table information

ABAP code to Add or insert data to an SAP database table








As discussed in the previous post there are two basic ways you can add data to an SAP database table, manually using standard SAP transactions or via ABAP code.

In that post, we have already discussed the first method which was to add data manually via t-codes such as SE16 and SM30. We will now discuss the option of doing it via ABAP code.

Using the ABAP method offers a lot more freedom to add data to any table. But with this freedom also comes great responsibility to understand what you are doing and to make sure what you are adding is correct or even valid. Mainly because this method allows you to also add data to fields that wouldn't usually be accepted via user screen. i.e. you can ignore check tables or domain value restrictions or error messages with screen processing.

Anyway here is a very simple ABAP program that shows you one way to add data to an SAP database table. The example demonstrates that there is no difference between tables that are maintainable and those that can't when using ABAP code to update an SAP dictionary table. See to Add data manually via SE16/SM30 for more info.

*&---------------------------------------------------------------------*
*& Report  ZADD_DATA.
*&
*&---------------------------------------------------------------------*
REPORT ZADD_DATA.

data: wa_J_3RF_PRECMET type J_3RF_PRECMET,
      wa_EKKO type EKKO.


***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

* This table is maintainable via SE16/SM30
wa_J_3RF_PRECMET-PRECCODE    = 1.
wa_J_3RF_PRECMET-OKPCODE     = 1.
wa_J_3RF_PRECMET-COUNTABLE   = 1.
wa_J_3RF_PRECMET-QUNIT       = 1.
wa_J_3RF_PRECMET-WUNIT       = 1.

MODIFY J_3RF_PRECMET from wa_J_3RF_PRECMET.


* This table is NOT maintainable via SE16/SM30 but you can still
* update it the same via ABAP code
*wa_EKKO-EBELN	 =
*wa_EKKO-BUKRS	 =
*wa_EKKO-BSTYP	 =
*wa_EKKO-BSART	 =
*MODIFY EKKO from wa_EKKO.