Monday, September 26, 2011

Inserting multiple entries in a database table

REPORT INSERTMULTIPLEENTRIES.
* Work area
TABLES CUSTOMERS.
* Internal table for new entries
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
             WITH HEADER LINE.
* Filling the internal table
ALL_CUSTOMERS-ID            = '12345678'.
ALL_CUSTOMERS-NAME = 'Brown'.
APPEND ALL_CUSTOMERS.
ALL_CUSTOMERS-ID          = '11111111'.
ALL_CUSTOMERS-NAME = 'Green'.
APPEND ALL_CUSTOMERS.
ALL_CUSTOMERS-ID          = '12121212'.
ALL_CUSTOMERS-NAME = 'White'.
APPEND ALL_CUSTOMERS.
* Inserting the internal table
INSERT CUSTOMERS FROM TABLE ALL_CUSTOMERS.

Inserting single entries in a database table

REPORT INSERTSINGLEENTRIES.
* Work area
TABLES CUSTOMERS.
* Record used as alternative work area
DATA MY_CUSTOMER LIKE CUSTOMERS.
* Inserting one entry from the work area
CUSTOMERS-ID = '12345678'.
CUSTOMERS-NAME = 'Brown'.
INSERT CUSTOMERS.
IF SY-SUBRC <> 0.
 WRITE: / 'Entry already exists:', CUSTOMERS-ID.
ENDIF.
* Inserting one entry from the record
MY_CUSTOMER-ID = '11111111'.
MY_CUSTOMER-NAME = 'Green'.
INSERT INTO CUSTOMERS VALUES MY_CUSTOMER.
IF SY-SUBRC <> 0.
 WRITE: / 'Entry already exists:', MY_CUSTOMER-ID.
ENDIF.

Drop Down lists in the selection parameters

PROGRAM ztest.   TYPE-POOLS : vrm.   DATA : name TYPE vrm_id,        list TYPE vrm_values,        value LIKE LINE OF list. ...