Вы находитесь на странице: 1из 84

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.

DATA myvar2 LIKE my_var."link on exist varible

CONSTANTS my_const TYPE string value 'sdsd'.

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

data int_01 type i value 5.


data int_02 type i value 10.
data int_03 type i value 3.
data res type float.

res = ( int_02 + int_01 ) / int_03.

write res .

length
lenght
data mvar01 type string value 'aaa'.
data lenght type i.

lenght = STRLEN( mvar01 ).


write lenght.

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'.

else . "if mavar01 > 0


write 'if mavar01 > 0 mavar01'.
endif.

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.

select * from <table_BD>.


endselect.

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.

The message appears in a dialog box, and the program termina


Terminatio When the user has confirmed the message, control returns to th
A n highest area menu.
Depending on the program context, an error dialog appears
E Error program terminates.
The message appears in a dialog box. Once the user has confirm
message, the program continues immediately after
I Status the MESSAGE statement.
The program continues normally after the MESSAGE statement
S Error message is displayed in the status bar of the next screen.

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'.

Warning message behaves similar to error message in report programs.


Exit Message No message is displayed, and the program terminates with a short dump. Short
dumps can be viewed in t-code ST22.

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'.

SAP Message Class

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.

What is a Message Class?

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.

How to create a Message Class?

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.

Messages can be issued as follows.

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.

We can also maintain placeholders for variables in messages.

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

WITH XYZ 1000

16
.

Output

The values XYZ and 1000 replaces the placeholders in the actual message.

17
,

.

/


.




.
10

( ).

18

ABAP
(
).

,
.
. ,


.


DATA .

:

19
- ;
- (

);
- , .

insert
"insert table

DATA scarr_wa type scarr.


scarr_wa-carrid = 'AE'. "key
scarr_wa-carrname = 'aeroflot3'.
scarr_wa-currcode = 'RUB'.
scarr_wa-url = 'http://www.aeroflot3.ru'.

INSERT INTO scarr VALUES scarr_wa.

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.

TYPES: BEGIN OF s_struc1,


field1 type i,
field2 type i,
field3 type i,
END OF s_struc1.

TYPES: BEGIN OF s_struc2,


field1 type i,
field2 type i,
field3 type i,
field4 type i,
END OF s_struc2.

TYPES: BEGIN OF s_struc3,


field1 type i,
field2 type i,
field3 type i,
field4 type i,
field5 type string,
END OF s_struc3.

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.

"declare working area internal table


data wa_itab_scarr1 like LINE OF itab_scarr1.
data wa_itab_scarr2 like LINE OF itab_scarr2.
data wa_itab_scarr3 like LINE OF itab_scarr3.

"inichializaion variables and insert


"wa_itab_scarr1
wa_itab_scarr1-FIELD1 = 1.wa_itab_scarr1-FIELD2 = 2.wa_itab_scarr1-FIELD3 =
2.
insert wa_itab_scarr1 into TABLE itab_scarr1.

wa_itab_scarr1-FIELD1 = 2.wa_itab_scarr1-FIELD2 = 4.wa_itab_scarr1-FIELD3 =


6.
insert wa_itab_scarr1 into TABLE itab_scarr1.

wa_itab_scarr1-FIELD1 = 3.wa_itab_scarr1-FIELD2 = 5.wa_itab_scarr1-FIELD3 =


7.
insert wa_itab_scarr1 into TABLE itab_scarr1.

"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_scarr2-FIELD1 = 2.wa_itab_scarr2-FIELD2 = 4.wa_itab_scarr2-FIELD3 =


6.wa_itab_scarr2-FIELD4 = 55.
insert wa_itab_scarr2 into TABLE itab_scarr2.

wa_itab_scarr2-FIELD1 = 3.wa_itab_scarr2-FIELD2 = 5.wa_itab_scarr2-FIELD3 =


7.wa_itab_scarr2-FIELD4 = 66.
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.

wa_itab_scarr3-FIELD1 = 2.wa_itab_scarr3-FIELD2 = 4.wa_itab_scarr3-FIELD3 =


6.wa_itab_scarr3-FIELD4 = 55.wa_itab_scarr3-field5 = 'record2'.
insert wa_itab_scarr3 into TABLE itab_scarr3.

wa_itab_scarr3-FIELD1 = 3.wa_itab_scarr3-FIELD2 = 5.wa_itab_scarr3-FIELD3 =


7.wa_itab_scarr3-FIELD4 = 66.wa_itab_scarr3-field5 = 'record3'.
insert wa_itab_scarr3 into TABLE itab_scarr3.

"MODIFY
NEW-LINE.

LOOP AT ITAB_SCARR1 into WA_ITAB_SCARR1.


write: /
wa_itab_scarr1-FIELD1,
wa_itab_scarr1-FIELD2,

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'.

LOOP AT ITAB_SCARR1 into WA_ITAB_SCARR1.


write: /
wa_itab_scarr1-FIELD1,
wa_itab_scarr1-FIELD2,
wa_itab_scarr1-FIELD3.
endloop.

"read - write one uniqle record!


new-line.
write 'read'.
read table ITAB_SCARR3 into WA_ITAB_SCARR3 "write one uniqle record!"
WITH TABLE KEY field5 = 'record3'.
if sy-subrc = 0.
write: / WA_ITAB_SCARR3-FIELD1,
WA_ITAB_SCARR3-FIELD2,
WA_ITAB_SCARR3-FIELD3,
WA_ITAB_SCARR3-FIELD4,
WA_ITAB_SCARR3-FIELD5.
endif.

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.

DATA itab_t01 TYPE STANDARD TABLE OF struct1. " internal table


DATA wa_itab_01 LIKE LINE OF itab_t01.

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.

PARAMETERS pa_from1 TYPE struct1-field1.


PARAMETERS pa_from2 TYPE struct1-field2.
PARAMETERS pa_from3 TYPE struct1-field3.
"PARAMETERS pa_from5 TYPE sy-time.

DATA strsql TYPE string. " command sql

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.

data a type string value 'aaa'.


data b type string value 'bbbb'.
concatenate a b 'klkjll' into b.

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.

types: begin of s_struc1,


mandt type mandt,
carrid type s_carr_id,
connid type s_conn_id,
fldate type s_date,
price type s_price,
currency type s_currcode,
planetype type s_planetye,

end of s_struc1.

data itab_scarr1 type STANDARD TABLE OF s_struc1.


data wa_itab_scarr1 like LINE OF itab_scarr1.

"
PARAMETERS p_carrid type sflight-carrid.

AUTHORITY-CHECK OBJECT 'ZAOCARRID'


ID 'ZCARRID' FIELD p_carrid
44
ID 'ACTVT' FIELD '03'.

if sy-subrc eq 0.
message ' ' type 'I'.

SELECT * from sflight into corresponding fields of wa_itab_scarr1.

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

TYPES: BEGIN OF s_struc1,


MANDT type MANDT,
46
CARRID type S_CARR_ID,
CONNID type S_CONN_ID,
FLDATE type S_DATE,
PRICE type S_PRICE,
CURRENCY type S_CURRCODE,
PLANETYPE type S_PLANETYE,

END OF s_struc1.

data itab_scarr1 type STANDARD TABLE OF sflight.

data wa_itab_scarr1 type sflight.


wa_itab_scarr1-MANDT = 100.
wa_itab_scarr1-CARRID = 'UA'.
wa_itab_scarr1-CONNID = '0280'.

wa_itab_scarr1-FLDATE = '20161203'.
wa_itab_scarr1-PRICE = 10.
wa_itab_scarr1-CURRENCY = '$'.
wa_itab_scarr1-PLANETYPE = 'rur0'.

insert into sflight values wa_itab_scarr1.

ABAP

47
48
.
REPORT ZE02.

data result type n.

PARAMETERS: opt1 type i.


PARAMETERS: opt2 type i.

PARAMETERS: add RADIOBUTTON GROUP gr01,


sub RADIOBUTTON GROUP gr01,
mult RADIOBUTTON GROUP gr01,
div RADIOBUTTON GROUP gr01.

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.

data result type n.

PARAMETERS: opt1 type i.


PARAMETERS: opt2 type i.

PARAMETERS: add RADIOBUTTON GROUP gr01,


sub RADIOBUTTON GROUP gr01,
mult RADIOBUTTON GROUP gr01,
div RADIOBUTTON GROUP gr01.

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.

"1 " by value


write: 'result-before' , result.
PERFORM testing_parameters using result changing opt1 opt2.
NEW-LINE.
write: 'result_after' , result.
" .

"2 " by value and result


*write: 'opt1-before' , opt1.
*PERFORM testing_parameters using result changing opt1 opt2.
*NEW-LINE.
*write: 'opt1_after' , opt1.
*" .

*"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

1 "1 " by value

2 " by value and result

52
3 *"3" by referense

53

REPORT Z177DELETESPACES.

data str(50) type c.


data dummy(50) type c.

str = 'aaa bb aaaaa aa rrr a ddd'.


"'1 /1 /4/6/1/2
data flag(1) type c.

data: i type i,
len type i.

len = strlen( str ).

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.

PARAMETERS pa_date LIKE sy-datum DEFAULT sy-datum.

INITIALIZATION.
IF pa_date = sy-datum.
pa_date = pa_date + 7.
ENDIF.

START-OF-SELECTION.

WRITE pa_date.

ABAP 2
*&---------------------------------------------------------------------*
*& Report ZE03
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ze03 LINE-COUNT 25(2). "2 top page end-page

*PARAMETERS pa_date LIKE sy-datum DEFAULT sy-datum.


*
*INITIALIZATION.
* IF pa_date = sy-datum.
* pa_date = pa_date + 7.
* ENDIF.
*
*START-OF-SELECTION.
*
* WRITE pa_date.

PARAMETERS: p_first TYPE i.


PARAMETERS: p_second(100).

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.'.

IF p_first IS NOT INITIAL .


MESSAGE 'please enter something' TYPE 'E'.
ENDIF.

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.

DATA: it_fieldcat TYPE slis_t_fieldcat_alv,


wa_fieldcat TYPE slis_fieldcat_alv,
it_kna1 TYPE TABLE OF ty_kna1,
wa_kna1 TYPE 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.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-cprog
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = it_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =

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

DATA: go_container1 TYPE REF TO cl_gui_custom_container,


go_container2 TYPE REF TO cl_gui_custom_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid.

* global table
data: it_sflight type TABLE OF sflight,
it_sbook TYPE TABLE OF sbook.

INCLUDE z_pbo_o01. "pbo module


INCLUDE z_pai_i01. "pai module

.
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'.

endmodule. " STATUS_0100 OUTPUT


*&---------------------------------------------------------------------*
*& Module SELECT_DATA OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module SELECT_DATA output.
select *
from sflight
into table it_sflight
up to 50 rows.
select *
from sbook
into table it_sbook
up to 50 rows.

endmodule. " SELECT_DATA OUTPUT


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'.

ENDMODULE. " STATUS_0100 OUTPUT


*&---------------------------------------------------------------------*
*& Module SELECT_DATA OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE select_data OUTPUT.
SELECT *
FROM sflight
INTO TABLE it_sflight
UP TO 50 ROWS.
SELECT *
FROM sbook
INTO TABLE it_sbook
UP TO 50 ROWS.

ENDMODULE. " SELECT_DATA OUTPUT


*&---------------------------------------------------------------------*
*& Module CREATE_GRID1 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE create_grid1 OUTPUT.

IF go_container1 IS NOT BOUND.


CREATE OBJECT go_container1
77
EXPORTING
container_name = 'CC_ALV1' "name of screen custctrl
EXCEPTIONS
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.

CHECK go_container1 IS BOUND.

CREATE OBJECT go_grid1


EXPORTING
i_parent = go_container1 " paren container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5.

CHECK go_grid1 IS BOUND.

CALL METHOD go_grid1->set_table_for_first_display


exporting
i_structure_name = 'SFLIGHT'
changing
it_outtab = it_sflight.

endmodule. " CREATE_GRID1 OUTPUT

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.

ENDMODULE. " USER_COMMAND_0100 INPUT

grid2 https://www.youtube.com/watch?v=tzV3zyR1XVM

process before output.


module status_0100.
module select_data.
module create_grid1.
module create_grid2.
*
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'.

endmodule. " STATUS_0100 OUTPUT


*&---------------------------------------------------------------------*
*& Module SELECT_DATA OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module select_data output.
select *
from sflight
into table it_sflight
up to 50 rows.
select *
from sbook
into table it_sbook
up to 50 rows.

79
endmodule. " SELECT_DATA OUTPUT
*&---------------------------------------------------------------------*
*& Module CREATE_GRID1 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module create_grid1 output.

if go_container1 is not bound.


create object go_container1
exporting
container_name = 'CC_ALV1' "name of screen custctrl
exceptions
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.

check go_container1 is bound.

create object go_grid1


exporting
i_parent = go_container1 " paren container
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.

check go_grid1 is bound.

call method go_grid1->set_table_for_first_display


exporting
i_structure_name = 'SFLIGHT'
changing
it_outtab = it_sflight.

endmodule. " CREATE_GRID1 OUTPUT


*&---------------------------------------------------------------------*
*& Module CREATE_GRID2 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module create_grid2 output.

if go_container2 is not bound.


create object go_container2
exporting
container_name = 'CC_ALV2' "name of screen custctrl
exceptions

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.

check go_container2 is bound.

create object go_grid2


exporting
i_parent = go_container2 " paren container
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.

check go_grid1 is bound.

call method go_grid2->set_table_for_first_display


exporting
i_structure_name = 'SFLIGHT'
changing
it_outtab = it_sflight.

endmodule. " CREATE_GRID2 OUTPUT

81
ALV .

,
*&---------------------------------------------------------------------*
*& Report Z_GAZ_PSA01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT z_gaz_psa01.

DATA: uname TYPE usr01-bname.

TYPES: BEGIN OF s_struc1,


bnane TYPE string,
smtp_addr(241) TYPE c,
dateupdaterecords TYPE d,
name_last(40) TYPE c,
END OF s_struc1.

TYPES: BEGIN OF s_user_info,


bname TYPE usr21-bname,
name_text TYPE adrp-name_text,
tel_number TYPE adcp-tel_number,
tel_extens TYPE adcp-tel_extens,
smtp_addr TYPE adr6-smtp_addr,
END OF s_user_info.

DATA itab_scarr1 TYPE STANDARD TABLE OF s_user_info.


DATA wa_itab_scarr1 LIKE LINE OF itab_scarr1.

SELECT
usr21~bname
adrp~name_text
adcp~tel_number
adcp~tel_extens
adr6~smtp_addr

FROM usr21 AS usr21


INNER JOIN adrc
ON usr21~addrnumber = adrc~addrnumber
INNER JOIN adrp
ON usr21~persnumber = adrp~persnumber
INNER JOIN adcp
ON usr21~addrnumber = adcp~addrnumber
AND usr21~persnumber = adcp~persnumber
INNER JOIN adr6
82
ON adcp~addrnumber = adr6~addrnumber
AND adcp~persnumber = adr6~persnumber
*LEFT JOIN adr2
* ON usr21~addrnumber = adr2~addrnumber
* AND usr21~persnumber = adr2~persnumber

"INNER JOIN adr6 as adr6 ON


" usr21~addrnumber = adr6~addrnumber
"AND
" usr21~persnumber = adr6~persnumber
*
*INNER JOIN v_usr_name AS v_usr_name ON
* usr21~bname = v_usr_name~bname
INTO wa_itab_scarr1.

.
"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.

"select Single usr21~bname into uname


"from usr21.
"inner join adr6
" on usr21~addrnumber = adr6~addrnumber
" and usr21~persnumber = adr6~persnumber
" where adr6~smtp_addr = YOU@YOURCOMPANY.COM'.

" write:/ uname.

1 button
REPORT Z_GAZ_PSA_BUTTON01.
TABLES: sscrfields.

SELECTION-SCREEN PUSHBUTTON 2(10) but1 USER-COMMAND usr1.


SELECTION-SCREEN PUSHBUTTON 20(10) but2 USER-COMMAND usr2.

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

Оценить