一.主程序
代码语言:javascript复制*&---------------------------------------------------------------------*
*& Report ZSF_BAPI_02
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSF_BAPI_02.
INCLUDE ZSF_BAPI_02_TOP. "全局变量
INCLUDE ZSF_BAPI_02_SCREEN."选择屏幕
INCLUDE ZSF_BAPI_02_F01. "获取数据到内表
INCLUDE ZSF_BAPI_02_C01. "导入数据判断
INCLUDE ZSF_BAPI_02_O01. "ALV显示
INCLUDE ZSF_BAPI_02_I01. "用户点击事件
INCLUDE ZSF_BAPI_02_BAPI01."调用BAPI
INITIALIZATION.
"模板下载图标设置
START-OF-SELECTION.
PERFORM UPLOUD_EXCEL. "导入EXCEL数据
二.全局变量
代码语言:javascript复制TABLES : SSCRFIELDS.
TYPE-POOLS: ICON. "引用图标
TYPES: BEGIN OF TY_DATA,
"采购订单抬头
BSART TYPE EKKO-BSART, "采购订单类型
LLIEF TYPE EKKO-LLIEF, "供应商代码
EKORG TYPE EKKO-EKORG, "采购组织
EKGRP TYPE EKKO-EKGRP, "采购组
BUKRS TYPE EKKO-BUKRS, "公司代码
EBELP TYPE EKPO-EBELP, "采购凭证项目编号
KNTTP TYPE EKPO-KNTTP, "科目分配类别
BSTYP TYPE EKPO-BSTYP, "项目类别
MATNR TYPE EKPO-MATNR, "物料编码
MENGE TYPE EKPO-MENGE, "订单数量
MEINS TYPE EKPO-MEINS, "订单单位
EINDT TYPE EKET-EINDT, "交货日期(需要转换)char8-char10
WERKS TYPE EKPO-WERKS, "工厂
LGORT TYPE EKPO-LGORT, "库存地点
END OF TY_DATA.
DATA: GT_DATA TYPE TABLE OF TY_DATA,
GW_DATA TYPE TY_DATA.
DATA: BEGIN OF GT_NUM OCCURS 0,
NUM TYPE I VALUE 0,
END OF GT_NUM.
DATA: BEGIN OF GW_ALV,
NUM, "自主定义编号
BOX, "自主选择按钮
ICON(4), "校验灯 图标
EBELN TYPE BAPIMEPOHEADER-PO_NUMBER, "接受采购凭证编号
LMESS TYPE STRING. "测试信息
INCLUDE STRUCTURE GW_DATA. "定义结构体继承的具体语句为:INCLUDE STRUCTURE
DATA: END OF GW_ALV,
GT_ALV LIKE STANDARD TABLE OF GW_ALV."参照gs_alv创建内表
*定义alv显示用到的全局参数
*定义FIELDCAT内表和工作区
DATA :GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE.
*定义布局
DATA: GW_LAYOUT TYPE LVC_S_LAYO,
GW_GRID_SETTINGS TYPE LVC_S_GLAY.
*设置字段排序
DATA : GT_SORT TYPE LVC_T_SORT WITH HEADER LINE.
*定义alv对象,alv回调时候用,一般不用
DATA: GR_GRID TYPE REF TO CL_GUI_ALV_GRID.
*为FIELDCAT定义宏,其中&1表示占位符
*以下含有“是否”的值范围内为空和X
DEFINE DE_FIELDCAT.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-FIELDNAME = &1. "字段名
GT_FIELDCAT-SCRTEXT_L = &2. "字段长描述
GT_FIELDCAT-KEY = &3. "主键,蓝底显示,默认冻结列
GT_FIELDCAT-NO_ZERO = &4. "不显示0值
GT_FIELDCAT-EDIT = &5. "是否编辑
GT_FIELDCAT-REF_FIELD = &6. "参考字段 &6 &7 一起使用
GT_FIELDCAT-REF_TABLE = &7. "参考表 &6 &7 一起使用
GT_FIELDCAT-FIX_COLUMN = &8. "冻结列
GT_FIELDCAT-ICON = &9. "图标
APPEND GT_FIELDCAT.
END-OF-DEFINITION.
三.选择屏幕
(在文本消息中给P_FILE赋值为‘需要上传的文件:’)
代码语言:javascript复制SELECTION-SCREEN BEGIN OF BLOCK B1K1 WITH FRAME TITLE TEXT-T01.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME . "上传文件
SELECTION-SCREEN END OF BLOCK B1K1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. "文件搜索帮助
PERFORM GET_FILENAME.
*&---------------------------------------------------------------------*
*& Form GET_FILENAME
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM GET_FILENAME .
"方法二:
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG "此处填SY-CPROG同样
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
*
ENDFORM.
四.获取数据到内表
代码语言:javascript复制*&---------------------------------------------------------------------*
*& 包含 ZSF_BAPI_02_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form UPLOUD_EXCEL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM UPLOUD_EXCEL .
"显示ALV,此步骤不进行检查和批导工作,仅作为EXCEL数据展示用.第一次ALV展示!
DATA:LT_INTERN TYPE STANDARD TABLE OF KCDE_INTERN_STRUC, "定义输出的内表
LS_INTERN TYPE KCDE_INTERN_STRUC, "定义内表所属的工作区
L_COL TYPE I. "定义行数
FIELD-SYMBOLS:<FS>. "在ABAP编程中使用非常广泛,类似于指针,可以指代任何变量。
"当不输入<type>时,<fs>继承赋给它的变量的所有属性
"当输入<type>时,赋给它的变量必须与<fs>同类型。
CHECK P_FILE IS NOT INITIAL.
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
FILENAME = P_FILE"读取导入的excel信息
I_BEGIN_COL = 1 "从excel表格的第一列开始读取
I_BEGIN_ROW = 2 "从excel表格的第二行开始读取,因为第一行存储所填信息字段
I_END_COL = 39 "最多读取的列数
I_END_ROW = 10000 "最多读取的数据行数,也就是一次做多9999行数据
TABLES
INTERN = LT_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CHECK LT_INTERN IS NOT INITIAL. "判断值已传入内表中
LOOP AT LT_INTERN INTO LS_INTERN.
MOVE LS_INTERN-COL TO L_COL. "将列号存入L_COL中
ASSIGN COMPONENT L_COL OF STRUCTURE GW_DATA TO <FS>. "再GW_EXCEL中的列号存入<FS>中
MOVE LS_INTERN-VALUE TO <FS>.
AT END OF ROW.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
INPUT = GW_DATA-MATNR
IMPORTING
OUTPUT = GW_DATA-MATNR
EXCEPTIONS
LENGTH_ERROR = 1
OTHERS = 2.
APPEND GW_DATA TO GT_DATA.
CLEAR GW_DATA.
ENDAT.
ENDLOOP.
"第一次调用ALV显示8
CLEAR GT_ALV. "防止数据重复,清空内表
LOOP AT GT_DATA INTO GW_DATA.
MOVE-CORRESPONDING GW_DATA TO GW_ALV.
"为每条数据编号
GW_ALV-NUM = GT_NUM-NUM 1 .
GT_NUM-NUM = GT_NUM-NUM 1 .
APPEND GT_NUM.
APPEND GW_ALV TO GT_ALV.
CLEAR GW_ALV.
ENDLOOP.
"调用ALV显示子程序
PERFORM FRM_RETURN.
ENDFORM.
五.对导入的数据进行判断
代码语言:javascript复制*&---------------------------------------------------------------------*
*& 包含 ZSF_BAPI_02_C01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_CHECK_DATA .
TYPES: BEGIN OF TY_EKKO,
BSART TYPE EKKO-BSART, "采购订单类型
LLIEF TYPE EKKO-LLIEF, "供应商代码
EKORG TYPE EKKO-EKORG, "采购组织
EKGRP TYPE EKKO-EKGRP, "采购组
END OF TY_EKKO.
TYPES: BEGIN OF TY_EKPO,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
WERKS TYPE EKPO-WERKS,
END OF TY_EKPO.
DATA: GT_EKKO TYPE TABLE OF TY_EKKO,
GW_EKKO TYPE TY_EKKO,
GT_EKPO TYPE TABLE OF TY_EKPO,
GW_EKPO TYPE TY_EKPO,
LV_SIGN(1). "标记
SELECT
BSART
LLIEF
EKORG
EKGRP
FROM EKKO
INTO CORRESPONDING FIELDS OF TABLE GT_EKKO.
SELECT
MATNR
WERKS
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE GT_EKPO.
SORT: GT_EKKO BY BSART LLIEF EKORG EKGRP ASCENDING,
GT_EKPO BY MATNR WERKS ASCENDING.
LOOP AT GT_DATA INTO GW_DATA.
MOVE-CORRESPONDING GW_DATA TO GW_ALV.
IF GW_ALV-BSART = ''.
LV_SIGN = 'R'.
GW_ALV-LMESS = '采购订单类型为必填'.
ENDIF.
IF GW_ALV-LLIEF = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '供应商代码为必输' INTO GW_ALV-LMESS.
ENDIF.
IF GW_ALV-EKORG = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '采购组织为必输' INTO GW_ALV-LMESS.
ENDIF.
IF GW_ALV-EKGRP = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '采购组为必输' INTO GW_ALV-LMESS.
ENDIF.
IF GW_ALV-MATNR = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '物料编码为必输' INTO GW_ALV-LMESS.
ENDIF.
IF GW_ALV-MENGE = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '订单数量为必填' INTO GW_ALV-LMESS.
ENDIF.
IF GW_ALV-EINDT = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '交货日期为必输' INTO GW_ALV-LMESS.
ENDIF.
IF GW_ALV-WERKS = ''.
LV_SIGN = 'R'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '工厂为必输' INTO GW_ALV-LMESS.
ENDIF.
IF LV_SIGN = 'R'.
GW_ALV-ICON = ICON_LED_RED.
ELSE.
READ TABLE GT_EKKO WITH KEY BSART = GW_ALV-BSART BINARY SEARCH TRANSPORTING NO FIELDS .
IF SY-SUBRC <> 0.
LV_SIGN = 'Y'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '不存在该采购订单类型请校验' INTO GW_ALV-LMESS.
ENDIF.
READ TABLE GT_EKKO WITH KEY LLIEF = GW_ALV-LLIEF BINARY SEARCH TRANSPORTING NO FIELDS .
IF SY-SUBRC <> 0.
LV_SIGN = 'Y'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '不存在该供货商请校验' INTO GW_ALV-LMESS.
ENDIF.
READ TABLE GT_EKKO WITH KEY EKORG = GW_ALV-EKORG BINARY SEARCH TRANSPORTING NO FIELDS .
IF SY-SUBRC <> 0.
LV_SIGN = 'Y'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '不存在该采购组织请校验' INTO GW_ALV-LMESS.
ENDIF.
READ TABLE GT_EKKO WITH KEY EKGRP = GW_ALV-EKGRP BINARY SEARCH TRANSPORTING NO FIELDS .
IF SY-SUBRC <> 0.
LV_SIGN = 'Y'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '不存在该采购组请校验' INTO GW_ALV-LMESS.
ENDIF.
READ TABLE GT_EKPO WITH KEY MATNR = GW_ALV-MATNR BINARY SEARCH TRANSPORTING NO FIELDS .
IF SY-SUBRC <> 0.
LV_SIGN = 'Y'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '不存在该物料编号请校验' INTO GW_ALV-LMESS.
ENDIF.
READ TABLE GT_EKPO WITH KEY WERKS = GW_ALV-WERKS BINARY SEARCH TRANSPORTING NO FIELDS .
IF SY-SUBRC <> 0.
LV_SIGN = 'Y'.
IF GW_ALV-LMESS <> ''.
CONCATENATE GW_ALV-LMESS '||' INTO GW_ALV-LMESS.
ENDIF.
CONCATENATE GW_ALV-LMESS '不存在该工厂请校验' INTO GW_ALV-LMESS.
ENDIF.
ENDIF.
IF LV_SIGN = 'Y'.
GW_ALV-ICON = ICON_LED_YELLOW.
ELSEIF LV_SIGN = ''.
GW_ALV-ICON = ICON_LED_GREEN.
ENDIF.
APPEND GW_ALV TO GT_ALV.
CLEAR GW_ALV.
CLEAR GW_DATA.
CLEAR LV_SIGN.
ENDLOOP.
ENDFORM.
六.ALV显示
代码语言:javascript复制*&---------------------------------------------------------------------*
*& 包含 ZSF_BAPI_02_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_RETURN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_RETURN .
REFRESH GT_FIELDCAT.
" DE_FIELDCAT 'NUM' '' '' '' '' '' '' '' ''. "不显示 用于标记的编号
" DE_FIELDCAT 'BOX' '' '' '' '' '' '' '' ''. "不显示 用于选择的标记
DE_FIELDCAT 'ICON' '校验灯' '' '' '' '' '' '' 'X'.
DE_FIELDCAT 'EBELN' '订单编号' '' '' '' '' '' '' ''.
DE_FIELDCAT 'BSART' '采购订单类型' '' '' '' '' '' '' ''.
DE_FIELDCAT 'LLIEF' '供应商代码' '' '' '' '' '' '' ''.
DE_FIELDCAT 'EKORG' '采购组织' '' '' '' '' '' '' ''.
DE_FIELDCAT 'EKGRP' '采购组' '' '' '' '' '' '' ''.
DE_FIELDCAT 'BUKRS' '公司代码' '' '' '' '' '' '' ''.
DE_FIELDCAT 'EBELP' '采购凭证项目编号' '' '' '' '' '' '' ''.
DE_FIELDCAT 'KNTTP' '科目分配类别' '' '' '' '' '' '' ''.
DE_FIELDCAT 'BSTYP' '项目类别' '' '' '' '' '' '' ''.
DE_FIELDCAT 'MATNR' '物料编码' '' '' '' '' '' '' ''.
DE_FIELDCAT 'MENGE' '订单数量' '' '' '' '' '' '' ''.
DE_FIELDCAT 'MEINS' '订单单位' '' '' '' '' '' '' ''.
DE_FIELDCAT 'EINDT' '交货日期' '' '' '' '' '' '' ''.
DE_FIELDCAT 'WERKS' '工厂' '' '' '' '' '' '' ''.
DE_FIELDCAT 'LGORT' '库存地点' '' '' '' '' '' '' ''.
DE_FIELDCAT 'LMESS' '错误信息' '' '' '' '' '' '' ''.
GW_LAYOUT-CWIDTH_OPT = 'X'. "自动优化宽度
GW_LAYOUT-BOX_FNAME = 'BOX'."ALV显示内表的一个字段,用于标记被选中
* GW_LAYOUT-ZEBRA = 'X'. "斑马条
* GW_LAYOUT-CWIDTH_OPT = 'X'. "最佳列宽
* WA_LAYOUT-SEL_MODE = ''. "选择模式,'A"在最左端有选择按钮
* WA_LAYOUT-EDIT = ''. "是否允许输入
* GW_LAYOUT-BOX_FNAME = 'BOX'. "ALV显示内表的一个字段,用于标记被选中
* WA_LAYOUT-STYLEFNAME = 'FIELD_STYLE'. "指定ALV单元格的样式,控制是否可编辑
* gw_LAYOUT-CTAB_FNAME = 'CELL_COLOR'. "单元格颜色设置
IF GT_ALV IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_BUFFER_ACTIVE = 'X'
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_SET_STATUS'
I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'
IS_LAYOUT_LVC = GW_LAYOUT
I_GRID_SETTINGS = GW_GRID_SETTINGS
IT_FIELDCAT_LVC = GT_FIELDCAT[]
IT_SORT_LVC = GT_SORT[]
I_SAVE = 'A'
TABLES
T_OUTTAB = GT_ALV.
ELSE.
MESSAGE TEXT-W01 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
FORM FRM_SET_STATUS USING IT_EXTAB TYPE SLIS_T_EXTAB.
DATA:WA_EXTAB_LINE LIKE LINE OF IT_EXTAB.
SET PF-STATUS 'SAPLSLVC_FULLSCREEN' EXCLUDING IT_EXTAB .
ENDFORM. " FRM_SET_STATUS
七.用户点击事件
代码语言:javascript复制FORM FRM_USER_COMMAND USING UCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
DATA: L_REF_ALV TYPE REF TO CL_GUI_ALV_GRID.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = L_REF_ALV.
IF L_REF_ALV IS NOT INITIAL.
CALL METHOD L_REF_ALV->CHECK_CHANGED_DATA.
ENDIF.
CASE UCOMM.
WHEN 'ZCHEAK'.
CLEAR GT_ALV.
PERFORM FRM_CHECK_DATA.
PERFORM FRM_RETURN.
SELFIELD-REFRESH = 'X'. "刷新界面
WHEN 'ZUPLOUD'.
LOOP AT GT_ALV INTO GW_ALV WHERE BOX = 'X'.
IF GW_ALV-ICON = ICON_LED_GREEN.
MODIFY GT_ALV FROM GW_ALV TRANSPORTING NUM.
ELSEIF GW_ALV-ICON = ICON_LED_YELLOW OR GW_ALV-ICON = ICON_LED_RED.
MESSAGE E001(00) WITH '选择错误,只能批导检查通过的数据!'.
ENDIF.
ENDLOOP.
PERFORM FRM_BAPI_DATA.
SELFIELD-REFRESH = 'X'. "刷新界面
ENDCASE.
ENDFORM.
八.BAPI的调用
代码语言:javascript复制*&---------------------------------------------------------------------*
*& 包含 ZSF_BAPI_02_BAPI01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_BAPI_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_BAPI_DATA .
DATA: GS_POHEADER LIKE BAPIMEPOHEADER,
GS_POHEADERX LIKE BAPIMEPOHEADERX,
GT_RETURN TYPE TABLE OF BAPIRET2,
GS_RETURN LIKE BAPIRET2,
GT_POITEM TYPE TABLE OF BAPIMEPOITEM,
GS_POITEM TYPE BAPIMEPOITEM,
GT_POITEMX TYPE TABLE OF BAPIMEPOITEMX,
GS_POITEMX TYPE BAPIMEPOITEMX,
GT_POSCHEDULE TYPE TABLE OF BAPIMEPOSCHEDULE,
GS_POSCHEDULE TYPE BAPIMEPOSCHEDULE,
GT_POSCHEDULEX TYPE TABLE OF BAPIMEPOSCHEDULX,
GS_POSCHEDULEX TYPE BAPIMEPOSCHEDULX.
"接返回值
DATA: GS_EXPHEADER LIKE BAPIMEPOHEADER.
IF GT_ALV IS NOT INITIAL.
LOOP AT GT_ALV INTO GW_ALV.
GS_POHEADER-DOC_TYPE = GW_ALV-BSART.
GS_POHEADERX-DOC_TYPE = 'X'.
GS_POHEADER-SUPPL_VEND = GW_ALV-LLIEF.
GS_POHEADERX-SUPPL_VEND = 'X'.
GS_POHEADER-PURCH_ORG = GW_ALV-EKORG.
GS_POHEADERX-PURCH_ORG = 'X'.
GS_POHEADER-PUR_GROUP = GW_ALV-EKGRP.
GS_POHEADERX-PUR_GROUP = 'X'.
GS_POHEADER-COMP_CODE = GW_ALV-BUKRS.
GS_POHEADERX-COMP_CODE = 'X'.
"以下为内表
GS_POITEM-PO_ITEM = GW_ALV-EBELP.
GS_POITEMX-PO_ITEM = 'X'.
GS_POITEM-ACCTASSCAT = GW_ALV-KNTTP.
GS_POITEMX-ACCTASSCAT = 'X'.
GS_POITEM-ITEM_CAT = GW_ALV-BSTYP.
GS_POITEMX-ITEM_CAT = 'X'.
GS_POITEM-MATERIAL = GW_ALV-MATNR.
GS_POITEMX-MATERIAL = 'X'.
GS_POITEM-QUANTITY = GW_ALV-MENGE.
GS_POITEMX-QUANTITY = 'X'.
GS_POITEM-PO_UNIT = GW_ALV-MEINS.
GS_POITEMX-PO_UNIT = 'X'.
GS_POSCHEDULE-DELIVERY_DATE = GW_ALV-EINDT.
GS_POSCHEDULEX-DELIVERY_DATE = 'X'.
GS_POITEM-PLANT = GW_ALV-WERKS.
GS_POITEMX-PLANT = 'X'.
GS_POITEM-STGE_LOC = GW_ALV-LGORT.
GS_POITEMX-STGE_LOC = 'X'.
APPEND GS_POITEM TO GT_POITEM.
APPEND GS_POITEMX TO GT_POITEMX.
APPEND GS_POSCHEDULE TO GT_POSCHEDULE.
APPEND GS_POSCHEDULEX TO GT_POSCHEDULEX.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = GS_POHEADER
POHEADERX = GS_POHEADERX
IMPORTING
* EXPPURCHASEORDER =
EXPHEADER = GS_EXPHEADER
* EXPPOEXPIMPHEADER =
TABLES
RETURN = GT_RETURN
POITEM = GT_POITEM
POITEMX = GT_POITEMX
POSCHEDULE = GT_POSCHEDULE
POSCHEDULEX = GT_POSCHEDULEX.
GW_ALV-EBELN = GS_EXPHEADER-PO_NUMBER.
*IF GT_RETURN-TYPE <> 'S'.
* IF GW_ALV-LMESS IS NOT INITIAL.
* CONCATENATE GS_ALV-LMESS '||' INTO GW_ALV-LMESS.
* GW_ALV-ICON = ICON_LED_YELLOW.
*ENDIF.
* CONCATENATE GW_ALV-LMESS GT_RETURN-MESSAGE INTO GW_ALV-LMESS.
* ENDIF.
ENDLOOP.
ENDIF.
ENDFORM.