0% found this document useful (0 votes)
2 views

ABAP Syntaxes1

Uploaded by

kanthykoduru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ABAP Syntaxes1

Uploaded by

kanthykoduru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ABAP Syntaxes:

ABAP Editor:

Every line in ABAP editor contains either a commented line or an executable statement.

Comment: This is to provide useful information to specify the purpose of the block of code.

To comment line – Use * at column 1 of each line or place the cursor anywhere on the line and use
CTRL + <

To uncomment line – Remove * at column 1 or place the cursor anywhere on the line and use CTRL +
>

To comment line partially – Place the cursor from where you want to comment and use “

To uncomment partially commented line – Remove “

To comment block of lines – Select all the lines and use CTRL with <

To uncomment block of lines – Select all the lines and use CTRL with >

Executable statement:

An executable statement is the combination of keywords, operators, variables.

Every executable statement ends with full stop (.)

Code can be N of lines but until full stop it considers as a single statement.

Comma (,) – for continuation, i.e statement is not yet completed.

Chain Operator (: ) – To avoid repetition of keywords.

Hyphen (-) – To refer an element of another element.

Ex. EKKO is a structure and EBELN, BUKRS, BSART are the fields inside this structure then if I have to
refer EBELN only then we need to write as EKKO-EBELN.

Keywords: All blue colour words are keywords.

Operators: All mathematical, Comparative, Logic operators are available.

Space is required before and after of each operator.

*** Variables: It is the name to be given for a memory storage location.

TYPES – To create reference to create variables.

DATA – To create a variable (Single Variable, Structure, Table).

CONSTANTS – To create fixed value variables.

TYPE – To refer a Data Element, Structure, Table, Table Type, Etc..

LIKE – To refer an object (Work Area, Internal Table, Variable).

We always use TYPE instead of LIKE.


Note - Name can be anything between < >.

Single Variable – Holds a single value.

Either we can refer to a data type with length or we can refer to a data element.

We always use data element as reference.

DATA <gv_var1> TYPE C LENGTH 10.

DATA <gv_var1> TYPE vbeln.

Structure – Holds single record with multiple fields.

Either we can refer to a local TYPES or we can refer to a global (SE11) structure.

TYPES: BEGIN OF gty_vbakx,

vbeln TYPE vbeln,

posnr TYPE posnr,

bukrs TYPE bukrs,

END OF gty_vbakx.

DATA <gs_struc1> TYPE gty_vbakx.

DATA <gs_struc1> TYPE zsvbakx. (zsvbakx is a structure created in SE11).

Internal Table – Holds multiple records with multiple fields.

Either we can refer to a local TYPES or we can refer to a global (SE11) structure or table type.

TYPES: BEGIN OF gty_vbakx,

vbeln TYPE vbeln,

posnr TYPE posnr,

bukrs TYPE bukrs,

END OF gty_vbakx.

DATA <gt_tab1> TYPE TABLE OF gty_vbakx.

DATA <gt_tab1> TYPE TABLE OF zsvbakx. (zsvbakx is a structure created in SE11).

DATA <gt_tab1> TYPE zttvbakx. (zttvbakx is a table type created in SE11).


Database table operations:

INSERT: It inserts new record, if already a record exist with same key fields then it goes to dump or
gives you error.

Insert single record into DB table.

1. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
2. Prepare data into structure fields.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
3. Use below syntax.

Syntax – INSERT <db table> FROM <gs_struc1>.

 APPEND is the keyword to insert a record at the end of an internal table.

Insert multiple records into DB table.

1. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
2. Declare a table with same type of DB table.
DATA <gt_tab1> TYPE TABLE OF <db table>.
3. Prepare data into structure.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
4. Fill internal table with each record using APPEND statement.
APPEND <gs_struc1> TO <gt_tab1>.
Repeat steps 3 & 4 for N number of records.
5. Use below syntax to insert.

Syntax – INSERT <db table> FROM TABLE <gt_tab1>.

UPDATE: It updates only if the matching record found using key fields.

If record does not exist then it fails to update.

Update single record into DB table.

1. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
2. Prepare data into structure fields.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
3. Use below syntax.
Syntax – UPDATE <db table> FROM <gs_struc1>.

Update multiple records into DB table.

1. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
2. Declare a table with same type of DB table.
DATA <gt_tab1> TYPE TABLE OF <db table>.
3. Prepare data into structure.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
4. Fill internal table with each record using APPEND statement.
APPEND <gs_struc1> TO <gt_tab1>.
Repeat steps 3 & 4 for N number of records.
5. Use below syntax to insert.

Syntax – UPDATE <db table> FROM TABLE <gt_tab1>.

MODIFY: It updates if the matching record found using key fields.

If record does not exist then it inserts new record.

MODIFY = INSERT + UPDATE.

Modify never fails so we use MODIFY for all cases.

Modify single record into DB table.

4. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
5. Prepare data into structure fields.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
6. Use below syntax.

Syntax – MODIFY <db table> FROM <gs_struc1>.

Modify multiple records into DB table.

6. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
7. Declare a table with same type of DB table.
DATA <gt_tab1> TYPE TABLE OF <db table>.
8. Prepare data into structure.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
9. Fill internal table with each record using APPEND statement.
APPEND <gs_struc1> TO <gt_tab1>.
Repeat steps 3 & 4 for N number of records.
10. Use below syntax to insert.
Syntax – MODIFY <db table> FROM TABLE <gt_tab1>.

DELETE: It deletes if the matching record found using key fields.

So just filling key fields to structure or internal table is enough to delete.

Delete single record into DB table.

7. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
8. Prepare data into structure fields.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
9. Use below syntax.

Syntax – DELETE <db table> FROM <gs_struc1>.

Delete multiple records into DB table.

11. Declare a structure with same type of DB table.


DATA <gs_struc1> TYPE <db table>.
12. Declare a table with same type of DB table.
DATA <gt_tab1> TYPE TABLE OF <db table>.
13. Prepare data into structure.
<gs_struc1>-field1 = ‘ABCD’.
<gs_struc1>-field2 = ‘XYZ’.
<gs_struc1>-field3 = ‘123’.
14. Fill internal table with each record using APPEND statement.
APPEND <gs_struc1> TO <gt_tab1>.
Repeat steps 3 & 4 for N number of records.
15. Use below syntax to insert.

Syntax – DELETE <db table> FROM TABLE <gt_tab1>.

To print messages: (E, I, S, W – should be in capital).

MESSAGE ‘Data modified successfully’ TYPE ‘S’.

Refresh the variables:

CLEAR – to clear the value in variable or a structure.

REFRESH – to clear the data of an internal table.

FREE – to clear the data and memory of an internal table.

To print output:

WRITE – to print the fixed value or a variable in output.

*** All fixed values must be declared using CONSTANTS keyword or using single quotes.

Variables should not be in single quotes.


In real time we never perform INSERT/UPDATE/MODIFY/DELETE on standard tables directly (but
we can perform on custom tables), because there should be dependencies which will impact so
we use FM/BDC to perform these operations.

Single I/P value:

PARAMETERS is the keyword to create single input value in a selection screen.

Syntax – PARAMETERS <p_val1> TYPE vbeln.

Range of I/P values:

It’s a two step process:

1. Create a variable referring to the data element.


2. Create I/P with range referring to the variable.

SELECT-OPTIONS is the keyword to create range of values of a single field.

1. Create a variable referring to a data element.


DATA <gv_var1> TYPE vbeln.
2. Create input field referring to the variable.
SELECT-OPTIONS <s_vbeln> FOR <gv_var1>.

You might also like