You are on page 1of 28

Program structure

Program structure
REPORT... -> Program start TYPES: -> Type declaration DATA:... -> Data declaration ... INITIALIZATION. -> Triggered in executable programs before the selection screen is displayed. ... SELECTION-SCREEN -> Parameters and select-options AT SELECTION-SCREEN. -> Events for the selection screen ... START-OF-SELECTION. -> Start of processing ... -> END-OF-SELECTION. ... FORM... -> Procedures ... ENDFORM.

SELECTION-SCREEN - Parameters
y You use the PARAMETERS statement to declare variables, similarly to the

DATA statement. Variables declared with the PARAMETERS statement are called parameters. For each parameter declared, an input field appears on the corresponding selection screen. PARAMETERS <p>[(<length>)] [TYPE <type>|LIKE <obj>] [DECIMALS <d>].
y To assign a default value to a parameter, you use the following syntax:

PARAMETERS <p> ...... DEFAULT <f> ......


y To make a parameter obligatory :

PARAMETERS <p> ...... OBLIGATORY.

PARAMETERS - examples
PARAMETERS: p_int TYPE i OBLIGATORY. PARAMETERS: p_val(10) TYPE c DEFAULT ABC. PARAMETERS: p_date TYPE d DEFAULT sy-datum. PARAMETERS: p_matnr TYPE matnr. START-OF-SELECTION. WRITE: p_int, p_val, p_date.

SELECTION-SCREEN Select-options
y Used for complex selections from database (SELECT) y Can have multiple values (single values or intervals) y SELECT-OPTIONS <seltab> for <f>. y <f> can be a column of a database table, or

an internal <f> field in the program. A selection table is an internal table object of the standard table type that has a standard key and a header line. Selection tables are used to store complex selections using a standardized procedure.

SELECTION-SCREEN Select-options
y Checking Selection Criteria

Use the following logical expression to check whether the contents of a field satisfy the criteria in a selection table: ... <f> IN <seltab> ....

SELECTION-SCREEN Select-options
y Example :

TABLES: mara. DATA v_matnr TYPE mara-matnr. SELECT-OPTIONS s_matnr FOR mara-matnr. START-OF-SELECTION. v_matnr = 100-100. IF v_matnr IN s_matnr. WRITE : Valoarea se afla in SELECT-OPTION. ENDIF.

SELECT-OPTIONS structure
The row type of a selection table is a structure that consists of the following four components: SIGN, OPTION, LOW and HIGH. Each row of a selection table that contains values represents a sub-condition for the complete selection criterion. Description of the individual components: SIGN The data type of SIGN is C with length 1. The contents of SIGN determine for each row whether the result of the row condition is to be included in or excluded from the resulting set of all rows. Possible values are I and E. I stands for inclusive (inclusion criterion - operators are not inverted) E stands for exclusive (exclusion criterion - operators are inverted) OPTION The data type of OPTION is C with length 2. OPTION contains the selection operator. The following operators are available: If HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP. These operators are the same as those that are used for logical expressions. Yet operators CP and NP do not have the full functional scope they have in normal logical expressions. They are only allowed if wildcards ( '*' or '+' ) are used in the input fields, and no escape character is defined. If HIGH is filled, you can use BT (BeTween) and NB (Not Between). These operators correspond to BETWEEN and NOT BETWEEN that you use when you check if a field belongs to a range

SELECT-OPTIONS structure
LOW The data type of LOW is the same as the column type of the database table, to which the selection criterion is linked. If HIGH is empty, the contents of LOW define a single field comparison. In combination with the operator in OPTION, it specifies a condition for the database selection. If HIGH is filled, the contents of LOW and HIGH specify the upper and lower limits for a range. In combination with the operator in OPTION, the range specifies a condition for the database selection. HIGH The data type of HIGH is the same as the column type of the database table, to which the selection criterion is linked. The contents of HIGH specify the upper limit for a range selection.

SELECT

SELECT Processing Single Records

Processing Single Records


y Example:

DATA: wa_scarr TYPE scarr. PARAMETERS: p_carrid TYPE s_carr_id. START-OF-SELECTION. SELECT SINGLE * INTO wa_scarr FROM scarr WHERE carrid = p_carrid. WRITE : wa_scarr-carrid, wa_scarr-carrname.

Select Loops

Select Loops
y Example:

TABLES: scarr. DATA: wa_scarr TYPE scarr. SELECT-OPTIONS: s_carrid FOR scarr-carrid. START-OF-SELECTION. SELECT * INTO wa_scarr FROM scarr WHERE carrid IN s_carrid. WRITE : / wa_scarr-carrid, wa_scarr-carrname. ENDSELECT.

Array Fetch

Array Fetch
TABLES: scarr. DATA: gt_scarr TYPE TABLE OF scarr, wa_scarr TYPE scarr. SELECT-OPTIONS: s_carrid FOR scarr-carrid. START-OF-SELECTION. SELECT * INTO TABLE gt_scarr FROM scarr WHERE carrid IN s_carrid. LOOP AT gt_scarr INTO wa_scarr. WRITE : / wa_scarr-carrid, wa_scarr-carrname. ENDLOOP.

INTO clause

INTO clause
TYPES: BEGIN OF ty_scarr, carrid TYPE s_carr_id, carrname TYPE s_carrname, END OF ty_scarr. DATA: wa_scarr TYPE ty_scarr. PARAMETERS: p_carrid TYPE s_carr_id. START-OF-SELECTION. SELECT SINGLE carrid carrname INTO wa_scarr FROM scarr WHERE carrid = p_carrid. WRITE : wa_scarr-carrid, wa_scarr-carrname.

INTO clause

INTO clause
DATA: wa_scarr TYPE scarr. PARAMETERS: p_carrid TYPE s_carr_id. START-OF-SELECTION. SELECT SINGLE carrid carrname INTO CORRESPONDING FIELDS OFwa_scarr FROM scarr WHERE carrid = p_carrid. WRITE : wa_scarr-carrid, wa_scarr-carrname.

INTO clause
DATA: gv_carrid TYPE s_carr_id, gv_carrname TYPE s_carrname. PARAMETERS: p_carrid TYPE s_carr_id. START-OF-SELECTION. SELECT SINGLE carrid carrname INTO (gv_carrid, gv_carrname) FROM scarr WHERE carrid = p_carrid. WRITE : gv_carrid, gv_carrname.

JOIN

[INNER] JOIN
Table 1 |----|----|----|----| | A | B | C | D | |----|----|----|----| | a1 | b1 | c1 | 1 | | a2 | b2 | c2 | 1 | | a3 | b3 | c3 | 2 | | a4 | b4 | c4 | 3 | |----|----|----|----| \ \ \ / \ / \/ Table 2 |----|----|----|----|----| | D | E | F | G | H | |----|----|----|----|----| | 1 | e1 | f1 | g1 | h1 | | 3 | e2 | f2 | g2 | h2 | | 4 | e3 | f3 | g3 | h3 | |----|----|----|----|----| / /

Inner Join |----|----|----|----|----|----|----|----|----| | A | B | C | D | D | E | F | G | H | |----|----|----|----|----|----|----|----|----| | a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 | | a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 | | a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 | |----|----|----|----|----|----|----|----|----|

JOIN example
TYPES: BEGIN of ty_str, matnr TYPE matnr, maktx TYPE maktx, END OF ty_str. TABLES: mara. DATA: gt_matnr TYPE TABLE OF ty_str, gs_matnr TYPE ty_str. SELEC T-OPTIONS s_matnr FOR mara-matnr. START-OF-SELECTION. SELECT mara~matnr makt~maktx INTO TABLE gt_matnr FROM mara JOIN makt ON mara~matnr = makt~matnr WHERE mara~matnr IN s_matnr. LOOP AT gt_matnr INTO gs_matnr. WRITE: / Material: , gs_matnr-matnr, Descriere: , gs_matnr-maktx. ENDLOOP.

LEFT [OUTER] JOIN


Tabelle 1 |----|----|----|----| | A | B | C | D | |----|----|----|----| | a1 | b1 | c1 | 1 | | a2 | b2 | c2 | 1 | | a3 | b3 | c3 | 2 | | a4 | b4 | c4 | 3 | |----|----|----|----| \ \ \ / \ / \/ Tabelle 2 |----|----|----|----|----| | D | E | F | G | H | |----|----|----|----|----| | 1 | e1 | f1 | g1 | h1 | | 3 | e2 | f2 | g2 | h2 | | 4 | e3 | f3 | g3 | h3 | |----|----|----|----|----| / /

Left Outer Join |----|----|----|----|----|----|----|----|----| | A | B | C | D | D | E | F | G | H | |----|----|----|----|----|----|----|----|----| | a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 | | a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 | | a3 | b3 | c3 | 2 |NULL|NULL|NULL|NULL|NULL| | a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 | |----|----|----|----|----|----|----|----|----|

SELECT - exercise
Sa se afiseze pe ecran urmatoarele campuri: - Cod material (MARA-MATNR) - Greutate bruta (MARA-BRGEW) - Greutate neta (MARA-NTGEW) - Descrierea materialului in engleza (MAKT-MAKTX) Pentru materialele care respecta urmatoarele criterii de selectie : - Cod material (MARA-MATNR) selectie multipla - Grupa materiale (MARA-MATKL) - parametru

You might also like