Open SQL Examples in ABAP - Part 1

 TABLES SCARR.

UPDATE SCARR.

SET CARRNAME = 'india' WHERE CARRID = 'MP'.

IF SY-SUBRC = 0.

MESSAGE 'record is updated successfully' TYPE I.

ELSE.

MESSAGE 'record is not updated' TYPE 'I'.

ENDIF.


TABLES SCARR.

DELETE FROM SCARR WHERE CARRID = 'UP'.

IF SY-SUBRC = 0.

MESSAGE 'record is DELETED successfully' TYPE 'I'.

ELSE.

MESSAGE 'record is not DELETED' TYPE 'I'.

ENDIF.

**--displaying records of MARA table

**with the help of explicit header line

DATA WA TYPE MARA.

**--database table loop

SELECT * FROM MARA INTO WA.

WRITE: / WA-MATNR,              "Material No.

WA-MBRSH,                 "Industry sector

WA-MTART,                   "Material type

WA-MEINS.                   "Unit of Measure

ENDSELECT.

**displaying records of MARA table

**with the help of Implicit header line

TABLES MARA.

**--database table loop

SELECT * FROM MARA.

WRITE: / MARA-MATNR,

MARA-MBRSH,

MARA-MTART,

MARA-MEINS.

ENDSELECT.

**--displaying raw material records only from MARA table

**with the help of Explicit header line.

DATA WA TYPE MARA.

**--WHERE clause is for filtering the records

SELECT * FROM MARA INTO WA WHERE MTART = 'ROH'.

WRITE: / WA-MATNR,

WA-MBRSH,

WA-MTART,

WA-MEINS.

ENDSELECT.

**displaying Raw Material records which are measured in KG

** only from MARA table.

DATA WA TYPE MARA.

**--Where clause is for filtering the Records

SELECT * FROM MARA INTO WA WHERE MTART = 'ROH' AND MEINS = 'KG'.

WRITE:/ WA-MATNR,

WA-MBRSH,

WA-MTART,

WA-MEINS.

ENDSELECT.

Comments

Popular posts from this blog

Domains and Data Elements

Currency Conversion from Local Currency to USD in BW

How to update exchange rates via process chain in BW