Az ABAP programozási nyelv

Helyesség

Prímszám kiíró program

Adott értékig felsorolja a prímszámokat.

REPORT zprime .
DATA : t_no TYPE i,
res TYPE p,
pr_no TYPE p,
tag TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS : pr_num TYPE i.
SELECTION-SCREEN END OF BLOCK b1.
pr_no = 1.
WHILE pr_no LE pr_num.
t_no = 2.
tag = 0.
WHILE t_no < pr_no.
res = pr_no MOD t_no.
IF res = 0.
WRITE : / pr_no.
WRITE : 'is not PRIME Number ' COLOR 3 INTENSIFIED OFF.
tag = 1.
EXIT.
ENDIF.
t_no = t_no + 1.
ENDWHILE.
IF tag = 0.
WRITE : / pr_no.
WRITE : 'is PRIME Number ' COLOR 6 INTENSIFIED OFF.
ENDIF.
pr_no = pr_no + 1.
ENDWHILE.

Dátum formázás

A program átalakít egy 20050428 formátumú dátumot, ilyenné: 28th Apr 2005.

FORM set_text_date.
DATA: month(9),
year(4),
date(2).
CASE p_frd+4(2).
WHEN '01'.
month = 'January'.
WHEN '02'.
month = 'February'.
WHEN '03'.
month = 'March'.
WHEN '04'.
month = 'April'.
WHEN '05'.
month = 'May'.
WHEN '06'.
month = 'June'.
WHEN '07'.
month = 'July'.
WHEN '08'.
month = 'August'.
WHEN '09'.
month = 'September'.
WHEN '10'.
month = 'October'.
WHEN '11'.
month = 'November'.
WHEN '12'.
month = 'December'.
WHEN OTHERS.
ENDCASE.
WRITE p_frd+0(4) TO year.
WRITE p_frd+6(2) TO date.
CONCATENATE month date ',' year INTO return_date SEPARATED BY space.
CONDENSE return_date.
ENDFORM.

ASCII kód és a neki megfelelő karakter közötti konvertálás

Hogyan alakítsuk át, az 'A' karaktere a neki megfelelő ASCII kóddá?

data : c value 'A'.
field-symbols : type x.
data : rn type i.
assign c to casting.
move to rn.
write rn.

Hogyan alakítsuk át, a 66-os ASCII kódot a neki megfeleő karakterré?

data : i type i value 66.
data : x type x.
field-symbols : type c.
move i to x.
assign x to casting type c.
move to c.
write c.

Könyvtár létrehozás

Egy adott könyvtár létrehozása a merevlemez-meghajtón.

REPORT ZGUI_DIR.

call function 'GUI_CREATE_DIRECTORY'
exporting
dirname = 'C:\TEST\'
EXCEPTIONS
FAILED = 1
OTHERS = 2.

if sy-subrc <> 0.
WRITE: / 'Error Code ',SY-SUBRC.
else.
WRITE: / 'Directory Created...'.
endif.

Fájlból olvasás

Adatfájlból való olvasás.

REPORT CHAP2602.
* Data declarations for later use
TABLES CUSTOMERS.
PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat'
LOWER CASE.
DATA: MSG_TEXT(50),
ALL_CUSTOMER_NAMES LIKE CUSTOMERS-NAME OCCURS 100
WITH HEADER LINE.
* Opening the File
OPEN DATASET FILENAME FOR INPUT IN TEXT MODE
MESSAGE MSG_TEXT.
IF SY-SUBRC NE 0.
WRITE: 'File cannot be opened.
Reason:', MSG_TEXT.
EXIT.
ENDIF.
* Reading Data
DO.
READ DATASET FILENAME INTO ALL_CUSTOMER_NAMES.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
APPEND ALL_CUSTOMER_NAMES.
ENDDO.
* Closing the file
CLOSE DATASET FILENAME.
* Display the result
LOOP AT ALL_CUSTOMER_NAMES.
WRITE / ALL_CUSTOMER_NAMES.
ENDLOOP.

Felhasználói megerősítés

REPORT ZPOPUPCONFIRM.
DATA: X_ANS(1) TYPE C.

call function 'POPUP_TO_CONFIRM_STEP'
exporting
* DEFAULTOPTION = 'Y'
textline1 = 'Do you want to continue'
* TEXTLINE2 = ' '
titel = 'Please Confirm'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
IMPORTING
ANSWER = X_ANS.

WRITE: / X_ANS.

Várakozás 30 másodpercig

FUNCTION Z_WAIT_30_SECS.

DATA: ZTIME LIKE SY-UZEIT.

GET TIME.

ZTIME = SY-UZEIT + 30.

DO.
GET TIME.
IF SY-UZEIT >= ZTIME.
EXIT.
ENDIF.
ENDDO.

ENDFUNCTION.