ABAP 一次性取出订单抬头和项目的所有长文本详解编程语言

需求:去除销售订单所有的抬头和行项目文本,ALV展示并保存在自建表中。

*&---------------------------------------------------------------------* 
*& Report ZSDR0005 
*&---------------------------------------------------------------------* 
*& 
*&---------------------------------------------------------------------* 
REPORT ZSDR0005. 
INCLUDE: ZPUB_LVC_FUNC. 
TABLES:ZTB_OSB03929,T001,VBAK,VBAP. 
DATA: H_NAME    LIKE THEAD-TDNAME, 
L_NAME    TYPE THEAD-TDNAME, 
GS_HEADER TYPE THEAD, 
GT_LTXT   TYPE STANDARD TABLE OF TLINE, 
LW_LTXT   TYPE TLINE. 
DATA: BEGIN OF IT_ALV OCCURS 0, 
ORDER           TYPE CHAR10, 
LINE            TYPE CHAR6, 
GE_MODEL_NUM    TYPE CHAR20, 
MTR_WIP         TYPE CHAR12, 
SOURCE          TYPE CHAR10, 
TYPE            TYPE CHAR30, 
NOTE            TYPE STRING, "TYPE CHAR3000, 
CUST_REQUEST_DT LIKE SY-DATUM, 
PROMISE_DT      LIKE SY-DATUM, 
END OF IT_ALV. 
TYPES: BEGIN OF TY_VBAP, 
VBELN TYPE VBAP-VBELN, 
POSNR TYPE VBAP-POSNR, 
MATNR TYPE VBAP-MATNR, 
GBSTA TYPE VBAP-GBSTA, 
ERDAT TYPE VBAK-ERDAT, 
END OF TY_VBAP. 
DATA: IT_VBAP        TYPE TABLE OF TY_VBAP, 
WA_VBAP        TYPE TY_VBAP, 
IT_AFPO        LIKE STANDARD TABLE OF AFPO WITH HEADER LINE, 
IT_VBEP1       LIKE STANDARD TABLE OF VBEP WITH HEADER LINE, 
IT_VBEP2       LIKE STANDARD TABLE OF VBEP WITH HEADER LINE, 
IT_STXH        LIKE STANDARD TABLE OF STXH WITH HEADER LINE, 
IT_STXL        LIKE STANDARD TABLE OF STXL WITH HEADER LINE, 
IT_TTXIT       LIKE STANDARD TABLE OF TTXIT WITH HEADER LINE, 
IT_ZTBOSB03929 LIKE STANDARD TABLE OF ZTB_OSB03929 WITH HEADER LINE, 
NOTE1          TYPE TLINE-TDLINE. 
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. 
SELECT-OPTIONS: S_ORG   FOR VBAK-VKORG,"SALES ORGANIZATION 
S_STP   FOR VBAK-KUNNR,"SOLD-TO PARTY 
S_MATNR FOR VBAP-MATNR,"MATERIAL 
S_ORDER FOR VBAP-VBELN,"SALES ORDER 
S_DATE  FOR VBAP-ERDAT."CREATED ON 
SELECTION-SCREEN SKIP. 
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-002. 
PARAMETERS: D1 RADIOBUTTON GROUP G1, "Open Sales Order 
D2 RADIOBUTTON GROUP G1. "All Sales Order 
PARAMETERS: C1 AS CHECKBOX."Save data to ZTB_OSB03929_ORDER_NOTES 
SELECTION-SCREEN END OF BLOCK B3. 
SELECTION-SCREEN END OF BLOCK B1. 
INITIALIZATION. 
CONCATENATE SY-DATUM+0(6)  '01' INTO S_DATE-LOW. 
S_DATE-HIGH = SY-DATUM. 
S_DATE-SIGN = 'I'. 
S_DATE-OPTION = 'BT'. 
APPEND S_DATE. 
START-OF-SELECTION. 
IF C1 = 'X'. 
PERFORM GET_DATA. 
"PERFORM DEL_DATA. 
PERFORM SAVE_DATA. 
ELSE. 
PERFORM GET_DATA. 
PERFORM DIS_DATA. 
ENDIF. 
FORM GET_DATA. 
SELECT VBAP~VBELN VBAP~POSNR VBAP~MATNR VBAP~GBSTA 
VBAK~ERDAT 
INTO CORRESPONDING FIELDS OF TABLE IT_VBAP 
FROM VBAP INNER JOIN VBAK ON VBAP~VBELN = VBAK~VBELN 
WHERE VBAP~VBELN IN S_ORDER AND VBAP~ERDAT IN S_DATE 
AND VBAP~MATNR IN S_MATNR AND VBAK~VKORG IN S_ORG 
AND VBAK~KUNNR IN S_STP AND VBAK~AUART NE 'ZQT'. 
IF D1 = 'X'. 
DELETE IT_VBAP WHERE GBSTA = 'C'. 
ENDIF. 
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_AFPO 
FROM AFPO FOR ALL ENTRIES IN IT_VBAP 
WHERE KDAUF = IT_VBAP-VBELN AND KDPOS = IT_VBAP-POSNR. 
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_VBEP1 
FROM VBEP FOR ALL ENTRIES IN IT_VBAP 
WHERE VBELN = IT_VBAP-VBELN AND POSNR = IT_VBAP-POSNR 
AND WMENG NE 0. 
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_VBEP2 
FROM VBEP FOR ALL ENTRIES IN IT_VBAP 
WHERE VBELN = IT_VBAP-VBELN AND POSNR = IT_VBAP-POSNR 
AND BMENG NE 0. 
SORT:IT_VBAP BY VBELN POSNR, 
IT_AFPO BY AUFNR POSNR, 
IT_VBEP1 BY VBELN POSNR, 
IT_VBEP2 BY VBELN POSNR. 
LOOP AT IT_VBAP INTO WA_VBAP. 
READ TABLE IT_AFPO WITH KEY KDAUF = WA_VBAP-VBELN KDPOS = WA_VBAP-POSNR BINARY SEARCH. 
READ TABLE IT_VBEP1 WITH KEY VBELN = WA_VBAP-VBELN POSNR = WA_VBAP-POSNR BINARY SEARCH. 
READ TABLE IT_VBEP2 WITH KEY VBELN = WA_VBAP-VBELN POSNR = WA_VBAP-POSNR BINARY SEARCH. 
H_NAME = WA_VBAP-VBELN. 
L_NAME = WA_VBAP-VBELN && WA_VBAP-POSNR. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' 
EXPORTING 
INPUT  = WA_VBAP-POSNR 
IMPORTING 
OUTPUT = WA_VBAP-POSNR. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' 
EXPORTING 
INPUT  = IT_AFPO-AUFNR 
IMPORTING 
OUTPUT = IT_AFPO-AUFNR. 
"取抬头文本 
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_STXH 
FROM STXH WHERE TDSPRAS = SY-LANGU AND TDOBJECT = 'VBBK' 
AND TDNAME = H_NAME. 
IF IT_STXH[] IS NOT INITIAL. 
LOOP AT IT_STXH. 
SELECT SINGLE TDTEXT INTO IT_TTXIT-TDTEXT 
FROM TTXIT WHERE TDOBJECT = 'VBBK' AND TDID = IT_STXH-TDID 
AND TDSPRAS = SY-LANGU. 
CALL FUNCTION 'READ_TEXT' 
EXPORTING 
ID                      = IT_STXH-TDID 
LANGUAGE                = SY-LANGU 
NAME                    = H_NAME 
OBJECT                  = 'VBBK' 
TABLES 
LINES                   = GT_LTXT 
EXCEPTIONS 
ID                      = 1 
LANGUAGE                = 2 
NAME                    = 3 
NOT_FOUND               = 4 
OBJECT                  = 5 
REFERENCE_CHECK         = 6 
WRONG_ACCESS_TO_ARCHIVE = 7 
OTHERS                  = 8. 
IF GT_LTXT IS NOT INITIAL. 
LOOP AT GT_LTXT INTO LW_LTXT. 
IF LW_LTXT-TDLINE IS NOT INITIAL. 
IT_ALV-ORDER = WA_VBAP-VBELN. 
IT_ALV-LINE  = WA_VBAP-POSNR. 
IT_ALV-GE_MODEL_NUM = WA_VBAP-MATNR. 
IT_ALV-MTR_WIP = IT_AFPO-AUFNR. 
IT_ALV-SOURCE = 'ORDER'. 
IT_ALV-TYPE = IT_TTXIT-TDTEXT. 
IT_ALV-CUST_REQUEST_DT = WA_VBAP-ERDAT. 
IT_ALV-PROMISE_DT = ''. 
IF SY-TABIX = 1. 
IT_ALV-NOTE = LW_LTXT-TDLINE. 
ELSE. 
CONCATENATE IT_ALV-NOTE LW_LTXT-TDLINE INTO IT_ALV-NOTE. 
ENDIF. 
APPEND IT_ALV. 
CLEAR:LW_LTXT,IT_ALV. 
ENDIF. 
ENDLOOP. 
ENDIF. 
CLEAR:GT_LTXT[]. 
ENDLOOP. 
ENDIF. 
"取行项目文本 
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_STXL 
FROM STXL WHERE TDSPRAS = SY-LANGU AND TDOBJECT = 'VBBP' 
AND TDNAME = L_NAME. 
IF IT_STXL[] IS NOT INITIAL. 
LOOP AT IT_STXL. 
SELECT SINGLE TDTEXT INTO IT_TTXIT-TDTEXT 
FROM TTXIT WHERE TDOBJECT = 'VBBP' AND TDID = IT_STXL-TDID 
AND TDSPRAS = SY-LANGU. 
CALL FUNCTION 'READ_TEXT' 
EXPORTING 
ID                      = IT_STXL-TDID 
LANGUAGE                = SY-LANGU 
NAME                    = L_NAME 
OBJECT                  = 'VBBP' 
TABLES 
LINES                   = GT_LTXT 
EXCEPTIONS 
ID                      = 1 
LANGUAGE                = 2 
NAME                    = 3 
NOT_FOUND               = 4 
OBJECT                  = 5 
REFERENCE_CHECK         = 6 
WRONG_ACCESS_TO_ARCHIVE = 7 
OTHERS                  = 8. 
IF GT_LTXT IS NOT INITIAL. 
LOOP AT GT_LTXT INTO LW_LTXT. 
IF LW_LTXT-TDLINE IS NOT INITIAL. 
IT_ALV-ORDER = WA_VBAP-VBELN. 
IT_ALV-LINE  = WA_VBAP-POSNR. 
IT_ALV-GE_MODEL_NUM = WA_VBAP-MATNR. 
IT_ALV-MTR_WIP = IT_AFPO-AUFNR. 
IT_ALV-SOURCE = 'LINE'. 
IT_ALV-TYPE = IT_TTXIT-TDTEXT. 
IT_ALV-CUST_REQUEST_DT = IT_VBEP1-EDATU. 
IT_ALV-PROMISE_DT = IT_VBEP2-EDATU. 
IF SY-TABIX = 1. 
IT_ALV-NOTE = LW_LTXT-TDLINE. 
ELSE. 
CONCATENATE IT_ALV-NOTE LW_LTXT-TDLINE INTO IT_ALV-NOTE. 
ENDIF. 
APPEND:IT_ALV. 
CLEAR:LW_LTXT,IT_ALV. 
ENDIF. 
ENDLOOP. 
CLEAR:GT_LTXT[]. 
ENDIF. 
ENDLOOP. 
ENDIF. 
CLEAR:WA_VBAP,IT_AFPO,IT_ALV,H_NAME,L_NAME,IT_VBEP1,IT_VBEP2. 
ENDLOOP. 
ENDFORM. 
FORM SAVE_DATA. 
LOOP AT IT_ALV. 
IT_ZTBOSB03929-SALES_ORD_NUM        = IT_ALV-ORDER. 
IT_ZTBOSB03929-SALES_ORD_LINE_NUM   = IT_ALV-LINE. 
IT_ZTBOSB03929-NOTE_SOURCE          = IT_ALV-SOURCE. 
IT_ZTBOSB03929-NOTE_TYPE            = IT_ALV-TYPE. 
IT_ZTBOSB03929-NOTE_TEXT            = IT_ALV-NOTE. 
APPEND IT_ZTBOSB03929. 
CLEAR:IT_ALV,IT_ZTBOSB03929. 
ENDLOOP. 
"MODIFY ZTB_OSB03929 FROM TABLE IT_ZTBOSB03929. 
INSERT ZTB_OSB03929 FROM TABLE IT_ZTBOSB03929 ACCEPTING DUPLICATE KEYS. 
ENDFORM. 
FORM DIS_DATA. 
ALV_CLEAR_DATA. 
ALV_ADD_DATA: 'IT_ALV' '' '' '' '' '' '' 'ORDER' 'Order', 
'IT_ALV' '' '' '' '' '' '' 'LINE' 'Line', 
'IT_ALV' '' '' '' '' '' '' 'GE_MODEL_NUM' 'GE_MODEL_NUM', 
'IT_ALV' '' '' '' '' '' '' 'MTR_WIP' 'MTR_WIP', 
'IT_ALV' '' '' '' '' '' '' 'SOURCE' 'Source', 
'IT_ALV' '' '' '' '' '' '' 'TYPE' 'Type', 
'IT_ALV' '' '' '' '' '' '' 'NOTE' 'Note', 
'IT_ALV' '' '' '' '' '' '' 'CUST_REQUEST_DT' 'CUST_REQUEST_DT', 
'IT_ALV' '' '' '' '' '' '' 'PROMISE_DT' 'PROMISE_DT'. 
ALV_SHOW_DATA IT_ALV. 
ENDFORM. 
FORM DEL_DATA. 
DELETE FROM ZTB_OSB03929. 
ENDFORM.

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19563.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论