Wednesday, April 7, 2010

How to Assign Dynamic Fields using Filed-Symbols in ABAP/4

You can create field name in run time and assign the created name in your field-symbols by statement "ASSIGN ... TO ...".

Example

DATA: name(20),

lv_check(1).

DATA: BEGIN OF itab OCCURS 0,
fld1(4),
fld2(4),

END OF itab.

FIELD-SYMBOLS .

...

...

LOOP AT itab.

IF lv_check = ’X’.

name = ’ITAB-FLD1’.

ELSE.

name = ’ITAB-FLD2’.

ENDIF.

ASSIGN (name) TO .

...

...

ENDLOOP.

Color in ABAP/4

Name Code Color

COL_BACKGROUND 0 depends on GUI

COL_HEADING 1 grayish-blue
COL_NORMAL 2 bright gray
COL_TOTAL 3 yellow
COL_KEY 4 bluish green
COL_POSITIVE 5 green
COL_NEGATIVE 6 red
COL_GROUP 7 violet

FORMAT Options of Format Statement in ABAP/4

Option          Description
COLOR n Specific background colors
INTENSIFIED Intensified the background color
INVERSE Swap background and foreground color
HOTSPOT Effect when mouse pointer and click
INPUT Generate input field
RESET Reset formats. The format will be backed to default format.

System Field When Generate ABAP/4 Report (Often to use)

Field     Description
COLNO the current column
LINNO the current line
LINCT Number of list lines
LINSZ Line size of list
SROWS Number of lines on screen
SCOLS Number of column on screen
TITLE Program title
PAGNO Current page in list

How to Find the Number of Entries of Internal Table in ABAP/4

We can find out how many entries of internal table by apply statement "DESCRIBE".

Example

DATA: it_tab TYPE TABLE OF BKPF WITH HEADER LINE,
tot_lines TYPE i.
...
...
DESCRIBE TABLE it_tab LINES tot_lines.

Or you can apply statement ’LOOP AT’ and count it.

Example

LOOP AT it_tab.
tot_lines = tot_lines + 1.
ENDLOOP.

Operator for comparing strings in ABAP/4

Operator     Description
CO Contains Only
CN Contains Not Only
CA Contains Any
NA Contains Not Any
CS Contains String
NS Contains No String
CP Matches Pattern
NP Not Match Pattern

How to Read Table Dynamically in ABAP/4

About statement "READ TABLE", we can generate code for read key dynamic as below:

DATA: BEGIN OF itab OCCURS 0,
fld1(2),

fld2(2),

fld3(10),

fld4 TYPE i,

END OF itab,

wa_tab LIKE itab,

gv_key1(4) TYPE C VALUE ’FLD1’,

gv_key2(4) TYPE C VALUE ’FLD2’.

...

...

...

READ TABLE itab INTO wa_tab
WITH KEY (gv_key1) = ’AA’
(gv_key2) = ’BB’.