處理數(shù)據(jù)先檢查再取數(shù)據(jù)
START-OF-SELECTION .
PERFORM CHECK_DATA.
PERFORM GET_DATA.
僅做簡(jiǎn)單檢查
FORM CHECK_DATA.
IF S_LIFNR IS INITIAL AND S_MATNR IS INITIAL AND S_EKORG IS INITIAL AND S_WERKS IS INITIAL AND S_MATKL IS INITIAL AND S_EKGRP IS INITIAL.
MESSAGE S208(00) WITH 'Please input query parameters'.
EXIT.
ENDIF.
ENDFORM.
取數(shù)據(jù)部分:GET_DATA. 最先大條件, 再做篩選锈拨。
FROM table 與INNER JOIN必須連在一起寫(xiě),不然會(huì)報(bào)錯(cuò)昭雌。
SELECT
A~LIFNR,
A~MATNR,
E~EKORG,
E~WERKS,
E~ESOKZ,
A~MEINS,
A~UMREZ,
A~UMREN,
A~VABME,
E~NETPR,
E~WAERS,
E~PEINH,
E~BPRME,
B~PEINH AS MM_PEINH,
A~LMEIN,
E~MWSKZ,
A~MFRNR,
E~EKGRP,
E~APLFZ,
E~MINBM,
E~NORBM,
E~INCO1,
E~INCO2,
A~IDNLF,
A~RELIF,
A~INFNR,
A~URZLA,
A~TELF1,
M~MTART,
E~LOEKZ,
C~MMSTA
INTO CORRESPONDING FIELDS OF TABLE @GT_ITAB
FROM EINA AS A "PIR:General Data
INNER JOIN EINE AS E ON A~INFNR = E~INFNR "PIR -Purchasing Organization Data
INNER JOIN MARA AS M ON A~MATNR = M~MATNR "General Material Data
LEFT JOIN MARC AS C ON A~MATNR = C~MATNR AND E~WERKS = C~WERKS "Plant Data for Material
LEFT JOIN MBEW AS B ON A~MATNR = B~MATNR AND E~WERKS = B~BWKEY "Material Valuation
WHERE A~MATNR IN @S_MATNR
AND E~WERKS IN @S_WERKS
AND A~LIFNR IN @S_LIFNR
AND E~EKORG IN @S_EKORG
AND E~ESOKZ IN @S_ESOKZ
AND M~MATKL IN @S_MATKL
AND E~EKGRP IN @S_EKGRP
AND M~MTART IN @S_MTART
再檢查:CHECK語(yǔ)句基于條件終止循環(huán)傳遞复唤。 如果CHECK語(yǔ)句中的條件被計(jì)算為false,則忽略CHECK語(yǔ)句之后的語(yǔ)句塊中的所有剩余語(yǔ)句烛卧,并且下一個(gè)循環(huán)開(kāi)始佛纫。 CHECK語(yǔ)句中的條件可以是任何邏輯表達(dá)式妓局。
CHECK跳轉(zhuǎn)的前提是<expr>為假時(shí)。
l CHECK只是跳出當(dāng)前事件塊呈宇,繼續(xù)下一個(gè)事件塊的處理好爬,相當(dāng)于方法的return;
l 另外甥啄,如果CHECK在循環(huán)(DO存炮、WHILE、LOOP)里蜈漓,只是跳出當(dāng)前循環(huán)而已穆桂;
l 如果CHECK出現(xiàn)在循環(huán)以外,退出的是當(dāng)前執(zhí)行的程序塊(processing block),例如一個(gè)FORM融虽,METHOD享完,或EVENT。
詳細(xì)參考 https://www.cnblogs.com/jiangzhengjun/p/4265443.html
CHECK SY-SUBRC = 0 .
SELECT * INTO TABLE gt_a017 FROM a017
WHERE matnr IN s_matnr
AND werks IN s_werks
AND lifnr IN s_lifnr
AND ekorg IN s_ekorg
AND esokz IN s_esokz.
IF sy-subrc = 0.
IF C_DEL = ' '.
DELETE GT_ITAB WHERE LOEKZ = 'X'. "Purch. info: Purch. organization data flagged for deletion
ENDIF.
SELECT * INTO TABLE GT_KONP FROM KONP
FOR ALL ENTRIES IN GT_A017
WHERE KNUMH = GT_A017-KNUMH.
SELECT * INTO TABLE GT_KONM FROM KONM
FOR ALL ENTRIES IN GT_A017
WHERE KNUMH = GT_A017-KNUMH.
ENDIF.
SORT gt_a017 BY matnr werks matnr ekorg esokz .
IF c_due = ' '.
DELETE gt_a017 WHERE datab > sy-datum OR datbi < sy-datum.
ELSE.
IF p_datab IS NOT INITIAL.
DELETE gt_a017 WHERE datab < p_datab.
ENDIF.
IF p_datbi IS NOT INITIAL.
DELETE gt_a017 WHERE datbi > p_datbi.
ENDIF.
ENDIF.
IF c_del = ' '.
DELETE gt_konp WHERE loevm_ko = 'X'.
ENDIF.
對(duì)表中數(shù)據(jù)進(jìn)行轉(zhuǎn)換有额,取值為內(nèi)部形式(物料號(hào)有前導(dǎo)零的時(shí)候被認(rèn)為是內(nèi)部形式般又;單位一般也有內(nèi)部形式外部形式之分)。在se11瀏覽數(shù)據(jù)的時(shí)候巍佑,顯示數(shù)據(jù)的畫(huà)面是使用內(nèi)部形式茴迁,當(dāng)detail overview的時(shí)候,則是外部形式句狼。顯示前轉(zhuǎn)換成外部形式笋熬。
在SAP系統(tǒng)里面很多地方都用到了長(zhǎng)文本,這些長(zhǎng)文本的值以其他字符的形式存在表STXL和STXH里面腻菇,不能直接去這兩個(gè)表里面去取值胳螟,而是要通過(guò)函數(shù)READ_TEXT去取. 很多新手不了解的地方可能就是怎么取到READ_TEXT函數(shù)里面的那些參數(shù)值,我這邊介紹兩種方法筹吐,通過(guò)這兩種方法都可以找到那幾個(gè)參數(shù):
一糖耸、第一種利用跟蹤查詢,不是用ST05跟蹤丘薛,而是去表里面跟蹤查詢嘉竟,比如你剛剛創(chuàng)建了一個(gè)銷售訂單的長(zhǎng)文本,這時(shí)候你可以去表STXH輸入日期和剛剛的時(shí)間洋侨,然后查看在這個(gè)表里剛剛產(chǎn)生的這些數(shù)據(jù)舍扰,依據(jù)此項(xiàng)就可以找到對(duì)應(yīng)的參數(shù)了,這個(gè)方法非常實(shí)用
二希坚、第二種前臺(tái)查看边苹,進(jìn)入長(zhǎng)文本編輯界面以后(記得是雙擊長(zhǎng)文本編輯器進(jìn)入),點(diǎn)擊菜單轉(zhuǎn)到—->表頭裁僧,里面出現(xiàn)的就是對(duì)應(yīng)的那些參數(shù)值个束,如下圖:
SE37: READ_TEXT
LOOP AT gt_itab.
CLEAR gt_itab-potxt.
CONCATENATE gt_itab-infnr gt_itab-ekorg '0' gt_itab-werks INTO tdname.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'BT'
language = 'E'
name = tdname
object = 'EINE'
* archive_handle = 0
* IMPORTING
* HEADER = GW_THEAD " Change 1 (need a header)
TABLES
lines = t_line
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF sy-subrc = 0.
* read table t_table into wa_tline index 1.
* I_ITAB-ZTEXT = wa_tline-tdline.
LOOP AT t_line INTO wa_tline.
CONCATENATE gt_itab-potxt wa_tline-tdline INTO gt_itab-potxt.
ENDLOOP.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = gt_itab-meins
* LANGUAGE = SY-LANGU
IMPORTING
* LONG_TEXT =
output = gt_itab-meins
* SHORT_TEXT =
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2
.
LOOP AT gt_a017 WHERE lifnr = gt_itab-lifnr
AND matnr = gt_itab-matnr
AND ekorg = gt_itab-ekorg
AND werks = gt_itab-werks
AND esokz = gt_itab-esokz.
* AND DATAB <= SY-DATUM
* AND DATBI >= SY-DATUM.
gt_itab-datab = gt_a017-datab.
gt_itab-datbi = gt_a017-datbi.
gt_itab-knumh = gt_a017-knumh.
LOOP AT gt_konp WHERE knumh = gt_a017-knumh.
IF gt_konp-kzbzg <> ''.
LOOP AT gt_konm WHERE knumh = gt_konp-knumh AND kopos = gt_konp-kopos.
CLEAR gt_out_tmp.
MOVE-CORRESPONDING gt_itab TO gt_out_tmp.
gt_out_tmp-kstbm = gt_konm-kstbm.
* IF gt_konm-kstbm <> 0.
gt_out_tmp-kbetr = gt_konm-kbetr.
* ENDIF.
gt_out_tmp-peinh = gt_konp-kpein.
gt_out_tmp-waers = gt_konp-konwa.
gt_out_tmp-bprme = gt_konp-kmein.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = gt_out_tmp-bprme
* LANGUAGE = SY-LANGU
IMPORTING
* LONG_TEXT =
output = gt_out_tmp-bprme
* SHORT_TEXT =
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2
.
gt_out_tmp-netpr = gt_konp-kbetr.
gt_out_tmp-loevm_ko = gt_konp-loevm_ko.
* Begin of change SAPCI#2690
IF c_cur IS NOT INITIAL.
PERFORM base_currency USING gt_out_tmp-netpr
gt_out_tmp-waers
gt_out_tmp-peinh
CHANGING gt_out_tmp-b_netpr
gt_out_tmp-b_waers
gt_out_tmp-b_netpr1.
ENDIF.
* End of change SAPCI#2690
APPEND gt_out_tmp.
ENDLOOP.
ELSE.
* CLEAR gt_out_tmp.
MOVE-CORRESPONDING gt_itab TO gt_out_tmp.
gt_out_tmp-peinh = gt_konp-kpein.
gt_out_tmp-waers = gt_konp-konwa.
gt_out_tmp-bprme = gt_konp-kmein.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = gt_out_tmp-bprme
* LANGUAGE = SY-LANGU
IMPORTING
* LONG_TEXT =
output = gt_out_tmp-bprme
* SHORT_TEXT =
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2
.
gt_out_tmp-netpr = gt_konp-kbetr.
gt_out_tmp-loevm_ko = gt_konp-loevm_ko.
* Begin of change SAPCI#2690
IF c_cur IS NOT INITIAL.
PERFORM base_currency USING gt_out_tmp-netpr
gt_out_tmp-waers
gt_out_tmp-peinh
CHANGING gt_out_tmp-b_netpr
gt_out_tmp-b_waers
gt_out_tmp-b_netpr1.
ENDIF.
* End of change SAPCI#2690
APPEND gt_out_tmp.
ENDIF.
ENDLOOP.
ENDLOOP.
IF sy-subrc <> 0 .
IF gt_itab-mtart = 'ZSV'.
* DATA:PV_MTART TYPE MARA-MTART.
* SELECT SINGLE MTART INTO PV_MTART FROM MARA WHERE MATNR = GT_ITAB-MATNR.
* IF PV_MTART = 'ZSV'.
MOVE-CORRESPONDING gt_itab TO gt_out_tmp.
APPEND gt_out_tmp.
ENDIF.
ENDIF.
ENDLOOP.
***{ D01K932831;CN0778;02/28/2019
LOOP AT gt_out_tmp.
*{ SAPCI-2801 Start
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = gt_out_tmp-lmein
IMPORTING
output = gt_out_tmp-lmein
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
IF gt_out_tmp-meins EQ gt_out_tmp-lmein.
gt_out_tmp-mm_netpr = gt_out_tmp-b_netpr1 * gt_out_tmp-mm_peinh.
ELSE.
DATA(lv_prcunit_buom) = gt_out_tmp-peinh * ( gt_out_tmp-umrez / gt_out_tmp-umren ).
gt_out_tmp-mm_netpr = ( gt_out_tmp-b_netpr / lv_prcunit_buom ) * gt_out_tmp-mm_peinh.
ENDIF.
*} SAPCI-2801 End