OPEN SQL examples in ABAP - Part 3
*===================================================
*Filtering the fields *displaying 2 fields data from SCARR table (Airlines) *with the help of two individual variables *by declaring them with built-in-data types *==================================================== DATA CIDN(3) TYPE C. DATA CNAME(20) TYPE C. SELECT CARRID CARRNAME INTO (CID, CNAME) FROM SCARR. WRITE:/ CID, CNAME. ENDSELECT.
******************************************************* *displaying 2 fields data from SCARR table (Airlines) *with the help of two individual variables *by declaring them with DB Table field References DATA CIDN TYPE SCARR-CARRID. DATA CNAME TYPE SCARR-CARRNAME. SELECT CARRID CARRNAME INTO (CIDN, CNAME) FROM SCARR. WRITE:/ CIDN, CNAME. ENDSELECT.
*********************************************** ***************** **creating Explicit header line with only two fields ** and displaying SCARR details DATA: BEGIN OF WA, CIDN (3) TYPE C, CNAME(20) TYPE C, END OF WA. SELECT CARRID CARRNAME INTO WA FROM SCARR. WRITE:/ WA-CIDN, WA-CNAME. ENDSELECT. *************************************************** **--creating Explicit header line with only two fields ** and displaying SCARR details DATA: BEGIN OF WA, CARRID TYPE SCARR-CARRID, CARRNAME TYPE SCARR-CARRNAME, END OF WA. SELECT CARRID CARRNAME INTO WA FROM SCARR. WRITE: / WA-CARRID, WA-CARRNAME. ENDSELECT.
**======================================================= **fetching only ONE record from DB table **displaying description of material 100-100 in English from MAKT table **======================================================== DATA: BEGIN OF WA, MATNR1 TYPE MAKT-MATNR, MAKTX1 TYPE MAKT-MAKTX, END OF WA. SELECT SINGLE MATNR MAKTX INTO WA FROM MAKT WHERE MATNR = '100-100' AND SPRAS = 'EN'. IF SY-SUBRC = 0. WRITE: / WA-MATNR1, WA-MAKTX1. ELSE. WRITE: / 'Description not found'. ENDIF.
*========================================================= *Creating User-Defined Data Types *Fetching only ONE record from DB table at a time *displaying descriptions of three materials 100-100, 100-200, 100-300 *in english language only from MAKT table *========================================================== **Creating a structure type (User defined data type) TYPES: BEGIN OF MATL, MATNR1 TYPE MAKT-MATNR, MAKTX1 TYPE MAKT-MAKTX, END OF MATL. **--Creating structures for holding data DATA WA100 TYPE MATL. DATA WA200 TYPE MATL. DATA WA300 TYPE MATL. SELECT SINGLE MATNR MAKTX INTO WA100 FROM MAKT WHERE MATNR = '100-100' AND SPRAS = 'EN'. SELECT SINGLE MATNR MAKTX INTO WA200 FROM MAKT WHERE MATNR = '100-200' AND SPRAS = 'EN'. SELECT SINGLE MATNR MAKTX INTO WA300 FROM MAKT WHERE MATNR = '100-300' AND SPRAS = 'EN'. WRITE: / WA100-MATNR1, WA100-MAKTX. WRITE: / WA200-MATNR1, WA200-MAKTX1. WRITE:/ WA300-MATNR1, WA300-MAKTX1.
********************************************************* *keeping structure type definition in type group and using the type group for current program *--Attaching type group to current program TYPE-POOLS ZDEL1. *--Creating Structures for holding data DATA WA100 TYPE ZDEL1-MAT. DATA WA200 TYPE ZDEL1-MAT. DATA WA300 TYPE ZDEL1-MAT. SELECT SINGLE MATNR MAKTX INTO WA100 FROM MAKT WHERE MATNR = '100-100' AND SPRAS = 'EN'. SELECT SINGLE MATNR MAKTX INTO WA200 FROM MAKT WHERE MATNR = '100-200' AND SPRAS = 'EN'. SELECT SINGLE MATNR MAKTX INTO WA300 FROM MAKT WHERE MATNR = '100-300' AND SPRAS = 'EN'. WRITE: / WA100-MATNR1, WA100-MAKTX1. WRITE:/ WA200-MATNR1, WA200-MAKTX1. WRITE:/ WA300-MATNR1, WA300-MAKTX1. ****************************************************************
Comments
Post a Comment