Академический Документы
Профессиональный Документы
Культура Документы
abap программа обучения
abap программа обучения
1 400
2 401
1 https://docs.google.com/file/d/0B2Q-dt5t3a6JWXltbGp6OU9Ud1E/edit
2 https://docs.google.com/file/d/0B2Q-dt5t3a6JM2hsZDl6OVZ1bFU/edit
3 402
https://habrahabr.ru/post/270335/
http://www.bourabai.kz/cm/abap.htm
: ALV grid
1
2
3
ABAP-
,
.
.
:
-ABAP- ;
- ABAP-
,
. .;
- (
,
);
-
(
, , ,
);
-
;
-
.
, ABAP-
,
.
ABAP-
( ),
ABAP-.
(
.)
.
,
6
, .
,
, ,
,
,
.
.
,
.
7
ABAP
ABAP,
SAP
( ). :
.
ABAP
. ,
, .
(
).
.
8
TYPES my_c_type1(8) TYPE c. " char 8
TYPES my_c_type2(5) TYPE n. "char numeric 5
TYPES my_c_type3(6) TYPE x. "byte numeric 6
TYPES my_c_type4(6) TYPE p. "package numeric 6
full data
TYPES my_c_type5 TYPE d. " date ggggmmdd(8)
TYPES my_c_type6 TYPE t. " time hhmmss(6)
TYPES my_c_type7 TYPE i. " int 4
TYPES my_c_type8 TYPE f. " float 8
TYPES my_c_type9 TYPE string. " string dynamic lenght
TYPES my_c_type10 TYPE xstring. " byte dynamic length
/
"local type
TYPES type_name type string.
DATA my_var TYPE type_name.
move
move mvar02 to mvar01 ... this copy: var2 = var1
data mvar01 type string value 'aaa'.
data mvar02 type string value 'bbb'.
move mvar02 to mvar01.
write mvar01.
clear
clear - this delete varyable
data mvar03 type string value 'aaa'.
data mvar04 type string value 'bbb'.
9
clear mvar04.
write mvar04.
arifmetical operation
+-/*
* stepen
div delenie na cheloe bez ostatka
mod delenie na cheloe chislo s ostatkom
write res .
length
lenght
data mvar01 type string value 'aaa'.
data lenght type i.
If/case
if/ case
data mavar01 type i.
mavar01 = -5.
if mavar01 > 0.
write 'mavar01 > 0'.
elseif mavar01 = 0.
write 'if mavar01= 0? mavar01=0'.
case mavar01.
when 1.
NEW-LINE.
write '1'.
write '1_1'.
when 2.
NEW-LINE.
write '2'.
write '2_1'.
when others.
NEW-LINE.
write '3'.
10
write '3_1'.
write '4'.
write '4_1'.
endcase.
"cycle
write 'do'.
do.
if sy-index = 3.
exit.
endif.
new-line.
write sy-index.
enddo.
new-line.
write 'while'.
data i type i value 0.
while i <= 4.
new-line.
write sy-index.
i = i + 1.
endwhile.
loop at <internal_table>.
endloop.
Messages in ABAP
Messages are usually used to tell the user what is going on. The following types of messages are
available in ABAP.
11
Depending on the program context, an error dialog appears
W Warning program terminates.
No message is displayed, and the program terminates with a sh
dump. Program terminations with a short dump normally only o
X Exit when a runtime error occurs.
The syntax for issuing a message is as follows.
MESSAGE<message>TYPE<messagetype>.
We can issue a status message as follows. Status message will be displayed in the status bar.
After the message is displayed the program continues after the MESSAGE statement.
MESSAGE'Thisisastatusmessage'TYPE'S'.
Information message will be displayed in a dialog box. Once the user has confirmed the
message, the program continues immediately after the MESSAGE statement.
MESSAGE'Thisisaninformationmessage'TYPE'I'.
Error message in report programs will be displayed in the status bar and when the user press
enter, the program terminates.
MESSAGE'Thisisanerrormessage'TYPE'E'.
MESSAGE'Thisproducesshortdump'TYPE'X'.
12
Termination Message appears in a dialog box, and the program terminates. When the user
has confirmed the message, control returns to the next-highest area menu.
MESSAGE'Thisisterminationmessage'TYPE'A'.
Instead of hardcode the message text in the program we can maintain the message text in text
symbols. In order to maintain text symbols use the menu path Goto->Text Elements->Text Symbols
in ABAP editor.
In the text symbols screen we can maintain the messages with a 3 character identifier.
13
Then use the following message statement.
MESSAGEtext-001TYPE'I'.
We know that we can use MESSAGE statement to issue a message in ABAP. What if we want to
issue the same message in more than one program? Do we need to hard code the same message text
or maintain the same text symbols in all the programs? The answer is NO. Instead of maintaining the
same message text in all the programs maintain the message in a Message class and use it in all the
programs.
Message Class is a like a container which holds a number of different messages. Each message in the
message class is identified with unique message number. So when you call a message in a ABAP
program, you need to specify the message class and message number.
First go to t-code SE91 i.e. Message Maintenance, enter the name of the message class and click on
create button.
14
Maintain the required message texts with message numbers. Then save the entries and assign it to
proper development class and transport request. Once the message class is saved we can use it in
our ABAP programs.
MESSAGEs000(ztest).
Output
15
In the above code, the message number, message class and message type are specified in the
MESSAGE statement. We can also specify the message class in the REPORT statement as shown
below, so that we can skip the message class in the MESSAGE statements of the program.
REPORTzmessages
MESSAGE-ID ztest
MESSAGEs000.
In the above message & is the placeholder. At runtime the placeholders (&) will be replaced by the
variable values specified in the MESSAGE statement.
REPORTzmessagesMESSAGEIDztest.
MESSAGEs001
16
.
Output
The values XYZ and 1000 replaces the placeholders in the actual message.
17
,
.
/
.
.
10
( ).
18
ABAP
(
).
,
.
. ,
.
DATA .
:
19
- ;
- (
);
- , .
insert
"insert table
20
MOVE-CORRESPONDING
. ,
.
.
MOVE.
,
:
21
()
.
,
.
,
, , .
.
.
, .
,
, , ,
.
-
.
. -
.
,
,
.
22
APPEND
23
.
.
INSERT
.
,
, -
-.
READ
.
MODIFY
.
DELETE
.
COLLECT
,
.
. ,
24
LOOP . . . ENDLOOP
LOOP
, INTO.
LOOP
.
DELETE
,
<>.
INSERT
.
APPEND
25
.
ABAP- .
REPORT ZBC400_135.
26
" declare internal table
data itab_scarr1 type STANDARD TABLE OF s_struc1.
data itab_scarr2 type STANDARD TABLE OF s_struc2.
data itab_scarr3 type STANDARD TABLE OF s_struc3.
"wa_itab_scarr2
wa_itab_scarr2-FIELD1 = 1.wa_itab_scarr2-FIELD2 = 2.wa_itab_scarr2-FIELD3 =
2.wa_itab_scarr2-FIELD4 = 44.
insert wa_itab_scarr2 into TABLE itab_scarr2.
"wa_itab_scarr3
wa_itab_scarr3-FIELD1 = 1.wa_itab_scarr3-FIELD2 = 2.wa_itab_scarr3-FIELD3 =
2.wa_itab_scarr3-FIELD4 = 44.wa_itab_scarr3-field5 = 'record1'.
insert wa_itab_scarr3 into TABLE itab_scarr3.
"MODIFY
NEW-LINE.
27
wa_itab_scarr1-FIELD3.
endloop.
"modify
wa_itab_scarr1-FIELD2 = 77777.
MODIFY ITAB_SCARR1 FROM WA_ITAB_SCARR1 TRANSPORTING FIELD2
WHERE FIELD2 = '2' OR FIELD2 = '5'.
concatenate
data a type string value 'aaa'.
data b type string value 'bbbb'.
concatenate a b 'klkjll' into b.
ABAP
TYPES: BEGIN OF struct1,
field1 TYPE i,
field2 TYPE i,
field3 TYPE i,
END OF struct1.
wa_itab_01-field1 = 1.
wa_itab_01-field2 = 2.
wa_itab_01-field3 = 3.
INSERT wa_itab_01 INTO TABLE itab_t01.
28
wa_itab_01-field1 = 1.
wa_itab_01-field2 = 5.
wa_itab_01-field3 = 6.
INSERT wa_itab_01 INTO TABLE itab_t01.
wa_itab_01-field1 = 4.
wa_itab_01-field2 = 5.
wa_itab_01-field3 = 6.
INSERT wa_itab_01 INTO TABLE itab_t01.
wa_itab_01-field1 = 10.
wa_itab_01-field2 = 5.
wa_itab_01-field3 = 6.
INSERT wa_itab_01 INTO TABLE itab_t01.
wa_itab_01-field1 = 11.
wa_itab_01-field2 = 7.
wa_itab_01-field3 = 6.
INSERT wa_itab_01 INTO TABLE itab_t01.
IF pa_from1 <> 0.
strsql = ' field1 = pa_from1 '.
ENDIF.
IF pa_from2 <> 0.
IF pa_from1 <> 0.
CONCATENATE strsql ' AND field2 = pa_from2 ' INTO strsql.
else.
strsql = ' field2 = pa_from2 '.
ENDIF.
ENDIF.
IF pa_from3 <> 0.
IF pa_from2 <> 0 OR pa_from1 <> 0.
CONCATENATE strsql ' AND field3 = pa_from3 ' INTO strsql.
else.
strsql = ' field3 = pa_from3 '.
ENDIF.
ENDIF.
*
*loop at itab_t01 into wa_itab_01.
*
*
*
** IF pa_from3 IS INITIAL.
** strSQL = ' field3 = pa_from3 '.
** ENDIF.
*
*
*
29
*
*endloop.
WRITE:/ 'strSQL: ', strsql .
NEW-LINE.
write b.
* write wa_itab_01-field1.
* write wa_itab_01-field2.
* write wa_itab_01-field3.
* new-line.
ABAP
AUTHORITY-CHECK
1 su20 .
30
2-
31
32
Su21
.
33
34
, .
35
.
36
.
37
SAP _ALL
38
pfcg.
39
.
40
41
42
AA AU
43
*&---------------------------------------------------------------------*
*& Report ZE01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZE01.
end of s_struc1.
"
PARAMETERS p_carrid type sflight-carrid.
if sy-subrc eq 0.
message ' ' type 'I'.
write :/
wa_itab_scarr1-MANDT,
wa_itab_scarr1-CARRID,
wa_itab_scarr1-CONNID,
wa_itab_scarr1-FLDATE,
wa_itab_scarr1-PRICE,
wa_itab_scarr1-CURRENCY,
wa_itab_scarr1-PLANETYPE.
ENDSELECT.
else.
message ' ' type 'I'.
endif.
45
SAP
END OF s_struc1.
wa_itab_scarr1-FLDATE = '20161203'.
wa_itab_scarr1-PRICE = 10.
wa_itab_scarr1-CURRENCY = '$'.
wa_itab_scarr1-PLANETYPE = 'rur0'.
ABAP
47
48
.
REPORT ZE02.
IF add = 'X'.
result = opt1 + opt2.
write: 'result', result.
NEW-LINE.
write sy-uname.
NEW-LINE.
write sy-datum.
ENDIF.
IF sub = 'X'.
result = opt1 - opt2.
write: 'result', result.
NEW-LINE.
write sy-uname.
NEW-LINE.
write sy-datum.
ENDIF.
IF mult = 'X'.
result = opt1 * opt2.
write: 'result', result.
49
NEW-LINE.
write sy-uname.
NEW-LINE.
write sy-datum.
ENDIF.
IF div = 'X'.
result = opt1 / opt2.
write: 'result', result.
NEW-LINE.
write sy-uname.
NEW-LINE.
write sy-datum.
ENDIF.
*&---------------------------------------------------------------------*
*& Report ZE02
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZE02.
IF add = 'X'.
result = opt1 + opt2.
perform print_system_data_and_resault USING result.
ENDIF.
IF sub = 'X'.
result = opt1 - opt2.
perform print_system_data_and_resault USING result.
ENDIF.
IF mult = 'X'.
result = opt1 * opt2.
perform print_system_data_and_resault USING result.
ENDIF.
IF div = 'X'.
result = opt1 / opt2.
perform print_system_data_and_resault USING result.
ENDIF.
NEW-LINE.
*form print_system_data.
* new-line.
50
* write sy-uname.
* new-line.
* write sy-datum.
*endform.
*"3" by referense
*write: 'opt2-before' , opt2.
*PERFORM testing_parameters using result changing opt1 opt2.
*NEW-LINE.
*write: 'opt2_after' , opt2.
*&---------------------------------------------------------------------*
*& Form PRINT_SYSTEM_DATA_AND_RESAULT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_RESULT text
*----------------------------------------------------------------------*
form PRINT_SYSTEM_DATA_AND_RESAULT using p_result.
write: 'p_result: ', p_result.
new-line.
write sy-uname.
new-line.
write sy-datum.
endform. " PRINT_SYSTEM_DATA_AND_RESAULT
*&---------------------------------------------------------------------*
*& Form TESTING_PARAMETERS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_RESULT text
* <--P_OPT1 text
* <--P_OPT2 text
*----------------------------------------------------------------------*
form TESTING_PARAMETERS using value(p_result)" by value
changing value(p_opt1) " by value and result
p_opt2. " by referense
add 1 to p_result.
write: 'result inside: ', p_result.
" .
*add 1 to p_opt1.
*write: 'p_opt1 optional inside: ', p_opt1.
51
" .
*add 1 to p_opt2.
*write: 'p_opt2 optional inside: ', p_opt2.
" .
endform. " TESTING_PARAMETERS
52
3 *"3" by referense
53
REPORT Z177DELETESPACES.
data: i type i,
len type i.
do len times.
if str+i(1) = ' '.
flag = 'X'.
else.
if flag = 'X'.
CONCATENATE dummy str+i(1) into dummy SEPARATED BY space.
clear flag.
else.
CONCATENATE dummy str+i(1) into dummy.
endif.
endif.
i = i + 1.
enddo.
write: / str.
new-line.
write dummy .
ABAP 1
*&---------------------------------------------------------------------*
*& Report ZE03
*&
*&---------------------------------------------------------------------*
54
*&
*&
*&---------------------------------------------------------------------*
REPORT ze03.
INITIALIZATION.
IF pa_date = sy-datum.
pa_date = pa_date + 7.
ENDIF.
START-OF-SELECTION.
WRITE pa_date.
ABAP 2
*&---------------------------------------------------------------------*
*& Report ZE03
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
INITIALIZATION.
WRITE 'initialization'.
AT SELECTION-SCREEN OUTPUT.
WRITE 'at AT SELECTION-SCREEN OUTPUT.' TO p_second.
*"
*LOOP AT SCREEN.
* screen-input = ''.
* MODIFY SCREEN.
*ENDLOOP.
55
AT SELECTION-SCREEN.
WRITE 'AT SELECTION-SCREEN.'.
START-OF-SELECTION.
WRITE 'START-OF-SELECTION..'.
DO 100 TIMES.
WRITE : / 'start of selection'.
ENDDO.
END-OF-SELECTION.
WRITE 'END-OF-SELECTION...'.
TOP-OF-PAGE.
WRITE:/ 'TOP_PAGE'.
END-OF-PAGE.
WRITE:/ 'END_PAGE'.
56
57
58
59
SELECTION-SCREEN
. ,
,
,
.
,
.
60
ALV
*&---------------------------------------------------------------------*
*& Report ZE05
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ze05.
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_kna1,
kunnr TYPE kunnr,
name1 TYPE name1,
END OF ty_kna1.
61
SELECT-OPTIONS: s_kunnr FOR wa_kna1-kunnr.
SELECT
kunnr
name1
FROM kna1
INTO TABLE it_kna1.
"WHERE
" kunnr IN s_kunnr.
wa_fieldcat-col_pos = '1'.
wa_fieldcat-row_pos = '1'.
wa_fieldcat-tabname = 'KNA1'.
wa_fieldcat-fieldname = 'KUNNR'.
wa_fieldcat-seltext_m = 'customer'.
"wa_fieldcat-fieldname = 'PSPID'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = '2'.
wa_fieldcat-row_pos = '1'.
wa_fieldcat-tabname = 'KNA1'.
wa_fieldcat-fieldname = 'NAME1'.
wa_fieldcat-seltext_m = 'NAME222'.
"wa_fieldcat-fieldname = 'PSPID'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
62
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_kna1
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
!!!
ALV c +
https://www.youtube.com/watch?v=tzV3zyR1XVM
63
64
65
66
Back
67
PBO-
68
.
69
.
.
70
71
ALV2
72
.
73
74
ALV 2
REPORT ze05_2.
*global object
* global table
data: it_sflight type TABLE OF sflight,
it_sbook TYPE TABLE OF sbook.
.
process before output.
module status_0100.
module select_data.
*
75
process after input.
module user_command_0100.
*&---------------------------------------------------------------------*
*& Include Z_PBO_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_0100 output.
SET PF-STATUS 'STATUS0100'.
"SET TITLEBAR 'xxx'.
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE SELECT_DATA.
MODULE CREATE_GRID1.
*
76
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
*& Include Z_PBO_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS0100'.
"SET TITLEBAR 'xxx'.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
78
*&---------------------------------------------------------------------*
*& Include Z_PAI_I01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
grid2 https://www.youtube.com/watch?v=tzV3zyR1XVM
*&---------------------------------------------------------------------*
*& Include Z_PBO_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status 'STATUS0100'.
"SET TITLEBAR 'xxx'.
79
endmodule. " SELECT_DATA OUTPUT
*&---------------------------------------------------------------------*
*& Module CREATE_GRID1 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module create_grid1 output.
if sy-subrc <> 0.
endif.
endif.
80
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
if sy-subrc <> 0.
endif.
endif.
81
ALV .
,
*&---------------------------------------------------------------------*
*& Report Z_GAZ_PSA01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_gaz_psa01.
SELECT
usr21~bname
adrp~name_text
adcp~tel_number
adcp~tel_extens
adr6~smtp_addr
.
"where adr6~smtp_addr = '' .
.
WRITE: /
wa_itab_scarr1-bname,
wa_itab_scarr1-name_text,
wa_itab_scarr1-tel_number,
wa_itab_scarr1-tel_extens,
wa_itab_scarr1-smtp_addr.
NEW-LINE.
ENDSELECT.
1 button
REPORT Z_GAZ_PSA_BUTTON01.
TABLES: sscrfields.
INITIALIZATION.
but1 = 'Hi'.
but2 = 'Bye'.
AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'USR1'.
MESSAGE 'Hi' TYPE 'S'.
WHEN 'USR2'.
MESSAGE 'Bye' TYPE 'S'.
ENDCASE.
83
ABAP XML
SAP
.
yrs_class_download
yrs_class_upload_xml
include:
YRS_CLASS_XML_CONST
ZBC400IN071
SINGLE MANDT
SY-SUBRC , SY-DBCNT
.
84