# ABAP4初学者示例

ABAP4初学者示例

PROGRAM  TEST.
TABLES:  EKKO,EKET,EKPO.

DATA: BEGIN OF ITAB OCCURS 0,
EBELN LIKE EKKO-EBELN,
MENGE LIKE EKPO-MENGE,
WEMNG LIKE EKET-WEMNG,
END OF ITAB.

DATA: MATNR  LIKE EKPO-MATNR,
MENGE  LIKE EKPO-MENGE,
WEMNG  LIKE EKET-WEMNG,
EBELN  LIKE EKPO-EBELN.

SELECT-OPTIONS:      EBELN1 FOR  EKKO-EBELN,
BEDAT FOR  EKKO-BEDAT,
EKGRP FOR  EKKO-EKGRP.

SELECT  K~EBELN
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM EKKO AS K
WHERE   K~EBELN IN EBELN1
AND   K~BEDAT IN BEDAT
AND   K~EKGRP IN EKGRP.

LOOP AT ITAB.
SELECT SUM( MENGE ) INTO ITAB-MENGE
FROM EKPO
WHERE EBELN EQ ITAB-EBELN.
MODIFY ITAB.
ENDLOOP.

LOOP AT ITAB.
SELECT SUM( WEMNG ) INTO ITAB-WEMNG
FROM EKET
WHERE EBELN EQ ITAB-EBELN.
MODIFY ITAB.
ENDLOOP.

TOP-OF-PAGE .
WRITE: /'采购凭证号',22 '物料号码',
47 '采购订单数量',77  '收到货物数量',
95 '完成标志'.
ULINE AT /1(130).
END-OF-PAGE .

START-OF-SELECTION.

IF R1 = 'X'.
LOOP AT ITAB.
SELECT S~MATNR S~MENGE P~WEMNG S~EBELN
INTO (MATNR, MENGE, WEMNG, EBELN)
FROM EKPO AS S INNER JOIN EKET AS P
ON S~EBELP = P~EBELP AND S~EBELN = P~EBELN
WHERE S~EBELN = ITAB-EBELN.
IF ITAB-MENGE > ITAB-WEMNG.
WRITE: /2 EBELN,23 MATNR,41 MENGE,
71 WEMNG,97 '否'.
ULINE AT /1(130).
CLEAR: EBELN,MATNR,MENGE,WEMNG.
ENDIF.
ENDSELECT.
ENDLOOP.

ELSEIF R2 = 'X'.
LOOP AT ITAB.
SELECT S~MATNR S~MENGE P~WEMNG S~EBELN
INTO (MATNR, MENGE, WEMNG, EBELN)
FROM EKPO AS S INNER JOIN EKET AS P
ON S~EBELP = P~EBELP AND S~EBELN = P~EBELN
WHERE S~EBELN = ITAB-EBELN.
IF  ITAB-MENGE <= ITAB-WEMNG.
WRITE: /2 EBELN,23 MATNR,41 MENGE,
71 WEMNG,97 '是'.
ULINE AT /1(130).
CLEAR: EBELN,MATNR,MENGE,WEMNG.
ENDIF.
ENDSELECT.
ENDLOOP.

ELSE.
LOOP AT ITAB.

SELECT S~MATNR S~MENGE P~WEMNG S~EBELN
INTO (MATNR, MENGE, WEMNG, EBELN)
FROM EKPO AS S INNER JOIN EKET AS P
ON S~EBELP = P~EBELP AND S~EBELN = P~EBELN
WHERE S~EBELN = ITAB-EBELN.
IF ITAB-MENGE > ITAB-WEMNG.
WRITE: /2 EBELN, 23 MATNR,41 MENGE,
71 WEMNG,97 '否'.
ULINE AT /1(130).
CLEAR: EBELN,MATNR,MENGE,WEMNG.
ENDIF.
ENDSELECT.
ENDLOOP.
ENDIF.

LOOP AT ITAB.
IF R3 = 'X' AND ITAB-MENGE <= ITAB-WEMNG.
SELECT S~MATNR S~MENGE P~WEMNG S~EBELN
INTO (MATNR, MENGE, WEMNG, EBELN)
FROM EKPO AS S INNER JOIN EKET AS P
ON S~EBELP = P~EBELP AND S~EBELN = P~EBELN
WHERE S~EBELN = ITAB-EBELN.
WRITE: /2 EBELN,23 MATNR,41 MENGE,
71 WEMNG,97 '是'.
ULINE AT /1(130).
CLEAR: EBELN,MATNR,MENGE,WEMNG.
ENDSELECT.
ENDIF.
ENDLOOP.

• 本文已收录于以下专栏：

举报原因： 您举报文章：ABAP4初学者示例 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)