* DATA
DATA(text) = 'ABC'.
* LOOP AT into work area
DATA: gt_scarr TYPE TABLE OF scarr.
SELECT carrid, carrname, currcode
FROM scarr
INTO CORRESPONDING FIELDS OF TABLE @gt_scarr
UP TO 30 ROWS.
LOOP AT gt_scarr INTO DATA(wa).
" wa control
ENDLOOP.
DATA: lt_0001 TYPE TABLE OF pa0001.
LOOP AT lt_0001 ASSIGNING FIELD-SYMBOL(<FS>).
<fs>-? = lt_itab[ matnr = '0001']-matnr.
ENDLOOP
* Old
READ TABLE gt_scarr INTO DATA(wa2) INDEX 1.
IF sy-subrc EQ 0.
wa2-carrid = 'BA'.
ENDIF.
* New
DATA(wa3) = gt_scarr[ 1 ].
* New
* wa = line_index( itab[ field = 'data' ] )
* New2
*IF line_exists( lt_tab[ field_name = abap_true ] ).
wa = value #( itab[ field = 'data' ] optional ).
DATA: lt_data LIKE gt_scarr,
ls_data LIKE LINE OF gt_scarr.
lt_data = gt_scarr.
" 'Structure ls_data에 '같은 타입으로 데이터를 설정/추가
ls_data = VALUE #( lt_data[ currcode = 'KRW' ] OPTIONAL ).
itab[ field = 'data' ]-field2 = 'data2'
DATA: lt_spfli_all TYPE TABLE OF spfli WITH NON-UNIQUE SORTED KEY carrid COMPONENTS carrid,
lt_spfli TYPE TABLE OF spfli.
SELECT *
FROM spfli
INTO TABLE @lt_spfli_all.
lt_spfli = FILTER #( lt_spfli_all USING KEY carrid
WHERE carrid = 'LH ' ).
DATA: lt_spfli_all2 TYPE TABLE OF spfli WITH NON-UNIQUE SORTED KEY carrid COMPONENTS carrid,
lt_spfli2 TYPE TABLE OF spfli.
SELECT *
FROM spfli
INTO TABLE @lt_spfli_all2.
DATA lt_filter TYPE SORTED TABLE OF scarr-carrid WITH UNIQUE KEY table_line.
lt_filter = VALUE #( ( 'AA ' ) ( 'LH ' ) ).
lt_spfli = FILTER #( lt_spfli_all IN lt_filter WHERE carrid = table_line ).
DATA: lv_msg TYPE char40 VALUE '안녕 안녕 안녕'.
DATA(lv_len) = strlen( lv_msg ).
DATA: lt_tab LIKE gt_scarr.
lt_tab = CORRESPONDING #( lt_data ).
lt_tab = CORRESPONDING #( BASE ( lt_tab ) lt_data[] ).
switch, cond문법은 case문과 비슷한 구조, 기능이며 변수에 값을 설정할 때 다른 변수의 값에 따라 동적으로 값을 설정하는데 사용된다.
동적인 프로그램을 개발하는데 유리하고 if문을 썼을 때 보다 코딩 라인을 줄일 수 있다.
old case 문
DATA(lv_char) = 'B'.
DATA lv_num TYPE int1.
"case문 사용
CASE lv_char.
WHEN 'A'.
lv_num = 1.
WHEN 'B'.
lv_num = 2.
WHEN 'C'.
lv_num = 3.
WHEN 'D'.
lv_num = 4.
WHEN OTHERS.
ENDCASE.
* New Cond 문
" cond 뒤에 i는 Type
lv_num = COND i( WHEN lv_char = 'A' THEN 1
WHEN lv_char = 'B' THEN 2
WHEN lv_char = 'C' THEN 3
WHEN lv_char = 'D' THEN 4 ).
* 이미 정의한 변수에 적용할 경우.
DATA lv_num2 TYPE int1.
lv_num2 = COND #( WHEN lv_char = 'A' THEN 1
WHEN lv_char = 'B' THEN 2
WHEN lv_char = 'C' THEN 3
WHEN lv_char = 'D' THEN 4 ).
*-- SWITCH
DATA(lv_num3) = SWITCH #( lv_char
WHEN 'A' THEN 1
WHEN 'B' THEN 2
WHEN 'B' THEN 3
WHEN 'B' THEN 4 ).
DATA: lv_lines TYPE i.
LOOP AT gt_scarr INTO DATA(ls_scarr) WHERE currcode = 'USD'.
lv_lines = lv_lines + 1.
ENDLOOP.
" New - Reduce 사용.
DATA(lv_lines2) = REDUCE i( INIT x = 0 FOR wa09 IN gt_scarr
WHERE ( currcode = 'USD' ) NEXT x = x + 1 ).
itab : BKPF
cds view : BSEG 및 기타 등등..
bkpf
cds view 생성
@AbapCatalog.sqlViewName: 'ZFI_CDS_test'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'fi 연습용 cds view'
define view zfi_cds_header as select from bkpf as a
left outer join t003t as b
on a.blart = b.blart
and b.spras = $session.system_language
{
// 전표 헤더
a.bukrs,
a.gjahr,
a.belnr,
a.blart,
b.ltext as blart_txt,
a.bstat ,
case a.bstat
when 'V' then '@5D@'
when '' then '@5B@'
else ''
end as STATUS,
a.budat,
a.bldat,
a.bktxt,
a.xblnr,
a.ppnam ,
a.usnam,
a.cpudt,
a.cputm,
a.waers,
a.stblg
}
*-- Get header using cds view
SELECT *
FROM ZFI_CDS_test // sql view name
INTO CORRESPONDING FIELDS OF TABLE @gt_header
WHERE bukrs = @pa_bukrs
AND budat IN @so_budat
AND belnr IN @so_belnr
AND blart IN @so_blart
AND waers IN @so_waers
AND cpudt IN @so_cpudt
AND usnam IN @so_usnam
AND bstat IN @rt_rb //선택옵션에 따라 select
AND stblg EQ @space // 역분개 전표 제외
ORDER BY bukrs , gjahr, belnr ASCENDING.
@AbapCatalog.sqlViewName: 'ZVFI_CDS_Item'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: '전표 아이템 CDS'
define view zfi_cds_Item
as select from zfi_cds_header as A
left outer join bseg as B on A.bukrs = B.bukrs
and A.belnr = B.belnr
and A.gjahr = B.gjahr
left outer join skat as C on B.hkont = C.saknr
and C.spras = $session.system_language
left outer join lfa1 as D on B.lifnr = D.lifnr
and D.land1 = $session.system_language
left outer join kna1 as E on B.kunnr = E.kunnr
left outer join anla as F on A.bukrs = F.bukrs
and B.anln1 = F.anln1
and B.anln2 = F.anln2
{
A.bukrs,
A.budat,
A.belnr,
A.cpudt,
B.gjahr,
A.usnam,
B.belnr as belnr_i,
A.blart, // 유형
B.buzei,
A.bstat,
B.bschl,
B.hkont,
C.txt50 as hkont_txt,
B.shkzg, // 차대변지시자
( case B.shkzg
when 'S' then B.wrbtr
end ) as wrbtr,
( case B.shkzg
when 'H' then B.wrbtr * -1
end ) as wrbtr_d,
... 기타 등등
}
IF gt_header IS NOT INITIAL .
SELECT *
FROM zvficds_i_edu17 // header cds view with bseg, skat, lfa1, kna1, anla
FOR ALL ENTRIES IN @gt_header
//-- Header 옵션
WHERE bukrs = @pa_bukrs
AND budat = @gt_header-budat
AND belnr = @gt_header-belnr
AND blart = @gt_header-blart
AND waers = @gt_header-waers
AND cpudt = @gt_header-cpudt
AND usnam = @gt_header-usnam
AND gjahr = @gt_header-gjahr
AND bstat IN @rt_rb // 선택옵션에 따라 select
//-- item 추가조건
AND hkont IN @so_hkont
AND lifnr IN @so_lifnr
AND kunnr IN @so_kunnr
AND kostl IN @so_kostl // 코스트센터
AND prctr IN @so_prctr // 손익센터
INTO CORRESPONDING FIELDS OF TABLE @gt_item.
ENDIF.