메뉴 건너뛰기

SAP 한국 커뮤니티

ABAP 핵심정리

SARA 2007.03.15 08:38 조회 수 : 17403 추천:38











AT


list 프로그램에서 줄바꿈이나 줄끝에 명령을 주기 위해 사용.

예제1>
LOOP AT -cofl_list ASSIGNING .
AT NEW cityto.
write :/8 -cityto.
ENDAT.
write :/16 -carrid,
-cannid.
ENDLOOP.

예제2>
LOOP AT it_flights INTO wa_flights.
ON CHANGE OF wa_flights-connid.
NEW-PAGE.
ENDON.

write:/ wa_flights-fldat,
................
AT line_size sy_vline.
ENDLOOP.

LINE-SIZE LINE-COUNT


LINE-SIZE 및 LINE-COUNT
Report 프로그램에서 REPORT 선언문과 함께 column과 line을
Global하게 setting 한다.

Line-size : 한 line에 보여줄 길이.
Line-count : 한 페이지에 보여줄 줄의 수를 말함.
Line-count = 10으로 하면 10개 적고 top-of-page의
내용이 적힌다.(new-page가 적용된다.)

<예제> REPORT sapbc405_fold_list_layout
LINE-SIZE 50
LINE-COUNT 12.

cf. list level에서 global한 line-size를 override하기 위해서는
NEW-PAGE LINE-COUNT 를 쓴다.



END-OF-PAGE


LIST 프로그램에서 FOOTER를 생성한다.

TOP-OF-PAGE


List 프로그램에서 Header를 제어하고자 할 때 쓰는 EVENT BLOCK.
This is triggered whenever a new page is created.

NO STANDARD PAGE HEADING.를 쓰지않고

TOP-OF-PAGE에서도 Header 정의하고, Text element에서도 정의하면
2가지 다 header 정보가 먹는다.


Format & Color



FORMAT COLOR [on|off]
INTENSIFIED [on|off]
INVERSE [on|off]
HOTSPOT [on|off]
INPUT [on|off]
RESET [on|off]

Currency & unit


Currency : Determines the number of decimal places for currency.

<예제>
Write AT: / sy-vline,
wa_sflight-price CURRENCY wa_sflight-currency.


Icon, line, symbol


<예제>

Report sapbc405_fold_icon_symbol_line.
*INCLUDE .
*INCLUDE .
INCLUDE . (Include 는 Include |
을 포괄적으로 내포한다.
IF SEATSFREE < 1.
write ICON_RED_LIGHT AS ICON.
ELSEIF SEATSFREE > 1.
write ICON_GRDDN_LIGHT AS ICON.
END IF.

IF WA_SFLIGHT-SEATSOCC < 10.
write SYM_LEFT_HAND AS SYMBOL.
ENDIF.

화면 디자인에서 icon을 사용하려면 Icon type을
먼저 선언하여야 한다
DATA : iconfield1 LIKE icons-text.

List Scroll Boundary


SET LEFT SCROLL-BOUNDARY [COLUMN lsb_column].

이 명령어 만나기 바로 전까지 write한 칼럼을 scroll fix 시기거나
명시된 칼럼 이전의 칼럼들을 scroll fix시킨다.

Scroll List to Last Page


Use SCROLL statement to scroll to any place in the list at
runtime; for example, the system could automatically display the
last page of the list.

Message


Inputs in Text element.

TEXT-xxx
'String'(xxx)


Message categories.
A Termination : The processing terminates.
It should be restarted.
X Exit : Like message type A,
but with short dump MESSAGE_TYPE_X
E Error: Processings is interrupted,
and the user must correct the entry.
W Warning : 사용자의 의도를 물어본다.
'Yes'면 Pass, 'No'면 return.
I Information : Information만 뿌려주고 진행한다.
S Success Displays information on the next screen.



System Fields


SY-LINCT : Line-count, number of lines from REPORT.
SY-LINSZ : Line-size, line width from REPORT statement.
SY-SROWS : Number of lines in the display window
SY-SCOLS : Number of columns in the display window
SY-PAGENO: Page number of the current page.
SY-LINNO : LINE number of the current line of the current page
SY-COLNO : Column number of the current column
SY-TITLE
SY-TABIX : Contains the index value of the newly inserted table.
SY-MANDT : Current CLIENT number.
SY-SPONO : Spool에 printing 날린 spool id를 가지고 있음.
SY-DBCNT : Table에서 읽은/update한/지운 레코드 갯수.
SY-DYNNR : 현재 SCREEN 번호를 가지고 있음.
SY-CPROG : 현재 프로그램 명을 가지고 있음.

On Change of


예제>
LOOP AT it_flights INTO wa_flights.
ON CHANGE OF wa_flights-connid.
NEW-PAGE.
ENDON.

write:/ wa_flights-fldat,
................
AT line_size sy_vline.
ENDLOOP.

AT NEW, AT END OF ~~


AT FIRST ~~~~ ENDAT.
loop의 처음 한 번만 실행

AT NEW ~~~~ ENDAT.
해당 필드의 값이 첫값이면 실행.

AT END OF ~~~ ENDAT.
해당 필드의 값이 sort의 끝값이면 실행

AT LAST ~~~~ ENDAT.
loop의 마지막 한 번만 실행.

단, 사용하기전에 internal table을 반드시 Sort 시킬것.

참조
ON CHANGE OF .
ENDON.

Sum & Under


When processing an internal table in a block starting
LOOP and concluded by ENDLOOP, SUM calculates the conttotals of
all fields of type I, F and P (see also
ABAP
number types) and places them in the LOOP output arealine of the
internal table or an explicitly specified area).

You can use the SUM statement both at the end and the
beginning of a control group (see also AT FIRST/LAST).

(예제)
AT END OF connid.
SUM.
FORMAT COLOR COL_TOTAL.
WRITE: / sy-vline,
'Summe'(007),
wa_flights-seatsmax UNDER wa_flights-seatsmax,
wa_flights-seatsocc UNDER wa_flights-seatsocc.
wa_flights-price UNDER wa_flights-price,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.

<쏘스>List 프로그램 표준


*& Report SAPBC405_DAPS_1
*&
*&---------------------------------------------------------------
*& L?ung; Aufgabe 1; Gruppenstufenverarbeitung mit interner
*&
*&---------------------------------------------------------------

INCLUDE z09dap_1top.
*INCLUDE bc405_daps_1top.

*&---------------------------------------------------------------
*& Event TOP-OF-PAGE
*&---------------------------------------------------------------

TOP-OF-PAGE.

* Title
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
WRITE: / sy-vline,
'Flugdaten'(001),
AT line_size sy-vline.
ULINE.

* Column header
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: sy-vline, 'Abflugsort'(004), AT line_size sy-vline.
WRITE: sy-vline, 'Ankunftsort'(005), AT line_size sy-vline.

WRITE: sy-vline, AT pos_c1 'Flug'(002).

* Fix left scroll boundary
SET LEFT SCROLL-BOUNDARY.
WRITE: 'Datum'(003),
AT pos_c3 'Preis'(006),
AT pos_c4 'Max.'(008),
AT pos_c5 'Bel.'(009),
AT line_size sy-vline.
ULINE.


*&---------------------------------------------------------------
*& Event INITIALIZATION
*&---------------------------------------------------------------

INITIALIZATION. " OPTIONAL

* Initialize select-options for CARRID
MOVE: 'AA' TO so_car-low,
'QF' TO so_car-high,
'BT' TO so_car-option,
'I' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
MOVE: 'AZ' TO so_car-low,
'EQ' TO so_car-option,
'E' TO so_car-sign.
APPEND so_car.
CLEAR so_car.

*&---------------------------------------------------------------
*& Event AT SELECTION-SCREEN ON BLOCK PARAM
*&---------------------------------------------------------------

AT SELECTION-SCREEN ON BLOCK param. " OPTIONAL

* check country for national flights is not empty
CHECK national = 'X' AND country = space.
MESSAGE e003(bc405).

*&---------------------------------------------------------------
*& Event START-OF-SELECTION
*&---------------------------------------------------------------

START-OF-SELECTION.

* Checking the output parameters
CASE mark.
WHEN all.
* Radiobutton ALL is marked
SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid IN so_car
AND spfli~connid IN so_con
AND sflight~fldate IN so_fdt.


WHEN national.
* Radiobutton NATIONAL is marked
SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid IN so_car
AND spfli~connid IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr = spfli~countryto
AND spfli~countryfr = country.


WHEN internat.
* Radiobutton INTERNAT is marked
SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid IN so_car
AND spfli~connid IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr NE spfli~countryto.

ENDCASE.

*&---------------------------------------------------------------
*& Event END-OF-SELECTION
*&---------------------------------------------------------------

END-OF-SELECTION.

*SORT it_flights BY carrid connid fldate.

* Control Level Processing: the internal tabel has to be sorted
SORT it_flights BY cityfrom cityto carrid connid.

* Data output
PERFORM data_output.

*&---------------------------------------------------------------
*& Form DATA_OUTPUT
*&---------------------------------------------------------------
* List output of flight data
*----------------------------------------------------------------

FORM data_output.

* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.

* Group Level: CITYFROM
AT NEW cityfrom.
NEW-PAGE.
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE: / sy-vline, wa_flights-cityfrom,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.

* Group Level: CITYTO
AT NEW cityto.
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, wa_flights-cityto,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.

* Single Record Processing
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
WRITE: wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: wa_flights-fldate,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
wa_flights-seatsmax,
wa_flights-seatsocc,
AT line_size sy-vline.
FORMAT RESET.

* Group Level: CONNID
AT END OF connid.
SUM.
FORMAT COLOR COL_TOTAL.
WRITE: / sy-vline,
'Summe'(007),
wa_flights-seatsmax UNDER wa_flights-seatsmax,
wa_flights-seatsocc UNDER wa_flights-seatsocc,
wa_flights-price UNDER wa_flights-price,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.

* Group Level: CITYFROM
AT END OF cityfrom.
ULINE.
ENDAT.

ENDLOOP.

ENDFORM. " DATA_OUTPUT




Control Level


리스트 프로그램 할 때 control level을 정해서 활용하고 싶을 때
주의 사항은 control level로 사용할 field의 순서가 중요하다.

만약에 Internal table을 sorted table이면 control level로 쓸
field를 key로 잡으면 되지만 standard table일 경우는
Internal table에서 참조하는 type을 선언할 때 control level로 사용
할 field를 제일 먼저 입력한다.

<예제>

TYPES: BEGIN OF linetype,
cityfrom LIKE spfli-cityfrom,
cityto LIKE spfli-cityto,
carrid LIKE spfli-carrid,
connid LIKE spfli-connid,
countryfr LIKE spfli-countryfr,
countryto LIKE spfli-countryto,
fldate LIKE sflight-fldate,
price LIKE sflight-price,
currency LIKE sflight-currency,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,

END OF linetype.

Select-options


(Syntex)

SELECT-OPTIONS FOR
DEFAULT
DEFAULT TO
MEMORY ID
LOWER CASE
OBLIGATORY
NO-EXTENSION
NO INTERVALS.

(SELECT-OPTION 으로 형성되는 I.T)
SING OPEION LOW HIGH

(예제)
SELECTION-SCREEN BEGIN OF BLOCK carr WIT FRAME.
SELECT-OPTIONS: so_carr FOR wa_sflight-carrid.
SELECTION-SCREEN END OF BLOCK carr.

Selection-screen 에서 screen 선택


selection scrren에서는 기본적으로 screen 1000번으로 생성이 된다.

하지만 이 default screen을 사용하고 싶지 않으 때 쓰는 것이
SELECTION-SCREEN BEGIN OF SCREEN ... END OF SCREEN
이다.

(예제)
SELECTION-SCREEN:
BEGIN OF SCREEN 1100.
PARAMETERS: pa_cus AS CHECKBOX,
pa_agy AS CHECKBOX.
SELECTION-SCREEN:
END OF SCREEN 1100.
.......

AT SELECTION-SCREEN ON pa_add.
IF pa_add = mark.
CALL SELECTION-SCREEN 1100.

Input Check AT SELECTION-SCREEN


(예제)
AT SELECTION-SCREEN ON so_dept.
IF ( so_dept-low < '060000' ).
Message e046(bc405).
ENDIF.


Basic form AT SELECTION-SCREEN.

Additions:

1. ... ON psel
2. ... ON END OF sel
3. ... ON VALUE-REQUES
4. ... ON HELP-REQUEST
5. ... ON RADIOBUTTON
6. ... ON BLOCK block
7. ... OUTPUT
8. ... ON EXIT-COMMAND

JOIN문의 syntex


SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid IN so_carr
AND spfli~connid IN so_con
AND sflight~fldate IN so_fdt.

주의)
속도상의 문제 때문에 반드시 Join 조건으로 client id를
명시하도록 한다.

LDB에서의 select-option과 check 사용


NODES: spfli,sflight,sbook.


SELECTION-SCREEN BEGIN OF BLOCK o_date WITh FRAME .
SELECT-OPTIONS: so_orddt FOR sbook-
order_date
default '19990110' to '19990731'.
SELECTION-SCREEN END OF BLOCK o_date.


GET sbook.
FORMAT COLOR COL_NORMAL.

CHECK so_orddt.

WRITE : / sy-vline,
sbook-bookid,
sbook-customid,
sbook-smoker,
sbook-luggweight UNIT sbook-wunit,
sbook-wunit,
sbook-order_date,
AT 90 sy-vline.

FORMAT RESET.

결국 so_orddt(sign/option/low/high)에 값이 있으면
Write하고 그렇지 않으면 write하지 않는다.
Logical Database 내에서 : Check statements end the current
processing block.

LDB에서의 control level


GET spfli.
FORMAT COLOR COL_KEY INTENSIFIED ON.

WRITE : / sy-vline,
spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-airpfrom,
spfli-cityto,
spfli-airpto,
AT 90 sy-vline.
FORMAT RESET.

GET spfli LATE.
ULINE.
NEW-PAGE.

(설명)
spfli table의 key 단위로 record가 다를 때마다 uline과 new-page를
실행한다.

Printing with GET_PRINT_PARAMETERS


DATA: print parameter_set LIKE pri_params,
valid,
list_text LIKE print_parameter_set-prtxt.
.....

START-OF-SELECTION.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
copies = 2 "Number of copies
destionation = 'LP01' "Printer
expiraton = 3 "Duration /d in spool
immediately = space "Print immediately
line_size = 100 "Width of list
release = 'X' "Delete task after print
no_dialog = space "Dialog is suppressed
receiver = sy-uname
list_text = list_text "Title
report = 'example' "Name
IMPORTING
out_parameters = print_parameter_set
valid = valid.

IF valid = 'X'.
NEW-PAGE PRINT ON PARAMETERS print_parameter_set NO DIALOG.

ALV grid control


*&---------------------------------------------------------------
*& Module pool ZEDU09_ALV_GRID
*&---------------------------------------------------------------

INCLUDE zedu09_alv_grid_top .

*선언부
PROGRAM zedu09_alv_grid .
DATA: ok_code LIKE sy-ucomm.

DATA: it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli.

DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
alv_grid TYPE REF TO cl_gui_alv_grid.

PARAMETERS : pa_crr TYPE spfli-carrid.


START-OF-SELECTION.

SELECT DISTINCT carrid connid FROM spfli
INTO CORRESPONDING FIELDS OF TABLE it_spfli
WHERE carrid = pa_crr.

CALL SCREEN 100.

*&---------------------------------------------------------------
*& Module CREATE_OBJECT OUTPUT
*&---------------------------------------------------------------
MODULE create_object OUTPUT.
IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container
EXPORTING container_name = 'container_1'.

CREATE OBJECT alv_grid
EXPORTING i_parent = g_custom_container.

ENDIF.
ENDMODULE. " CREATE_OBJECT OUTPUT

*----------------------------------------------------------------
*& Module DATA_INPU OUTPUT
*&---------------------------------------------------------------
MODULE data_intpu OUTPUT.

CALL METHOD alv_grid->set_table_for_first_display
EXPORTING i_structure_name = 'spfli'
CHANGING it_outtab = it_spfli.

ENDMODULE. " DATA_INTPU OUTPUT

*&---------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------
MODULE user_command_0100 INPUT.
CLEAR ok_code.
CASE ok_code.
WHEN 'BACK'.
* CALL METHOD g_custom_container->free.
LEAVE TO SCREEN 0.
WHEN 'RW'.
* CALL METHOD g_custom_container->free.
LEAVE TO SCREEN 0.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------
module status_0100 output.
SET PF-STATUS 'AAAA'.
* SET TITLEBAR 'xxx'.

endmodule. " STATUS_0100 OUTPUT

Message Class 사용법


방법 1
Message i654(BCTRAIN)
*BCTRAIN은 MESSAGE CLASS이다.

방법 2
Report z09test Message-id z09class.
......
Message i001.
......
Message i100(BCTRAIN).

Logical Database


주의 : Program의 Attribute에 LDB의 이름을 주어야 한다.

선언부 : NODES: spfli,sflight,sbook.

Data읽기 : GET spfli.
GET sflight.
GET sbook.

* Possible node types
- Database table
- DDIC type : Table or structure.
- Data type : Type that was defined in a type group.
- Dynamic type : Type is specified in program.


Top-of-page during line-selection


Detailed linst의 header를 규정한다.

TOP-OF-PAGE DURING LINE-SELECTION.
CHECK sy-ucomm = 'BOOK'.
FORMAT COLOR COL_HEADING.
ULINE.
WRITE: / 'Flight:'(t01), wa_sbook-carrid, wa_sbook-connid,
AT sy-linsz space,
/ 'Date:'(t02), wa_sbook-fldate, AT sy-linsz space.
ULINE.

Cursor 효과 Loop


*&---------------------------------------------------------------
*& Report
Z_TEST_EDU09 *
*&---------------------------------------------------------------

REPORT z_test_edu09 .

TYPES:

BEGIN OF t_conn,

cityfrom TYPE spfli-cityfrom,

cityto TYPE spfli-cityto,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

END OF t_conn.


DATA:

conn_list TYPE STANDARD TABLE OF t_conn,


BEGIN OF wa_travel,

dest TYPE spfli-cityto,

cofl_list LIKE conn_list,

END OF wa_travel,


travel_list LIKE SORTED TABLE OF wa_travel WITH UNIQUE KEY dest.


PARAMETERS: pa_start TYPE spfli-cityfrom DEFAULT 'FRANKFURT'.


FIELD-SYMBOLS:

TYPE t_conn,

TYPE t_conn,

LIKE wa_travel.



SELECT carrid connid cityfrom cityto

FROM spfli

INTO CORRESPONDING FIELDS OF TABLE conn_list.



SORT conn_list BY cityfrom cityto ASCENDING AS TEXT.



*** build up nested table.

LOOP AT conn_list ASSIGNING
WHERE cityfrom = pa_start.

wa_travel-dest = -cityto.

LOOP AT conn_list ASSIGNING
WHERE cityfrom = wa_travel-dest.

APPEND TO wa_travel-cofl_list.

ENDLOOP.



SORT wa_travel-cofl_list BY cityto carrid ASCENDING AS TEXT.

INSERT wa_travel INTO TABLE travel_list.

ENDLOOP.



*** output:

LOOP AT travel_list ASSIGNING .

WRITE: / -dest.



LOOP AT -cofl_list ASSIGNING .

AT NEW cityto.

WRITE : /8 -cityto.

ENDAT.

WRITE: /16 -carrid,

-connid.

ENDLOOP.

ENDLOOP.



*** Âü°í ******

// OCCURS 0 는 Type도 자동 생성한다..
Tables: SPFLI,sflight.

Data:

BEGIN OF itab occurs 0.

carrid LIKE SPFLI-carrid,

connid LIKE SPFLI-connid,

planetype LIKE sflight-planetype,

.

.

.

End of itab.

Setting the Cursor Positon Dynamically


SET CURSOR FIELD sdyn_conn-connid OFFSET .

Popup Window size


CALL SCREEN 101
STARTING AT left_col 좌표값.
END AT right_col 좌표값.

Modifying Attributes Dynamically


Screen의 속성(Attrigute)를 코딩 내에서 변경하고 싶을 경우
LOOP AT SCREEN.
MODIFY SCREEN.
ENDLOOP.
구문을 사용한다.



(예제)

MODULE modify_screen OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'SEL'. *GROUP전체를 한꺼번에 제어함.
screen-input = 1.
ENDIF.

IF screen-name = 'SDYN_CONN-CARRID'.
screen-active = 0.
ENDIF.

MODIFY SCREEN.

ENDLOOP.

ENDMODULE.

Modifiable Static Attributes.


SCREEN-LENGTH. : screen object의 길이를 제어.
SCREEN-INPUT. :
SCREEN-OUTPUT.
SCREEN-REQUIRED.
SCREEN-INTENSIFIED.
SCREEN-INVISIBLE.
SCREEN-ACTIVE.

교제 : 3권 19-10

현재 Cursor가 위치한 line 및 fieldname.



1.LIST프로그램에서 현재 Cursor가 위치한 line 수를 알아내기.

DATA : line(10) TYPE p.

GET CURSOR LINE line.

이렇게 하면 변수 line에는 colum heading,list heading line수가
더해진 수가 line에 대입된다.

2.현재 cursor의 field name 구하기.

DATA : fieldname(30) TYPE c.

GET CURSOR FIELD fieldname.

이렇게 하면 변수 fieldname에는 'wa_sbook-fldate'와 같은 형태의
값이 대입된다.

Exit와 Check 의 차이


Loop 안에서 Exit는 Loop자체를 빠져나간다.

반면에 Check는 조건을 만족시키지 못할 경우 다음 loop으로

넘어간다.

<쏘스>List, detail list, call screen


*----------------------------------------------------------------
* INCLUDE BC410DIAS_DYNPROTOP 교재3권 19-39
---------------------------------------------------------------*
PROGRAM sapbc410dias_dynpro.

* workarea and internal table for flights
DATA: mark,
wa_sflight TYPE sflight,
it_sflight LIKE TABLE OF wa_sflight.

* workarea and internal tables for bookings
DATA: wa_sbook TYPE sbook,
it_sbook_read LIKE TABLE OF wa_sbook,
it_sbook LIKE TABLE OF wa_sbook.

* sflight key for testing changes
DATA: BEGIN OF key_sflight,
carrid LIKE wa_sflight-carrid,
connid LIKE wa_sflight-connid,
fldate LIKE wa_sflight-fldate,
END OF key_sflight.
* field name for GET CURSOR
DATA fieldname(50).

* fields for ok_code processing
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE ok_code.

* selection screen for choosing connections
SELECTION-SCREEN BEGIN OF BLOCK conn WITH FRAME TITLE text-001.
SELECT-OPTIONS: so_car FOR wa_sflight-carrid,
so_con FOR wa_sflight-connid.
SELECTION-SCREEN END OF BLOCK conn.


*----------------------------------------------------------------
* INCLUDE 10DIAS_DYNPROE01
*----------------------------------------------------------------

START-OF-SELECTION.
PERFORM read_flights.

END-OF-SELECTION.
PERFORM display_flights.
SET PF-STATUS 'BASE'.
SET TITLEBAR 'BASE'.
CLEAR wa_sflight-carrid.

*&---------------------------------------------------------------
*& Event AT USER-COMMAND
*&---------------------------------------------------------------
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'BOOK'.
* CHECK NOT WA_SFLIGHT-CARRID IS INITIAL.
REFRESH it_sbook.
DO.
READ LINE sy-index FIELD VALUE mark.
IF sy-subrc NE 0. EXIT. ENDIF.
CHECK NOT mark IS INITIAL.
PERFORM read_bookings
USING wa_sflight-carrid
wa_sflight-connid
wa_sflight-fldate
' '.
APPEND LINES OF it_sbook_read TO it_sbook.
ENDDO.
SORT it_sbook BY carrid connid fldate bookid.
PERFORM display_bookings.
SET PF-STATUS 'BOOK'.
SET TITLEBAR 'BOOK'.
CLEAR: wa_sflight-carrid,
wa_sbook-bookid.
WHEN 'SELECT'.
DO.
READ LINE sy-index.
IF sy-subrc NE 0. EXIT. ENDIF.
MODIFY CURRENT LINE FIELD VALUE mark FROM 'X'.
ENDDO.
WHEN 'DESELECT'.
DO.
READ LINE sy-index.
IF sy-subrc NE 0. EXIT. ENDIF.
MODIFY CURRENT LINE FIELD VALUE mark FROM space.
ENDDO.
WHEN 'SRTU'.
CHECK NOT wa_sbook-bookid IS INITIAL.
GET CURSOR FIELD fieldname.
fieldname = fieldname+9.
SORT it_sbook BY carrid connid fldate (fieldname).
PERFORM display_bookings.
sy-lsind = sy-lsind - 1.
CLEAR wa_sbook-bookid.
WHEN 'SRTD'.
CHECK NOT wa_sbook-bookid IS INITIAL.
GET CURSOR FIELD fieldname.
fieldname = fieldname+9.
SORT it_sbook BY carrid connid fldate (fieldname)
DESCENDING.
PERFORM display_bookings.
sy-lsind = sy-lsind - 1.
CLEAR wa_sbook-bookid.

ENDCASE.

TOP-OF-PAGE DURING LINE-SELECTION.
CHECK sy-ucomm = 'BOOK'
OR sy-ucomm = 'SRTD'
OR sy-ucomm = 'SRTU'.
FORMAT COLOR COL_HEADING.
ULINE.
WRITE: / 'Flight:'(t01), wa_sbook-carrid, wa_sbook-connid,
AT sy-linsz space,
/ 'Date:'(t02), wa_sbook-fldate, AT sy-linsz space.
ULINE.

*&---------------------------------------------------------------
*& Event AT LINE-SELECTION.
*&---------------------------------------------------------------
AT LINE-SELECTION.
CALL SCREEN 100.

*----------------------------------------------------------------
***INCLUDE BC410DIAS_DYNPROF01.
*----------------------------------------------------------------

*&---------------------------------------------------------------
*& Form READ_FLIGHTS
*&---------------------------------------------------------------

FORM read_flights.
SELECT * INTO TABLE it_sflight FROM sflight
WHERE carrid IN so_car
AND connid IN so_con.
SORT it_sflight BY carrid connid fldate.
ENDFORM.

*&---------------------------------------------------------------
*& Form DISPLAY_FLIGHTS
*&---------------------------------------------------------------
FORM display_flights.
LOOP AT it_sflight INTO wa_sflight.

WRITE: / mark AS CHECKBOX,
wa_sflight-carrid,
wa_sflight-connid,
wa_sflight-fldate,
wa_sflight-price CURRENCY wa_sflight-currency,
wa_sflight-currency,
wa_sflight-seatsmax,
wa_sflight-seatsocc.
HIDE: wa_sflight.
ENDLOOP.
ENDFORM. " DISPLAY_FLIGHTS
*&---------------------------------------------------------------
*& Form READ_BOOKINGS
*&---------------------------------------------------------------

FORM read_bookings USING p_carrid LIKE wa_sbook-carrid
p_connid LIKE wa_sbook-connid
p_fldate LIKE wa_sbook-fldate
p_cancelled LIKE wa_sbook-cancelled.

SELECT * INTO TABLE it_sbook_read FROM sbook
WHERE carrid = p_carrid
AND connid = p_connid
AND fldate = p_fldate
AND cancelled = p_cancelled.

ENDFORM. " READ_BOOKINGS

*&---------------------------------------------------------------
*& Form DISPLAY_BOOKINGS
*&---------------------------------------------------------------
FORM display_bookings.

LOOP AT it_sbook INTO wa_sbook.

IF key_sflight-carrid NE wa_sbook-carrid
OR key_sflight-connid NE wa_sbook-connid
OR key_sflight-fldate NE wa_sbook-fldate.
MOVE-CORRESPONDING wa_sbook TO key_sflight.
NEW-PAGE.
ENDIF.

WRITE: / wa_sbook-bookid,
wa_sbook-customid,
wa_sbook-custtype,
wa_sbook-luggweight UNIT wa_sbook-wunit,
wa_sbook-wunit,
wa_sbook-class,
wa_sbook-order_date,
wa_sbook-cancelled.
HIDE wa_sbook-bookid.
ENDLOOP.

ENDFORM. " DISPLAY_BOOKINGS

List에서의 validate line check


교재3권 16-14

AT USER-COMMAND.

CHECK NOT wa_sflight-carrid IS INITIAL.

CASE sy-ucomm.
WHEN 'BOOK'.
REFRESH it_sbook.
PERFORM read_bookings.
.......
.......

CLEAR wa_sflight-carrid.


..........
..........
AFTER Display of all flight data.

HIDE: wa_sflight.


END-OF-SELECTION.
PERFORM display_flights.
SET PF-STATUS 'BASE'.
SET TITLEBAR 'BASE'.
CLEAR wa_sflight-carrid.


CNT SUM


SUM().
CNT().


Program Type


Executeable program : Type 1

Module pool program : Type M

Fuction Group : Type F

Include program : Type I

Interface pool : Type J

Class pool : Type K

Selection Screen의 Event들


1. INITIALIZATION.
selection screen 보여지기 전에 수행.
주로 고정된 Default 값을 세팅 할 때 많으씀.

2. AT SELECTION-SCREEN OUTPUT
selection screen이 보여지기 직전에 수행.
이 이벤트를 통해 selection screen을 Dynamic하게
구성할 수 있다.

3. AT SELECTION-SCREEN ON HELP-REQUEST FOR
field document를 다양하게 구성 할 수 있다.(F1 key보다 우선함)

4. AT SELECTION-SCREEN ON VALUE-REQUEST FOR
search help를 더욱 다양하게 구성할 수 있다.
이것은 field에 asign한 search help보다도 우선순위가 높다.

List에서 mark 된것 읽기.


DO.
CLEAR: mark.
READ LINE sy-index FIELD VALUE mark.
IF sy-subrc <> 0.
EXIT.
ENDIF.
CHECK NOT mark IS INITIAL.
APPEND wa_stravelag TO p_itab_travel.
ENDDO.

TYPE 문 선언시 include structure


TYPES: BEGIN OF stravel_type.
INCLUDE STRUCTURE stravelag.
TYPES: mark_changed,
END OF stravel_type.

위의 선언내용은 stravel_type이라는 line type구조로
type을 선언하는데 있어 기존에 Abap dictinary에
정의되어있는 straelag를 가져오고 또한 mark_changed라는
임의의 flag변수를 추가시켜 하나의 line-type형태의
'stravel_type'을 정의하고있음.


STANDARD head write의 예1


FORM write_header.
WRITE: / 'Travel agency data'(007), AT sy-linsz sy-pagno.
ULINE.
FORMAT COLOR COL_HEADING.
WRITE AT: /pos2 'Agency'(001),
pos3 'Name'(002),
pos4 'Street'(003),
pos5 'Postal Code'(004),
pos6 'City'(005),
pos7 'Country'(006).
ULINE.
ENDFORM.

위에서 pos2-7까지는 top-include에서 미리 상수(CONSTANTS)로
아래와 같이 정의 되어있어야한다.

CONSTANTS: pos1 TYPE i VALUE 1,
pos2 TYPE i VALUE 3,
pos3 TYPE i VALUE 14,
pos4 TYPE i VALUE 40,
pos5 TYPE i VALUE 71,
pos6 TYPE i VALUE 82,
pos7 TYPE i VALUE 108.

STANDARD field write 예1


FORM write_data.
LOOP AT itab_stravelag INTO wa_stravelag.
WRITE AT: /pos1 mark AS CHECKBOX,
pos2 wa_stravelag-agencynum COLOR COL_KEY,
pos3 wa_stravelag-name,
pos4 wa_stravelag-street,
pos5 wa_stravelag-postcode,
pos6 wa_stravelag-city,
pos7 wa_stravelag-country.
HIDE: wa_stravelag.
ENDLOOP.
ENDFORM.

ALV_Advenced.


*&---------------------------------------------------------------
*& Include Z88_ALV_GRID_TOP
*&---------------------------------------------------------------

PROGRAM z09_alv_advence .

TABLES sflight.

TYPES: BEGIN OF t_con,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
price LIKE sflight-price,
currency LIKE sflight-currency,
planetype LIKE sflight-planetype,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
paymentsum LIKE sflight-paymentsum,
free_seats LIKE sflight-seatsocc,
icon_name(30),
END OF t_con.

DATA: gt_outtab TYPE STANDARD TABLE OF t_con,
wa_outtab TYPE t_con.

DATA: gt_fieldcat TYPE lvc_t_fcat,
wa_fieldcat LIKE LINE OF gt_fieldcat.

DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
alv_grid TYPE REF TO cl_gui_alv_grid.


DATA: ok_code LIKE sy-ucomm,
save_ok LIKE ok_code.

DATA: pos_free TYPE i VALUE 10,
pos_icon TYPE i VALUE 11.

SELECTION-SCREEN BEGIN OF BLOCK connection WITH FRAME.
SELECT-OPTIONS: so_car FOR wa_outtab-carrid,
so_con FOR wa_outtab-connid.
SELECTION-SCREEN END OF BLOCK connection.


============================================================

START-OF-SELECTION.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF wa_outtab
WHERE carrid IN so_car
AND connid IN so_con.
wa_outtab-free_seats = wa_outtab-seatsmax - wa_outtab-
seatsocc.

IF wa_outtab-free_seats > 0.
wa_outtab-icon_name = ICON_GREEN_LIGHT.
ELSE.
wa_outtab-icon_name = ICON_RED_LIGHT.
ENDIF.
APPEND wa_outtab TO gt_outtab.
ENDSELECT.

CALL SCREEN 100.
*&---------------------------------------------------------------
*& Module CREATE_OBJECTS OUTPUT
*&---------------------------------------------------------------
MODULE create_objects OUTPUT.

IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = 'JUNSEOK'.
CREATE OBJECT alv_grid
EXPORTING i_parent = g_custom_container.
ENDIF.
ENDMODULE. " CREATE_OBJECTS OUTPUT

*&---------------------------------------------------------------
*& Module TRANSFER OUTPUT
*&---------------------------------------------------------------
MODULE transfer OUTPUT.

CALL METHOD alv_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
CHANGING it_outtab = gt_outtab
it_fieldcatalog = gt_fieldcat.
ENDMODULE. " TRANSFER OUTPUT

*&---------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------
MODULE status_0100 OUTPUT.
SET PF-STATUS 'S100'.
SET TITLEBAR 'T100'.

ENDMODULE. " STATUS_0100 OUTPUT

*&---------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------
MODULE user_command_0100 INPUT.

save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------
*& Module FIELD_CATALOG OUTPUT
*&---------------------------------------------------------------

MODULE field_catalog OUTPUT.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'FREE_SEATS'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'SEATSMAX'.

wa_fieldcat-coltext = text-001.
wa_fieldcat-seltext = text-001.
wa_fieldcat-col_pos = pos_free.
APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'ICON_NAME'.
wa_fieldcat-icon = 'X'. " Displayed as Icon

wa_fieldcat-coltext = text-001.
wa_fieldcat-seltext = text-001.
wa_fieldcat-col_pos = pos_icon.
APPEND wa_fieldcat TO gt_fieldcat.

ENDMODULE. " FIELD_CATALOG OUTPUT


ABAP Program Types


Type 1 : Excutable program.

Type M : Module pool.

Type F : Function group.

Type I : Include program.

Text field 속성


Dynamically Modifiable Attributes : text field
교과서 : 3권 20-9.

SCREEN-REQUIRED
SCREEN-INPUT
SCREEN-OUTPUT
SCREEN-INTENSIFIED
SCREEN-INVISIBLE
SCREEN-LENGTH
SCREEN-ACTIVE
SCREEN-DISPLAY_3D
SCREEN-VALUE_HELP
SCREEN-REQUEST

Input field check.


Field (field name)
Module (module명) ON INPUT.

CHAIN.
Field: (field name 1),
(field name 2),
,,,,,,,,,, .
Module (module명) ON CHAIN-INPUT
ENDCHAIN.


Field (field name)
Module (module명) ON REQUEST.

CHAIN.
Field: (field name 1),
(field name 2),
,,,,,,,,,, .
Module (module명) ON CHAIN-REQUEST
ENDCHAIN.


Subscreen에서의 제약사항.


The following restrictions apply to subscreens:

- CALL SUBSCREEN ... is not allowed between LOOP
and ENDLOOP or between CHAIN and ENDCHAIN.

- A subscreen may not have a named OK_CODE field.

- Object names must be unique within the set of all subscreens
called in a single main screen.

- Subscreens may not contain a module with the AT EXIT-COMMAND
addition.

- You cannot use the SET TITLEBAR, SET PF-STATUS, SET SCREEN,
or LEAVE SCREEN statements in the modules of a subscreen.

Subscreen calling





Creating Tab strip


1. tab strip을 screen editor를 이용하여 그린다.

2. Top Include에 반드시 Controler을 정의한다.

예) CONTROLS : my_tab_strip TYPE TABSTRIP.

교과서 3춴 22-19참조

Selection Screen as subscreen


SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
SELECT-OPTIONS : s_carr for spfli-carrid.
s_conn for spfli-connid.
SELECTION-SCREEN END OF SCREEN 101.

3권 22-28:참조



Table control에 data 채우기


교과서 3권 23-21.



Table control의 내용 변경


교과서 3권 23-24.


Locking


Locking(고과서 4권 5-9)

1. Setting and Deleting logical locks.

- Lock setting은 lock module을 만들어서 setting한다.

가. 먼저 Lock object를 만든다.

나. Lock object를 만들고 Activate시키면 Enqueue, Dequeue
function이 만들어진다.

다. Calling the lock module.
CALL FUNCTION 'ENQUEUE_ESFLIGHT'
EXPROTING
~~~~
CALL FUNCTION 'DEQUEUE_ESFLIGHT'
EXPORTING
~~~~

- Deleting lock

가. Leave program, Leave to Transaction

나. message 'A','X'.

다. /n

* locking object 생성 -> se11(ABAP dictionary)
lock talbe 보기 -> sm12

2. Locking object type
E : exclusive, cumulative
S : shared
X : exclusive, not cumulative(lock may only be set once.)


LOCKING의 기본 형태
FORM save.
*lock dataset
PERFORM enq_scustom.
PERFORM number_get_next USING scustom.
PERFORM save_scustom.
*unlock dataset
PERFORM deq_all.
ENDFORM.

Syncronous Calls


New Program
1. SUBMIT
2. LEAVE TO TRANSACTION


Insert program
1.SUBMIT AND RETURN.
2.CALL TRANSACTION
3.CALL FUNCTION

교과서 3권 7-4

T-code 정리


SE09 Change Request 관리
SE11 ABAP Dictionary table,view,data type,domain,
search help,lock object만듬.
SE14 database utility
SE16 DATA BROWSER
SE30 Runtime Analysis (프로그램실행)
SE36 logical DB 정보
SE37 Function Builder
SE38 ABAP Editor(Report Programing)
SE39 Splitscreen Editor(소스2개 비교할때 유리)
SE41 Menu painter
SE43 Area Menu
SE51 Screen painter
SE54 Table view generation
SE80 Object Navigator
SE81 Application Hierarchy : Display
SE84 Repository Information System
SM02 Send system message
SM04 User Overview 현재 connectino된 User정보
SM12 Lock table을 보여준다.
SM13 update log 정보를 본다.
SM21 System log (Erorr발생시 check)
SM30 To execute the maintenaance view
SM35 Batch input : Session Overview
SM36 Define Background Job
SM37 Background Job Maintenance
SM50 Process Overview
SM51 Servers
SM59 RFC관련
SNRO Number object만드는곳.(자동채번)
SQ01 SAP Query
SQ02 Functional Area
SQ03 User Group
ST05 SQL Trace
ST22 SHORT DUMP LOG 정보
SU01 User management
SU53 Display Authorization values for user