2006 Aug 24 3:12 PM
Hi,
i have written a program which read the data either from the frontend or from the server and will post(BDC) the FI document using that data.
now my requirement is to get the output for error messages list too. right from the starting to the successful completion of the execution.
valauable input is appreciable and if anyone done in the same manner do provide me the sample code.
if needed i will post the full code. do give me the personal mail id.
thank u
2006 Aug 24 3:17 PM
Hi,
Below is a similar code for your requirment. Please go through it and follow the logic.
[code]REPORT ZMMM0047
LINE-COUNT 65
LINE-SIZE 238
MESSAGE-ID Z2
NO STANDARD PAGE HEADING.
----
T A B L E S
----
TABLES: MARA, " General Material Data
T130M, " Material master maintenance
VBAK. " Sales Document: Header Data
----
S E L E C T I O N - S C R E E N
----
*-- Selection screen for Materials
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
*-- BDC Group
PARAMETERS: P_BDCGRP(12) TYPE C OBLIGATORY,
*-- BDC User
P_BDCUSR(12) TYPE C OBLIGATORY DEFAULT SY-UNAME,
*-- Hold Date
P_DATE TYPE SY-DATUM OBLIGATORY DEFAULT SY-DATUM.
SELECTION-SCREEN END OF BLOCK B1.
*-- Selection screen for Sales orders
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
*-- BDC Group
PARAMETERS: P_GROUP(12) TYPE C OBLIGATORY,
*-- BDC User
P_USER(12) TYPE C OBLIGATORY DEFAULT SY-UNAME,
*-- Hold date
P_DATE1 TYPE SY-DATUM OBLIGATORY DEFAULT SY-DATUM.
*-- Sales document type
SELECT-OPTIONS: S_AUART FOR VBAK-AUART OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B2.
*-- Selection screen for Test
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-004.
*-- Test only
PARAMETERS: P_TEST AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK B3.
----
T Y P E S
----
*-- Types declaration for final data
TYPES: BEGIN OF T_FINAL,
MATNR TYPE ZMMARA-MATNR, " 6' material
WERKS TYPE ZMMARA-WERKS, " Plant
ZZAMATNR TYPE ZMMARA-ZZAMATNR, " 12' materials (Rolls)
KWMENG1 TYPE VBAP-KWMENG, " Cum.order quantity 12' YD2 per ROL
KWMENG2 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per ROL
KWMENG3 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per RL2
KWMENG TYPE VBAP-KWMENG, " Out-Quantity / 2
UMREZ1 TYPE VBAP-KWMENG, " Prev.value for YD2 per ROL for 6'
UMREZ2 TYPE VBAP-KWMENG, " Prev.value for YD2 per RL2 for 6'
VBELN TYPE VBAP-VBELN, " Sales document
POSNR TYPE VBAP-POSNR, " Sales document item
MSG(20) TYPE C, " Error message
END OF T_FINAL.
*-- Types definition for MARM
TYPES BEGIN OF T_MARM.
INCLUDE STRUCTURE MARM. " Units of Measure for Material
TYPES AZSUB TYPE SMEINH-AZSUB. " Number of Lower-Level UOM
TYPES END OF T_MARM.
*-- Types definition for BILDTAB
TYPES: BEGIN OF T_BILDTAB.
INCLUDE STRUCTURE MBILDTAB. " Material Master View Selection
" Screens
TYPES: END OF T_BILDTAB.
*-- Types definition for BDCDATA
TYPES BEGIN OF T_BDCDATA.
INCLUDE STRUCTURE BDCDATA. Batch input: New table field"
" structure
TYPES END OF T_BDCDATA.
*-- Types definition for Sales order details
TYPES: BEGIN OF T_STAB,
VBELN TYPE VBAP-VBELN, Sales document"
POSNR TYPE VBAP-POSNR, " Sales document item
END OF T_STAB.
*-- Types definition for VAPMA data
TYPES: BEGIN OF T_VAPMA.
INCLUDE STRUCTURE VAPMA. " Sales Index: Order Items by Material
TYPES: END OF T_VAPMA.
----
I N T E R N A L T A B L E S
----
*-- Internal table to hold new material values
DATA: IT_MARA TYPE STANDARD TABLE OF ZMMARA WITH HEADER LINE,
*-- Internal table to hold Final data
IT_FINAL TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE,
*-- Internal table to hold IT_MARM data
IT_MARM TYPE STANDARD TABLE OF T_MARM WITH HEADER LINE,
*-- Internal table to hold IT_BILDTAB
IT_BILDTAB TYPE STANDARD TABLE OF T_BILDTAB WITH HEADER LINE,
*-- Internal table to hold IT_BDCDATA
IT_BDCDATA TYPE STANDARD TABLE OF T_BDCDATA WITH HEADER LINE,
*-- Internal table to hold IT_SUCCS data
IT_REPORT TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE,
*-- Internal table to hold VAPMA data
IT_VAPMA TYPE STANDARD TABLE OF T_VAPMA WITH HEADER LINE,
*-- Internal table to hold VBAP data
IT_VBAP TYPE STANDARD TABLE OF T_STAB WITH HEADER LINE,
*-- Internal table to hold VBUP data
IT_VBUP TYPE STANDARD TABLE OF T_STAB WITH HEADER LINE,
*-- Internal table to hold Final data
IT_FINAL1 TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE.
*-- Structure to hold R_FIELD data
DATA: BEGIN OF R_FIELD,
NAME TYPE BDCDATA-FNAM, " Field name
PARENS(6) TYPE C VALUE '($)', " Number
END OF R_FIELD.
----
V A R I A B L E S
----
DATA: V_KWMENG TYPE I, " Cum.order quantity
V_KWMENG1 TYPE VBAP-KWMENG, " Cum.order quantity 12' YD2 per ROL
V_KWMENG2 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per ROL
V_KWMENG3 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per RL2
V_ERROR TYPE C, " Error flag
V_LOOP_CNT TYPE I, " Loop counter
V_LOOP_CN TYPE I, " Loop counter
V_BDCFNAM TYPE BDCDATA-FNAM, " BDC field name
V_TABIX TYPE SY-TABIX, " SY-TABIX
V_TABIX1 TYPE SY-TABIX, " SY-TABIX
V_SEL_LINE(20) TYPE C, " Selection line
V_SEL_TEXT(20) TYPE C, " Selection text
V_PAGE TYPE I, " Page number
V_ROL(6) TYPE N, " Final ROL VALUE
V_RL2(6) TYPE N, " Final RL2 value
V_BDC_OPEN TYPE C VALUE 'N', " BDC Open flag
V_FLG_COL TYPE I VALUE '1', " Color flag
V_TABIX2 TYPE SY-TABIX, " SY-TABIX
V_DOC_UP TYPE C. " Sales document update flag
----
C O N S T A T N T S
----
CONSTANTS: K_ROL(3) TYPE C VALUE 'ROL', " Constant ROL
K_YD2(3) TYPE C VALUE 'YD2', " Constant YD2
K_RL2(3) TYPE C VALUE 'RL2', " Constant RL2
K_X TYPE C VALUE 'X', " Constant X
K_MRP1 TYPE T133A-AUSWG VALUE '12', " MRP1 Data
K_MM02 TYPE TSTC-TCODE VALUE 'MM02'," Constant MM02
K_N TYPE C VALUE 'N', " Constant N
K_S TYPE C VALUE 'S', " Constant S
K_Y TYPE C VALUE 'Y'. " Constant Y
----
T O P O F P A G E
----
TOP-OF-PAGE.
PERFORM TOP_OF_PAGE. " Top of page
PERFORM HEADING_AUDIT_REPORT. " Heading for Audit report
----
S T A R T O F S E L E C T I O N
----
START-OF-SELECTION.
*-- Get new materials
PERFORM GET_NEW_MATERIAL.
*-- Get cumulative order quantities
PERFORM GET_CUM_ORDER_QUANITY.
IF NOT IT_FINAL[] IS INITIAL.
*-- Get final sales orders
PERFORM GET_SALES_ORDERS.
IF NOT IT_FINAL1[] IS INITIAL.
IF P_TEST <> K_X.
*-- Call transactions MM02 and VA02
PERFORM CALL_MM02_VA02.
ENDIF.
ELSE.
V_ERROR = K_X.
STOP.
ENDIF. " IT_FINAL1
ELSE.
V_ERROR = K_X.
STOP.
ENDIF. " IT_FINAL
----
E N D O F S E L E C T I O N
----
END-OF-SELECTION.
IF V_ERROR <> K_X.
IF P_TEST = K_X.
IF NOT IT_FINAL1[] IS INITIAL.
*-- Audit report
PERFORM WRITE_AUDIT_REPORT.
ENDIF.
ELSE.
IF NOT IT_REPORT[] IS INITIAL.
*-- Perform Audit report
PERFORM WRITE_FINAL_AUDIT_REPORT.
ENDIF.
ENDIF. " P_TEST
ELSE.
MESSAGE I100 WITH 'No Materials Selected'(016).
ENDIF. " V_ERROR
&----
*& Form GET_NEW_MATERIAL
&----
Get new materials
----
FORM GET_NEW_MATERIAL.
*-- Get new materials
CALL FUNCTION 'Z_GET_NEW_MATERIAL'
TABLES
MARA = IT_MARA.
IF IT_MARA[] IS INITIAL.
V_ERROR = K_X.
STOP.
ENDIF.
ENDFORM. " GET_NEW_MATERIAL
&----
*& Form GET_CUM_ORDER_QUANITY
&----
Get cumulative order quantities
----
FORM GET_CUM_ORDER_QUANITY.
REFRESH: IT_FINAL.
CLEAR: IT_FINAL,
V_KWMENG,
V_KWMENG1,
V_KWMENG2,
V_KWMENG3.
LOOP AT IT_MARA.
*-- Determine the number of YD2 per ROL for the 12' material
CALL FUNCTION 'Z_MATERIAL_UNIT_CONVERSION'
EXPORTING
MATERIAL = IT_MARA-ZZAMATNR
QUANTITY = '1'
IN_UNIT = K_ROL
OUT_UNIT = K_YD2
IMPORTING
OUT_QUANTITY = V_KWMENG1
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
CLEAR V_KWMENG1.
CONTINUE.
ELSE.
*-- Determine the number of YD2 per ROL for the 6' material
CALL FUNCTION 'Z_MATERIAL_UNIT_CONVERSION'
EXPORTING
MATERIAL = IT_MARA-MATNR
QUANTITY = '1'
IN_UNIT = K_ROL
OUT_UNIT = K_YD2
IMPORTING
OUT_QUANTITY = V_KWMENG2
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
CLEAR V_KWMENG2.
CONTINUE.
ELSE.
*-- Determine the number of YD2 per RL2 for the 6' material
CALL FUNCTION 'Z_MATERIAL_UNIT_CONVERSION'
EXPORTING
MATERIAL = IT_MARA-MATNR
QUANTITY = '1'
IN_UNIT = K_RL2
OUT_UNIT = K_YD2
IMPORTING
OUT_QUANTITY = V_KWMENG3
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
CLEAR V_KWMENG3.
CONTINUE.
ELSE.
*-- Get final values into IT_FINAL table
V_KWMENG = ( V_KWMENG1 / 2 ).
IF V_KWMENG1 <> V_KWMENG3
OR V_KWMENG <> V_KWMENG2.
IT_FINAL-MATNR = IT_MARA-MATNR.
IT_FINAL-WERKS = IT_MARA-WERKS.
IT_FINAL-ZZAMATNR = IT_MARA-ZZAMATNR.
IT_FINAL-KWMENG1 = V_KWMENG1.
IT_FINAL-KWMENG2 = V_KWMENG2.
IT_FINAL-KWMENG3 = V_KWMENG3. " OUT-QUANTITY
IT_FINAL-KWMENG = ( V_KWMENG3 / 2 ). " OUT-QUANTITY / 2
APPEND IT_FINAL.
CLEAR: IT_FINAL,
V_KWMENG,
V_KWMENG1,
V_KWMENG2,
V_KWMENG3.
ENDIF.
ENDIF. " V_KWMENG3
ENDIF. " V_KWMENG2
ENDIF. " V_KWMENG1
ENDLOOP. " IT_MARA
ENDFORM. " GET_CUM_ORDER_QUANITY
&----
*& Form BUILD_BDCTAB
&----
Build BDC data
----
FORM BUILD_BDCTAB.
REFRESH: IT_BDCDATA.
CLEAR: IT_BDCDATA,
MARA.
*-- Select MTART MBRSH VPSTA from MARA
SELECT SINGLE MTART
VPSTA
MBRSH
MEINS
FROM MARA
INTO (MARA-MTART, MARA-MBRSH, MARA-VPSTA, MARA-MEINS)
WHERE MATNR = IT_FINAL1-MATNR.
IF SY-SUBRC = 0.
PERFORM SET_SELECT_VIEW. " Select view ('MM02', MRP1 Data)
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0060',
' ' 'RMMG1-MATNR' IT_FINAL1-MATNR, " New Material number
' ' 'BDC_OKCODE' '/00'.
*-- Check if MRP1 Data is in Page 1
IF V_PAGE = 1.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0070',
' ' 'BDC_CURSOR' V_SEL_TEXT,
' ' 'BDC_OKCODE' '=ENTR',
' ' V_SEL_LINE K_X.
ELSE.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0070',
' ' 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)',
' ' 'BDC_OKCODE' '=P+'.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0070',
' ' 'BDC_CURSOR' V_SEL_TEXT,
' ' 'BDC_OKCODE' '=ENTR',
' ' V_SEL_LINE K_X.
ENDIF. " V_PAGE
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0080',
' ' 'BDC_CURSOR' 'RMMG1-WERKS',
' ' 'RMMG1-WERKS' IT_FINAL1-WERKS, " Plant
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPLMGMM' '3002',
' ' 'BDC_OKCODE' '=ZU02'. " UOM
REFRESH IT_MARM.
CLEAR IT_MARM.
*-- Select MARM data into IT_MARM
SELECT * FROM MARM
INTO TABLE IT_MARM
WHERE MATNR = IT_FINAL1-MATNR.
IF SY-SUBRC = 0.
LOOP AT IT_MARM.
V_TABIX = SY-TABIX.
IF IT_MARM-MEINH IS INITIAL.
IT_MARM-MEINH = MARA-MEINS.
ENDIF.
IF IT_MARM-UMREN <> 0.
IT_MARM-AZSUB = IT_MARM-UMREZ / IT_MARM-UMREN.
ENDIF.
MODIFY IT_MARM INDEX V_TABIX.
ENDLOOP. " IT_MARM
*-- Sort to get the same sequence as on screen
SORT IT_MARM BY AZSUB ASCENDING MEINH.
*-- Update ROL value
READ TABLE IT_MARM WITH KEY MEINH = K_ROL.
IF SY-SUBRC = 0.
IT_FINAL1-UMREZ1 = IT_MARM-UMREZ.
MODIFY IT_FINAL1 INDEX V_TABIX1 TRANSPORTING UMREZ1.
CLEAR V_LOOP_CNT.
V_LOOP_CNT = SY-TABIX.
*-- Get ROL position
PERFORM LOOP_VAR USING 'SMEINH-UMREZ' V_LOOP_CNT V_BDCFNAM.
CLEAR V_ROL.
V_ROL = IT_FINAL1-KWMENG.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '3100',
' ' V_BDCFNAM V_ROL. " ROL
ENDIF. " IT_MARM
*-- Update RL2 value
READ TABLE IT_MARM WITH KEY MEINH = K_RL2.
IF SY-SUBRC = 0.
IT_FINAL1-UMREZ2 = IT_MARM-UMREZ.
MODIFY IT_FINAL1 INDEX V_TABIX1 TRANSPORTING UMREZ2.
CLEAR V_LOOP_CN.
V_LOOP_CN = SY-TABIX.
*-- Get RL2 position
PERFORM LOOP_VAR USING 'SMEINH-UMREZ' V_LOOP_CN V_BDCFNAM.
CLEAR V_RL2.
V_RL2 = IT_FINAL1-KWMENG3.
PERFORM DYNPRO USING ' ' V_BDCFNAM V_RL2. " RL2
ENDIF. " IT_MARM
PERFORM DYNPRO USING ' ' 'BDC_OKCODE' '=BU'. " Save
ENDIF. " IT_MARM
ENDIF. " MARA
ENDFORM. " BUILD_BDCTAB
&----
*& Form SET_SELECT_VIEW
&----
Select view (MRP1 data) from MM02
----
FORM SET_SELECT_VIEW.
DATA: LV_NUM(2) TYPE N, " Selection position
LV_SEL_POS TYPE I, " Selection position
LV_BILDSEQUENZ TYPE T133A-BILDS. " Screen Sequence Number
REFRESH: IT_BILDTAB.
CLEAR: IT_BILDTAB,
V_SEL_LINE,
V_SEL_TEXT,
V_PAGE.
V_SEL_LINE = 1.
*-- Select data from T130M
SELECT SINGLE * FROM T130M
WHERE TCODE = K_MM02.
IF SY-SUBRC = 0.
CALL FUNCTION 'BILDSEQUENZ_IDENTIFY'
EXPORTING
BRANCHE = MARA-MBRSH
MATERIALART = MARA-MTART
TCODE_REF = T130M-TRREF
IMPORTING
BILDSEQUENZ = LV_BILDSEQUENZ
EXCEPTIONS
WRONG_CALL = 1
NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
CLEAR LV_BILDSEQUENZ.
ELSE.
*-- Find selection views
CALL FUNCTION 'SELECTION_VIEWS_FIND'
EXPORTING
BILDSEQUENZ = LV_BILDSEQUENZ
PFLEGESTATUS = T130M-PSTAT
TABLES
BILDTAB = IT_BILDTAB
EXCEPTIONS
CALL_WRONG = 1
EMPTY_SELECTION = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
CLEAR IT_BILDTAB.
ENDIF.
ENDIF. " LV_BILDSEQUENZ
ENDIF. " T130M
*-- Determine Popup selection
LOOP AT IT_BILDTAB.
AUTHORITY-CHECK OBJECT 'M_MATE_STA'
ID 'ACTVT' FIELD '02'
ID 'STATM' FIELD IT_BILDTAB-PSTAT.
IF SY-SUBRC NE 0.
DELETE IT_BILDTAB.
ENDIF.
ENDLOOP. " IT_BILDTAB
*-- Get the MRP1 Data position
READ TABLE IT_BILDTAB WITH KEY AUSWG = K_MRP1.
IF SY-SUBRC = 0.
LV_SEL_POS = SY-TABIX.
ELSE.
LV_SEL_POS = 0.
ENDIF.
*-- Determine if MRP1 Data is on first page
IF LV_SEL_POS <= 18.
V_PAGE = 1.
ELSE.
V_PAGE = 2.
LV_SEL_POS = LV_SEL_POS - 18.
ENDIF.
*-- Build field name for correct view(s)
CLEAR: R_FIELD.
MOVE: '($)' TO R_FIELD-PARENS,
'MSICHTAUSW-KZSEL' TO R_FIELD-NAME,
LV_SEL_POS TO LV_NUM.
REPLACE '$' WITH LV_NUM INTO R_FIELD-PARENS.
CONDENSE R_FIELD NO-GAPS.
MOVE: R_FIELD TO V_SEL_LINE.
CLEAR R_FIELD.
MOVE: '($)' TO R_FIELD-PARENS,
'MSICHTAUSW-DYTXT' TO R_FIELD-NAME,
LV_SEL_POS TO LV_NUM.
REPLACE '$' WITH LV_NUM INTO R_FIELD-PARENS.
CONDENSE R_FIELD NO-GAPS.
MOVE R_FIELD TO V_SEL_TEXT.
CLEAR R_FIELD.
ENDFORM. " SET_SELECT_VIEW
&----
*& Form DYNPRO
&----
Format the passed parameters into dynpro format and Fill BDCDATA
----
FORM DYNPRO USING DYNBEGIN TYPE ANY
NAME TYPE ANY
VALUE TYPE ANY.
*-- Fill BDCDATA
CLEAR IT_BDCDATA.
IF DYNBEGIN = 'X'.
MOVE: NAME TO IT_BDCDATA-PROGRAM,
VALUE TO IT_BDCDATA-DYNPRO,
'X' TO IT_BDCDATA-DYNBEGIN.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ELSE.
MOVE: NAME TO IT_BDCDATA-FNAM,
VALUE TO IT_BDCDATA-FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ENDIF. " DYNBEGIN
ENDFORM. " DYNPRO
&----
*& Form LOOP_VAR
&----
Handling Loop Var
----
FORM LOOP_VAR USING FIELDNAME TYPE ANY
LOOP_CNT TYPE ANY
BDCFNAM TYPE ANY.
DATA: LV_NUM TYPE N. " Loop counter
CLEAR: BDCFNAM,
R_FIELD.
MOVE: '($)' TO R_FIELD-PARENS.
MOVE: FIELDNAME TO R_FIELD-NAME,
LOOP_CNT TO LV_NUM.
REPLACE '$' WITH LV_NUM INTO R_FIELD-PARENS.
CONDENSE R_FIELD NO-GAPS.
MOVE R_FIELD TO BDCFNAM.
CLEAR R_FIELD.
ENDFORM. " LOOP_VAR
&----
*& Form SAVE_MM02_BDC_SESSION
&----
Save BDC Session
----
FORM SAVE_MM02_BDC_SESSION.
IF V_BDC_OPEN = K_N. "First failed transaction
*-- BDC_OPEN
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_BDCGRP
HOLDDATE = P_DATE
KEEP = K_X
USER = P_BDCUSR
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Open'(005).
STOP.
ENDIF.
V_BDC_OPEN = K_Y.
ENDIF. " V_BDC_OPEN
*-- BDC_INSERT
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = K_MM02
TABLES
DYNPROTAB = IT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Insert'(006).
STOP.
ENDIF.
ENDFORM. " SAVE_MM02_BDC_SESSION
&----
*& Form BUILD_BDCDATA_VA02
&----
Build BDC data
----
FORM BUILD_BDCDATA_VA02.
REFRESH IT_BDCDATA.
CLEAR IT_BDCDATA.
*-- Populate BDCDATA for VA02 transaction
PERFORM DYNPRO USING:
'X' 'SAPMV45A' '0102',
' ' 'BDC_CURSOR' 'VBAK-VBELN',
' ' 'BDC_OKCODE' '=ENT2',
' ' 'VBAK-VBELN' IT_FINAL1-VBELN,
'X' 'SAPMV45A' '4001',
' ' 'BDC_OKCODE' '=POPO',
' ' 'BDC_CURSOR' 'VBAP-MATNR(03)',
'X' 'SAPMV45A' '0251',
' ' 'BDC_CURSOR' 'RV45A-POSNR',
' ' 'BDC_OKCODE' '=POSI',
' ' 'RV45A-POSNR' IT_FINAL1-POSNR,
'X' 'SAPMV45A' '4001',
' ' 'BDC_OKCODE' '=PKAU',
' ' 'BDC_CURSOR' 'RV45A-VBAP_SELKZ(01)',
'X' 'SAPMV45A' '4003',
' ' 'BDC_OKCODE' '=ENT1',
' ' 'VBAP-VRKME' 'yd2', " yd2
'X' 'SAPMV45A' '4003',
' ' 'BDC_OKCODE' '=SICH',
' ' 'VBAP-VRKME' 'rol', " rol
'X' 'SAPLSPO2' '0101',
' ' 'BDC_OKCODE' '=OPT1'. " Save
ENDFORM. " BUILD_BDCDATA_VA02
&----
*& Form SAVE_BDC_SESSION_VA02
&----
Save BDC session for VA02
----
FORM SAVE_BDC_SESSION_VA02.
IF V_BDC_OPEN = K_N. "First failed transaction
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_GROUP
HOLDDATE = P_DATE1
KEEP = K_X
USER = P_USER
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Open'(005).
STOP.
ENDIF.
V_BDC_OPEN = K_Y.
ENDIF. " V_BDC_OPEN
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'VA02'
TABLES
DYNPROTAB = IT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Insert'(006).
STOP.
ENDIF.
ENDFORM. " SAVE_BDC_SESSION_VA02
&----
*& Form WRITE_AUDIT_REPORT
&----
Audit Report
----
FORM WRITE_AUDIT_REPORT.
FORMAT RESET.
FORMAT COLOR COL_NORMAL.
CLEAR V_TABIX.
*-- Audit report
LOOP AT IT_FINAL1.
*-- Color Intensification
IF V_FLG_COL = 1.
FORMAT INTENSIFIED ON.
ELSE.
FORMAT INTENSIFIED OFF.
ENDIF.
V_FLG_COL = V_FLG_COL * -1.
V_TABIX = SY-TABIX.
AT NEW MATNR.
READ TABLE IT_FINAL1 INDEX V_TABIX.
WRITE:/ SY-ULINE(238).
WRITE:/ SY-VLINE,
(20) IT_FINAL1-MATNR, SY-VLINE,
(10) IT_FINAL1-WERKS, SY-VLINE,
(30) IT_FINAL1-ZZAMATNR, SY-VLINE,
(30) IT_FINAL1-KWMENG1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_FINAL1-UMREZ1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_FINAL1-KWMENG UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_FINAL1-UMREZ2 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_FINAL1-KWMENG3 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
217(20) IT_FINAL1-MSG, SY-VLINE.
WRITE:/ SY-ULINE(238).
ENDAT.
WRITE:/ SY-VLINE.
IF NOT IT_FINAL1-VBELN IS INITIAL
AND NOT IT_FINAL1-POSNR IS INITIAL.
WRITE: 'Order-'(018),10(12) IT_FINAL1-VBELN,
(10) IT_FINAL1-POSNR.
ENDIF.
WRITE: 217(20) IT_FINAL1-MSG, SY-VLINE.
ENDLOOP. " IT_FINAL1
WRITE:/ SY-ULINE(238).
ENDFORM. " WRITE_AUDIT_REPORT
&----
*& Form TOP_OF_PAGE
&----
Top of page
----
FORM TOP_OF_PAGE.
*-- Armstrong header
CALL FUNCTION 'Z_STD_HEADER'
EXPORTING
PROGNAME = SY-CPROG
LINESIZE = SY-LINSZ
PAGENO = SY-PAGNO
HEADER2 = 'Audit Report'(003).
ENDFORM. " TOP_OF_PAGE
&----
*& Form HEADING_AUDIT_REPORT
&----
Heading for Audit report
----
FORM HEADING_AUDIT_REPORT.
*-- Audit report headings
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE:/ SY-ULINE(238).
WRITE:/ SY-VLINE,
(20) '6'' Material'(007), SY-VLINE,
(10) 'Plant'(008), SY-VLINE,
(30) '12'' Material'(009), SY-VLINE,
(30) 'Curr.12''Material(YD2/ROL)'(010), SY-VLINE,
(30) 'Prev.6'' Material(YD2/ROL)'(011), SY-VLINE,
(20) 'New 6'' Material(ROL)'(012), SY-VLINE,
(30) 'Prev.6'' Material(YD2/RL2)'(013), SY-VLINE,
(20) 'New 6'' Material(RL2)'(014), SY-VLINE,
(20) 'Update Message'(015), SY-VLINE.
FORMAT COLOR OFF.
ENDFORM. " HEADING_AUDIT_REPORT
&----
*& Form GET_SALES_ORDERS
&----
Get sales orders
----
FORM GET_SALES_ORDERS.
*-- Select VAPMA data
SELECT * FROM VAPMA
INTO TABLE IT_VAPMA
FOR ALL ENTRIES IN IT_FINAL
WHERE MATNR = IT_FINAL-MATNR
AND AUART IN S_AUART
AND WERKS = IT_FINAL-WERKS
AND TRVOG = '0'.
IF SY-SUBRC = 0.
*-- Select VBAP data
SELECT VBELN
POSNR
FROM VBAP
INTO TABLE IT_VBAP
FOR ALL ENTRIES IN IT_VAPMA
WHERE VBELN = IT_VAPMA-VBELN
AND POSNR = IT_VAPMA-POSNR
AND VRKME = K_ROL.
IF SY-SUBRC = 0.
*-- Select VBUP data
SELECT VBELN
POSNR
FROM VBUP
INTO TABLE IT_VBUP
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELN = IT_VBAP-VBELN
AND POSNR = IT_VBAP-POSNR
AND GBSTA = 'A'.
ENDIF. " VBAP
SORT IT_VBUP BY VBELN POSNR.
*-- Get final sales orders and materials
CLEAR V_TABIX2.
LOOP AT IT_VAPMA.
V_TABIX2 = SY-TABIX.
READ TABLE IT_VBUP WITH KEY VBELN = IT_VAPMA-VBELN
POSNR = IT_VAPMA-POSNR
BINARY SEARCH.
IF SY-SUBRC <> 0.
DELETE IT_VAPMA INDEX V_TABIX2.
ENDIF.
ENDLOOP. " IT_VAPMA
SORT IT_VAPMA BY MATNR.
SORT IT_FINAL BY MATNR.
*-- Get VBELN and POSNR into IT_FINAL1 table
CLEAR IT_FINAL.
LOOP AT IT_FINAL.
READ TABLE IT_VAPMA WITH KEY MATNR = IT_FINAL-MATNR
BINARY SEARCH.
IF SY-SUBRC = 0.
CLEAR IT_VAPMA.
LOOP AT IT_VAPMA WHERE MATNR = IT_FINAL-MATNR.
IT_FINAL1-MATNR = IT_FINAL-MATNR.
IT_FINAL1-WERKS = IT_FINAL-WERKS.
IT_FINAL1-ZZAMATNR = IT_FINAL-ZZAMATNR.
IT_FINAL1-KWMENG1 = IT_FINAL-KWMENG1.
IT_FINAL1-KWMENG2 = IT_FINAL-KWMENG2.
IT_FINAL1-KWMENG3 = IT_FINAL-KWMENG3.
IT_FINAL1-KWMENG = IT_FINAL-KWMENG.
IT_FINAL1-UMREZ1 = IT_FINAL-UMREZ1.
IT_FINAL1-UMREZ2 = IT_FINAL-UMREZ2.
IT_FINAL1-VBELN = IT_VAPMA-VBELN.
IT_FINAL1-POSNR = IT_VAPMA-POSNR.
APPEND IT_FINAL1.
CLEAR IT_FINAL1.
ENDLOOP. " IT_VAMPA
ELSE.
IT_FINAL1-MATNR = IT_FINAL-MATNR.
IT_FINAL1-WERKS = IT_FINAL-WERKS.
IT_FINAL1-ZZAMATNR = IT_FINAL-ZZAMATNR.
IT_FINAL1-KWMENG1 = IT_FINAL-KWMENG1.
IT_FINAL1-KWMENG2 = IT_FINAL-KWMENG2.
IT_FINAL1-KWMENG3 = IT_FINAL-KWMENG3.
IT_FINAL1-KWMENG = IT_FINAL-KWMENG.
IT_FINAL1-UMREZ1 = IT_FINAL-UMREZ1.
IT_FINAL1-UMREZ2 = IT_FINAL-UMREZ2.
APPEND IT_FINAL1.
CLEAR IT_FINAL1.
ENDIF.
ENDLOOP. " IT_FINAL
SORT IT_FINAL1 BY MATNR.
ENDIF. " VAPMA
ENDFORM. " GET_SALES_ORDERS
&----
*& Form CALL_MM02_VA02
&----
Update materials and sales orders
----
FORM CALL_MM02_VA02.
REFRESH: IT_REPORT.
CLEAR: IT_REPORT,
V_DOC_UP.
LOOP AT IT_FINAL1.
V_TABIX1 = SY-TABIX.
AT NEW MATNR.
READ TABLE IT_FINAL1 INDEX V_TABIX1.
*-- Build BDCTAB for MM02 transaction
PERFORM BUILD_BDCTAB.
*-- Call transaction MM02
CALL TRANSACTION K_MM02
USING IT_BDCDATA
MODE 'A' "K_N
UPDATE K_S.
IF SY-SUBRC = 0.
V_DOC_UP = K_X.
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
CLEAR IT_REPORT-MSG.
APPEND IT_REPORT.
CLEAR IT_REPORT.
ELSE.
CLEAR V_DOC_UP.
*-- If call transaction fails populate BDC SESSION
PERFORM SAVE_MM02_BDC_SESSION.
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
IT_REPORT-MSG = 'Failed'(019).
APPEND IT_REPORT.
CLEAR IT_REPORT.
ENDIF. " MM02
ENDAT. " MATNR
IF V_DOC_UP = K_X.
IF NOT IT_FINAL1-VBELN IS INITIAL
AND NOT IT_FINAL1-POSNR IS INITIAL.
*-- Build BDCDATA for VA02 transaction
PERFORM BUILD_BDCDATA_VA02.
*-- Call VA02 transaction
CALL TRANSACTION 'VA02'
USING IT_BDCDATA
MODE K_N
UPDATE K_S.
IF SY-SUBRC <> 0.
*-- Populate Error table with the message
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
IT_REPORT-VBELN = IT_FINAL1-VBELN.
IT_REPORT-POSNR = IT_FINAL1-POSNR.
IT_REPORT-MSG = 'Failed'(019).
APPEND IT_REPORT.
CLEAR IT_REPORT.
*-- Save session for error records
PERFORM SAVE_BDC_SESSION_VA02.
*-- If call transaction is success
ELSE.
*-- Populate success table
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
IT_REPORT-VBELN = IT_FINAL1-VBELN.
IT_REPORT-POSNR = IT_FINAL1-POSNR.
CLEAR IT_REPORT-MSG.
APPEND IT_REPORT.
CLEAR IT_REPORT.
ENDIF. " VA02
ENDIF. " IT_FINAL1-VBELN POSNR NOT INITIAL
ENDIF. " V_DOC_UP = K_X
ENDLOOP. " IT_FINAL1
*-- Close BDC_GROUP
IF V_BDC_OPEN = K_Y.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error closing BDC Group'(017).
ENDIF.
V_BDC_OPEN = K_N.
ENDIF. " V_BDC_OPEN
ENDFORM. " CALL_MM02_VA02
&----
*& Form WRITE_FINAL_AUDIT_REPORT
&----
Final audit report
----
FORM WRITE_FINAL_AUDIT_REPORT.
*-- Get final data into FINAL table
FORMAT RESET.
FORMAT COLOR COL_NORMAL.
CLEAR V_TABIX.
*-- Audit report
LOOP AT IT_REPORT.
V_TABIX = SY-TABIX.
*-- Color Intensification
IF V_FLG_COL = 1.
FORMAT INTENSIFIED ON.
ELSE.
FORMAT INTENSIFIED OFF.
ENDIF.
V_FLG_COL = V_FLG_COL * -1.
AT NEW MATNR.
READ TABLE IT_REPORT INDEX V_TABIX.
WRITE:/ SY-ULINE(238).
WRITE:/ SY-VLINE,
(20) IT_REPORT-MATNR, SY-VLINE,
(10) IT_REPORT-WERKS, SY-VLINE,
(30) IT_REPORT-ZZAMATNR, SY-VLINE,
(30) IT_REPORT-KWMENG1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_REPORT-UMREZ1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_REPORT-KWMENG UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_REPORT-UMREZ2 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_REPORT-KWMENG3 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
217(20) IT_REPORT-MSG, SY-VLINE.
WRITE:/ SY-ULINE(238).
ENDAT.
WRITE:/ SY-VLINE.
IF NOT IT_REPORT-VBELN IS INITIAL
AND NOT IT_REPORT-POSNR IS INITIAL.
WRITE: 'Order-'(018),10(12) IT_REPORT-VBELN,
(10) IT_REPORT-POSNR.
ENDIF.
WRITE: 217(20) IT_REPORT-MSG, SY-VLINE.
ENDLOOP. " IT_REPORT
WRITE:/ SY-ULINE(238).
ENDFORM. " WRITE_FINAL_AUDIT_REPORT
[/code]
Thanks,
GSK
Hi,
i have written a program which read the data either from the frontend or from the server and will post(BDC) the FI document using that data.
now my requirement is to get the output for error messages list too. right from the starting to the successful completion of the execution.
valauable input is appreciable and if anyone done in the same manner do provide me the sample code.
if needed i will post the full code. do give me the personal mail id.
thank u
2006 Aug 24 3:17 PM
Hi,
Below is a similar code for your requirment. Please go through it and follow the logic.
[code]REPORT ZMMM0047
LINE-COUNT 65
LINE-SIZE 238
MESSAGE-ID Z2
NO STANDARD PAGE HEADING.
----
T A B L E S
----
TABLES: MARA, " General Material Data
T130M, " Material master maintenance
VBAK. " Sales Document: Header Data
----
S E L E C T I O N - S C R E E N
----
*-- Selection screen for Materials
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
*-- BDC Group
PARAMETERS: P_BDCGRP(12) TYPE C OBLIGATORY,
*-- BDC User
P_BDCUSR(12) TYPE C OBLIGATORY DEFAULT SY-UNAME,
*-- Hold Date
P_DATE TYPE SY-DATUM OBLIGATORY DEFAULT SY-DATUM.
SELECTION-SCREEN END OF BLOCK B1.
*-- Selection screen for Sales orders
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
*-- BDC Group
PARAMETERS: P_GROUP(12) TYPE C OBLIGATORY,
*-- BDC User
P_USER(12) TYPE C OBLIGATORY DEFAULT SY-UNAME,
*-- Hold date
P_DATE1 TYPE SY-DATUM OBLIGATORY DEFAULT SY-DATUM.
*-- Sales document type
SELECT-OPTIONS: S_AUART FOR VBAK-AUART OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B2.
*-- Selection screen for Test
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-004.
*-- Test only
PARAMETERS: P_TEST AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK B3.
----
T Y P E S
----
*-- Types declaration for final data
TYPES: BEGIN OF T_FINAL,
MATNR TYPE ZMMARA-MATNR, " 6' material
WERKS TYPE ZMMARA-WERKS, " Plant
ZZAMATNR TYPE ZMMARA-ZZAMATNR, " 12' materials (Rolls)
KWMENG1 TYPE VBAP-KWMENG, " Cum.order quantity 12' YD2 per ROL
KWMENG2 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per ROL
KWMENG3 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per RL2
KWMENG TYPE VBAP-KWMENG, " Out-Quantity / 2
UMREZ1 TYPE VBAP-KWMENG, " Prev.value for YD2 per ROL for 6'
UMREZ2 TYPE VBAP-KWMENG, " Prev.value for YD2 per RL2 for 6'
VBELN TYPE VBAP-VBELN, " Sales document
POSNR TYPE VBAP-POSNR, " Sales document item
MSG(20) TYPE C, " Error message
END OF T_FINAL.
*-- Types definition for MARM
TYPES BEGIN OF T_MARM.
INCLUDE STRUCTURE MARM. " Units of Measure for Material
TYPES AZSUB TYPE SMEINH-AZSUB. " Number of Lower-Level UOM
TYPES END OF T_MARM.
*-- Types definition for BILDTAB
TYPES: BEGIN OF T_BILDTAB.
INCLUDE STRUCTURE MBILDTAB. " Material Master View Selection
" Screens
TYPES: END OF T_BILDTAB.
*-- Types definition for BDCDATA
TYPES BEGIN OF T_BDCDATA.
INCLUDE STRUCTURE BDCDATA. Batch input: New table field"
" structure
TYPES END OF T_BDCDATA.
*-- Types definition for Sales order details
TYPES: BEGIN OF T_STAB,
VBELN TYPE VBAP-VBELN, Sales document"
POSNR TYPE VBAP-POSNR, " Sales document item
END OF T_STAB.
*-- Types definition for VAPMA data
TYPES: BEGIN OF T_VAPMA.
INCLUDE STRUCTURE VAPMA. " Sales Index: Order Items by Material
TYPES: END OF T_VAPMA.
----
I N T E R N A L T A B L E S
----
*-- Internal table to hold new material values
DATA: IT_MARA TYPE STANDARD TABLE OF ZMMARA WITH HEADER LINE,
*-- Internal table to hold Final data
IT_FINAL TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE,
*-- Internal table to hold IT_MARM data
IT_MARM TYPE STANDARD TABLE OF T_MARM WITH HEADER LINE,
*-- Internal table to hold IT_BILDTAB
IT_BILDTAB TYPE STANDARD TABLE OF T_BILDTAB WITH HEADER LINE,
*-- Internal table to hold IT_BDCDATA
IT_BDCDATA TYPE STANDARD TABLE OF T_BDCDATA WITH HEADER LINE,
*-- Internal table to hold IT_SUCCS data
IT_REPORT TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE,
*-- Internal table to hold VAPMA data
IT_VAPMA TYPE STANDARD TABLE OF T_VAPMA WITH HEADER LINE,
*-- Internal table to hold VBAP data
IT_VBAP TYPE STANDARD TABLE OF T_STAB WITH HEADER LINE,
*-- Internal table to hold VBUP data
IT_VBUP TYPE STANDARD TABLE OF T_STAB WITH HEADER LINE,
*-- Internal table to hold Final data
IT_FINAL1 TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE.
*-- Structure to hold R_FIELD data
DATA: BEGIN OF R_FIELD,
NAME TYPE BDCDATA-FNAM, " Field name
PARENS(6) TYPE C VALUE '($)', " Number
END OF R_FIELD.
----
V A R I A B L E S
----
DATA: V_KWMENG TYPE I, " Cum.order quantity
V_KWMENG1 TYPE VBAP-KWMENG, " Cum.order quantity 12' YD2 per ROL
V_KWMENG2 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per ROL
V_KWMENG3 TYPE VBAP-KWMENG, " Cum.order quantity 6' YD2 per RL2
V_ERROR TYPE C, " Error flag
V_LOOP_CNT TYPE I, " Loop counter
V_LOOP_CN TYPE I, " Loop counter
V_BDCFNAM TYPE BDCDATA-FNAM, " BDC field name
V_TABIX TYPE SY-TABIX, " SY-TABIX
V_TABIX1 TYPE SY-TABIX, " SY-TABIX
V_SEL_LINE(20) TYPE C, " Selection line
V_SEL_TEXT(20) TYPE C, " Selection text
V_PAGE TYPE I, " Page number
V_ROL(6) TYPE N, " Final ROL VALUE
V_RL2(6) TYPE N, " Final RL2 value
V_BDC_OPEN TYPE C VALUE 'N', " BDC Open flag
V_FLG_COL TYPE I VALUE '1', " Color flag
V_TABIX2 TYPE SY-TABIX, " SY-TABIX
V_DOC_UP TYPE C. " Sales document update flag
----
C O N S T A T N T S
----
CONSTANTS: K_ROL(3) TYPE C VALUE 'ROL', " Constant ROL
K_YD2(3) TYPE C VALUE 'YD2', " Constant YD2
K_RL2(3) TYPE C VALUE 'RL2', " Constant RL2
K_X TYPE C VALUE 'X', " Constant X
K_MRP1 TYPE T133A-AUSWG VALUE '12', " MRP1 Data
K_MM02 TYPE TSTC-TCODE VALUE 'MM02'," Constant MM02
K_N TYPE C VALUE 'N', " Constant N
K_S TYPE C VALUE 'S', " Constant S
K_Y TYPE C VALUE 'Y'. " Constant Y
----
T O P O F P A G E
----
TOP-OF-PAGE.
PERFORM TOP_OF_PAGE. " Top of page
PERFORM HEADING_AUDIT_REPORT. " Heading for Audit report
----
S T A R T O F S E L E C T I O N
----
START-OF-SELECTION.
*-- Get new materials
PERFORM GET_NEW_MATERIAL.
*-- Get cumulative order quantities
PERFORM GET_CUM_ORDER_QUANITY.
IF NOT IT_FINAL[] IS INITIAL.
*-- Get final sales orders
PERFORM GET_SALES_ORDERS.
IF NOT IT_FINAL1[] IS INITIAL.
IF P_TEST <> K_X.
*-- Call transactions MM02 and VA02
PERFORM CALL_MM02_VA02.
ENDIF.
ELSE.
V_ERROR = K_X.
STOP.
ENDIF. " IT_FINAL1
ELSE.
V_ERROR = K_X.
STOP.
ENDIF. " IT_FINAL
----
E N D O F S E L E C T I O N
----
END-OF-SELECTION.
IF V_ERROR <> K_X.
IF P_TEST = K_X.
IF NOT IT_FINAL1[] IS INITIAL.
*-- Audit report
PERFORM WRITE_AUDIT_REPORT.
ENDIF.
ELSE.
IF NOT IT_REPORT[] IS INITIAL.
*-- Perform Audit report
PERFORM WRITE_FINAL_AUDIT_REPORT.
ENDIF.
ENDIF. " P_TEST
ELSE.
MESSAGE I100 WITH 'No Materials Selected'(016).
ENDIF. " V_ERROR
&----
*& Form GET_NEW_MATERIAL
&----
Get new materials
----
FORM GET_NEW_MATERIAL.
*-- Get new materials
CALL FUNCTION 'Z_GET_NEW_MATERIAL'
TABLES
MARA = IT_MARA.
IF IT_MARA[] IS INITIAL.
V_ERROR = K_X.
STOP.
ENDIF.
ENDFORM. " GET_NEW_MATERIAL
&----
*& Form GET_CUM_ORDER_QUANITY
&----
Get cumulative order quantities
----
FORM GET_CUM_ORDER_QUANITY.
REFRESH: IT_FINAL.
CLEAR: IT_FINAL,
V_KWMENG,
V_KWMENG1,
V_KWMENG2,
V_KWMENG3.
LOOP AT IT_MARA.
*-- Determine the number of YD2 per ROL for the 12' material
CALL FUNCTION 'Z_MATERIAL_UNIT_CONVERSION'
EXPORTING
MATERIAL = IT_MARA-ZZAMATNR
QUANTITY = '1'
IN_UNIT = K_ROL
OUT_UNIT = K_YD2
IMPORTING
OUT_QUANTITY = V_KWMENG1
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
CLEAR V_KWMENG1.
CONTINUE.
ELSE.
*-- Determine the number of YD2 per ROL for the 6' material
CALL FUNCTION 'Z_MATERIAL_UNIT_CONVERSION'
EXPORTING
MATERIAL = IT_MARA-MATNR
QUANTITY = '1'
IN_UNIT = K_ROL
OUT_UNIT = K_YD2
IMPORTING
OUT_QUANTITY = V_KWMENG2
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
CLEAR V_KWMENG2.
CONTINUE.
ELSE.
*-- Determine the number of YD2 per RL2 for the 6' material
CALL FUNCTION 'Z_MATERIAL_UNIT_CONVERSION'
EXPORTING
MATERIAL = IT_MARA-MATNR
QUANTITY = '1'
IN_UNIT = K_RL2
OUT_UNIT = K_YD2
IMPORTING
OUT_QUANTITY = V_KWMENG3
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
CLEAR V_KWMENG3.
CONTINUE.
ELSE.
*-- Get final values into IT_FINAL table
V_KWMENG = ( V_KWMENG1 / 2 ).
IF V_KWMENG1 <> V_KWMENG3
OR V_KWMENG <> V_KWMENG2.
IT_FINAL-MATNR = IT_MARA-MATNR.
IT_FINAL-WERKS = IT_MARA-WERKS.
IT_FINAL-ZZAMATNR = IT_MARA-ZZAMATNR.
IT_FINAL-KWMENG1 = V_KWMENG1.
IT_FINAL-KWMENG2 = V_KWMENG2.
IT_FINAL-KWMENG3 = V_KWMENG3. " OUT-QUANTITY
IT_FINAL-KWMENG = ( V_KWMENG3 / 2 ). " OUT-QUANTITY / 2
APPEND IT_FINAL.
CLEAR: IT_FINAL,
V_KWMENG,
V_KWMENG1,
V_KWMENG2,
V_KWMENG3.
ENDIF.
ENDIF. " V_KWMENG3
ENDIF. " V_KWMENG2
ENDIF. " V_KWMENG1
ENDLOOP. " IT_MARA
ENDFORM. " GET_CUM_ORDER_QUANITY
&----
*& Form BUILD_BDCTAB
&----
Build BDC data
----
FORM BUILD_BDCTAB.
REFRESH: IT_BDCDATA.
CLEAR: IT_BDCDATA,
MARA.
*-- Select MTART MBRSH VPSTA from MARA
SELECT SINGLE MTART
VPSTA
MBRSH
MEINS
FROM MARA
INTO (MARA-MTART, MARA-MBRSH, MARA-VPSTA, MARA-MEINS)
WHERE MATNR = IT_FINAL1-MATNR.
IF SY-SUBRC = 0.
PERFORM SET_SELECT_VIEW. " Select view ('MM02', MRP1 Data)
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0060',
' ' 'RMMG1-MATNR' IT_FINAL1-MATNR, " New Material number
' ' 'BDC_OKCODE' '/00'.
*-- Check if MRP1 Data is in Page 1
IF V_PAGE = 1.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0070',
' ' 'BDC_CURSOR' V_SEL_TEXT,
' ' 'BDC_OKCODE' '=ENTR',
' ' V_SEL_LINE K_X.
ELSE.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0070',
' ' 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)',
' ' 'BDC_OKCODE' '=P+'.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0070',
' ' 'BDC_CURSOR' V_SEL_TEXT,
' ' 'BDC_OKCODE' '=ENTR',
' ' V_SEL_LINE K_X.
ENDIF. " V_PAGE
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '0080',
' ' 'BDC_CURSOR' 'RMMG1-WERKS',
' ' 'RMMG1-WERKS' IT_FINAL1-WERKS, " Plant
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPLMGMM' '3002',
' ' 'BDC_OKCODE' '=ZU02'. " UOM
REFRESH IT_MARM.
CLEAR IT_MARM.
*-- Select MARM data into IT_MARM
SELECT * FROM MARM
INTO TABLE IT_MARM
WHERE MATNR = IT_FINAL1-MATNR.
IF SY-SUBRC = 0.
LOOP AT IT_MARM.
V_TABIX = SY-TABIX.
IF IT_MARM-MEINH IS INITIAL.
IT_MARM-MEINH = MARA-MEINS.
ENDIF.
IF IT_MARM-UMREN <> 0.
IT_MARM-AZSUB = IT_MARM-UMREZ / IT_MARM-UMREN.
ENDIF.
MODIFY IT_MARM INDEX V_TABIX.
ENDLOOP. " IT_MARM
*-- Sort to get the same sequence as on screen
SORT IT_MARM BY AZSUB ASCENDING MEINH.
*-- Update ROL value
READ TABLE IT_MARM WITH KEY MEINH = K_ROL.
IF SY-SUBRC = 0.
IT_FINAL1-UMREZ1 = IT_MARM-UMREZ.
MODIFY IT_FINAL1 INDEX V_TABIX1 TRANSPORTING UMREZ1.
CLEAR V_LOOP_CNT.
V_LOOP_CNT = SY-TABIX.
*-- Get ROL position
PERFORM LOOP_VAR USING 'SMEINH-UMREZ' V_LOOP_CNT V_BDCFNAM.
CLEAR V_ROL.
V_ROL = IT_FINAL1-KWMENG.
PERFORM DYNPRO USING:
'X' 'SAPLMGMM' '3100',
' ' V_BDCFNAM V_ROL. " ROL
ENDIF. " IT_MARM
*-- Update RL2 value
READ TABLE IT_MARM WITH KEY MEINH = K_RL2.
IF SY-SUBRC = 0.
IT_FINAL1-UMREZ2 = IT_MARM-UMREZ.
MODIFY IT_FINAL1 INDEX V_TABIX1 TRANSPORTING UMREZ2.
CLEAR V_LOOP_CN.
V_LOOP_CN = SY-TABIX.
*-- Get RL2 position
PERFORM LOOP_VAR USING 'SMEINH-UMREZ' V_LOOP_CN V_BDCFNAM.
CLEAR V_RL2.
V_RL2 = IT_FINAL1-KWMENG3.
PERFORM DYNPRO USING ' ' V_BDCFNAM V_RL2. " RL2
ENDIF. " IT_MARM
PERFORM DYNPRO USING ' ' 'BDC_OKCODE' '=BU'. " Save
ENDIF. " IT_MARM
ENDIF. " MARA
ENDFORM. " BUILD_BDCTAB
&----
*& Form SET_SELECT_VIEW
&----
Select view (MRP1 data) from MM02
----
FORM SET_SELECT_VIEW.
DATA: LV_NUM(2) TYPE N, " Selection position
LV_SEL_POS TYPE I, " Selection position
LV_BILDSEQUENZ TYPE T133A-BILDS. " Screen Sequence Number
REFRESH: IT_BILDTAB.
CLEAR: IT_BILDTAB,
V_SEL_LINE,
V_SEL_TEXT,
V_PAGE.
V_SEL_LINE = 1.
*-- Select data from T130M
SELECT SINGLE * FROM T130M
WHERE TCODE = K_MM02.
IF SY-SUBRC = 0.
CALL FUNCTION 'BILDSEQUENZ_IDENTIFY'
EXPORTING
BRANCHE = MARA-MBRSH
MATERIALART = MARA-MTART
TCODE_REF = T130M-TRREF
IMPORTING
BILDSEQUENZ = LV_BILDSEQUENZ
EXCEPTIONS
WRONG_CALL = 1
NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
CLEAR LV_BILDSEQUENZ.
ELSE.
*-- Find selection views
CALL FUNCTION 'SELECTION_VIEWS_FIND'
EXPORTING
BILDSEQUENZ = LV_BILDSEQUENZ
PFLEGESTATUS = T130M-PSTAT
TABLES
BILDTAB = IT_BILDTAB
EXCEPTIONS
CALL_WRONG = 1
EMPTY_SELECTION = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
CLEAR IT_BILDTAB.
ENDIF.
ENDIF. " LV_BILDSEQUENZ
ENDIF. " T130M
*-- Determine Popup selection
LOOP AT IT_BILDTAB.
AUTHORITY-CHECK OBJECT 'M_MATE_STA'
ID 'ACTVT' FIELD '02'
ID 'STATM' FIELD IT_BILDTAB-PSTAT.
IF SY-SUBRC NE 0.
DELETE IT_BILDTAB.
ENDIF.
ENDLOOP. " IT_BILDTAB
*-- Get the MRP1 Data position
READ TABLE IT_BILDTAB WITH KEY AUSWG = K_MRP1.
IF SY-SUBRC = 0.
LV_SEL_POS = SY-TABIX.
ELSE.
LV_SEL_POS = 0.
ENDIF.
*-- Determine if MRP1 Data is on first page
IF LV_SEL_POS <= 18.
V_PAGE = 1.
ELSE.
V_PAGE = 2.
LV_SEL_POS = LV_SEL_POS - 18.
ENDIF.
*-- Build field name for correct view(s)
CLEAR: R_FIELD.
MOVE: '($)' TO R_FIELD-PARENS,
'MSICHTAUSW-KZSEL' TO R_FIELD-NAME,
LV_SEL_POS TO LV_NUM.
REPLACE '$' WITH LV_NUM INTO R_FIELD-PARENS.
CONDENSE R_FIELD NO-GAPS.
MOVE: R_FIELD TO V_SEL_LINE.
CLEAR R_FIELD.
MOVE: '($)' TO R_FIELD-PARENS,
'MSICHTAUSW-DYTXT' TO R_FIELD-NAME,
LV_SEL_POS TO LV_NUM.
REPLACE '$' WITH LV_NUM INTO R_FIELD-PARENS.
CONDENSE R_FIELD NO-GAPS.
MOVE R_FIELD TO V_SEL_TEXT.
CLEAR R_FIELD.
ENDFORM. " SET_SELECT_VIEW
&----
*& Form DYNPRO
&----
Format the passed parameters into dynpro format and Fill BDCDATA
----
FORM DYNPRO USING DYNBEGIN TYPE ANY
NAME TYPE ANY
VALUE TYPE ANY.
*-- Fill BDCDATA
CLEAR IT_BDCDATA.
IF DYNBEGIN = 'X'.
MOVE: NAME TO IT_BDCDATA-PROGRAM,
VALUE TO IT_BDCDATA-DYNPRO,
'X' TO IT_BDCDATA-DYNBEGIN.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ELSE.
MOVE: NAME TO IT_BDCDATA-FNAM,
VALUE TO IT_BDCDATA-FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
ENDIF. " DYNBEGIN
ENDFORM. " DYNPRO
&----
*& Form LOOP_VAR
&----
Handling Loop Var
----
FORM LOOP_VAR USING FIELDNAME TYPE ANY
LOOP_CNT TYPE ANY
BDCFNAM TYPE ANY.
DATA: LV_NUM TYPE N. " Loop counter
CLEAR: BDCFNAM,
R_FIELD.
MOVE: '($)' TO R_FIELD-PARENS.
MOVE: FIELDNAME TO R_FIELD-NAME,
LOOP_CNT TO LV_NUM.
REPLACE '$' WITH LV_NUM INTO R_FIELD-PARENS.
CONDENSE R_FIELD NO-GAPS.
MOVE R_FIELD TO BDCFNAM.
CLEAR R_FIELD.
ENDFORM. " LOOP_VAR
&----
*& Form SAVE_MM02_BDC_SESSION
&----
Save BDC Session
----
FORM SAVE_MM02_BDC_SESSION.
IF V_BDC_OPEN = K_N. "First failed transaction
*-- BDC_OPEN
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_BDCGRP
HOLDDATE = P_DATE
KEEP = K_X
USER = P_BDCUSR
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Open'(005).
STOP.
ENDIF.
V_BDC_OPEN = K_Y.
ENDIF. " V_BDC_OPEN
*-- BDC_INSERT
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = K_MM02
TABLES
DYNPROTAB = IT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Insert'(006).
STOP.
ENDIF.
ENDFORM. " SAVE_MM02_BDC_SESSION
&----
*& Form BUILD_BDCDATA_VA02
&----
Build BDC data
----
FORM BUILD_BDCDATA_VA02.
REFRESH IT_BDCDATA.
CLEAR IT_BDCDATA.
*-- Populate BDCDATA for VA02 transaction
PERFORM DYNPRO USING:
'X' 'SAPMV45A' '0102',
' ' 'BDC_CURSOR' 'VBAK-VBELN',
' ' 'BDC_OKCODE' '=ENT2',
' ' 'VBAK-VBELN' IT_FINAL1-VBELN,
'X' 'SAPMV45A' '4001',
' ' 'BDC_OKCODE' '=POPO',
' ' 'BDC_CURSOR' 'VBAP-MATNR(03)',
'X' 'SAPMV45A' '0251',
' ' 'BDC_CURSOR' 'RV45A-POSNR',
' ' 'BDC_OKCODE' '=POSI',
' ' 'RV45A-POSNR' IT_FINAL1-POSNR,
'X' 'SAPMV45A' '4001',
' ' 'BDC_OKCODE' '=PKAU',
' ' 'BDC_CURSOR' 'RV45A-VBAP_SELKZ(01)',
'X' 'SAPMV45A' '4003',
' ' 'BDC_OKCODE' '=ENT1',
' ' 'VBAP-VRKME' 'yd2', " yd2
'X' 'SAPMV45A' '4003',
' ' 'BDC_OKCODE' '=SICH',
' ' 'VBAP-VRKME' 'rol', " rol
'X' 'SAPLSPO2' '0101',
' ' 'BDC_OKCODE' '=OPT1'. " Save
ENDFORM. " BUILD_BDCDATA_VA02
&----
*& Form SAVE_BDC_SESSION_VA02
&----
Save BDC session for VA02
----
FORM SAVE_BDC_SESSION_VA02.
IF V_BDC_OPEN = K_N. "First failed transaction
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_GROUP
HOLDDATE = P_DATE1
KEEP = K_X
USER = P_USER
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Open'(005).
STOP.
ENDIF.
V_BDC_OPEN = K_Y.
ENDIF. " V_BDC_OPEN
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'VA02'
TABLES
DYNPROTAB = IT_BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error during BDC Insert'(006).
STOP.
ENDIF.
ENDFORM. " SAVE_BDC_SESSION_VA02
&----
*& Form WRITE_AUDIT_REPORT
&----
Audit Report
----
FORM WRITE_AUDIT_REPORT.
FORMAT RESET.
FORMAT COLOR COL_NORMAL.
CLEAR V_TABIX.
*-- Audit report
LOOP AT IT_FINAL1.
*-- Color Intensification
IF V_FLG_COL = 1.
FORMAT INTENSIFIED ON.
ELSE.
FORMAT INTENSIFIED OFF.
ENDIF.
V_FLG_COL = V_FLG_COL * -1.
V_TABIX = SY-TABIX.
AT NEW MATNR.
READ TABLE IT_FINAL1 INDEX V_TABIX.
WRITE:/ SY-ULINE(238).
WRITE:/ SY-VLINE,
(20) IT_FINAL1-MATNR, SY-VLINE,
(10) IT_FINAL1-WERKS, SY-VLINE,
(30) IT_FINAL1-ZZAMATNR, SY-VLINE,
(30) IT_FINAL1-KWMENG1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_FINAL1-UMREZ1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_FINAL1-KWMENG UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_FINAL1-UMREZ2 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_FINAL1-KWMENG3 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
217(20) IT_FINAL1-MSG, SY-VLINE.
WRITE:/ SY-ULINE(238).
ENDAT.
WRITE:/ SY-VLINE.
IF NOT IT_FINAL1-VBELN IS INITIAL
AND NOT IT_FINAL1-POSNR IS INITIAL.
WRITE: 'Order-'(018),10(12) IT_FINAL1-VBELN,
(10) IT_FINAL1-POSNR.
ENDIF.
WRITE: 217(20) IT_FINAL1-MSG, SY-VLINE.
ENDLOOP. " IT_FINAL1
WRITE:/ SY-ULINE(238).
ENDFORM. " WRITE_AUDIT_REPORT
&----
*& Form TOP_OF_PAGE
&----
Top of page
----
FORM TOP_OF_PAGE.
*-- Armstrong header
CALL FUNCTION 'Z_STD_HEADER'
EXPORTING
PROGNAME = SY-CPROG
LINESIZE = SY-LINSZ
PAGENO = SY-PAGNO
HEADER2 = 'Audit Report'(003).
ENDFORM. " TOP_OF_PAGE
&----
*& Form HEADING_AUDIT_REPORT
&----
Heading for Audit report
----
FORM HEADING_AUDIT_REPORT.
*-- Audit report headings
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE:/ SY-ULINE(238).
WRITE:/ SY-VLINE,
(20) '6'' Material'(007), SY-VLINE,
(10) 'Plant'(008), SY-VLINE,
(30) '12'' Material'(009), SY-VLINE,
(30) 'Curr.12''Material(YD2/ROL)'(010), SY-VLINE,
(30) 'Prev.6'' Material(YD2/ROL)'(011), SY-VLINE,
(20) 'New 6'' Material(ROL)'(012), SY-VLINE,
(30) 'Prev.6'' Material(YD2/RL2)'(013), SY-VLINE,
(20) 'New 6'' Material(RL2)'(014), SY-VLINE,
(20) 'Update Message'(015), SY-VLINE.
FORMAT COLOR OFF.
ENDFORM. " HEADING_AUDIT_REPORT
&----
*& Form GET_SALES_ORDERS
&----
Get sales orders
----
FORM GET_SALES_ORDERS.
*-- Select VAPMA data
SELECT * FROM VAPMA
INTO TABLE IT_VAPMA
FOR ALL ENTRIES IN IT_FINAL
WHERE MATNR = IT_FINAL-MATNR
AND AUART IN S_AUART
AND WERKS = IT_FINAL-WERKS
AND TRVOG = '0'.
IF SY-SUBRC = 0.
*-- Select VBAP data
SELECT VBELN
POSNR
FROM VBAP
INTO TABLE IT_VBAP
FOR ALL ENTRIES IN IT_VAPMA
WHERE VBELN = IT_VAPMA-VBELN
AND POSNR = IT_VAPMA-POSNR
AND VRKME = K_ROL.
IF SY-SUBRC = 0.
*-- Select VBUP data
SELECT VBELN
POSNR
FROM VBUP
INTO TABLE IT_VBUP
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELN = IT_VBAP-VBELN
AND POSNR = IT_VBAP-POSNR
AND GBSTA = 'A'.
ENDIF. " VBAP
SORT IT_VBUP BY VBELN POSNR.
*-- Get final sales orders and materials
CLEAR V_TABIX2.
LOOP AT IT_VAPMA.
V_TABIX2 = SY-TABIX.
READ TABLE IT_VBUP WITH KEY VBELN = IT_VAPMA-VBELN
POSNR = IT_VAPMA-POSNR
BINARY SEARCH.
IF SY-SUBRC <> 0.
DELETE IT_VAPMA INDEX V_TABIX2.
ENDIF.
ENDLOOP. " IT_VAPMA
SORT IT_VAPMA BY MATNR.
SORT IT_FINAL BY MATNR.
*-- Get VBELN and POSNR into IT_FINAL1 table
CLEAR IT_FINAL.
LOOP AT IT_FINAL.
READ TABLE IT_VAPMA WITH KEY MATNR = IT_FINAL-MATNR
BINARY SEARCH.
IF SY-SUBRC = 0.
CLEAR IT_VAPMA.
LOOP AT IT_VAPMA WHERE MATNR = IT_FINAL-MATNR.
IT_FINAL1-MATNR = IT_FINAL-MATNR.
IT_FINAL1-WERKS = IT_FINAL-WERKS.
IT_FINAL1-ZZAMATNR = IT_FINAL-ZZAMATNR.
IT_FINAL1-KWMENG1 = IT_FINAL-KWMENG1.
IT_FINAL1-KWMENG2 = IT_FINAL-KWMENG2.
IT_FINAL1-KWMENG3 = IT_FINAL-KWMENG3.
IT_FINAL1-KWMENG = IT_FINAL-KWMENG.
IT_FINAL1-UMREZ1 = IT_FINAL-UMREZ1.
IT_FINAL1-UMREZ2 = IT_FINAL-UMREZ2.
IT_FINAL1-VBELN = IT_VAPMA-VBELN.
IT_FINAL1-POSNR = IT_VAPMA-POSNR.
APPEND IT_FINAL1.
CLEAR IT_FINAL1.
ENDLOOP. " IT_VAMPA
ELSE.
IT_FINAL1-MATNR = IT_FINAL-MATNR.
IT_FINAL1-WERKS = IT_FINAL-WERKS.
IT_FINAL1-ZZAMATNR = IT_FINAL-ZZAMATNR.
IT_FINAL1-KWMENG1 = IT_FINAL-KWMENG1.
IT_FINAL1-KWMENG2 = IT_FINAL-KWMENG2.
IT_FINAL1-KWMENG3 = IT_FINAL-KWMENG3.
IT_FINAL1-KWMENG = IT_FINAL-KWMENG.
IT_FINAL1-UMREZ1 = IT_FINAL-UMREZ1.
IT_FINAL1-UMREZ2 = IT_FINAL-UMREZ2.
APPEND IT_FINAL1.
CLEAR IT_FINAL1.
ENDIF.
ENDLOOP. " IT_FINAL
SORT IT_FINAL1 BY MATNR.
ENDIF. " VAPMA
ENDFORM. " GET_SALES_ORDERS
&----
*& Form CALL_MM02_VA02
&----
Update materials and sales orders
----
FORM CALL_MM02_VA02.
REFRESH: IT_REPORT.
CLEAR: IT_REPORT,
V_DOC_UP.
LOOP AT IT_FINAL1.
V_TABIX1 = SY-TABIX.
AT NEW MATNR.
READ TABLE IT_FINAL1 INDEX V_TABIX1.
*-- Build BDCTAB for MM02 transaction
PERFORM BUILD_BDCTAB.
*-- Call transaction MM02
CALL TRANSACTION K_MM02
USING IT_BDCDATA
MODE 'A' "K_N
UPDATE K_S.
IF SY-SUBRC = 0.
V_DOC_UP = K_X.
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
CLEAR IT_REPORT-MSG.
APPEND IT_REPORT.
CLEAR IT_REPORT.
ELSE.
CLEAR V_DOC_UP.
*-- If call transaction fails populate BDC SESSION
PERFORM SAVE_MM02_BDC_SESSION.
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
IT_REPORT-MSG = 'Failed'(019).
APPEND IT_REPORT.
CLEAR IT_REPORT.
ENDIF. " MM02
ENDAT. " MATNR
IF V_DOC_UP = K_X.
IF NOT IT_FINAL1-VBELN IS INITIAL
AND NOT IT_FINAL1-POSNR IS INITIAL.
*-- Build BDCDATA for VA02 transaction
PERFORM BUILD_BDCDATA_VA02.
*-- Call VA02 transaction
CALL TRANSACTION 'VA02'
USING IT_BDCDATA
MODE K_N
UPDATE K_S.
IF SY-SUBRC <> 0.
*-- Populate Error table with the message
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
IT_REPORT-VBELN = IT_FINAL1-VBELN.
IT_REPORT-POSNR = IT_FINAL1-POSNR.
IT_REPORT-MSG = 'Failed'(019).
APPEND IT_REPORT.
CLEAR IT_REPORT.
*-- Save session for error records
PERFORM SAVE_BDC_SESSION_VA02.
*-- If call transaction is success
ELSE.
*-- Populate success table
IT_REPORT-MATNR = IT_FINAL1-MATNR.
IT_REPORT-WERKS = IT_FINAL1-WERKS.
IT_REPORT-ZZAMATNR = IT_FINAL1-ZZAMATNR.
IT_REPORT-KWMENG1 = IT_FINAL1-KWMENG1.
IT_REPORT-KWMENG2 = IT_FINAL1-KWMENG2.
IT_REPORT-KWMENG3 = IT_FINAL1-KWMENG3.
IT_REPORT-KWMENG = IT_FINAL1-KWMENG.
IT_REPORT-UMREZ1 = IT_FINAL1-UMREZ1.
IT_REPORT-UMREZ2 = IT_FINAL1-UMREZ2.
IT_REPORT-VBELN = IT_FINAL1-VBELN.
IT_REPORT-POSNR = IT_FINAL1-POSNR.
CLEAR IT_REPORT-MSG.
APPEND IT_REPORT.
CLEAR IT_REPORT.
ENDIF. " VA02
ENDIF. " IT_FINAL1-VBELN POSNR NOT INITIAL
ENDIF. " V_DOC_UP = K_X
ENDLOOP. " IT_FINAL1
*-- Close BDC_GROUP
IF V_BDC_OPEN = K_Y.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE I100 WITH 'Error closing BDC Group'(017).
ENDIF.
V_BDC_OPEN = K_N.
ENDIF. " V_BDC_OPEN
ENDFORM. " CALL_MM02_VA02
&----
*& Form WRITE_FINAL_AUDIT_REPORT
&----
Final audit report
----
FORM WRITE_FINAL_AUDIT_REPORT.
*-- Get final data into FINAL table
FORMAT RESET.
FORMAT COLOR COL_NORMAL.
CLEAR V_TABIX.
*-- Audit report
LOOP AT IT_REPORT.
V_TABIX = SY-TABIX.
*-- Color Intensification
IF V_FLG_COL = 1.
FORMAT INTENSIFIED ON.
ELSE.
FORMAT INTENSIFIED OFF.
ENDIF.
V_FLG_COL = V_FLG_COL * -1.
AT NEW MATNR.
READ TABLE IT_REPORT INDEX V_TABIX.
WRITE:/ SY-ULINE(238).
WRITE:/ SY-VLINE,
(20) IT_REPORT-MATNR, SY-VLINE,
(10) IT_REPORT-WERKS, SY-VLINE,
(30) IT_REPORT-ZZAMATNR, SY-VLINE,
(30) IT_REPORT-KWMENG1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_REPORT-UMREZ1 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_REPORT-KWMENG UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(30) IT_REPORT-UMREZ2 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
(20) IT_REPORT-KWMENG3 UNIT SPACE LEFT-JUSTIFIED, SY-VLINE,
217(20) IT_REPORT-MSG, SY-VLINE.
WRITE:/ SY-ULINE(238).
ENDAT.
WRITE:/ SY-VLINE.
IF NOT IT_REPORT-VBELN IS INITIAL
AND NOT IT_REPORT-POSNR IS INITIAL.
WRITE: 'Order-'(018),10(12) IT_REPORT-VBELN,
(10) IT_REPORT-POSNR.
ENDIF.
WRITE: 217(20) IT_REPORT-MSG, SY-VLINE.
ENDLOOP. " IT_REPORT
WRITE:/ SY-ULINE(238).
ENDFORM. " WRITE_FINAL_AUDIT_REPORT
[/code]
Thanks,
GSK
2006 Aug 24 3:36 PM
Hi Srini,
when you are reading the data from the application file
OPEN DATASET v_file FOR INPUT MESSAGE msg
IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
append msg to it_msg.
ENDIF.
and when you call transaction say
CALL TRANSACTION 'VA01' USING BDCDATA MODE 'N'
MESSAGES INTO it_msg.
it_msg will have all the required messages
Regards,
Vidya
2006 Aug 24 3:43 PM
hi,
You can use
OPEN DATASET dsn FOR INPUT MESSAGE msg
IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET file INTO line.
IF sy-subrc <> 0.
APPEND MSG TO IT_MSG_TABLE.
EXIT.
ENDIF.
WRITE: / line.
ENDDO.
CLOSE DATASET dsn.
this will get all the messages in msg. This will get the messages while opening the file.
To handle the msg while calling the transaction just add.
CALL TRANSACTION 'SE38' USING BDCDATA MODE 'N'
<b>MESSAGES INTO ITAB</b>.
You can later loop at this table and get the messages.
loop at it_msg_table.
*format the message by using FM FORMAT_MESSAGE
endloop.
Regards,
Richa
2006 Aug 24 4:06 PM
Srini,
Wasn't my code usefull.
Look at the logic in the FORM CALL_MM02_VA02.
Thanks,
GSK
2006 Aug 25 2:54 AM
Hi G.S.k,
i haven't checked it yesterday.
here is my code for your preview. i am not able to locate mistake. can u check for me once.
thanks
report zgl0080 "FI DOCUMENT POSTING INTERFACE
no standard page heading
line-size 160. "120.
*----
-
Program Name : ZGL0080
Program Title : FI DOCUMENT POSTING INTERFACE
Release : ecc 5.0
Module : FI
*
Description : This program will read the data (given in the
required format) either from the frontend or from
the server and will post the FI document using
that data.
*
Authority Check : Auhority Check for Reading the Input Data File on
the Server is done.
Note : Ensure the 'Do not copy tax code' option in the Editing option
is marked.
I N C L U D E P R O G R A M S *
************************************************************************
include zglp001.
include rsbdcil3.
data: v_vbund(6) type c.
Copy from RSBDC_PROTOCOL
data: begin of bdclm occurs 0.
include structure bdclm.
data: counter type i,
longtext type bdc_mpar,
end of bdclm.
data: save_mpar type bdc_mpar.
data:
digits(10) type c value '0123456789',
mtext(124) type c, "Messagetext
mtext1(124) type c, "Messagetext
mtext2(273) type c, "Messagetext
do_condense type c,
mtvaroff type i,
parcnt type i,
mparcnt type i,
x(1) type c value 'X'.
*
data: "Aufbereitung Messagetext
begin of mttab occurs 4,
off(02) type n,
len(02) type n,
text(80),
end of mttab.
*
data:begin of par,
len(02) type n,
text(254),
end of par.
*
field-symbols: .
End of Copy from RSBDC_PROTOCOL
************************************************************************
TYPE GROUPS *
************************************************************************
type-pools: slis,
sabc.
************************************************************************
T A B L E S *
************************************************************************
tables: bbkpf, "Doc Header for Accntng Document (Batch Input Structure)
bbseg, "Accounting Document Segment (Batch Input Structure)
bwith, "Document-withholding tax info (batch input structure)
bbtax, "Document Taxes (Batch Input Structure)
ztif_file,"Interface Data Filenames
t100, "Messages
t003,"Document Types
t041c, "Reasons for Reverse Posting
t007a,"Tax Keys
t036,"Planning levels
t880, "trading partner
ztifpr, "interface files that are processed
t856, "consolidation transaction types
tka02."Controlling area assignment
************************************************************************
S E L E C T I O N S C R E E N *
************************************************************************
selection-screen begin of block b1 with frame title text-105."Parameters
PC Filename
selection-screen begin of line.
parameters: p_rpfile radiobutton group rgp default 'X'.
selection-screen comment 6(40) text-p01 for field p_rpfile.
selection-screen position 47.
parameters: p_pfile like rlgrap-filename
default 'c: emp ipost.txt'.
selection-screen end of line.
PC File format in tab delimited format
selection-screen begin of line.
selection-screen position 3.
parameters: p_pctab radiobutton group rgp2 default 'X'.
selection-screen comment 5(20) text-p10 for field p_pctab.
PC File format in comma delimited format (csv)
selection-screen position 27.
parameters: p_pccsv radiobutton group rgp2.
selection-screen comment 29(20) text-p18 for field p_pccsv.
PC File format in fixed length format
selection-screen position 51.
parameters: p_pcfix radiobutton group rgp2.
selection-screen comment 53(20) text-p11 for field p_pcfix.
selection-screen end of line.
selection-screen skip.
Read from interface directory <NFS>
selection-screen begin of line.
parameters:p_rnfile radiobutton group rgp. "File on the Server
selection-screen comment 5(40) text-p19 for field p_rnfile.
*selection-screen position 47.
*parameters: p_nffile type c length 98 lower case
default '/usr/sap/XXX/int/XXX/in'.
selection-screen end of line.
Interface file in Directory
selection-screen begin of line.
selection-screen comment 3(43) text-p20.
selection-screen position 47.
parameters: p_nffile type c length 90 lower case
default 'leave blank!!!'.
default '/usr/sap/CRD/interface/FMS/'.
default '/sapdata/interface/as400/'.
selection-screen end of line.
selection-screen skip.
Server Filename
selection-screen begin of line.
parameters:p_rsfile radiobutton group rgp. "File on the Server
**parameters:p_rsfile(1) type c no-display.
selection-screen comment 5(40) text-p02 for field p_rsfile.
selection-screen position 47.
parameters: p_sfile type c length 98 lower case
default 'fipost.txt'.
default 'fipost.txt' no-display.
selection-screen end of line.
Server File Input Directory
selection-screen begin of line.
selection-screen comment 3(40) text-p03.
selection-screen position 47.
parameters: p_sdir type c length 40 lower case"OBLIGATORY
default '/usr/sap/SYSID/interface/xxx/in/'.
default '/usr/sap/CRD/interface/FMS/'.
default '/sapdata/interface/as400/'.
selection-screen end of line.
Server File Output Directory
selection-screen begin of line.
selection-screen comment 3(40) text-p04.
selection-screen position 47.
parameters: p_sdiro type c length 40 lower case"OBLIGATORY
default '/usr/sap/SYSID/interface/xxx/out/'.
default '/sapdata/interface/as400/'.
selection-screen end of line.
Name of Batch input session
selection-screen begin of line.
selection-screen comment 3(40) text-p13.
selection-screen position 47.
parameters: p_group(9) default 'FIPOST' obligatory.
selection-screen end of line.
remove trading partner value if GL account is NOT found in table ZTGL003
selection-screen skip.
parameters: p_tdpr as checkbox default 'X'.
Keep Server File after processed
*selection-screen begin of line.
*selection-screen position 3.
parameters: p_keep as checkbox default 'X'.
parameters: p_keep default ' ' no-display.
*selection-screen comment 6(40) text-p09 for field p_keep.
*selection-screen end of line.
selection-screen skip.
Daily Files from table
selection-screen begin of line.
parameters: p_rdfile radiobutton group rgp.
parameters: p_rdfile no-display.
selection-screen comment 3(40) text-p05 for field p_rdfile.
selection-screen end of line.
selection-screen skip.
selection-screen skip.
Weekly Files from table
selection-screen comment 3(40) text-p06.
selection-screen begin of line.
parameters: p_rw1f radiobutton group rgp.
parameters: p_rw1f no-display.
selection-screen comment 5(10) text-pw1 for field p_rw1f.
selection-screen position 17.
parameters: p_rw2f radiobutton group rgp.
parameters: p_rw2f no-display.
selection-screen comment 19(10) text-pw2 for field p_rw2f.
selection-screen position 31.
parameters: p_rw3f radiobutton group rgp.
parameters: p_rw3f no-display.
selection-screen comment 33(10) text-pw3 for field p_rw3f.
selection-screen position 45.
parameters: p_rw4f radiobutton group rgp.
parameters: p_rw4f no-display.
selection-screen comment 47(10) text-pw4 for field p_rw4f.
selection-screen position 59.
parameters: p_rw5f radiobutton group rgp.
parameters: p_rw5f no-display.
selection-screen comment 61(10) text-pw5 for field p_rw5f.
selection-screen end of line.
selection-screen begin of line.
parameters: p_rw6f radiobutton group rgp.
parameters: p_rw6f no-display.
selection-screen comment 5(10) text-pw6 for field p_rw6f.
selection-screen position 17.
parameters: p_rw7f radiobutton group rgp.
parameters: p_rw7f no-display.
selection-screen comment 19(10) text-pw7 for field p_rw7f.
selection-screen end of line.
selection-screen skip.
selection-screen skip.
Monthly Files from table
selection-screen comment 3(40) text-p07.
selection-screen begin of line.
parameters: p_rm1f radiobutton group rgp.
parameters: p_rm1f no-display.
selection-screen comment 5(15) text-pm1 for field p_rm1f.
selection-screen position 21.
parameters: p_rm4f radiobutton group rgp.
parameters: p_rm4f no-display.
selection-screen comment 23(15) text-pm4 for field p_rm4f.
selection-screen end of line.
selection-screen skip.
Yearly Files from table
selection-screen begin of line.
parameters: p_ryfile radiobutton group rgp.
parameters: p_ryfile no-display.
selection-screen comment 3(40) text-p08 for field p_ryfile.
selection-screen end of line.
Single Files from table
selection-screen begin of line.
parameters: p_rafile radiobutton group rgp.
parameters: p_rafile no-display.
selection-screen comment 3(40) text-p12 for field p_rafile.
selection-screen position 47.
parameters: p_fileno like ztif_file-fileno.
parameters: p_fileno no-display.
matchcode object zsh_if_file.
selection-screen end of line.
selection-screen end of block b1.
Batch Input Parameters
selection-screen begin of block b2 with frame title text-119.
selection-screen begin of line.
selection-screen comment 1(40) text-p15. "Data Transfer Mode
selection-screen end of line.
Posting via batch mode
selection-screen begin of line.
parameters: p_rmodeb radiobutton group rgp3 default 'X'.
selection-screen comment 3(25) text-p16 for field p_rmodeb.
Direct posting
selection-screen position 29.
parameters: p_rmodec radiobutton group rgp3.
selection-screen comment 31(25) text-p17 for field p_rmodec.
selection-screen end of line.
parameters: p_mode like ctu_params-dismode default 'N'.
selection-screen skip.
parameters: p_test as checkbox default 'X'. "Test Run
selection-screen end of block b2.
************************************************************************
D A T A D E C L A R A T I O N *
************************************************************************
constants: c_fb01 like bbkpf-tcode value 'FB01',
c_fbv1 like bbkpf-tcode value 'FBV1',
c_fbb1 like bbkpf-tcode value 'FBB1',
c_fbs1 like bbkpf-tcode value 'FBS1'.
constants: c_daily value 'D',
c_weekly value 'W',
c_monthly value 'M',
c_yearly value 'Y',
c_filelength type i value 128,
no_data value '/', "no data character
c_server_tmp_path type string
value '/usr/sap/interface/tmp/',
c_error value 'E',
c_success value 'S'.
data: c_server_tmp_path type string
value '/usr/sap/CRD/interface/fms/out/'.
data: t_rawfile(1000) occurs 0 with header line,
t_errfile(1000) occurs 0 with header line.
data: begin of g_file_hdr_rec,
stype type bbkpf-stype,"Batch Input Interface Record Type
tcode type bbkpf-tcode,"Transaction Code
bldat type bbkpf-bldat,"Document Date (batch input)
blart type bbkpf-blart,"Document type
bukrs type bbkpf-bukrs,"Company Code
budat type bbkpf-budat,"Posting Date (batch input)
waers type bbkpf-waers,"Currency Key
kursf type bbkpf-kursf,"Exchange Rate Direct Quotation
xblnr type bbkpf-xblnr,"Reference Document Number
bktxt type bbkpf-bktxt,"Document Header Text
vbund type bbkpf-vbund,"Company ID of Trading Partner
stodt type bbkpf-stodt,"Reversal Posting Date (batch input)
stgrd type bbkpf-stgrd,"Reason for Reversal
end of g_file_hdr_rec.
data: begin of g_file_item_rec,
stype type bbseg-stype,"Batch Input Interface Record Type
newbs type bbseg-newbs,"Posting Key for the Next Line Item
newko type bbseg-newko,"Account or Matchcode for Next Line Item
wrbtr type bbseg-wrbtr,"Amount in document currency
dmbtr type bbseg-dmbtr,"Amount in local currency
fwbas type bbseg-fwbas, "Tax Base Amount in Document Currency
hwbas type bbseg-hwbas, "Tax Base Amount in Local Currency
mwskz type bbseg-mwskz,"Tax on Sales/Purchases Code
zuonr type bbseg-zuonr,"Assignment number
sgtxt type bbseg-sgtxt,"Item Text
fdlev type bbseg-fdlev,"Planning level
zfbdt type bbseg-zfbdt,"Baseline Date
zterm type bbseg-zterm,"Terms of payment key
zlsch type bbseg-zlsch,"Payment Method
zlspr type bbseg-zlspr,"Payment Block Key
qsskz_i type bbseg-qsskz,"Withholding Tax Code for Invoice
qsskz_p type bbseg-qsskz,"Withholding Tax Code for Payment
kostl type bbseg-kostl,"Cost Center
aufnr type bbseg-aufnr,"Order Number
prctr type bbseg-prctr,"Profit Center
vbund type bbseg-vbund,"Company ID of Trading Partner
newum like bbseg-newum, "Spl G/L Indicator for Next Line Item
newbw like bbseg-newbw, "asset transaction type
gsber like bbseg-gsber, "business area
hbkid like bbseg-hbkid, "house bank
for extended withholding tax at invoice
witht_i like bwith-witht, "withhold tax type
wt_qsshb_i like bwith-wt_qsshb, "withhold tax base amt in Doc Curry
wt_qsshh_i like bwith-wt_qsshh, "withhold tax base amt in Loc Curry
wt_qbuihb_i like bwith-wt_qbuihb, "withholding tax amt in Doc Curry
wt_qbuihh_i like bwith-wt_qbuihh, "withholding tax amt in Loc Curry
for extended withholding tax at payment
witht_p like bwith-witht, "withhold tax type
wt_qsshb_p like bwith-wt_qsshb, "withhold tax base amt in Doc Curry
wt_qsshh_p like bwith-wt_qsshh, "withhold tax base amt in Loc Curry
wt_qbuihb_p like bwith-wt_qbuihb, "withholding tax amt in Doc Curry
wt_qbuihh_p like bwith-wt_qbuihh, "withholding tax amt in Loc Curry
valut like bbseg-valut, "value date
bewar like bbseg-bewar, "consolidation transaction type
end of g_file_item_rec.
data: begin of t_doc_hdr occurs 1,
file_row_no type i,
runno(10).
include structure g_file_hdr_rec.
data: hwaer like bkpf-hwaer.
data: end of t_doc_hdr.
data: begin of t_doc_item occurs 1,
file_row_no type i,
runno(10),
item_no type i.
include structure g_file_item_rec.
data: rke_prctr like bbseg-rke_prctr,
katyp like cskb-katyp,
end of t_doc_item.
data: t_bidoc_hdr like t_doc_hdr occurs 1 with header line,
t_bidoc_item like t_doc_item occurs 1 with header line.
data: t_errdoc_hdr like t_doc_hdr occurs 1 with header line,
t_errdoc_item like t_doc_item occurs 1 with header line.
data: t_datafile type string occurs 1 with header line.
data: t_abaplist like abaplist occurs 0 with header line,
t_asciilist like solisti1 occurs 0 with header line.
data: g_server_file like ibipparms-path,
g_server_tmp_file like ibipparms-path,
g_server_prc_file like ibipparms-path,
g_server_err_file like ibipparms-path.
data: g_doc_hdr_err,
g_doc_item_err,
g_doc_hdr_read_cnt type i,
g_doc_item_read_cnt type i,
g_total_rec_read_cnt type i.
data: g_doc_check type i,
g_doc_posted type i,
g_doc_error type i.
data: g_title2 like sy-title.
data: g_session_name like bgr00-group,
g_bdc_prog_name like sy-repid value 'RFBIBL01'.
data: g_start_time like sy-uzeit,
g_end_time like sy-uzeit.
data: g_prog_call_mode.
data: g_job_error. "To indicate overall job is success
data: gztifpr type ztifpr,
g_housekeep_stat(1) type c.
data: subrc_file like sy-subrc,
i_listfile LIKE BTCXPM OCCURS 0 WITH HEADER LINE.
data: fname LIKE RLGRAP-FILENAME.
constants: cmd_listfile LIKE SXPGCOLIST-NAME VALUE 'ZLIST_FILE',
opt_listfile LIKE SXPGCOLIST-PARAMETERS VALUE '$file'.
ranges: r_tcode for bbkpf-tcode.
************************************************************************
A T S E L E C T I O N - S C R E E N *
************************************************************************
*checking for the blank entry in the file name field
at selection-screen.
if p_rpfile = 'X' and p_rsfile = 'X'. "this occurs during submit program again
clear p_rpfile. "hence has to reset p_rpfile as this is default to X.
elseif p_rnfile = 'X' and p_rsfile = 'X'.
clear p_rnfile.
endif.
if p_rpfile = 'X'.
if p_pfile is initial.
message e398(00) with 'Enter PC filename'.
endif.
else.
if p_sfile is initial.
message e398(00) with 'Enter Server filename'.
endif.
if p_sdir is initial.
message e398(00) with 'Enter Server input directory'.
endif.
if p_rafile = 'X' and p_fileno is initial.
message e398(00) with 'Enter file no in table'.
endif.
endif.
*getting the value of the frontend filename field
at selection-screen on value-request for p_pfile.
call function 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_pfile.
at selection-screen on value-request for p_fileno.
perform f4_help_on_p_fileno.
************************************************************************
TOP-OF-PAGE *
************************************************************************
top-of-page.
perform page_header using t_doc_hdr-bukrs sy-title g_title2.
************************************************************************
S T A R T O F D A T A S E L E C T I O N *
************************************************************************
start-of-selection.
if p_test is initial.
g_title2 = '(Actual run)'.
else.
g_title2 = '(Test run)'.
endif.
g_job_error = 'N'.
concatenate '/usr/sap/' sy-sysid '/interface/temp/' into c_server_tmp_path.
perform write_start_message_log.
if p_rnfile = 'X'. "read from interface directory
perform submit_files_fr_interface_dir.
perform write_end_message_log.
concatenate p_group 'Overview' into p_sfile
separated by space.
perform send_mail_to_user.
stop.
endif.
if p_rdfile = 'X' or
p_rw1f = 'X' or p_rw2f = 'X' or p_rw3f = 'X' or p_rw4f = 'X' or
p_rw5f = 'X' or p_rw6f = 'X' or p_rw7f = 'X' or
p_rm1f = 'X' or p_rm4f = 'X' or p_ryfile = 'X' .
perform submit_multiple_files.
perform write_end_message_log.
stop.
endif.
if p_rpfile = 'X' and sy-batch = 'X'.
write: at /3 'PC file cannot be uploaded using background mode'.
perform stop_processing.
elseif p_rpfile = 'X'.
perform read_pc_file.
elseif p_rsfile = 'X'.
perform read_server_file.
elseif p_rafile = 'X'.
perform read_single_job_file.
endif.
perform validate_file_data.
clear g_housekeep_stat.
if p_test is initial and g_job_error = 'N'.
perform post_data.
endif.
if p_test is initial and g_job_error <> 'N'.
perform file_housekeep.
endif.
perform write_end_message_log.
perform send_mail_to_user.
end-of-selection.
************************************************************************
S U B - R O U T I N E S *
***********************************************************************
*&----
*
*& Form get_internal_format
*&----
*
Convert number fields to prefix with '0'
*----
*
form get_internal_format changing p_runno type c."LIKE itab_head-runno.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_runno
IMPORTING
output = p_runno.
endform. " get_internal_format
*&----
*
*& Form build_data_file
*&----
*
Prepare internal table to format into structure for FI posting
*----
*
form build_data_file.
data: t_bgr00 like bgr00.
data: begin of t_bbkpf occurs 0,
runno(10).
include structure bbkpf.
data: end of t_bbkpf.
data: begin of t_bbseg occurs 0,
runno(10).
include structure bbseg.
data: end of t_bbseg.
data: begin of t_bwith occurs 0,
runno(10).
include structure bwith.
data: end of t_bwith.
data: begin of t_bbtax occurs 0,
runno(10).
include structure bbtax.
data: end of t_bbtax.
data: s_bbkpf like dfies occurs 0 with header line.
data: s_bbseg like dfies occurs 0 with header line.
data: s_bbtax like dfies occurs 0 with header line.
data: s_bwith like dfies occurs 0 with header line.
data: itab_lfbw like lfbw occurs 0 with header line.
data: ind_itab like sy-tabix.
data: fname(61),
f_line type i,
l_acctno like bseg-saknr,
l_acct_type like tbsl-koart,
l_saknr like skb1-saknr,
l_ktopl like t001-ktopl.
field-symbols: .
*populate the document item data strcuture
loop at t_bidoc_item where runno = t_bidoc_hdr-runno
and fwbas is initial and hwbas is initial. "syp
move-corresponding t_bidoc_item to bbseg.
If item has trading partner value, remove trading partner value
if GL account is NOT found in ZTGL003
if not t_bidoc_item-vbund is initial and not p_tdpr is initial.
clear: l_acct_type, l_saknr, l_acctno, l_ktopl.
select single koart into l_acct_type
from tbsl
where bschl = t_bidoc_item-newbs.
if l_acct_type = 'S'.
l_saknr = t_bidoc_item-newko.
perform get_internal_format changing l_saknr.
select single ktopl into l_ktopl from t001 where bukrs = t_bidoc_hdr-bukrs.
select single glacc into l_acctno from ZTGL003
where coa = l_ktopl and
( type = 'F' or type = 'Z' )
and glacc = l_saknr.
if sy-subrc <> 0.
remove trading partner value
clear bbseg-vbund.
endif.
endif.
endif.
bbseg-tbnam = 'BBSEG'.
clear: bbseg-fwbas, bbseg-hwbas.
if t_bidoc_hdr-waers = t_bidoc_hdr-hwaer.
clear: bbseg-hwbas.
endif.
perform check_doc_and_local_currency using t_bidoc_hdr-bukrs
t_bidoc_hdr-waers
changing bbseg-dmbtr.
perform conver_date_int_to_ext
changing bbseg-zfbdt.
perform conver_date_int_to_ext
changing bbseg-valut.
perform get_internal_format changing bbseg-newko.
if not bbseg-kostl is initial.
perform get_internal_format changing bbseg-kostl.
endif.
if not bbseg-prctr is initial.
perform get_internal_format changing bbseg-prctr.
endif.
if not bbseg-aufnr is initial.
perform get_internal_format changing bbseg-aufnr.
endif.
*pass company code to the CO-PA structure
if not bbseg-rke_prctr is initial or
not bbseg-rke_wwbsg is initial or
not bbseg-rke_wwspn is initial or
not bbseg-rke_wwprd is initial or
not bbseg-rke_wwchl is initial or
not bbseg-rke_wwcst is initial or
not bbseg-rke_wwtmk is initial or
not bbseg-rke_wwexc is initial.
if t_bidoc_item-katyp = '11'.
bbseg-rke_bukrs = t_bidoc_hdr-bukrs.
endif.
assign bbseg to = '/'.
endif.
endif.
enddo.
t_datafile = bbseg.
append t_datafile.
move-corresponding bbseg to t_bbseg.
t_bbseg-runno = t_bidoc_item-runno.
append: t_bbseg.
clear: t_bbseg, t_datafile,bbseg.
check not ( t_bidoc_item-qsskz_i is initial and
t_bidoc_item-qsskz_p is initial ).
unassign: .
perform get_vendor_wt_tax_info tables itab_lfbw
using t_bidoc_item-newko
t_bidoc_hdr-bukrs.
loop at itab_lfbw where wt_subjct = 'X'.
bwith-stype = t_bidoc_item-stype.
bwith-tbnam = 'BWITH'.
if itab_lfbw-witht = 'IV'.
if itab_lfbw-witht = t_bidoc_item-witht_i.
bwith-witht = t_bidoc_item-witht_i.
bwith-wt_withcd = t_bidoc_item-qsskz_i.
bwith-WT_QSSHB = t_bidoc_item-wt_qsshb_i.
bwith-WT_QBUIHB = t_bidoc_item-wt_qbuihb_i.
if t_bidoc_hdr-waers <> t_bidoc_hdr-hwaer.
bwith-WT_QSSHH = t_bidoc_item-wt_qsshh_i.
bwith-WT_QBUIHH = t_bidoc_item-wt_qbuihh_i.
endif.
elseif itab_lfbw-witht = 'PM'.
elseif itab_lfbw-witht = t_bidoc_item-witht_p.
bwith-witht = t_bidoc_item-witht_p.
bwith-wt_withcd = t_bidoc_item-qsskz_p.
bwith-WT_QSSHB = t_bidoc_item-wt_qsshb_p.
bwith-WT_QBUIHB = t_bidoc_item-wt_qbuihb_p.
if t_bidoc_hdr-waers <> t_bidoc_hdr-hwaer.
bwith-WT_QSSHH = t_bidoc_item-wt_qsshh_p.
bwith-WT_QBUIHH = t_bidoc_item-wt_qbuihh_p.
endif.
else.
that is vendor master has withholding tax type and it does
not exist in the file; need to set to zero.
bwith-witht = itab_lfbw-witht.
bwith-wt_withcd = itab_lfbw-witht.
bwith-WT_QSSHB = 0.
bwith-WT_QBUIHB = 0.
if t_bidoc_hdr-waers .
*populate the tax data structure
loop at t_bidoc_item where runno = t_bidoc_hdr-runno.
if ( not t_bidoc_item-fwbas is initial )
or ( not t_bidoc_item-hwbas is initial ).
bbtax-stype = t_bidoc_item-stype.
bbtax-tbnam = 'BBTAX'.
bbtax-fwste = t_bidoc_item-wrbtr.
bbtax-fwste = bbtax-fwste * 100.
PERFORM get_internal_format CHANGING bbtax-fwste.
bbtax-mwskz = t_bidoc_item-mwskz.
bbtax-bschl = t_bidoc_item-newbs.
bbtax-hwste = t_bidoc_item-dmbtr.
perform check_doc_and_local_currency using t_bidoc_hdr-bukrs
t_bidoc_hdr-waers
changing bbtax-hwste.
assign bbtax to = '/'.
endif.
endif.
enddo.
t_datafile = bbtax. append t_datafile.
move-corresponding bbtax to t_bbtax.
t_bbtax-runno = t_bidoc_item-runno.
append t_bbtax.
clear: t_bbtax,t_datafile, bbtax.
endif.
clear t_bidoc_item.
endloop.
clear: t_bbkpf.
endloop.
endform. " build_data_file
*&----
*
*& Form fill_structure_with_no_data
*&----
*
form fill_structure_with_no_data using p_t_bgr00" structure bgr00
p_no_data.
call function 'FILL_STRUCTURE'
EXPORTING
fill_value = p_no_data
CHANGING
fill_struc = p_t_bgr00.
endform. " fill_structure_with_no_data
*&----
*
*& Form get_table_fields
*&----
*
form get_table_fields tables p_tab_struct structure dfies
using value(p_tabname) like dcobjdef-name.
call function 'RM_TABLE_FIELDS_GET'
exporting
tabname = p_tabname
IMPORTING
GOTSTATE =
tables
c_table_struct = p_tab_struct
C_ERROR_ITAB =
.
endform. " get_table_fields
*&----
*
*& Form transfer_data_file_to_server
*&----
*
form transfer_data_file_to_server.
data: l_msg(60),
l_cnt type i.
CONCATENATE '/sapdata/interface/tmp/' sy-cprog sy-datum
get time.
concatenate c_server_tmp_path sy-cprog '_' sy-datum '_'
sy-uzeit '_' sy-uname into g_server_tmp_file.
open dataset g_server_tmp_file for output in text mode
encoding default message l_msg.
if sy-subrc ne 0.
write: at /3 'Error in writing to temporary file:',
(70) g_server_tmp_file.
write: at /3 'Error message:', l_msg.
perform stop_processing.
else.
write: at /3 'Writing to temporary file:', (70) g_server_tmp_file.
endif.
clear l_cnt.
loop at t_datafile.
transfer t_datafile to g_server_tmp_file.
add 1 to l_cnt.
endloop.
close dataset g_server_tmp_file.
write: at /3 'No. of records written:', (10) l_cnt.
skip.
endform. " transfer_data_file_to_server
*&----
*
*& Form call_update_program
*&----
*
form call_update_program.
call function 'LIST_FREE_MEMORY'
TABLES
listobject = t_abaplist.
submit rfbibl01
with ds_name = g_server_tmp_file
with fl_check = p_test
with callmode = p_mode
with max_comm = '1000'
with pa_xprot = 'X'
with xlog = 'X'
exporting list to memory
and return.
call function 'LIST_FROM_MEMORY'
TABLES
listobject = t_abaplist
EXCEPTIONS
not_found = 1
others = 2.
if sy-subrc = 0.
call function 'LIST_TO_ASCI'
EXPORTING
list_index = -1
TABLES
listasci = t_asciilist
listobject = t_abaplist
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
others = 3.
if sy-subrc = 0.
skip.
write: at /3 'Batch Input Session Log'.
write: at /3 '----
-
'.
loop at t_asciilist.
write: at /3(117) t_asciilist-line.
endloop.
endif.
endif.
skip.
endform. " call_update_program
*&----
*
*& Form conver_date_int_to_ext
*&----
*
form conver_date_int_to_ext changing p_date.
data: f_date1 like sy-datum,
f_date2(10),
f_date3(8),
slen type i,
pos1(2)." TYPE i,
pos2(2)." TYPE i.
f_date1 = p_date.
write f_date1 to f_date2.
slen = strlen( f_date2 ).
do slen times.
pos1 = sy-index - 1.
pos2 = sy-index.
if f_date2+pos1(01) co digits.
concatenate f_date3 f_date2+pos1(01) into f_date3.
endif.
enddo.
p_date = f_date3.
endform. " conver_date_int_to_ext
*&----
*
*& Form check_doc_and_local_currency
*&----
*
form check_doc_and_local_currency using p1_bukrs
p1_waers
changing p1_dmbtr.
data: wa_t001 like t001.
call function 'FI_COMPANY_CODE_DATA'
EXPORTING
i_bukrs = p1_bukrs
IMPORTING
e_t001 = wa_t001
EXCEPTIONS
system_error = 1
others = 2.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
if wa_t001-waers = p1_waers.
clear p1_dmbtr.
endif.
endform. " check_doc_and_local_currency
*&----
*
*& Form get_vendor_wt_tax_info
*&----
*
form get_vendor_wt_tax_info tables p_itab_lfbw structure lfbw
using p_newko
p_bukrs.
data: f_lifnr like lfb1-lifnr.
refresh p_itab_lfbw.
shift p_newko left deleting leading '0'.
f_lifnr = p_newko.
perform get_internal_format changing f_lifnr.
call function 'FI_WT_READ_LFBW'
exporting
i_lifnr = f_lifnr
i_bukrs = p_bukrs
I_TYPE =
tables
t_lfbw = p_itab_lfbw
exceptions
not_found = 1
others = 2
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " get_vendor_wt_tax_info
*&----
*
*& Form validate_file_data
*&----
*
form validate_file_data.
data: begin of l_t001.
include structure t001.
data: kalsm like t007a-kalsm,
end of l_t001.
data: l_pc_bukrs like t001-bukrs.
data: l_saknr like skb1-saknr,
l_lifnr like lfb1-lifnr,
l_kunnr like knb1-kunnr,
l_witht like lfbw-witht,
l_qsskz like lfbw-wt_withcd,
l_acct_type like tbsl-koart,
l_umskz like tbslt-umskz,
l_account like bbseg-newko,
l_asset like anla-anln1,
l_subasset like anla-anln2,
l_sep_anln2(1) type c.
data: l_fwbas like bseg-fwbas,
l_hwbas like bseg-hwbas,
l_amount like bseg-dmbtr.
data: l_wt_qsshb_i like bwith-wt_qsshb,
l_wt_qsshb_p like bwith-wt_qsshb,
l_wt_qsshh_i like bwith-wt_qsshh,
l_wt_qsshh_p like bwith-wt_qsshh,
l_gsber like tgsb-gsber,
l_bwasl like tabw-bwasl,
l_hbkid like bseg-hbkid,
l_vbund like bseg-vbund,
l_shkzg like bseg-shkzg,
l_trtyp like t856-trtyp.
data: lt_lfbw like lfbw occurs 0 with header line.
data: l_subrc like sy-subrc.
data: lt_item like t_doc_item occurs 1 with header line.
data: l_doc_err_cnt type i,
l_doc_ok_cnt type i,
l_item_no type i.
data: begin of l_cost_element,
kstar type cskb-kstar,
katyp type cskb-katyp,
end of l_cost_element.
data: l_debit_docamt like bseg-wrbtr,
l_credit_docamt like bseg-wrbtr,
l_debit_locamt like bseg-dmbtr,
l_credit_locamt like bseg-dmbtr,
e_gjahr like bkpf-gjahr,
e_monat like bkpf-monat,
l_pdate like bkpf-budat,
l_monat like t001b-frpe1,
lchar type string.
define transaction_codes.
r_tcode-sign = 'I'.
r_tcode-option = 'EQ'.
r_tcode-low = &1.
append r_tcode.
end-of-definition.
transaction_codes c_fb01.
transaction_codes c_fbv1.
transaction_codes c_fbb1.
transaction_codes c_fbs1.
write: at /3 'Validating input file.'.
skip.
describe table t_doc_hdr lines g_doc_hdr_read_cnt.
if g_doc_hdr_read_cnt = 0.
write: at /3 'No document header records found.'.
perform stop_processing.
endif.
describe table t_doc_item lines g_doc_item_read_cnt.
if g_doc_item_read_cnt = 0.
write: at /3 'No document item records found.'.
perform stop_processing.
endif.
g_total_rec_read_cnt = g_doc_hdr_read_cnt + g_doc_item_read_cnt.
loop at t_doc_hdr.
clear: g_doc_hdr_err,
g_doc_item_err.
add 1 to g_doc_check.
Check Transaction code
if not t_doc_hdr-tcode in r_tcode.
perform output_doc_hdr_err using
'Invalid transaction code :'
t_doc_hdr-tcode.
endif.
Check document date
perform check_date using t_doc_hdr-bldat
'Y'
'Y'
'Document date'.
Check document type
select single * from t003
where blart = t_doc_hdr-blart.
if not sy-subrc is initial.
perform output_doc_hdr_err using
'Invalid document type :'
t_doc_hdr-blart.
endif.
Check Company Code
if t_doc_hdr-bukrs ne l_t001-bukrs or
l_t001-bukrs is initial.
clear l_t001.
select single * into corresponding fields of l_t001
from t001
where bukrs = t_doc_hdr-bukrs.
if sy-subrc <> 0.
perform output_doc_hdr_err using
'Invalid company code :'
t_doc_hdr-bukrs.
else.
select single kalsm into l_t001-kalsm
from t005
where land1 = l_t001-land1.
select single *
from tka02 into tka02
where bukrs = l_t001-bukrs.
endif.
endif.
t_doc_hdr-hwaer = l_t001-waers.
Check Posting Date
perform check_date using t_doc_hdr-budat
'Y'
'Y'
'Posting date'.
Check Currency key
call function 'READ_TCURC'
EXPORTING
i_waers = t_doc_hdr-waers
EXCEPTIONS
not_found = 1
others = 2.
if sy-subrc <> 0.
perform output_doc_hdr_err using
'Invalid currency :'
t_doc_hdr-waers.
endif.
Check trading partner
if not t_doc_hdr-vbund is initial.
clear l_vbund.
l_vbund = t_doc_hdr-vbund.
perform get_internal_format changing l_vbund.
select single * from t880 where rcomp = l_vbund..
if not sy-subrc is initial.
perform output_doc_hdr_err using
'Trading Partner cannot be entered at header level :'
t_doc_hdr-vbund.
endif.
endif.
Check reversal date
if t_doc_hdr-tcode = 'FBS1'.
reversal date is required
perform check_date using t_doc_hdr-stodt
'Y'
'Y'
'Reversal date'.
else.
perform check_date using t_doc_hdr-stodt
'Y'
'N'
'Reversal date'.
endif.
Check Reversal Reason
if not t_doc_hdr-stgrd = space.
select single *
from t041c
where stgrd = t_doc_hdr-stgrd.
if not sy-subrc is initial.
perform output_doc_hdr_err using
'Invalid Reversal Reason :'
t_doc_hdr-stgrd.
endif.
endif.
Check whether posting period is open
call function 'RP_CHECK_DATE'
EXPORTING
date = t_doc_hdr-budat
EXCEPTIONS
date_invalid = 1
others = 2.
if sy-subrc = 0.
write t_doc_hdr-budat to l_pdate DD/MM/YYYY.
CALL FUNCTION 'FI_PERIOD_DETERMINE'
EXPORTING
i_budat = l_pdate
i_bukrs = t_doc_hdr-bukrs
IMPORTING
e_gjahr = e_gjahr
e_monat = e_monat
EXCEPTIONS
OTHERS = 8.
if sy-subrc = 0.
l_monat = e_monat.
CALL FUNCTION 'FI_PERIOD_CHECK'
EXPORTING I_BUKRS = t_doc_hdr-bukrs
I_GJAHR = e_gjahr
I_KOART = '+'
I_KONTO = '+'
I_MONAT = l_monat
EXCEPTIONS OTHERS = 4.
if not sy-subrc is initial.
perform output_doc_hdr_err using
'Posting period for posting date not open :'
t_doc_hdr-budat.
endif.
endif.
endif.
refresh lt_item.
clear l_item_no.
clear: l_debit_docamt, l_credit_docamt, l_debit_locamt, l_credit_locamt.
Check items
loop at t_doc_item where runno = t_doc_hdr-runno.
add 1 to l_item_no.
t_doc_item-item_no = l_item_no.
Check posting key
clear: l_acct_type, l_shkzg.
select single koart shkzg into (l_acct_type, l_shkzg)
from tbsl
where bschl = t_doc_item-newbs.
if sy-subrc ne 0.
perform output_doc_item_err using
'Invalid posting key:'
t_doc_item-newbs.
endif.
check for invalid characters in amount field.
clear lchar.
lchar = t_doc_item-wrbtr.
if not lchar co '1234567890.'.
perform output_doc_item_err using
'Invalid characer in document amount field:'
t_doc_item-wrbtr.
endif.
clear lchar.
lchar = t_doc_item-dmbtr.
if not lchar co '1234567890.'.
perform output_doc_item_err using
'Invalid characer in local currency amount field:'
t_doc_item-dmbtr.
endif.
sum up total debit and credit for line items in each document
if l_shkzg = 'S'. "debit.
l_debit_docamt = l_debit_docamt + t_doc_item-wrbtr.
l_debit_locamt = l_debit_locamt + t_doc_item-dmbtr.
else.
l_credit_docamt = l_credit_docamt + t_doc_item-wrbtr.
l_credit_locamt = l_credit_locamt + t_doc_item-dmbtr.
endif.
Check special G/L indicator
select single umskz into l_umskz
from tbslt
where spras = sy-langu
and bschl = t_doc_item-newbs
and umskz = t_doc_item-newum.
if sy-subrc ne 0.
perform output_doc_item_err using
'Invalid special G/L indicator:'
t_doc_item-newum.
endif.
Check the account (gl,vendor,customer)
if t_doc_item-newko is initial.
perform output_doc_item_err using
'Enter account'
t_doc_item-newko.
endif.
if not l_t001-bukrs is initial.
if l_acct_type = 'S'.
shift t_doc_item-newko left deleting leading '0'.
l_saknr = t_doc_item-newko.
perform get_internal_format changing l_saknr.
call function 'FI_GL_ACCOUNT_CHECK'
EXPORTING
i_bukrs = l_t001-bukrs
i_saknr = l_saknr
EXCEPTIONS
gl_account_a = 1
gl_account_b = 2
others = 3.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid G/L account :'
t_doc_item-newko.
endif.
elseif l_acct_type = 'K'.
shift t_doc_item-newko left deleting leading '0'.
l_lifnr = t_doc_item-newko.
if l_lifnr(2) <> 'JD'.
perform get_internal_format changing l_lifnr.
call function 'FI_VENDOR_CHECK'
EXPORTING
i_bukrs = t_doc_hdr-bukrs
i_lifnr = l_lifnr
EXCEPTIONS
vendor = 1
others = 2.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid vendor account :'
t_doc_item-newko.
endif.
else.
If vendor number start with JDE, this is old vendor number,
need to lookup LFB1 to search for actual vendor number,
shift l_lifnr left by 2 places.
select lifnr into t_doc_item-newko
from lfb1
where bukrs = t_doc_hdr-bukrs
and altkn = l_lifnr.
exit.
endselect.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid JDE vendor number :'
t_doc_item-newko.
endif.
endif.
clear t_doc_item-prctr.
elseif l_acct_type = 'D'.
shift t_doc_item-newko left deleting leading '0'.
l_kunnr = t_doc_item-newko.
perform get_internal_format changing l_kunnr.
call function 'FI_CUSTOMER_CHECK'
EXPORTING
i_bukrs = t_doc_hdr-bukrs
i_kunnr = l_kunnr
EXCEPTIONS
customer = 1
others = 2.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid customer account :'
t_doc_item-newko.
endif.
clear t_doc_item-prctr.
elseif l_acct_type = 'A'.
shift t_doc_item-newko left deleting leading '0'.
l_account = t_doc_item-newko.
perform get_internal_format changing l_account.
l_sep_anln2 = '-'.
clear: l_asset, l_subasset.
call function 'AM_ASSET_NUMBER_INPUT'
EXPORTING
i_input = l_account
i_separator = l_sep_anln2
IMPORTING
e_anln1 = l_asset
e_anln2 = l_subasset.
call function 'ASSET_EXISTENCE_CHECK'
EXPORTING
i_bukrs = t_doc_hdr-bukrs
i_anln1 = l_asset
i_anln2 = l_subasset
EXCEPTIONS
ANLAGE_DEAKTIV = 1
ANLAGE_GELOESCHT = 2
ANLAGE_NOT_FOUND = 3
ANLAGE_IST_INVM = 4
ANLAGE_GESPERRT = 5
OTHERS = 6.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid asset number :'
t_doc_item-newko.
endif.
else.
perform output_doc_item_err using
'Account type (posting key) not catered for:'
l_acct_type.
endif.
endif.
Check amount in Document currency must ne 0 if tcode ne FBB1
l_amount = t_doc_item-wrbtr.
if l_amount is initial and t_doc_hdr-tcode ne 'FBB1'.
perform output_doc_item_err using
'Enter amount in document currency.'
''.
endif.
Checking Tax code
if t_doc_item-mwskz ne space.
select single * from t007a where kalsm = l_t001-kalsm and
mwskz = t_doc_item-mwskz.
if not sy-subrc is initial.
perform output_doc_item_err using
'Invalid tax code :'
t_doc_item-mwskz.
endif.
endif.
Check tax amount
l_fwbas = t_doc_item-fwbas.
if l_fwbas is initial.
clear t_doc_item-fwbas.
endif.
l_hwbas = t_doc_item-hwbas.
if l_hwbas is initial.
clear t_doc_item-hwbas.
endif.
Checking planning level
if t_doc_item-fdlev ne space.
select single * from t036 where ebene = t_doc_item-fdlev.
if not sy-subrc is initial.
perform output_doc_item_err using
'Invalid planning level :'
t_doc_item-fdlev.
endif.
endif.
Check baseline date
perform check_date using t_doc_item-zfbdt
'N'
'N'
'Baseline date'.
perform check_date using t_doc_item-valut
'N'
'N'
'Value date'.
Check payment method
if t_doc_item-zlsch ne space and
not l_t001-land1 is initial.
call function 'T042Z_SINGLE_READ'
EXPORTING
i_land1 = l_t001-land1
i_zlsch = t_doc_item-zlsch
EXCEPTIONS
not_found = 1
others = 2.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid payment method :'
t_doc_item-zlsch.
endif.
endif.
Check withholding tax code
if not t_doc_item-qsskz_i is initial or
not t_doc_item-qsskz_p is initial.
perform get_vendor_wt_tax_info tables lt_lfbw
using t_doc_item-newko
t_doc_hdr-bukrs.
endif.
if not t_doc_item-qsskz_i is initial.
l_witht = 'IV'.
l_witht = t_doc_item-witht_i.
l_qsskz = t_doc_item-qsskz_i.
elseif not t_doc_item-qsskz_p is initial.
l_witht = 'PM'.
l_witht = t_doc_item-witht_p.
l_qsskz = t_doc_item-qsskz_p.
endif.
if not t_doc_item-qsskz_i is initial or
not t_doc_item-qsskz_p is initial.
l_lifnr = t_doc_item-newko.
perform get_internal_format changing l_lifnr.
read table lt_lfbw with key lifnr = l_lifnr
bukrs = t_doc_hdr-bukrs
witht = l_witht
wt_withcd = l_qsskz.
clear l_lifnr.
if not sy-subrc is initial.
perform output_doc_item_err using
'Invalid withholding tax type/tax code :'
l_qsskz.
endif.
endif.
Check withholding tax base amount
l_wt_qsshb_i = t_doc_item-wt_qsshb_i.
if l_wt_qsshb_i is initial.
clear t_doc_item-wt_qsshb_i.
endif.
l_wt_qsshb_p = t_doc_item-wt_qsshb_p.
if l_wt_qsshb_p is initial.
clear t_doc_item-wt_qsshb_p.
endif.
l_wt_qsshh_i = t_doc_item-wt_qsshh_i.
if l_wt_qsshh_i is initial.
clear t_doc_item-wt_qsshh_i.
endif.
l_wt_qsshh_p = t_doc_item-wt_qsshh_p.
if l_wt_qsshh_p is initial.
clear t_doc_item-wt_qsshh_p.
endif.
Check cost element type
if l_acct_type = 'S'.
if l_saknr ne l_cost_element-kstar.
clear l_cost_element.
select single * into corresponding fields of l_cost_element
from cskb
where kokrs = tka02-kokrs
and kstar = l_saknr
and datbi >= sy-datum.
endif.
else.
clear l_cost_element.
endif.
t_doc_item-katyp = l_cost_element-katyp.
if not l_cost_element is initial.
if l_cost_element-katyp <> '01'.
No cost center required for revenue element <not true for CapitaLand>
cost centre is now required for revenue and expense accounts
clear t_doc_item-kostl.
if l_cost_element-katyp = '11'.
t_doc_item-rke_prctr = t_doc_item-prctr.
endif.
elseif l_cost_element-katyp = '01' and
else.
if t_doc_item-kostl is initial.
perform output_doc_item_err using
'Missing cost center for account'
t_doc_item-newko.
endif.
endif.
else.
clear: t_doc_item-kostl.
endif.
Check cost center
if t_doc_item-kostl ne space.
perform get_internal_format changing t_doc_item-kostl.
call function 'K_COSTCENTER_EXISTENCE_CHECK'
EXPORTING
kokrs = tka02-kokrs
kostl = t_doc_item-kostl
bypassing_buffer = 'X'
EXCEPTIONS
not_at_all = 1
others = 2.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid cost center :'
t_doc_item-kostl.
endif.
endif.
Check internal order
if t_doc_item-aufnr ne space.
perform get_internal_format changing t_doc_item-aufnr.
perform read_order using t_doc_item-aufnr
changing l_subrc.
if l_subrc <> 0.
perform output_doc_item_err using
'Invalid internal order :'
t_doc_item-aufnr.
endif.
endif.
check business area
if not t_doc_item-gsber is initial.
clear l_gsber.
select single gsber into l_gsber from tgsb
where gsber = t_doc_item-gsber.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid business area :'
t_doc_item-gsber.
endif.
endif.
check asset transaction type
if not t_doc_item-newbw is initial.
clear l_bwasl.
select single bwasl into l_bwasl from tabw
where bwasl = t_doc_item-newbw.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid transaction type :'
t_doc_item-newbw.
endif.
endif.
check consolidation transaction type
if not t_doc_item-bewar is initial.
clear l_trtyp.
select single trtyp into l_trtyp from t856
where trtyp = t_doc_item-bewar.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid transaction type :'
t_doc_item-bewar.
endif.
endif.
Check house bank
if not t_doc_item-hbkid is initial.
clear l_hbkid.
select single hbkid into l_hbkid from t012
where bukrs = t_doc_hdr-bukrs
and hbkid = t_doc_item-hbkid.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid house bank :'
t_doc_item-hbkid.
endif.
endif.
Check profit center
if not t_doc_item-prctr is initial.
perform get_internal_format changing t_doc_item-prctr.
select single bukrs into l_pc_bukrs
from cepc_bukrs
where kokrs = tka02-kokrs
and prctr = t_doc_item-prctr.
if sy-subrc <> 0.
perform output_doc_item_err using
'Invalid profit center :'
t_doc_item-prctr.
endif.
endif.
Check trading partner
if not t_doc_item-vbund is initial.
v_vbund = t_doc_item-vbund.
clear l_vbund.
l_vbund = t_doc_item-vbund.
perform get_internal_format changing l_vbund.
if strlen( v_vbund ) = 1.
concatenate '00000' v_vbund into v_vbund.
elseif strlen( v_vbund ) = 2.
concatenate '0000' v_vbund into v_vbund.
elseif strlen( v_vbund ) = 3.
concatenate '000' v_vbund into v_vbund.
elseif strlen( v_vbund ) = 4.
concatenate '00' v_vbund into v_vbund.
elseif strlen( v_vbund ) = 5.
concatenate '0' v_vbund into v_vbund.
endif.
select single * from t880 where rcomp = t_doc_item-vbund.
select single * from t880 where rcomp = l_vbund.
if not sy-subrc is initial.
perform output_doc_item_err using
'Invalid Trading Partner entered at item level :'
t_doc_item-vbund.
endif.
endif.
modify t_doc_item.
append t_doc_item to lt_item.
endloop. "End of check items loop
Check total debit and credit in document is equal
if not ( l_debit_docamt = l_credit_docamt and
l_debit_locamt = l_credit_locamt ).
perform output_doc_hdr_err using
'Total debit amount not equal to total credit amount' ''.
endif.
if g_doc_hdr_err = 'Y' or g_doc_item_err = 'Y'.
add 1 to l_doc_err_cnt.
append t_doc_hdr to t_errdoc_hdr.
append lines of lt_item to t_errdoc_item.
else.
add 1 to l_doc_ok_cnt.
append t_doc_hdr to t_bidoc_hdr.
append lines of lt_item to t_bidoc_item.
endif.
modify t_doc_hdr.
endloop.
skip.
write: at /3 'No. of document headers read :',
(6) g_doc_hdr_read_cnt,
at /3 'No. of document items read :',
(6) g_doc_item_read_cnt,
at /3 'Total no. of records read :',
(6) g_total_rec_read_cnt.
skip.
write: at /3 'No. of documents checked succesfully :',
(6) l_doc_ok_cnt,
at /3 'No. of documents contain errors :',
(6) l_doc_err_cnt.
skip.
endform. " validate_file_data
*&----
*
*& Form check_date
*&----
*
form check_date using p_date
p_hdr
p_required
p_date_name.
data: l_msg1(60),
l_msg2(60).
concatenate 'Enter' p_date_name
into l_msg1 separated by space.
concatenate 'Invalid' p_date_name ':'
into l_msg2 separated by space.
if p_date is initial.
if p_required = 'Y'.
if p_hdr = 'Y'.
perform output_doc_hdr_err using
l_msg1 ''.
else.
perform output_doc_item_err using
l_msg1 ''.
endif.
endif.
else.
call function 'RP_CHECK_DATE'
EXPORTING
date = p_date
EXCEPTIONS
date_invalid = 1
others = 2.
if sy-subrc <> 0.
if p_hdr = 'Y'.
perform output_doc_hdr_err using
l_msg2 ''.
else.
perform output_doc_item_err using
l_msg2 ''.
endif.
endif.
endif.
endform. " check_date
*&----
*
*& Form read_order
*&----
*
form read_order using p1_aufnr
changing p_subrc like sy-subrc.
clear p_subrc.
call function 'K_AUFK_READ'
EXPORTING
i_aufnr = p1_aufnr
EXCEPTIONS
not_found = 1
others = 2.
p_subrc = sy-subrc.
endform. " read_order
*&----
*
*& Form send_mail_to_user
*&----
*
form send_mail_to_user.
data: doc_data like sodocchgi1,
obj_head like solisti1 occurs 0 with header line,
obj_cont like solisti1 occurs 0 with header line,
reclist like somlreci1 occurs 0 with header line,
line_char type i.
data: l_jobinfo like ztif_file,
l_descr_len type i,
l_jobtype(6),
l_jobtext(10),
l_mail_descr(50),
l_job_descr(50),
l_pagno type sy-pagno,
l_linno type sy-linno.
check sy-batch = 'X'.
if p_test is initial.
l_jobtype = 'Actual'.
else.
l_jobtype = 'Test'.
endif.
if g_job_error = 'N'.
l_jobtext = 'success'.
else.
l_jobtext = 'fail'.
endif.
if 'Overview' co p_sfile. "syp
clear l_jobtext.
endif.
clear l_jobinfo.
if not p_fileno is initial.
select single * into l_jobinfo
from ztif_file
where progname = sy-repid
and fileno = p_fileno.
Example of l_mail_descr
Actual run success - FI I/F Job D001 (xxxx)
Test run fail - FI I/F Job D001 (xxxx)
concatenate l_jobtype 'run' l_jobtext '- FI I/F Job'
l_jobinfo-fileno
into l_mail_descr separated by space.
l_descr_len = 50 - strlen( l_mail_descr ) - 3.
if l_descr_len > 30.
l_descr_len = 30.
endif.
if l_descr_len > 0.
l_job_descr = l_jobinfo-filedescr(l_descr_len).
endif.
concatenate '(' l_job_descr ')' into l_job_descr.
concatenate l_mail_descr l_job_descr into l_mail_descr
separated by space.
else.
concatenate l_jobtype 'run' l_jobtext '-'
g_session_name p_sfile
into l_mail_descr separated by space.
endif.
if l_jobinfo-euser1 is initial.
l_jobinfo-euser1 = sy-uname.
endif.
translate l_jobinfo-euser1 to upper case.
if not l_jobinfo-euser2 is initial.
translate l_jobinfo-euser2 to upper case.
endif.
Fill the attributes of the document
doc_data-obj_name = sy-title.
doc_data-obj_descr = l_mail_descr.
doc_data-obj_langu = sy-langu.
doc_data-sensitivty = 'O'.
doc_data-obj_prio = '1'.
doc_data-proc_type = 'T'.
doc_data-proc_name = 'SP01'.
doc_data-skip_scren = 'X'.
*fill the document header data
obj_head = 'FILE NAME AND PATH IN THE SERVER'.
append obj_head.
obj_head = p_filename.
append obj_head.
*fill the document item data
while l_pagno <= sy-pagno.
add 1 to l_pagno.
clear l_linno.
while l_linno <= sy-linno.
add 1 to l_linno.
read line l_linno of page l_pagno.
if sy-subrc = 0.
obj_cont = sy-lisel.
append obj_cont.
else.
exit.
endif.
endwhile.
endwhile.
fill the receiver list
reclist-receiver = l_jobinfo-euser1.
reclist-rec_type = 'B'.
reclist-express = 'X'.
append reclist.
if not l_jobinfo-euser2 is initial.
reclist-receiver = l_jobinfo-euser2.
append reclist.
endif.
if not ( l_jobinfo-euser1 = sy-uname or l_jobinfo-euser2 = sy-uname ).
reclist-receiver = sy-uname.
append reclist.
endif.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = doc_data
document_type = 'RAW'
put_in_outbox = ' '
COMMIT_WORK = ' '
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
object_header = obj_head
object_content = obj_cont
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
receivers = reclist
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8
.
if sy-subrc <> 0.
write: at /3 'Error in sending mail (', (1) sy-subrc, ')'.
endif.
endform. " send_mail_to_user
*&----
*
*& Form file_post_processing
*&----
*
form file_post_processing.
data: l_msg(60),
l_cnt type i,
l_success.
delete dataset g_server_tmp_file.
perform file_housekeep.
check not g_server_prc_file is initial.
open dataset g_server_prc_file for output in text mode
encoding non-unicode message l_msg.
if sy-subrc ne 0.
write: at /3 'Error writing to Processed file:',
(70) g_server_prc_file,
at /3 'Error message:', l_msg.
else.
write: at /3 'Writing to Processed file:',
(70) g_server_prc_file.
clear l_cnt.
loop at t_rawfile.
transfer t_rawfile to g_server_prc_file.
add 1 to l_cnt.
endloop.
write: at /3 'No. of records written:', (10) l_cnt.
close dataset g_server_prc_file.
l_success = 'Y'.
endif.
skip.
if not t_errdoc_hdr[] is initial.
open dataset g_server_err_file for output in text mode
encoding non-unicode message l_msg.
if sy-subrc ne 0.
write: at /3 'Error writing to Error file:',
(70) g_server_err_file,
at /3 'Error message:', l_msg.
else.
write: at /3 'Writing to Error file:',
(70) g_server_err_file.
sort t_errdoc_hdr by file_row_no.
sort t_errdoc_item by file_row_no.
clear l_cnt.
loop at t_errdoc_hdr.
read table t_rawfile index t_errdoc_hdr-file_row_no.
if sy-subrc = 0.
transfer t_rawfile to g_server_err_file.
add 1 to l_cnt.
loop at t_errdoc_item
where runno = t_errdoc_hdr-runno.
read table t_rawfile index t_errdoc_item-file_row_no.
if sy-subrc = 0.
transfer t_rawfile to g_server_err_file.
add 1 to l_cnt.
endif.
endloop.
endif.
endloop.
write: at /3 'No. of records written:', (10) l_cnt.
close dataset g_server_err_file.
endif.
endif.
skip.
if p_keep is initial and
l_success = 'Y' and
t_doc_hdr[] <> t_errdoc_hdr[].
delete dataset g_server_file.
if sy-subrc = 0.
write: at /3 'Original file deleted successfully:',
g_server_file.
endif.
endif.
endform. " file_post_processing
*=======================================================================
form file_housekeep.
data: l_msg(60),
l_cnt type i,
l_success.
check g_housekeep_stat is initial.
check not g_server_prc_file is initial.
open dataset g_server_prc_file for output in text mode
encoding non-unicode message l_msg.
if sy-subrc ne 0.
write: at /3 'Error writing to Processed file:',
g_server_prc_file,
(70) g_server_prc_file,
at /3 'Error message:', l_msg.
else.
write: at /3 'Writing to Processed file:',
g_server_prc_file.
(70) g_server_prc_file.
clear l_cnt.
loop at t_rawfile.
transfer t_rawfile to g_server_prc_file.
add 1 to l_cnt.
endloop.
write: at /3 'No. of records written:', (10) l_cnt.
close dataset g_server_prc_file.
l_success = 'Y'.
endif.
skip.
if not t_errdoc_hdr[] is initial.
open dataset g_server_err_file for output in text mode
encoding non-unicode message l_msg.
if sy-subrc ne 0.
write: at /3 'Error writing to Error file:',
g_server_err_file,
(70) g_server_err_file,
at /3 'Error message:', l_msg.
else.
write: at /3 'Writing to Error file:',
g_server_err_file.
(70) g_server_err_file.
sort t_errdoc_hdr by file_row_no.
sort t_errdoc_item by file_row_no.
clear l_cnt.
loop at t_errdoc_hdr.
read table t_rawfile index t_errdoc_hdr-file_row_no.
if sy-subrc = 0.
transfer t_rawfile to g_server_err_file.
add 1 to l_cnt.
loop at t_errdoc_item
where runno = t_errdoc_hdr-runno.
read table t_rawfile index t_errdoc_item-file_row_no.
if sy-subrc = 0.
transfer t_rawfile to g_server_err_file.
add 1 to l_cnt.
endif.
endloop.
endif.
endloop.
write: at /3 'No. of records written:', (10) l_cnt.
close dataset g_server_err_file.
endif.
endif.
skip.
if p_keep is initial and
l_success = 'Y' and
t_doc_hdr[] <> t_errdoc_hdr[].
delete dataset g_server_file.
if sy-subrc = 0.
write: at /3 'Original file deleted successfully:',
g_server_file.
endif.
endif.
g_housekeep_stat = 'Y'.
endform.
*&----
*
*& Form read_server_file
*&----
*
form read_server_file .
data: l_msg(60).
data: l_line like t_rawfile.
data: l_fname like authb-filename,
l_file_ext like authb-filename.
data: l_file_row_no type i.
if p_sdiro is initial.
p_sdiro = p_sdir.
endif.
split p_sfile at '.' into l_fname l_file_ext.
concatenate p_sdir p_sfile into g_server_file.
concatenate p_sdiro 'prc_' l_fname '_' sy-datum '_' sy-uzeit
into g_server_prc_file.
concatenate p_sdiro 'err_' l_fname '_' sy-datum '_' sy-uzeit
into g_server_err_file.
if not l_file_ext is initial.
concatenate g_server_prc_file '.' l_file_ext into g_server_prc_file.
concatenate g_server_err_file '.' l_file_ext into g_server_err_file.
endif.
open dataset g_server_file for input in text mode
encoding non-unicode message l_msg.
if sy-subrc ne 0.
write: at /3 'Error in reading server file:',
(70) g_server_file.
g_server_file.
write: at /3 'Error message:', (70) l_msg.
perform stop_processing.
else.
write: at /3 'Reading server file:', (70) g_server_file.
write: at /3 'Reading server file:', g_server_file.
endif.
skip.
do.
read dataset g_server_file into l_line.
if not sy-subrc is initial.
exit.
endif.
t_rawfile = l_line.
append t_rawfile.
enddo.
close dataset g_server_file.
perform process_rawfile.
endform. " read_server_file
*&----
*
*& Form output_doc_hdr_err
*&----
*
form output_doc_hdr_err using wp_message
wp_var1.
g_doc_hdr_err = 'Y'.
write: at /3 'Record', (6) t_doc_hdr-file_row_no,
' Document ', t_doc_hdr-runno, 'header :',
wp_message, wp_var1.
g_job_error = 'Y'.
endform. " output_doc_hdr_err
*&----
*
*& Form output_doc_item_err
*&----
*
form output_doc_item_err using wp_message
wp_var1.
g_doc_item_err = 'Y'.
write: at /3 'Record', (6) t_doc_item-file_row_no,
' Document ', t_doc_item-runno, 'item',
(3) t_doc_item-item_no,
':', wp_message, wp_var1.
g_job_error = 'Y'.
endform. " output_doc_item_err
*&----
*
*& Form submit_multiple_files
*&----
*
form submit_multiple_files .
data: lt_file like ztif_file occurs 1 with header line.
data: l_freq like ztif_file-zfreq,
l_freq_txt(30),
l_descr(100).
if p_rdfile = 'X'.
l_freq = 'D'.
l_freq_txt = 'Daily'.
elseif p_rw1f = 'X'.
l_freq = 'W1'.
l_freq_txt = 'Weekly (Monday)'.
elseif p_rw2f = 'X'.
l_freq = 'W2'.
l_freq_txt = 'Weekly (Tuesday)'.
elseif p_rw3f = 'X'.
l_freq = 'W3'.
l_freq_txt = 'Weekly (Wednesday)'.
elseif p_rw4f = 'X'.
l_freq = 'W4'.
l_freq_txt = 'Weekly (Thursday)'.
elseif p_rw5f = 'X'.
l_freq = 'W5'.
l_freq_txt = 'Weekly (Friday)'.
elseif p_rw6f = 'X'.
l_freq = 'W6'.
l_freq_txt = 'Weekly (Saturday)'.
elseif p_rw7f = 'X'.
l_freq = 'W7'.
l_freq_txt = 'Weekly (Sunday)'.
elseif p_rm1f = 'X'.
l_freq = 'M1'.
l_freq_txt = 'Monthly (1st working day)'.
elseif p_rm4f = 'X'.
l_freq = 'M4'.
l_freq_txt = 'Monthly (4th working day)'.
elseif p_ryfile = 'X'.
l_freq = 'Y'.
l_freq_txt = 'Yearly'.
endif.
select * into table lt_file
from ztif_file
where progname = sy-repid
and zfreq = l_freq.
if sy-subrc ne 0.
write: at /3 'No', l_freq_txt, 'file found'.
perform stop_processing.
endif.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at lt_file.
concatenate 'Submitting' l_freq_txt 'job' lt_file-fileno
lt_file-filedescr into l_descr
separated by space.
write: at /3 l_descr.
if sy-repid = 'ZGL0080'.
submit ZGL0080
with p_fileno = lt_file-fileno
with p_tdpr = p_tdpr
with p_keep = p_keep
with p_pccsv = ''
with p_pcfix = 'X'
with p_pctab = ''
with p_pfile = p_pfile
with p_rafile = 'X'
with p_rdfile = ''
with p_rpfile = ''
with p_rsfile = ''
with p_rw1f = ''
with p_rw2f = ''
with p_rw3f = ''
with p_rw4f = ''
with p_rw5f = ''
with p_rw6f = ''
with p_rw7f = ''
with p_rm1f = ''
with p_rm4f = ''
with p_ryfile = ''
with p_sdir = p_sdir
with p_sdiro = p_sdiro
with p_sfile = p_sfile
with p_test = p_test
and return.
else.
submit ZGL0080_v2
with p_fileno = lt_file-fileno
with p_tdpr = p_tdpr
with p_keep = p_keep
with p_pccsv = ''
with p_pcfix = 'X'
with p_pctab = ''
with p_pfile = p_pfile
with p_rafile = 'X'
with p_rdfile = ''
with p_rmfile = ''
with p_rpfile = ''
with p_rsfile = ''
with p_rw1f = ''
with p_rw2f = ''
with p_rw3f = ''
with p_rw4f = ''
with p_rw5f = ''
with p_rw6f = ''
with p_rw7f = ''
with p_rm1f = ''
with p_rm4f = ''
with p_ryfile = ''
with p_sdir = p_sdir
with p_sdiro = p_sdiro
with p_sfile = p_sfile
with p_test = p_test
and return.
endif.
endloop.
endform. " submit_multiple_files
*&----
*
*& Form post_data
*&----
*
form post_data .
check p_test is initial.
perform get_session_name.
perform build_data_file.
perform transfer_data_file_to_server.
if p_rmodec = 'X' and sy-batch is initial.
perform post_data_direct.
else.
perform post_data_batch.
endif.
perform file_post_processing.
endform. " post_data
*&----
*
*& Form read_pc_file
*&----
*
form read_pc_file .
data: l_pc_filename type string.
data: l_message like bapiret2-message.
l_pc_filename = p_pfile.
call function 'GUI_UPLOAD'
EXPORTING
filename = l_pc_filename
filetype = 'ASC'
has_field_separator = ' '
TABLES
data_tab = t_rawfile
EXCEPTIONS
file_open_error = 1
file_read_error = 2
others = 17.
if sy-subrc <> 0.
write: at /3 'Error uploading file:', (70) p_pfile.
perform stop_processing.
else.
write: at /3 'Reading PC file:', (70) p_pfile.
if t_rawfile[] is initial.
write: at /3 'No records found'.
perform stop_processing.
elseif p_pcfix = 'X'.
perform process_rawfile.
else.
perform process_delimited_file.
endif.
endif.
skip.
endform. " read_pc_file
*&----
*
*& Form process_rawfile
*&----
*
form process_rawfile .
data: l_file_row_no type i,
l_line like t_rawfile,
l_runno type i,
l_str(1000) type c.
loop at t_rawfile.
l_line = t_rawfile.
add 1 to l_file_row_no.
if l_line(1) = '1'.
l_runno = l_runno + 1.
g_file_hdr_rec = l_line.
clear t_doc_hdr.
move-corresponding g_file_hdr_rec to t_doc_hdr.
t_doc_hdr-runno = l_runno.
t_doc_hdr-file_row_no = l_file_row_no.
perform get_internal_format changing t_doc_hdr-runno.
t_doc_hdr-runno(01) = 'D'.
append t_doc_hdr.
elseif l_line(1) = '2'.
clear g_file_item_rec.
g_file_item_rec = l_line.
move-corresponding g_file_item_rec to t_doc_item.
t_doc_item-runno = t_doc_hdr-runno.
t_doc_item-file_row_no = l_file_row_no.
append t_doc_item.
else.
l_str = l_line.
condense l_str.
if not l_str is initial.
l_str = l_line.
write: at /3 'Unknown record type found:',
(70) l_str(1).
write: at /3 'Error record is: ',
(70) l_str.
write: at /3 'Read # as space in error record'.
perform stop_processing.
endif.
endif.
endloop.
endform. " process_rawfile
*&----
*
*& Form process_delimited_file
*&----
*
form process_delimited_file.
data: t_line(50) occurs 0 with header line.
data: l_file_row_no type i,
l_line like t_rawfile,
l_runno type i.
data: l_delimiter,
l_str(1000) type c.
if p_pccsv = 'X'.
l_delimiter = ','.
else.
l_delimiter = cl_abap_char_utilities=>horizontal_tab.
endif.
loop at t_rawfile.
add 1 to l_file_row_no.
clear t_line.
refresh t_line.
if t_rawfile(1) = '1'.
l_runno = l_runno + 1.
clear t_doc_hdr.
split t_rawfile at l_delimiter into t_doc_hdr-stype
t_doc_hdr-tcode
t_doc_hdr-bldat
t_doc_hdr-blart
t_doc_hdr-bukrs
t_doc_hdr-budat
t_doc_hdr-waers
t_doc_hdr-kursf
t_doc_hdr-xblnr
t_doc_hdr-bktxt
t_doc_hdr-vbund
t_doc_hdr-stodt
t_doc_hdr-stgrd.
if t_doc_hdr-tcode <> 'FBS1'.
clear: t_doc_hdr-stodt, t_doc_hdr-stgrd.
endif.
t_doc_hdr-runno = l_runno.
perform get_internal_format changing t_doc_hdr-runno.
t_doc_hdr-runno(1) = 'D'.
append t_doc_hdr.
elseif t_rawfile(1) = '2'.
clear t_doc_item.
split t_rawfile at l_delimiter
into t_doc_item-stype
t_doc_item-newbs
t_doc_item-newko
t_doc_item-wrbtr
t_doc_item-dmbtr
t_doc_item-fwbas
t_doc_item-hwbas
t_doc_item-mwskz
t_doc_item-zuonr
t_doc_item-sgtxt
t_doc_item-fdlev
t_doc_item-zfbdt
t_doc_item-zterm
t_doc_item-zlsch
t_doc_item-zlspr
t_doc_item-qsskz_i
t_doc_item-qsskz_p
t_doc_item-kostl
t_doc_item-aufnr
t_doc_item-prctr
t_doc_item-vbund
t_doc_item-newum "Spl G/L Indicator
t_doc_item-newbw
t_doc_item-gsber
t_doc_item-hbkid
t_doc_item-witht_i
t_doc_item-wt_qsshb_i
t_doc_item-wt_qsshh_i
t_doc_item-wt_qbuihb_i
t_doc_item-wt_qbuihh_i
t_doc_item-witht_p
t_doc_item-wt_qsshb_p
t_doc_item-wt_qsshh_p
t_doc_item-wt_qbuihb_p
t_doc_item-wt_qbuihh_p
t_doc_item-valut
t_doc_item-bewar.
t_doc_item-runno = l_runno.
perform get_internal_format changing t_doc_item-runno.
t_doc_item-runno(1) = 'D'.
append t_doc_item.
else.
l_str = t_rawfile.
condense l_str.
if not l_str is initial.
l_str = t_rawfile.
write:/ l_str.
replace all occurrences of '#' in :
l_str with SPACE in character mode.
write:/ sy-subrc.
write:/ l_str.
write: at /3 'Unknown record type found:',
(70) l_str(1).
write: at /3 'Error record is: ',
(70) l_str.
write: at /3 'Read # as space in error record'.
perform stop_processing.
endif.
endif.
endloop.
endform. " process_delimited_file
*&----
*
*& Form stop_processing.
*&----
*
form stop_processing.
skip.
write: at /3 'Program is stopped due to errors encountered!'.
perform write_end_message_log.
g_job_error = 'Y'.
perform send_mail_to_user.
stop.
endform. " stop_processing
*&----
*
*& Form write_start_message_log
*&----
*
form write_start_message_log.
skip.
write: / '----
-
',
/ '| M e s s a g e L o g |' color col_positive,
/ '----
-
'.
endform. " write_start_message_log
*&----
*
*& Form write_end_message_log
*&----
*
form write_end_message_log.
skip.
write: / '----
-
',
/ '| E n d o f M e s s a g e L o g |'
color col_positive,
/ '----
-
'.
skip.
endform. " write_end_message_log
*&----
*
*& Form read_single_job_file
*&----
*
form read_single_job_file .
data: l_file like ztif_file,
l_job_descr(100).
select single * into l_file
from ztif_file
where progname = sy-repid
and fileno = p_fileno.
if sy-subrc ne 0.
write: at /3 'File no', p_fileno, 'is not found in ZTIF_FILE'.
perform stop_processing.
endif.
if l_file-zfreq = 'D'.
concatenate 'Daily job' l_file-fileno '(' l_file-filedescr ')'
into l_job_descr separated by space.
elseif l_file-zfreq(1) = 'W'.
concatenate 'Weekly job' l_file-fileno '(' l_file-filedescr ')'
into l_job_descr separated by space.
elseif l_file-zfreq(1) = 'M'.
concatenate 'Monthly job' l_file-fileno '(' l_file-filedescr ')'
into l_job_descr separated by space.
elseif l_file-zfreq = 'Y'.
concatenate 'Yearly job' l_file-fileno '(' l_file-filedescr ')'
into l_job_descr separated by space.
else.
concatenate 'Job' l_file-fileno '(' l_file-filedescr ')'
into l_job_descr separated by space.
endif.
write: at /3(100) l_job_descr.
p_sfile = l_file-filename.
perform read_server_file.
endform. " read_single_job_file
*&----
*
*& Form post_data_direct
*&----
*
form post_data_direct .
call function 'LIST_FREE_MEMORY'
TABLES
listobject = t_abaplist.
submit rfbibl01
with ds_name = g_server_tmp_file
with fl_check = p_test
with callmode = 'C'
with anz_mode = p_mode
with max_comm = '1000'
with pa_xprot = 'X'
with xlog = 'X'
exporting list to memory
and return.
call function 'LIST_FROM_MEMORY'
TABLES
listobject = t_abaplist
EXCEPTIONS
not_found = 1
others = 2.
if sy-subrc = 0.
call function 'LIST_TO_ASCI'
EXPORTING
list_index = -1
TABLES
listasci = t_asciilist
listobject = t_abaplist
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
others = 3.
if sy-subrc = 0.
skip.
write: at /3 'Batch Input Session Log'.
write: at /3 '----
-
'.
loop at t_asciilist.
write: at /3(117) t_asciilist-line.
if t_asciilist-line(5) = 'FB007'.
FB007 - Session 1 session name xxx was opened
This message appears only if there is error in batch session
g_job_error = 'Y'.
endif.
endloop.
endif.
endif.
skip.
endform. " post_data_direct
*&----
*
*& Form post_data_batch
*&----
*
form post_data_batch .
call function 'LIST_FREE_MEMORY'
TABLES
listobject = t_abaplist.
get time.
g_start_time = sy-uzeit.
submit rfbibl01
with ds_name = g_server_tmp_file
with fl_check = p_test
with callmode = 'B'
with max_comm = '1000'
with pa_xprot = 'X'
with xlog = 'X'
exporting list to memory
and return.
get time.
g_end_time = sy-uzeit.
perform release_batch_session.
endform. " post_data_batch
*&----
*
*& Form get_session_name
*&----
*
form get_session_name .
data: l_group like apqi-groupid,
l_runno type i,
l_runno_txt(2),
l_pos type i.
if not p_fileno is initial.
Example : FIIF-D001
Session name will be FIIF-D001-NN
concatenate 'FIIF-' p_fileno into p_group.
endif.
concatenate p_group '-%' into l_group.
l_runno = 1.
select groupid
from apqi
into l_group
where datatyp = 'BDC'
and mandant = sy-mandt
and groupid like l_group
and progid = g_bdc_prog_name
and creator = sy-uname
and credate = sy-datum
order by groupid descending.
exit.
endselect.
if sy-subrc = 0.
l_pos = strlen( l_group ) - 2.
if l_group+l_pos(2) co digits.
l_runno = l_group+l_pos(2).
add 1 to l_runno.
endif.
endif.
l_runno_txt = l_runno.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_runno_txt
IMPORTING
output = l_runno_txt.
concatenate p_group '-' l_runno_txt into g_session_name.
endform. " get_session_name
*&----
*
*& Form release_batch_session
*&----
*
form release_batch_session .
data: l_apqi like apqi,
l_apql like apql,
l_jobname like tbtcjob-jobname,
l_jobno like tbtcjob-jobcount,
l_jobhead like tbtcjob,
l_bdclm type bdclm.
data: begin of lt_log occurs 50, " plain log information in TemSe
enterdate like btctle-enterdate,
entertime like btctle-entertime,
logmessage(366) type c,
end of lt_log.
data: begin of lt_job occurs 1,
jobno like tbtcjob-jobcount,
qid like apqi-qid,
end of lt_job.
data: l_job_stime like sy-uzeit,
l_time_now like sy-uzeit,
l_one_day like sy-uzeit value '235959',
l_diff_in_mins type i.
write: at /3 'Releasing batch input session'.
select * into l_apqi
from apqi
where datatyp = 'BDC'
and mandant = sy-mandt
and groupid = g_session_name
and progid = g_bdc_prog_name
and userid = sy-uname
and creator = sy-uname
and credate = sy-datum.
and cretime >= g_start_time.
and cretime <= g_end_time.
exit.
endselect.
if sy-subrc ne 0.
write: at /3 'No batch input session found for release'.
perform stop_processing.
endif.
call function 'LIST_FREE_MEMORY'
TABLES
listobject = t_abaplist.
refresh: t_abaplist, t_asciilist.
submit rsbdcsub
with mappe = g_session_name
with von = sy-datum "Date from
with bis = sy-datum "Date to
with z_verarb = 'X'
with fehler = ''
with logall = ''
exporting list to memory
and return.
call function 'LIST_FROM_MEMORY'
TABLES
listobject = t_abaplist
EXCEPTIONS
not_found = 1
others = 2.
if sy-subrc = 0.
call function 'LIST_TO_ASCI'
EXPORTING
list_index = -1
TABLES
listasci = t_asciilist
listobject = t_abaplist
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
others = 3.
endif.
loop at t_asciilist.
lt_job-jobno = t_asciilist-line+45(8).
if lt_job-jobno co digits.
lt_job-qid = t_asciilist-line+62(20).
append lt_job.
endif.
endloop.
get time.
l_job_stime = sy-uzeit.
l_jobname = g_session_name.
loop at lt_job.
l_jobno = lt_job-jobno.
do.
clear l_jobhead.
call function 'BP_JOB_READ'
EXPORTING
job_read_jobcount = l_jobno
job_read_jobname = l_jobname
job_read_opcode = 20 "All job data
IMPORTING
job_read_jobhead = l_jobhead
EXCEPTIONS
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 3
others = 4.
if sy-subrc ne 0.
write: at /3 'Error reading job for batch input session'.
exit.
endif.
if l_jobhead-status = 'A' or l_jobhead-status = 'F'.
exit.
else.
get time.
l_time_now = sy-uzeit.
if l_time_now >= l_job_stime.
l_diff_in_mins = ( l_job_stime - l_time_now ) / 60.
else.
l_diff_in_mins = ( l_job_stime + l_one_day - l_time_now )
/ 60.
endif.
if l_diff_in_mins >= 120.
This is to avoid endless loop in checking job
To stop checking after 2 hrs.
write: at /3 'Time exceeded 2 hrs in checking job status.'.
perform stop_processing.
endif.
endif.
enddo.
select * into l_apql
from apql
where qid = lt_job-qid.
exit.
endselect.
if sy-subrc ne 0.
write: at /3 'Cannot find batch input session log'.
perform stop_processing.
endif.
select * into l_apqi
from apqi
where datatyp = 'BDC'
and mandant = sy-mandt
and groupid = g_session_name
and progid = g_bdc_prog_name
and userid = sy-uname
and creator = sy-uname
and qid = lt_job-qid.
if l_apqi-qstate = 'E'.
g_job_error = 'Y'.
endif.
exit.
endselect.
perform read_bdc_log_plain tables lt_log
using l_apql-temseid
l_apql-mandant.
clear bdclm. refresh bdclm.
loop at lt_log.
l_bdclm = lt_log.
clear bdclm.
bdclm = l_bdclm.
append bdclm.
endloop.
endloop.
write: at /3 'BDC Log for', g_session_name, ':'.
perform extend_message_texts.
endform. " release_batch_session
*----
*
Form: extend_message_texts
Copy from RSBDC_PROTOCOL *
*----
*
form extend_message_texts.
data: l_line(117).
clear l_line with '-'.
skip.
write: at /3(115) l_line.
write: at /3 '|' no-gap, (08) 'Time' color col_heading,
'|' no-gap, (90) 'Message' color col_heading,
'|' no-gap, (01) 'T' color col_heading,
'|' no-gap, (02) 'ID' color col_heading,
'|' no-gap, (03) 'MNo' color col_heading,
'|' no-gap.
write: at /3(115) l_line.
format color off.
loop at bdclm.
LM = BDCLM.
save_mpar = bdclm-mpar.
perform get_text.
bdclm-longtext = mtext.
bdclm-mpar = save_mpar.
modify bdclm.
write: at /3 '|' no-gap, (08) bdclm-intime,
'|' no-gap, (90) bdclm-longtext,
'|' no-gap, (01) bdclm-mart,
'|' no-gap, (02) bdclm-mid,
'|' no-gap, (03) bdclm-mnr,
'|' no-gap.
endloop.
write: at /3(115) l_line.
skip.
endform. "extend_message_texts
*----
*
FORM : get_text *
Copy from RSBDC_PROTOCOL *
*----
*
form get_text.
*
Aufbereiten des Messagetextes
*
data: shiftln type i,
vartcnt type i,
fdpos like sy-fdpos.
if bdclm-mparcnt cn digits. "Korrupter Datensatz:
bdclm-mparcnt = 0. "z.B. Hexnullen
endif.
select single * from t100
where sprsl = sy-langu
and arbgb = bdclm-mid
and msgnr = bdclm-mnr.
*
if sy-subrc eq 0.
clear: mtext,
parcnt,
mparcnt,
sy-fdpos.
*
move bdclm-mparcnt to mparcnt.
*
if t100-text ca '$&'. "Kennung fuer parameter:
move t100-text to mtext1. " alt '$' --- neu '&'
else.
move t100-text to mtext.
exit.
endif.
variable teile aus batch-input protokoll in mttab bringen.
refresh mttab.
clear shiftln.
do mparcnt times.
clear: par, mttab.
move bdclm-mpar to par.
if par-len cn digits or par-len eq 0. "convert_no_number
par-len = 1. "entschärfen
endif.
write par-text to mttab-text(par-len).
move par-len to mttab-len.
move mparcnt to mttab-off.
append mttab.
shiftln = par-len + 2.
shift bdclm-mpar by shiftln places.
enddo.
*
mtext2 = mtext1.
if bdclm-mid eq '00' and " sonderbehandlung s00368
bdclm-mnr eq '368' and
bdclm-mart eq 'S'.
clear mtext2.
clear mttab.
read table mttab index 1.
write mttab-text to mtext2+0(mttab-len).
clear mttab.
read table mttab index 2.
write mttab-text to mtext2+35(mttab-len).
mtext = mtext2.
exit.
endif.
do_condense = x.
clear: vartcnt, mtvaroff.
while vartcnt le 3.
vartcnt = vartcnt + 1.
if mtext1 ca '$&'.
parcnt = parcnt + 1.
if sy-fdpos gt 0.
fdpos = sy-fdpos - 1. " neu sy簷fdpos -1
else.
fdpos = sy-fdpos.
endif.
shift mtext1 by sy-fdpos places.
if mtext1(1) eq '&'.
shift mtext1 by 1 places.
case mtext1(1).
when ' '. "'& '
perform replace_var using '& ' parcnt fdpos.
when '$'. "'&&'
perform replace_var using '&&' 0 fdpos.
when '1'. "'&1'
perform replace_var using '&1' 1 fdpos.
when '2'. "'&2'
perform replace_var using '&2' 2 fdpos.
when '3'. "'&3'
perform replace_var using '&3' 3 fdpos.
when '4'. "'&4'
perform replace_var using '&4' 4 fdpos.
when others. "'&'
perform replace_var using '&<' parcnt fdpos.
endcase.
endif.
if mtext1(1) eq '$'.
shift mtext1 by 1 places.
case mtext1(1).
when ' '. "'$ '
perform replace_var using '$ ' parcnt fdpos.
when '$'. "'$$'
perform replace_var using '$$' 0 fdpos.
when '1'. "'$1'
perform replace_var using '$1' 1 fdpos.
when '2'. "'$2'
perform replace_var using '$2' 2 fdpos.
when '3'. "'$3'
perform replace_var using '$3' 3 fdpos.
when '4'. "'$4'
perform replace_var using '$4' 4 fdpos.
when others. "'$'
perform replace_var using '$<' parcnt fdpos.
endcase.
endif.
endif.
endwhile.
*
if mtext2 ca '%%_D_%%'.
replace '%%_D_%%' with '$' into mtext2.
endif.
if mtext2 ca '%%_A_%%'.
replace '%%_A_%%' with '&' into mtext2.
endif.
if do_condense eq space.
mtext = mtext2.
else.
condense mtext2 .
mtext = mtext2.
endif.
else.
mtext = '???????????????????????????????????????????????????'.
endif.
*
endform. " get_text
*----
*
FORM : replace_var *
Copy from RSBDC_PROTOCOL *
*----
*
form replace_var using vark
vari type i
varpos.
*
ersetzen der variablen teile einer fehlermeldung
*
data: var(02),
var1,
moff type i.
*
clear: mttab , moff.
var = vark.
shift var by 1 places.
case var.
when ' '. "'& '
read table mttab index vari.
if sy-subrc eq 0.
moff = varpos + mtvaroff. "neu
assign mtext2+moff(*) to . "neu
mtvaroff = 7. "neu
endif.
endif.
*
endcase.
*
do_condense = space.
*
endform. "replace_var
*&----
*
*& Form f4_help_on_p_fileno
*&----
*
form f4_help_on_p_fileno .
data: begin of it_fields occurs 1.
include structure help_value.
data: end of it_fields.
data: begin of it_values occurs 1,
text like ztif_file-filename,
end of it_values.
data: l_file like ztif_file.
data: l_fileno like ztif_file-fileno.
refresh: it_fields, it_values.
it_fields-tabname = 'ZTIF_FILE'.
it_fields-fieldname = 'FILENO'.
it_fields-selectflag = 'X'.
append it_fields.
clear it_fields-selectflag.
it_fields-fieldname = 'ZFREQ'.
append it_fields.
it_fields-fieldname = 'FILEDESCR'.
append it_fields.
it_fields-fieldname = 'FILENAME'.
append it_fields.
it_fields-fieldname = 'EUSER1'.
append it_fields.
it_fields-fieldname = 'EUSER2'.
append it_fields.
select * into l_file
from ztif_file
where progname = sy-repid.
it_values-text = l_file-fileno.
append it_values.
it_values-text = l_file-zfreq.
append it_values.
it_values-text = l_file-filedescr.
append it_values.
it_values-text = l_file-filename.
append it_values.
it_values-text = l_file-euser1.
append it_values.
it_values-text = l_file-euser2.
append it_values.
endselect.
call function 'HELP_VALUES_GET_WITH_TABLE'
IMPORTING
select_value = l_fileno
TABLES
fields = it_fields
valuetab = it_values.
if not l_fileno is initial.
p_fileno = l_fileno.
endif.
endform. " f4_help_on_p_fileno
*&----
*
*& Form
*&----
*
FORM GET_FILE_FR_UNIX CHANGING SUBRC.
DATA : STR LIKE SXPGCOLIST-PARAMETERS,
lstat like EXTCMDEXEX-STATUS,
lexitcode like EXTCMDEXEX-EXITCODE.
STR = opt_listfile.
REPLACE '$file' WITH FNAME INTO STR.
str = p_sdir.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
COMMANDNAME = cmd_listfile
ADDITIONAL_PARAMETERS = STR
IMPORTING
STATUS = lstat
EXITCODE = lexitcode
TABLES
EXEC_PROTOCOL = i_listfile
EXCEPTIONS
NO_PERMISSION = 1
COMMAND_NOT_FOUND = 2
PARAMETERS_TOO_LONG = 3
SECURITY_RISK = 4
WRONG_CHECK_CALL_INTERFACE = 5
PROGRAM_START_ERROR = 6
PROGRAM_TERMINATION_ERROR = 7
X_ERROR = 8
PARAMETER_EXPECTED = 9
TOO_MANY_PARAMETERS = 10
ILLEGAL_COMMAND = 11
WRONG_ASYNCHRONOUS_PARAMETERS = 12
CANT_ENQ_TBTCO_ENTRY = 13
JOBCOUNT_GENERATION_ERROR = 14
OTHERS = 15.
SUBRC = SY-SUBRC.
if subrc is initial.
if lstat = 'E'.
subrc = lexitcode.
endif.
endif.
endform. "GET_FILE_FR_UNIX
*&----
*
*& Form submit_files_fr_interface_dir
*&----
*
form submit_files_fr_interface_dir .
data: lt_file like ztif_file occurs 1 with header line.
data: l_freq like ztif_file-zfreq,
l_freq_txt(30),
l_descr(100),
pri_params like pri_params.
call function 'GET_PRINT_PARAMETERS'
importing OUT_PARAMETERS = pri_params.
perform get_file_fr_unix changing subrc_file.
if not subrc_file is initial.
g_job_error = 'Y'.
write:/ 'Error in reading from interface directory'.
loop at i_listfile.
write:/ i_listfile-message.
endloop.
clear p_sfile.
exit.
perform stop_processing.
endif.
describe table i_listfile.
if sy-tfill is initial.
write: at /3 'No file found in interface directory'.
clear p_sfile.
exit.
perform stop_processing.
endif.
loop at i_listfile.
check whether file has been processed
if p_test is initial and g_job_error = 'N'.
select single * from ztifpr where filename = i_listfile-message.
if sy-subrc = 0.
concatenate 'File' i_listfile-message 'was previously processed. Not processed now!'
into l_descr
separated by space.
write: at /3 l_descr.
continue.
else.
if p_test is initial.
gztifpr-filename = i_listfile-message.
gztifpr-psodt = sy-datum.
insert into ztifpr values gztifpr.
endif.
endif.
endif.
concatenate 'Submitting File' i_listfile-message
into l_descr
separated by space.
write: at /3 l_descr.
p_sfile = i_listfile-message.
if sy-repid = 'ZGL0080'.
submit zgl0080
with p_fileno = ''
with p_tdpr = p_tdpr
with p_keep = p_keep
with p_pccsv = ''
with p_pcfix = 'X'
with p_pctab = ''
with p_pfile = ''
with p_rafile = ''
with p_rdfile = ''
with p_rpfile = ''
with p_rsfile = 'X'
with p_rw1f = ''
with p_rw2f = ''
with p_rw3f = ''
with p_rw4f = ''
with p_rw5f = ''
with p_rw6f = ''
with p_rw7f = ''
with p_rm1f = ''
with p_rm4f = ''
with p_ryfile = ''
with p_group = p_group
with p_sdir = p_sdir
with p_sdiro = p_sdiro
with p_sfile = p_sfile
with p_test = p_test
to sap-spool SPOOL PARAMETERS pri_params WITHOUT SPOOL DYNPRO
and return.
endif.
endloop.
clear p_sfile.
endform.
2006 Aug 25 3:33 AM
Hi Srini,
call function 'BP_JOB_READ'
EXPORTING
job_read_jobcount = l_jobno
job_read_jobname = l_jobname
job_read_opcode = 20 "All job data
IMPORTING
job_read_jobhead = l_jobhead
EXCEPTIONS
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 3
others = 4.
if sy-subrc ne 0.
write: at /3 'Error reading job for batch input session'.
exit.
endif.
if l_jobhead-status = 'A' or l_jobhead-status = 'F'.
exit.
else.
get time.
l_time_now = sy-uzeit.
if l_time_now >= l_job_stime.
l_diff_in_mins = ( l_job_stime - l_time_now ) / 60.
else.
l_diff_in_mins = ( l_job_stime + l_one_day - l_time_now )
/ 60.
endif.
if l_diff_in_mins >= 120.
This is to avoid endless loop in checking job
To stop checking after 2 hrs.
write: at /3 'Time exceeded 2 hrs in checking job status.'.
perform stop_processing.
endif.
endif.
enddo.
Here, include a logic to read the error messages once the job is completed.
The FM BP_JOBLOG_SHOW_SM37B will write messages ( Error/Success/Warning ).
If you want to get all the Messages into an internal table then use FM BP_JOBLOG_READ.
Best regards,
Prashant
2006 Aug 25 4:58 AM
Hello Srini
If your report is running as a job the previously proposed solution is quite straightforward.
If you are starting your report manually and you want to have the messages in a persistent for in the system the you could use the SAP standard log. Function group SBAL contains all the required function modules.
Here is the procedure:
(1) You have to create your own log object and subobject (transaction SLG0). For example, you could have object='Z_FI' and subobject='POSTING'.
(2) At the beginning of your report you create a log using function module BAL_LOG_CREATE. As input you use your object, subobject and an external number (e.g. timestamp or filename would be appropriate).
(3) When you excecute the BDC in your program add the returned messages to your log using function module BAL_LOG_MSG_ADD.
(4) At the end of your report save the log using function module BAL_DB_SAVE (function group SBAL_DB).
That's all. Using transaction SLG1 you can see the logs containing the messages of the FI postings.
Final remark: if you get familiar with the log functionality you could use more advanced features like setting a priority of the messages, display as trees, etc.
Regards
Uwe
2006 Aug 25 5:38 AM
Dear Uwe and Prashanth,
i got what i neededexactly.
thanks a lot for the info Uwe onlog files.
awarded points...
2006 Aug 25 7:53 AM
Hi Srini,
I just logged in. Hope you did it.
Please close the post if your issues has been resolved.
Thanks,
GSK
2006 Aug 25 8:19 AM
hi G.S.K
how to close the post!
i am not able to locate the closing option.
2006 Aug 25 9:23 AM
Hi,
Give max points to a post. That is 10 (or) Click Black color star in a post.
Thanks,
GSK