OPEN SQL EXAMPLES IN ABAP – PART 2

 *******************************************

**displaying Raw Materials and Finished products

**only from MARA table.

DATA WA TYPE MARA.

*

**--WHERE clause is for filtering the records

SELECT * FROM MARA INTO WA

WHERE MTART = 'ROH' OR MTART = 'FERT'.

WRITE: / WA-MATNR,

WA-MBRSH,

WA-MTART,

WA-MEINS.

ENDSELECT.

*

**************************************************

**--displaying all materials except Raw Materials

** only from MARA table.

DATA WA TYPE MARA.

*

**WHERE clause is for filtering the records

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

WRITE: / WA-MATNR,

WA-MBRSH,

WA-MTART,

WA-MEINS.

ENDSELECT.

*

***********************************************
*LIKE OPERATOR

**--displaying all customer's details from KNA1

**whose name  contains 'Jack'.

DATA WA TYPE KNA1.

SELECT * INTO WA FROM KNA1

WHERE NAME1 LIKE '%Jack%'.

WRITE:/

WA-KUNNR,

WA-NAME1,

WA-STRAS,

WA-ORT01,

WA-LAND1.

ENDSELECT.
************************************LIKE OPERATOR

**Displaying all customer's details from KNA1

**whose name contains 'h' as 3rd character

*

DATA WA TYPE KNA1.

SELECT * INTO WA

FROM KNA1

WHERE NAME1 LIKE '   h%'.

WRITE:/

WA-KUNNR,

WA-NAME1,

WA-STRAS,

WA-ORT01,

WA-LAND1.

ENDSELECT.
******************************IN OPERATOR

**--displaying all customer's details from KNA1

**who belong to USA and Germany only

*

DATA WA TYPE KNA1.

SELECT * INTO WA

FROM KNA1

WHERE LAND1 IN ('US', 'DE').

WRITE:/

WA-KUNNR,

WA-NAME1,

WA-STRAS,

WA-ORT01,

WA-LAND1.

ENDSELECT.
******************************************

**--displaying 1st 5 customer's details form KNA1

DATA WA TYPE KNA1.

SELECT * INTO WA

FROM KNA1

UP TO 5 ROWS.

WRITE:/

WA-KUNNR,

WA-NAME1,

WA-STRAS,

WA-ORT01,

WA-LAND1.

ENDSELECT.





 

Comments

Popular posts from this blog

Domains and Data Elements

How to update exchange rates via process chain in BW

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server