SAP ABAP 中有关数据查询与计算问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAP ABAP 中有关数据查询与计算问题相关的知识,希望对你有一定的参考价值。

(1) 关联表EKKO、EKPO、EKET MAKT,取出采购订单号、物料、物料描述、采购订单下单量、下单日期、交期、请购部门。
(2) 计算已收货量:根据采购订单号、项目号关联采购订单历史表EKBE,首先根据借贷标识EKBE-SHKZG将EKBE-MENGE(数量)赋予正负号,SHKZG为S时为正数,SHKZG为H时为负数。再将相同采购订单号、项目号、EKBE-VGABE=1的数量(EKBE-MENGE)汇总,计算出已收货量
(3) 计算未清量:用采购订单行项目的数量减去已收货量得出未清量.
(4) 供应商描述:根据EKKO-LIFNR供应商账号关联表LFA1- NAME1取出描述.
(5) 物料描述:根据料号关联表MAKT-MAKTX,取出物料描述.
(6) 选择界面有”未清采购订单”的参数,控制显示的范围,如果选中,则仅显示未清的采购订单(未清量不等于0的),默认为选中状态. At select screen on
(7) 表格执行的结果分表头信息和项目信息,详见“消息输出界面”。输出的结果需要直接打印,打印内容宽度要适合页面。
给我指明 如何查询数据库 并且计算就可以了
SELECT
EKKO~BEDAT EKKO~EBELN EKPO~EBELP EKPO~AFNAM EKPO~MENGE EKPO~MEINS EKET~EINDT MAKT~MATNR MAKT~MAKTX LFA1~ LIFNR
LFA1~ NAME1
INTO CORRESPONDING FIELDS OF TABLE ITAB
From LFAL inner join EKKO on LFAL~LIFNR = EKKO~LIFNR
Inner join EKET on EKKO ~EBELN = EKET ~EBELN
Inner join EKPO on EKET~EBELN = EKPO~EBELN
AND EKET~EBELP = EKPO~EBELP
inner join MARK on EKKO~MATNR = MARK ~ MATNR.
Where LFA1~ NAME1in NAME1 .
Select EKBE-SHKZG EKBE-MENGE EKBE-VGABE from EKBE
INTO EKBE
From LFAL inner join EKKO on LFAL~LIFNR = EKKO~LIFNR
Inner join EKET on EKKO ~EBELN = EKET ~EBELN
Inner join EKBE on EKET~EBELN = EKBE~EBELN
AND EKET~EBELP = EKBE~EBELP
Where LFA1~ NAME1in NAME1 .
If EKBE-SHKZG = S.
EKBE -MENGE = EKBE -MENGE.
Else.
EKBE -MENGE = - EKBE -MENGE.
Endif.
loop at itab into wa.
Wa-yijiao = EKBE –MENGE.
Append wa to itab.
If EKBE-VGABE=1.
Collect itab.
Endloop.

Endselect.
ENDFORM.

代码你自己都贴出来了...
建议:
SELECT
EKKO~BEDAT EKKO~EBELN EKPO~EBELP EKPO~AFNAM EKPO~MENGE EKPO~MEINS EKET~EINDT MAKT~MATNR MAKT~MAKTX LFA1~ LIFNR
LFA1~ NAME1
INTO CORRESPONDING FIELDS OF TABLE ITAB
From LFAL inner join EKKO on LFAL~LIFNR = EKKO~LIFNR
Inner join EKET on EKKO ~EBELN = EKET ~EBELN
Inner join EKPO on EKET~EBELN = EKPO~EBELN
AND EKET~EBELP = EKPO~EBELP
inner join MARK on EKKO~MATNR = MARK ~ MATNR.
Where LFA1~ NAME1in NAME1 .
"这里已经取出订单数量了.LOOP去查交货数量就好了.
LOOP AT ITAB.
Select EKBE-SHKZG EKBE-MENGE EKBE-VGABE from EKBE
INTO CORRESPONDING FIELDS OF TABLE WA_EKBE
From LFAL inner join EKKO on LFAL~LIFNR = EKKO~LIFNR
Inner join EKET on EKKO ~EBELN = EKET ~EBELN
Inner join EKBE on EKET~EBELN = EKBE~EBELN
AND EKET~EBELP = EKBE~EBELP
Where LFA1~ NAME1in NAME1
AND EKET~EBELN = ITAB-EBELN
AND EKET~EBELP = ITAB-EBELP .
LOOP AT WA_EKBE.
If WA_EKBE-SHKZG = S.
WA_EKBE -MENGE = WA_EKBE -MENGE.
Else.
WA_EKBE -MENGE = WA_EKBE -MENGE * -1.
Endif.
交货数量ITAB = 交货数量ITAB + WA_EKBE -MENGE.
ENDLOOP.
"汇总
If EKBE-VGABE=1.
Collect itab.
endif.

ENDLOOP.

未经测试!!!
参考技术A 本来需要做一个PO统计,正好兄台给了解释,多谢多谢,很详细,很需要! 参考技术B 你不是都写清楚了吗? 还想知道什么?追问

我要的是代码

追答

要代码的话,没人能帮你了。写这段代码得半天时间。

参考技术C adasdasd

关于SAP ABAP table control 显示数据、修改数据的问题

我用screen painter画了个屏幕,然后在选项卡内建了个与内表相联系的table control,
(1)显示数据:table control是能得到数据的,但刚进屏幕时,table control并没有显示数据,需要回车或点击什么才能显示出来,这是什么原因啊,要怎么改代码啊?
(2)修改数据:现在要修改table control内的数据,但修改数据后回车,数据还是原来的数据,并没有修改成功,这是什么原因啊,要怎么改代码啊?

问题1:取内表数据你改到pbo事件中完成(显示table control前)。
目前可能你写到pai才会造成回车后才能显示数据。。。
问题2:追加modify命令
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TBL_9000'
LOOP AT ITAB_9100.
CHAIN.
FIELD H_9100-MATNR.
FIELD H_9100-ERSDA.
MODULE TBL_9000_MODIFY ON CHAIN-REQUEST.
endchain.
ENDLOOP.
module TBL_9000_MODIFY input.
MODIFY ITAB_9100
FROM H_9100
INDEX TBL_9000-CURRENT_LINE.
endmodule. " TBL_9000_MODIFY INPUT追问

这些不是自动生成的代码吗?
我的还是修改不了啊。。

追答

MODULE TBL_9000_MODIFY ON CHAIN-REQUEST.
module TBL_9000_MODIFY input.
MODIFY ITAB_9100
FROM H_9100
INDEX TBL_9000-CURRENT_LINE.
endmodule. " TBL_9000_MODIFY INPUT
这两块代码需要你加进去,很容易的

参考技术A TABLE CONTROL里面最初显示界面是 PBO显示的,按钮是先触发了PAI ,然后走PBO的,所以在要写在PBO里面 参考技术B 主程序:

*声明table control里面表控件使用的结构
TABLES demo_conn.
*声明table control
CONTROLS sflight TYPE TABLEVIEW USING SCREEN 100.
*定义control cols表的行工作区
DATA col LIKE LINE OF sflight-cols.
*定义一个整型变量用来存储内表行数
DATA fill TYPE i.
*定义内表用来填充control的table
DATA itab TYPE STANDARD TABLE OF demo_conn.
*定义OK_CODE 存储ftcode
DATA ok_code TYPE sy-ucomm.
DATA ok_save TYPE sy-ucomm.

*---------------------------------------------------------*
*Event blocks *
*---------------------------------------------------------*

*start-of-selection event---------------------------------
START-OF-SELECTION.

*获取数据
SELECT *
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE itab.
*取得内表行数
DESCRIBE TABLE itab LINES fill.
*初始化table control的行数
sflight-lines = fill.

CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* 设置菜单 工具 栏
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_001'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module MODIFY_CT INPUT
*&---------------------------------------------------------------------*
* 更新内表
*----------------------------------------------------------------------*
MODULE modify_ct INPUT.
MODIFY itab FROM demo_conn INDEX sflight-current_line.
ENDMODULE. " MODIFY_CT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* 处理那些按钮事件
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
ok_save = ok_code.
CLEAR ok_code.
CASE ok_save.
WHEN 'CHANGE'.
*当点击修改按钮,此时要需要修改control cols的input属性(cols包含所有列相关信息)
LOOP AT sflight-cols INTO col WHERE index GT 2.
IF col-screen-input EQ '1'.
col-screen-input = '0'.
modify sflight-cols from col index sy-tabix.
ELSEIF col-screen-input EQ '0'.
col-screen-input = '1'.
modify sflight-cols from col index sy-tabix.
ELSE.
ENDIF.
ENDLOOP.
*当点击sort_down按钮,此时需要对内表针对选中的地列进行排序
WHEN 'SORT_DOWN'.
READ TABLE sflight-cols INTO col WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab BY (col-screen-name+10) DESCENDING.
col-selected = ''.
MODIFY sflight-cols FROM col INDEX sy-tabix.
ENDIF.
*当点击sort_up按钮。。。。 。。。
WHEN 'SORT_UP'.
READ TABLE sflight-cols INTO col WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab BY (col-screen-name+10) ASCENDING.
col-selected = ''.
MODIFY sflight-cols FROM col INDEX sy-tabix.
ENDIF.
*当点击删除按钮,此时需要更新内表
WHEN 'DELETE'.
READ TABLE sflight-cols INTO col WITH KEY screen-input = '1'.
IF sy-subrc = 0.
LOOP AT itab INTO demo_conn WHERE mark = 'X'.
DELETE itab INDEX sy-tabix.
ENDLOOP.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module READ_DATA OUTPUT
*&---------------------------------------------------------------------*
* 读取内表数据
*----------------------------------------------------------------------*
MODULE read_data OUTPUT.
READ TABLE itab INTO demo_conn INDEX sflight-current_line.
ENDMODULE. " READ_DATA OUTPUT
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* 强制退出
*----------------------------------------------------------------------*
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. " CANCEL INPUT

屏幕逻辑流:

PROCESS BEFORE OUTPUT.
MODULE status_0100.
LOOP WITH CONTROL sflight.
MODULE read_data.
ENDLOOP.
PROCESS AFTER INPUT.
MODULE cancel AT EXIT-COMMAND.
LOOP WITH CONTROL sflight.
MODULE modify_ct.
ENDLOOP.
MODULE user_command_0100.

以上是关于SAP ABAP 中有关数据查询与计算问题的主要内容,如果未能解决你的问题,请参考以下文章

abap开发具体项目经验

sap abap中为啥table和该table的view有些数据会不同

sap 怎么看abap程序逻辑取值

ABAP系列SAP ABAP 实现FTP的文件上传与下载

SAP ABAP 运算符

SAP ABAP开发是做啥?