WMS函数组:2.销售订单创建
FUNCTION ZRFC_SO_CREATE.
*"----------------------------------------------------------------------
*"*"本地接口:
*" TABLES
*" IT_SOHEADER STRUCTURE ZRFC_SO_CREATE_H OPTIONAL
*" IT_SODETAIL STRUCTURE ZRFC_SO_CREATE_P OPTIONAL
*" IT_VBAK STRUCTURE ZINTERFACE_RETURN OPTIONAL
*" ET_LOG STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
DATA TMP_BSTKD LIKE VBKD-BSTKD.
DATA TMP_KUNNR LIKE VBAK-KUNNR.
DATA TMP_SUM LIKE VBAK-NETWR.
CLEAR : TMP_BSTKD,TMP_KUNNR,TMP_SUM.
DATA: IT_HEADER LIKE BAPISDHD1,
IT_HEADERX LIKE BAPISDHD1X,
IT_ITEM LIKE BAPISDITM OCCURS 0 WITH HEADER LINE,
IT_ITEMX LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE,
IT_PARTNER LIKE BAPIPARNR OCCURS 0 WITH HEADER LINE,
IT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
IT_CONDITIONS LIKE BAPICOND OCCURS 0 WITH HEADER LINE,
I_LOG LIKE BAPIRETURN1 OCCURS 0 WITH HEADER LINE,
EP_VBELN LIKE VBAK-VBELN,
IT_BAPICUCFG LIKE BAPICUCFG OCCURS 0 WITH HEADER LINE,
IT_BAPICUVAL LIKE BAPICUVAL OCCURS 0 WITH HEADER LINE,
IT_BAPICUPRT LIKE TABLE OF BAPICUPRT WITH HEADER LINE,
IT_SCHEDULES_INX TYPE STANDARD TABLE OF BAPISCHDLX
WITH HEADER LINE,
IT_SCHEDULES_IN TYPE STANDARD TABLE OF BAPISCHDL
WITH HEADER LINE,
LT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
LT_ORDER_TEXT LIKE BAPISDTEXT OCCURS 0 WITH HEADER LINE,
LT_ORDER_HEADER_INX LIKE BAPISDHD1X
.
CLEAR : IT_HEADER,
IT_HEADERX,
IT_ITEM,
IT_ITEMX,
IT_PARTNER,
IT_RETURN ,
IT_SCHEDULES_INX,
IT_SCHEDULES_IN ,
* EP_SUBRC,
I_LOG .
REFRESH:
IT_ITEM,
IT_ITEMX,
IT_PARTNER,
IT_RETURN ,
IT_SCHEDULES_INX,
IT_SCHEDULES_IN ,
I_LOG.
DATA: ITH LIKE ZSO_CREATE_HEAD,
ITD LIKE ZSO_CREATE_DETL.
DATA: TAX_RATE TYPE KBETR.
* ADD BY LH 获取销售订单税率
CALL FUNCTION 'ZRFC_GET_MWST'
* EXPORTING
* ALAND = 'CN'
* TAXK1 = '1'
* TAXM1 = '1'
* DATBI = SY-DATUM
* DATAB = SY-DATUM
IMPORTING
KBETR = TAX_RATE.
* SORT IT_SOHEADER.
LOOP AT IT_SOHEADER.
TMP_BSTKD = IT_SOHEADER-BSTKD.
TMP_KUNNR = IT_SOHEADER-KUNNR.
PERFORM F_ADD_ZERO USING TMP_KUNNR.
SELECT SINGLE BSTKD INTO TMP_BSTKD FROM ZSO_CREATE_HEAD WHERE BSTKD = TMP_BSTKD .
IF SY-SUBRC = 0.
MOVE IT_SOHEADER-BSTKD TO IT_VBAK-BILLNO .
IT_VBAK-SUBRC = '-1'.
MOVE '重复回写' TO IT_VBAK-MSG .
APPEND IT_VBAK.
ENDIF.
CHECK SY-SUBRC <> 0.
*******SHIP_TYPE
IF IT_SOHEADER-SHIP_TYPE IS NOT INITIAL.
IT_HEADER-SHIP_TYPE = IT_SOHEADER-SHIP_TYPE.
IT_HEADERX-SHIP_TYPE = 'X'.
ENDIF.
****客户条件组
IF IT_SOHEADER-CSTCNDGRP1 IS NOT INITIAL.
IT_HEADER-CSTCNDGRP1 = IT_SOHEADER-CSTCNDGRP1.
IT_HEADERX-CSTCNDGRP1 = 'X'.
ENDIF.
IF IT_SOHEADER-CSTCNDGRP2 IS NOT INITIAL.
IT_HEADER-CSTCNDGRP2 = IT_SOHEADER-CSTCNDGRP2.
IT_HEADERX-CSTCNDGRP2 = 'X'.
ENDIF.
IF IT_SOHEADER-CSTCNDGRP3 IS NOT INITIAL.
IT_HEADER-CSTCNDGRP3 = IT_SOHEADER-CSTCNDGRP3.
IT_HEADERX-CSTCNDGRP3 = 'X'.
ENDIF.
IF IT_SOHEADER-CSTCNDGRP4 IS NOT INITIAL.
IT_HEADER-CSTCNDGRP4 = IT_SOHEADER-CSTCNDGRP4.
IT_HEADERX-CSTCNDGRP4 = 'X'.
ENDIF.
IF IT_SOHEADER-CSTCNDGRP5 IS NOT INITIAL.
IT_HEADER-CSTCNDGRP5 = IT_SOHEADER-CSTCNDGRP5.
IT_HEADERX-CSTCNDGRP5 = 'X'.
ENDIF.
******* 订单类型
IF IT_SOHEADER-HEAD_TYPE IS NOT INITIAL.
IT_HEADER-DOC_TYPE = IT_SOHEADER-HEAD_TYPE.
IT_HEADERX-DOC_TYPE = 'X'.
ELSE.
IT_HEADER-DOC_TYPE = 'ZOR'.
IT_HEADERX-DOC_TYPE = 'X'.
ENDIF.
******* 订单送达方采购订单编号
IF IT_SOHEADER-PURCH_NO_S IS NOT INITIAL.
IT_HEADER-PURCH_NO_S = IT_SOHEADER-PURCH_NO_S.
IT_HEADERX-PURCH_NO_S = 'X'.
ENDIF.
******** 订单原因
IT_HEADER-PO_SUPPLEM = IT_SOHEADER-BSTZD.
IT_HEADERX-PO_SUPPLEM = 'X'.
IT_HEADER-ORD_REASON = IT_SOHEADER-AUGRU.
IT_HEADERX-ORD_REASON = 'X'.
******** 订单发票冻结原因
IT_HEADER-BILL_BLOCK = ' '.
IT_HEADERX-BILL_BLOCK = 'X'.
****** 销售组织
IT_HEADER-SALES_ORG = IT_SOHEADER-VKORG.
IT_HEADERX-SALES_ORG = 'X'.
****** 装运条件
IF IT_SOHEADER-SHIP_COND IS NOT INITIAL.
IT_HEADER-SHIP_COND = IT_SOHEADER-SHIP_COND.
IT_HEADERX-SHIP_COND = 'X'.
ENDIF.
****** 分销渠道
IT_HEADER-DISTR_CHAN = IT_SOHEADER-VTWEG.
IT_HEADERX-DISTR_CHAN = 'X'.
*************DCMS编号
IT_HEADER-PURCH_NO_C = IT_SOHEADER-BSTKD.
IT_HEADERX-PURCH_NO_C = 'X'.
****** 产品组
IT_HEADER-DIVISION = IT_SOHEADER-SPART.
IT_HEADERX-DIVISION = 'X'.
IT_HEADERX-UPDATEFLAG = 'I'.
****** 销售办事处
PERFORM F_ADD_ZERO USING IT_SOHEADER-KUNNR.
SELECT SINGLE VKBUR
INTO IT_HEADER-SALES_OFF
FROM KNVV
WHERE KUNNR = IT_SOHEADER-KUNNR
AND VKORG = IT_SOHEADER-VKORG
AND VTWEG = IT_SOHEADER-VTWEG.
IT_HEADERX-SALES_OFF = 'X'.
* it_header-PRICE_DATE = IT_SOHEADER-KETDAT.
* it_headerX-PRICE_DATE = 'X'.
****售达方
CLEAR:IT_PARTNER[].
IT_PARTNER-PARTN_ROLE = 'AG'.
IT_PARTNER-PARTN_NUMB = IT_SOHEADER-KUNNR.
APPEND IT_PARTNER.
*****送达方
*IF IT_SOHEADER-ADR IS INITIAL.
* it_partner-partn_role = 'WE'.
* it_partner-partn_numb = IT_SOHEADER-kunnr.
*
*ELSE.
PERFORM F_ADD_ZERO USING IT_SOHEADER-KUNNR1.
IT_PARTNER-PARTN_ROLE = 'WE'.
IT_PARTNER-PARTN_NUMB = IT_SOHEADER-KUNNR1.
*ENDIF.
APPEND IT_PARTNER.
CLEAR:LT_ORDER_TEXT[].
*** 抬头文本
IF IT_SOHEADER-ADR IS NOT INITIAL.
LT_ORDER_TEXT-TEXT_ID = '0001'.
LT_ORDER_TEXT-LANGU = '1'.
LT_ORDER_TEXT-TEXT_LINE = IT_SOHEADER-ADR.
APPEND LT_ORDER_TEXT.
ENDIF.
CLEAR : IT_ITEM, IT_ITEM[],
IT_ITEMX,IT_ITEMX[],
IT_SCHEDULES_IN, IT_SCHEDULES_IN[],
IT_BAPICUCFG[], IT_BAPICUVAL[],
IT_CONDITIONS, IT_CONDITIONS[],
IT_SCHEDULES_INX, IT_SCHEDULES_INX[],
IT_CONDITIONS,IT_CONDITIONS[]
.
* SORT IT_SODETAIL.
LOOP AT IT_SODETAIL WHERE BSTKD = IT_SOHEADER-BSTKD.
IT_ITEMX-UPDATEFLAG = 'I'.
*****物料组543
IF IT_SODETAIL-PRC_GROUP5 IS NOT INITIAL.
IT_ITEM-PRC_GROUP5 = IT_SODETAIL-PRC_GROUP5.
IT_ITEMX-PRC_GROUP5 = 'X'.
ENDIF.
IF IT_SODETAIL-PRC_GROUP4 IS NOT INITIAL.
IT_ITEM-PRC_GROUP4 = IT_SODETAIL-PRC_GROUP4.
IT_ITEMX-PRC_GROUP4 = 'X'.
ENDIF.
IF IT_SODETAIL-PRC_GROUP3 IS NOT INITIAL.
IT_ITEM-PRC_GROUP3 = IT_SODETAIL-PRC_GROUP3.
IT_ITEMX-PRC_GROUP3 = 'X'.
ENDIF.
*****客户条件组543
IF IT_SODETAIL-CSTCNDGRP5 IS NOT INITIAL.
IT_ITEM-CSTCNDGRP5 = IT_SODETAIL-CSTCNDGRP5.
IT_ITEMX-CSTCNDGRP5 = 'X'.
ENDIF.
IF IT_SODETAIL-CSTCNDGRP4 IS NOT INITIAL.
IT_ITEM-CSTCNDGRP4 = IT_SODETAIL-CSTCNDGRP4.
IT_ITEMX-CSTCNDGRP4 = 'X'.
ENDIF.
IF IT_SODETAIL-CSTCNDGRP3 IS NOT INITIAL.
IT_ITEM-CSTCNDGRP3 = IT_SODETAIL-CSTCNDGRP3.
IT_ITEMX-CSTCNDGRP3 = 'X'.
ENDIF.
*****行项目
IT_ITEM-ITM_NUMBER = IT_SODETAIL-POSNR.
IT_ITEMX-ITM_NUMBER = 'X'.
* 物料
PERFORM F_ADD_ZERO USING IT_SODETAIL-MATNR.
IT_ITEM-MATERIAL = IT_SODETAIL-MATNR.
IT_ITEMX-MATERIAL = 'X'.
*工厂
IT_ITEM-PLANT = IT_SODETAIL-WERKS.
IT_ITEMX-PLANT = 'X'.
IT_ITEM-STORE_LOC = IT_SODETAIL-LGORT.
IT_ITEMX-STORE_LOC = 'X'.
*数量
IT_ITEM-TARGET_QTY = IT_SODETAIL-KWMENG.
IT_ITEMX-TARGET_QTY = 'X'.
*增加行项目类别
IF IT_SODETAIL-ITEM_CATEG IS NOT INITIAL.
IT_ITEM-ITEM_CATEG = IT_SODETAIL-ITEM_CATEG.
IT_ITEMX-ITEM_CATEG = 'X'.
ENDIF.
APPEND IT_ITEM.
APPEND IT_ITEMX.
****计划行
IT_SCHEDULES_IN-ITM_NUMBER = IT_SODETAIL-POSNR.
IF IT_SODETAIL-ETDAT IS INITIAL.
IT_SCHEDULES_IN-REQ_DATE = SY-DATUM.
ELSE.
IT_SCHEDULES_IN-REQ_DATE = IT_SODETAIL-ETDAT.
ENDIF.
IT_SCHEDULES_IN-REQ_QTY = IT_SODETAIL-KWMENG.
APPEND IT_SCHEDULES_IN.
* 计划行标志
IT_SCHEDULES_INX-ITM_NUMBER = IT_SODETAIL-POSNR.
IT_SCHEDULES_INX-UPDATEFLAG = 'X'.
IT_SCHEDULES_INX-REQ_QTY = 'X'.
APPEND IT_SCHEDULES_INX.
****创建价格条件
******特价商品输入单价
*
IF IT_SOHEADER-HEAD_TYPE = 'ZZRE' .
CLEAR IT_SODETAIL-KBETR.
CLEAR IT_SODETAIL-KBETR1.
ENDIF.
IF IT_SODETAIL-KBETR IS NOT INITIAL.
IT_CONDITIONS-ITM_NUMBER = IT_SODETAIL-POSNR.
IF IT_SOHEADER-HEAD_TYPE = 'ZDR' OR IT_SOHEADER-HEAD_TYPE = 'ZCR' OR IT_SOHEADER-HEAD_TYPE CP 'ZSO*'.
IT_CONDITIONS-COND_TYPE = 'ZDR0'.
IT_CONDITIONS-COND_VALUE = IT_SODETAIL-KBETR / TAX_RATE.
ELSE.
IF IT_SOHEADER-HEAD_TYPE+0(2) = 'RE' .
IT_CONDITIONS-COND_TYPE = 'ZPR3'.
ELSE.
IT_CONDITIONS-COND_TYPE = 'ZPR2'. "条件类型
ENDIF.
IT_CONDITIONS-COND_P_UNT = '1000'.
IT_CONDITIONS-COND_VALUE = IT_SODETAIL-KBETR * 1000 / TAX_RATE."含税单价转换净价
ENDIF.
IT_CONDITIONS-CURRENCY = 'CNY'.
ENDIF.
IF IT_SODETAIL-KBETR1 IS NOT INITIAL.
IT_CONDITIONS-ITM_NUMBER = IT_SODETAIL-POSNR.
IF IT_SOHEADER-HEAD_TYPE = 'ZDR' OR IT_SOHEADER-HEAD_TYPE = 'ZCR' OR IT_SOHEADER-HEAD_TYPE CP 'ZSO*'.
IT_CONDITIONS-COND_TYPE = 'ZDR0'.
IT_CONDITIONS-COND_VALUE = IT_SODETAIL-KBETR1 / TAX_RATE.
ELSE.
IF IT_SOHEADER-HEAD_TYPE+0(2) = 'RE' .
IT_CONDITIONS-COND_TYPE = 'ZPR3'.
ELSE.
IT_CONDITIONS-COND_TYPE = 'ZPR2'. "条件类型
ENDIF.
IT_CONDITIONS-COND_P_UNT = '1000'.
IT_CONDITIONS-COND_VALUE = IT_SODETAIL-KBETR1 * 1000 / IT_SODETAIL-KWMENG / TAX_RATE."含税单价转换净价
ENDIF.
IT_CONDITIONS-CURRENCY = 'CNY'.
ENDIF.
APPEND IT_CONDITIONS.
IF IT_SOHEADER-HEAD_TYPE = 'RE2' AND IT_SODETAIL-ITEM_CATEG = 'ZRE2'.
IT_CONDITIONS-COND_TYPE = 'ZDS1'.
IT_CONDITIONS-COND_VALUE = 1000.
IT_CONDITIONS-CURRENCY = 'CNY'.
APPEND IT_CONDITIONS.
ENDIF.
ENDLOOP.
DATA: IT_PARTNERADDRESSES LIKE BAPIADDR1 OCCURS 0 WITH HEADER LINE.
CLEAR: IT_PARTNERADDRESSES,IT_PARTNERADDRESSES[].
SELECT ADRNR INTO IT_PARTNERADDRESSES-ADDR_NO
FROM KNA1
WHERE KTOKD = 'Z007'
AND KUNNR = IT_SOHEADER-KUNNR.
APPEND IT_PARTNERADDRESSES.
ENDSELECT.
CLEAR IT_RETURN.
* CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
* EXPORTING
* ORDER_HEADER_IN = IT_HEADER
* ORDER_HEADER_INX = IT_HEADERX
* BEHAVE_WHEN_ERROR = ' '
* IMPORTING
* SALESDOCUMENT = EP_VBELN
* TABLES
* RETURN = IT_RETURN
* ORDER_ITEMS_IN = IT_ITEM
* ORDER_ITEMS_INX = IT_ITEMX
* ORDER_SCHEDULES_IN = IT_SCHEDULES_IN
* ORDER_SCHEDULES_INX = IT_SCHEDULES_INX
* ORDER_CONDITIONS_IN = IT_CONDITIONS
* ORDER_TEXT = LT_ORDER_TEXT
* ORDER_PARTNERS = IT_PARTNER.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
SALES_HEADER_IN = IT_HEADER
SALES_HEADER_INX = IT_HEADERX
BEHAVE_WHEN_ERROR = ' '
IMPORTING
SALESDOCUMENT_EX = EP_VBELN
TABLES
RETURN = IT_RETURN
SALES_ITEMS_IN = IT_ITEM
SALES_ITEMS_INX = IT_ITEMX
SALES_SCHEDULES_IN = IT_SCHEDULES_IN
SALES_SCHEDULES_INX = IT_SCHEDULES_INX
SALES_CONDITIONS_IN = IT_CONDITIONS
SALES_TEXT = LT_ORDER_TEXT
SALES_PARTNERS = IT_PARTNER
PARTNERADDRESSES = IT_PARTNERADDRESSES.
SORT IT_RETURN.
LOOP AT IT_RETURN.
MOVE IT_RETURN TO ET_LOG.
MOVE IT_SOHEADER-BSTKD TO ET_LOG-ID.
APPEND ET_LOG.
ENDLOOP.
IF EP_VBELN IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
COMMIT WORK AND WAIT.
****更新扩展字段
DATA: SET_EXPR TYPE STRING.
CLEAR SET_EXPR.
IF IT_SOHEADER-EXT01 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT01 = IT_SOHEADER-EXT01 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT02 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT02 = IT_SOHEADER-EXT02 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT03 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT03 = IT_SOHEADER-EXT03 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT04 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT04 = IT_SOHEADER-EXT04 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT05 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT05 = IT_SOHEADER-EXT05 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT06 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT06 = IT_SOHEADER-EXT06 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT07 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT07 = IT_SOHEADER-EXT07 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT08 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT08 = IT_SOHEADER-EXT08 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT09 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT09 = IT_SOHEADER-EXT09 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT10 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT10 = IT_SOHEADER-EXT10 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT11 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT11 = IT_SOHEADER-EXT11 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT12 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT12 = IT_SOHEADER-EXT12 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT13 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT13 = IT_SOHEADER-EXT13 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT14 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT14 = IT_SOHEADER-EXT14' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT15 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT15 = IT_SOHEADER-EXT15 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT16 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT16 = IT_SOHEADER-EXT16 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT17 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT17 = IT_SOHEADER-EXT17 ' INTO SET_EXPR .
ENDIF.
IF IT_SOHEADER-EXT18 IS NOT INITIAL.
CONCATENATE SET_EXPR ' EXT18 = IT_SOHEADER-EXT18 ' INTO SET_EXPR .
ENDIF.
WRITE SET_EXPR.
IF SET_EXPR IS NOT INITIAL.
UPDATE VBAK SET (SET_EXPR) WHERE VBELN = EP_VBELN.
ENDIF.
"记录成功记录
MOVE-CORRESPONDING IT_SOHEADER TO ITH.
ITH-VBELN = EP_VBELN.
ITH-ERDAT = SY-DATUM.
MODIFY ZSO_CREATE_HEAD FROM ITH.
SORT IT_SODETAIL.
LOOP AT IT_SODETAIL WHERE BSTKD = IT_SOHEADER-BSTKD.
MOVE-CORRESPONDING IT_SODETAIL TO ITD.
ITD-ERDAT = SY-DATUM.
MODIFY ZSO_CREATE_DETL FROM ITD.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
MOVE EP_VBELN TO IT_VBAK-SAPNO .
MOVE IT_SOHEADER-BSTKD TO IT_VBAK-BILLNO.
IF EP_VBELN IS INITIAL.
IT_VBAK-SUBRC = '-1'.
DATA STRS TYPE STRING.
SORT IT_RETURN.
LOOP AT IT_RETURN WHERE TYPE = 'E' OR TYPE = 'W'.
CONCATENATE STRS IT_RETURN-MESSAGE INTO STRS.
ENDLOOP.
MOVE STRS TO IT_VBAK-MSG.
ENDIF.
APPEND IT_VBAK.
CLEAR IT_SOHEADER.
CLEAR IT_HEADER.
CLEAR IT_HEADERX.
ENDLOOP.
ENDFUNCTION.