Skip to Content
0
Former Member
May 19, 2008 at 10:20 AM

help urgent

194 Views

HI ALL,

I WANT TO KNOW THE INPUT FILE STRUCTURE FOR THE BELOW PROGRAM.

ITS TRUELY URGENT.

*--Constant

CONSTANTS : c_maint(1) value 'M'.

*data from the Excel is picked up into this internal table

DATA : BEGIN OF ITAB OCCURS 0,

FIELD1(200),

FIELD2(20),

FIELD3(20),

FIELD4(30),

FIELD5(50),

FIELD6(50),

FIELD7(50),

FIELD8(50),

FIELD9(50),

FIELD10(50),

END OF ITAB.

Data:

MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,

E_GROUP_OPENED,

P_BDCNM LIKE APQI-GROUPID VALUE 'TRA_ORD_ERRORS'.

*--Header information for sales order is stored in this table

DATA : BEGIN OF IVBAK,

auart like vbak-auart, "Order type

VBELN LIKE VBAK-VBELN, "Sales Order number

VKORG LIKE VBAK-VKORG, "Sales Organisation

VTWEG LIKE VBAK-VTWEG, "Distribution channel 10

SPART LIKE VBAK-SPART, "Division 10

SOLD_TO LIKE KNA1-KUNNR, "Sold to party

SHIP_CONT LIKE KNA1-NAME2, "SHIP to contact

SHIP_TO LIKE KNA1-KUNNR, "Ship to party

INSTALL_TO LIKE KNA1-KUNNR, "Install to party

BILL_TO LIKE KNA1-KUNNR, "Bill to Party

BILL_CONT LIKE KNA1-NAME2, "Bill to contact

payer like KNA1-kunnr, "Payer

SUBMI LIKE VBAK-SUBMI, "Collective number for RFQs

ZTERM LIKE VBKD-ZTERM, "Payment terms

BSTNK LIKE VBAK-BSTNK, "Purchase order number

AUDAT(10), "Booking date

bstdk(10), "PO Date

SA LIKE KNA1-KUNNR, "Sales rep

CE LIKE KNA1-KUNNR,

SR LIKE KNA1-KUNNR,

waerk like VBAK-WAERK,

belnr like bkpf-belnr, "FI Document

desc(1),

END OF IVBAK.

*---Item level data is stored in this table

DATA : BEGIN OF IVBAP OCCURS 0,

POSNR LIKE VBAP-POSNR, "Item number in spread sheet

MATNR LIKE VBAP-MATNR, "Material number

ZMENG(14) TYPE C , "Quantity

VENDAT LIKE VEDA-VENDDAT, "Cycle end date

MWERT1 LIKE RCTMS-MWERT, "Relase number

KBETR(15) TYPE C, "AMount

WBS(24) TYPE C, "WBS element

text(1) type c,

END OF IVBAP.

*--Use for call function to display message

DATA BEGIN OF MSG OCCURS 0.

INCLUDE STRUCTURE FIMSG.

DATA END OF MSG.

*--bdc table

DATA : BEGIN OF BDC_TAB OCCURS 0.

INCLUDE STRUCTURE BDCDATA .

DATA : END OF BDC_TAB.

*--Capture the errors in the transaction

DATA : BEGIN OF ERR_MSG OCCURS 100 .

INCLUDE STRUCTURE BDCMSGCOLL .

DATA : END OF ERR_MSG.

DATA: BEGIN OF SUBSTRINGS OCCURS 10,

LINE(72) TYPE C,

END OF SUBSTRINGS.

  • Table for splitting incoming line texts into multiple 72 char length

  • strings to be inserted in line long text field.

DATA: BEGIN OF line_texts OCCURS 10,

line_no type i,

seq_no type i,

text(72) TYPE C,

END OF line_texts.

*--Function key Exclude table

DATA : BEGIN OF PFKEY OCCURS 2,

FCODE(4),

END OF PFKEY.

*--BDC loop field declaration

DATA : MATERIAL(13) VALUE 'VBAP-MATNR( )',

QUANTITY(15) VALUE 'RV45A-KWMENG( )',

Item_cat(13) VALUE 'VBAP-PSTYV( )',

SELECTION(29) VALUE 'RV45A-VBAP_SELKZ( )',

BILL_DATE(13) VALUE 'FPLT-AFDAT( )',

BILL_QTY(13) VALUE 'FPLT-FAKWR( )',

COUNTE(1) TYPE N,

INDEX(1) TYPE N.

data tab_idx type i.

*--Flag and temerary variables

data: ERRORS, "Error message

V_VBELN LIKE VBAK-VBELN. "Document number hold

data: line_no type i.

data: seq_no type i.

data: txt_fld(2040) type c.

*--File name

SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.

  • Sales Org

parameters: p_vkorg like vbak-vkorg obligatory.

*--File name

PARAMETERS : P_FILENM LIKE IBIPPARMS-PATH

DEFAULT 'C:\MY document\FAM2.TXT' obligatory.

SELECTION-SCREEN END OF BLOCK BK1.

*--File name display

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILENM.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

FILE_NAME = P_FILENM

EXCEPTIONS

OTHERS = 1.

*--User command

AT USER-COMMAND.

*--Display the documents when there is no error in updating sales order

*--Variable is set after the call transaction

IF ERRORS = ' '.

*--Variable V_vbeln is set after the sales order updated from the error

*--Message table depending on the error message number

SET PARAMETER ID 'AUN' FIELD V_VBELN.

CASE SY-UCOMM.

WHEN 'DISP'.

*--Display sales order

PERFORM DISPLAY_SALES_ORDER.

WHEN 'CHAN'.

*--Change the sales order

PERFORM CHANGE_SALES_ORDER.

ENDCASE.

ENDIF.

START-OF-SELECTION.

*--Initialis the messages

CALL FUNCTION 'FI_MESSAGE_INIT'.

*--Perform the Excel file

PERFORM UPLOAD_EXCEL_FILE.

IF ERRORS = 'X'.

message e000 with 'Error while uploading the input file'.

ENDIF.

*--Update the header data from first 3 rows

PERFORM UPDATE_HEADER.

*--update the item data and billing plan.

PERFORM UPDATE_ITEMS.

*----Update bdc table

PERFORM UPDATE_BDC.

*--Call transaction

PERFORM CALL_VA01.

&----


*& Form UPLOAD_EXCEL_FILE

&----


  • Upload the data from excel file

----


FORM UPLOAD_EXCEL_FILE.

data : v_filenm like RLGRAP-FILENAMe.

clear v_filenm.

move p_filenm to v_filenm.

*--uploade the excel file.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = v_FILENM

FILETYPE = 'DAT'

TABLES

DATA_TAB = ITAB

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

OTHERS = 8.

IF SY-SUBRC NE 0.

*--Fill messages

PERFORM FILL_MSG USING 'ZZ' 'E' '920' P_FILENM SPACE SPACE SPACE.

*--Collect it

PERFORM COLLECT_MSG.

ERRORS = 'X'.

ENDIF.

read table itab index 1.

if sy-subrc <> 0 or ( itab-field1 = space and itab-field2 = space and

itab-field3 = space and itab-field4 = space ).

ERRORS = 'X'.

endif.

ENDFORM. " UPLOAD_EXCEL_FILE

----


  • FORM FILL_MSG *

----


  • This subroutine fills data into internal structure, MSG, which *

  • stores relevant error message information. *

----


  • --> MSGNO - Message no. *

  • --> MSGV1 - Message variable 1 *

  • --> MSGV2 - Message variable 2 *

  • --> MSGV3 - Message variable 3 *

  • --> MSGV4 - Message variable 4 *

----


FORM FILL_MSG USING MSGID MSGTY MSGNO MSGV1 MSGV2 MSGV3 MSGV4.

MSG-MSORT = '1'.

MSG-MSGID = MSGID.

MSG-MSGTY = MSGTY.

MSG-MSGNO = MSGNO.

MSG-MSGV1 = MSGV1.

MSG-MSGV2 = MSGV2.

MSG-MSGV3 = MSGV3.

MSG-MSGV4 = MSGV4.

ENDFORM.

----


  • FORM COLLECT_MSG *

----


  • This subroutine logs all errors occur during the execution of *

  • BDC *

----


FORM COLLECT_MSG.

CALL FUNCTION 'FI_MESSAGE_COLLECT'

EXPORTING

I_FIMSG = MSG

EXCEPTIONS

MSGID_MISSING = 1

MSGNO_MISSING = 2

MSGTY_MISSING = 3

OTHERS = 4.

ENDFORM.

&----


*& Form UPDATE_HEADER

&----


  • Update the data at the header level of the sales order

----


FORM UPDATE_HEADER.

*--third line will be the header information

READ TABLE ITAB INDEX 3.

ivbak-auart = 'OR'.

IVBAK-VKORG = p_vkorg.

IVBAK-VTWEG = '10'.

IVBAK-SPART = '10'.

IVBAK-SOLD_TO = ITAB-FIELD4.

IVBAK-INSTALL_TO = ITAB-FIELD4.

read table itab index 5. "Booking date

ivbak-audat = itab-field10.

IF IVBAK-AUDAT = SPACE. "System date if book date = ' '.

write sy-datum to IVBAK-AUDAT.

ENDIF.

read table itab index 7. "PO Number

write itab-field6 to ivbak-bstnk right-justified.

IVBAK-BSTDK = ITAB-FIELD10.

read table itab index 11. "RFQ

IVBAK-SUBMI = ITAB-FIELD6.

read table itab index 9. "Bill to and Sales Rep

IVBAK-BILL_TO = ITAB-FIELD4.

IVBAK-Payer = IVBAK-BILL_TO.

IVBAK-SA = ITAB-FIELD6.

IVBAK-CE = ITAB-FIELD6.

IVBAK-SR = ITAB-FIELD6.

read table itab index 15. "Bill to contact

concatenate itab-field3 itab-field4 into ivbak-bill_cont separated by

space.

read table itab index 16. "Ship to

IVBAK-SHIP_TO = ITAB-FIELD4.

read table itab index 21. "Payment terms

ivbak-zterm = itab-field10.

read table itab index 23.

concatenate itab-field3 itab-field4 into ivbak-ship_cont

separated by space. "Ship to contact

iVBAK-WAERK = itab-field10.

*--Get header text

tab_idx = 26.

READ TABLE ITAB index tab_idx.

line_no = 0.

seq_no = 0.

while itab-field1 ns 'Training Line Item Information'.

concatenate itab-field1 itab-field2 itab-field3

itab-field4 itab-field5 itab-field6 itab-field7

itab-field8 itab-field9 itab-field10

into txt_fld SEPARATED by space.

if txt_fld <> space.

ivbak-desc = 'Y'.

perform parse_text_n using txt_fld.

loop at substrings.

seq_no = seq_no + 1.

line_texts-line_no = line_no.

line_texts-seq_no = seq_no.

line_texts-text = substrings-line.

append line_texts.

endloop.

refresh substrings.

clear txt_fld.

endif.

tab_idx = tab_idx + 1.

read table itab index tab_idx.

endwhile.

ENDFORM. " UPDATE_HEADER

&----


*& Form UPDATE_ITEMS

&----


  • Update the item data into IVBAP and Billing plan bill_plan table

----


FORM UPDATE_ITEMS.

*--The item data start from line 5

Do.

tab_idx = tab_idx + 1.

read table itab index tab_idx.

  • Item line column headings

if ( itab-field1 = space and itab-field2 CS 'Course No.' and

itab-field3 = 'Business Unit' and itab-field4 = 'WBS Element' ) or

( itab-field1 = space and itab-field2 = space and

itab-field3 = space and itab-field4 = space ).

continue.

elseif itab-field1 co '0123456789 ' and itab-field2 <> space and

itab-field4 <> space and itab-field10 co '0123456789.," '.

perform fill_item_data.

elseif itab-field7 <> 'Currency'.

exit. "End of line items.

ENDIF.

ENDDO.

*--Rearrange the internal tables

DELETE IVBAP WHERE ( MATNR = '0' or matnr = ' ' ).

SORT IVBAP BY POSNR.

ENDFORM. " UPDATE_ITEMS

&----


*& Form UPDATE_BDC

&----


  • Update the BDC table

----


FORM UPDATE_BDC.

*--Update header information

PERFORM UPDATE_HEADER_INFO.

*--Update item information

PERFORM UPDATE_ITEM_INFO.

*--Save document

PERFORM SAVE_SALES_ORDER.

ENDFORM. " UPDATE_BDC

PERFORM DYNPRO USING :

'X' 'SAPMV45A' '0101', "Initial screen

' ' 'VBAK-AUART' ivbak-auart, "Order type ZVC

' ' 'VBAK-VKORG' IVBAK-VKORG, "Sales organisation

' ' 'VBAK-VTWEG' IVBAK-VTWEG, "Distribution channel

' ' 'VBAK-SPART' IVBAK-SPART, "Division

' ' 'BDC_OKCODE' '=ENT2'.

PERFORM DYNPRO USING:

'X' 'SAPMV45A' '4001', "Overview screen

' ' 'KUAGV-KUNNR' IVBAK-SOLD_TO, "Sold to

' ' 'VBKD-BSTKD' IVBAK-BSTNK, "Purchase order number

' ' 'VBKD-BSTDK' IVBAK-BSTDK, "PO DATE

' ' 'VBKD-ZTERM' IVBAK-ZTERM, "Payment terms

' ' 'BDC_OKCODE' 'KBES'.

PERFORM DYNPRO USING:

'X' 'SAPMV45A' '4002', "Header business data

' ' 'VBAK-SUBMI' IVBAK-SUBMI, "RFQ#

' ' 'BDC_SUBSCR' 'SAPMV45A',

' ' 'BDC_OKCODE' '=T\01',

'X' 'SAPMV45A' '4002',

' ' 'VBAK-AUDAT' IVBAK-AUDAT, "Document date

' ' 'BDC_OKCODE' '=T\10'.

if not ivbak-waerk is initial.

PERFORM DYNPRO USING :

' ' 'VBAK-WAERK' IVBAK-WAERK. "Currency

endif.

PERFORM DYNPRO USING :

' ' 'BDC_OKCODE' '/EBACK'.

PERFORM DYNPRO USING :

' ' 'BDC_OKCODE' '=BACK',

'X' 'SAPMV45A' '4001', "Overview screen

' ' 'BDC_OKCODE' 'ZSRS', "Sales rep

'X' 'SAPLZSSR' '9000', "Sales rep popup screen

' ' 'SZORS-KUNNRSR(3)' IVBAK-SR, "Sales rep

' ' 'BDC_OKCODE' 'CONT',

'X' 'SAPMV45A' '4001'. "Overview screen

PERFORM DYNPRO USING :

' ' 'BDC_OKCODE' 'KPAR',

'X' 'SAPDV02P' '6924', "Header partnrs

' ' 'RV02P-KUNDE(2)' IVBAK-INSTALL_TO, "Install-at party (IN)

' ' 'RV02P-SELKZ(3)' 'X',

' ' 'RV02P-KUNDE(3)' IVBAK-BILL_to, "Bill to party

' ' 'BDC_OKCODE' '=S\PICK',

*Start Comment Lokesh

  • 'X' 'SAPDV02P' '0644',

  • ' ' 'VBADR-NAME2' IVBAK-bill_CONT,

*End Comment Lokesh

*Start Lokesh

'X' 'SAPLV09C' '5000',

' ' 'ADDR1_DATA-NAME2' IVBAK-bill_CONT,

*End Lokesh

  • Start venkatp

  • ' ' 'BDC_OKCODE' '=BACK',

' ' 'BDC_OKCODE' 'ENT1',

  • End venkatp

'X' 'SAPDV02P' '6924'. "Header partnrs

if not IVBAK-payer is initial.

PERFORM DYNPRO USING :

' ' 'RV02P-KUNDE(4)' IVBAK-payer. "Payer (BP)

endif.

PERFORM DYNPRO USING :

' ' 'RV02P-SELKZ(5)' 'X',

' ' 'RV02P-KUNDE(5)' IVBAK-SHIP_TO, "Ship to party

' ' 'BDC_OKCODE' '=S\PICK',

*Start Comment Lokesh

  • 'X' 'SAPDV02P' '0644',

  • ' ' 'VBADR-NAME2' IVBAK-SHIP_CONT,

*End Comment Lokesh

*Start Lokesh

'X' 'SAPLV09C' '5000',

' ' 'ADDR1_DATA-NAME2' IVBAK-SHIP_CONT,

*End Lokesh

  • Start venkatp

  • ' ' 'BDC_OKCODE' '=BACK',

' ' 'BDC_OKCODE' 'ENT1',

  • End venkatp

'X' 'SAPDV02P' '6924', "Header partnrs

' ' 'BDC_OKCODE' '=S\BACK',

'X' 'SAPMV45A' '4001'. "Overview screen

IF IVBAK-DESC <> SPACE.

*-Long text.

PERFORM DYNPRO USING :

' ' 'BDC_OKCODE' 'KTEX',

'X' 'SAPMV45A' '4002',

' ' 'RTEXT-SPRAS(3)' 'EN',

' ' 'RTEXT-SELKZ(3)' 'X',

' ' 'BDC_OKCODE' '/2',

'X' 'SAPLSTXX' '1100'.

perform input_long_texts using 0.

PERFORM DYNPRO USING :

'X' 'SAPMV45A' '4002',

' ' 'BDC_OKCODE' '=BACK'.

PERFORM DYNPRO USING :

'X' 'SAPMV45A' '4001'.

endif.

PERFORM DYNPRO USING :

' ' MATERIAL IVBAP-MATNR, "Material number

' ' QUANTITY IVBAP-ZMENG, "Quantityt

' ' ITEM_CAT 'ZOR5'. "item category

IF IVBAK-AUART = 'OR'.

PERFORM DYNPRO USING :

' ' 'BDC_OKCODE' '=ENT1', "Material Config

'X' 'SAPLCEI0' '0109', "Config screen

' ' 'RCTMS-MNAME(1)' 'RELEASE', "Release

' ' 'RCTMS-MWERT(1)' IVBAP-MWERT1, "Release #

' ' 'BDC_OKCODE' '=BACK'.

ENDIF.

  • Chages Lokesh Ecc 5.0

PERFORM DYNPRO USING :

'X' 'SAPMV45A' '4001', "Overview screen

' ' SELECTION 'X',

  • ' ' 'BDC_OKCODE' 'PKON', "Material Pricing screen

' ' 'BDC_OKCODE' 'PKAU', "Material Pricing screen

'X' 'SAPMV45A' '4003',

' ' 'BDC_OKCODE' 'PEIN', "Material Pricing screen

' ' 'BDC_OKCODE' 'T\06', "Material Pricing screen

'X' 'SAPMV45A' '5003', "Overview screen

  • 'X' 'SAPMV61A' '6200',

' ' 'BDC_OKCODE' 'V69A_KOAN', "Add new pricing

  • 'X' 'SAPMV61A' '6200', "Material pricing screen

'X' 'SAPMV45A' '5003', "Overview screen

  • 'X' 'SAPLV69A' '6201', "Material pricing screen

' ' 'KOMV-KSCHL(02)' 'ZPR0', "Condition type

' ' 'KOMV-KBETR(02)' IVBAP-KBETR. "Condition Amount

IF IVBAK-AUART = 'OR'.

PERFORM DYNPRO USING :

' ' 'BDC_SUBSCR' 'SAPMV45A', "Account Assignment

' ' 'BDC_OKCODE' '=T\07',

'X' 'SAPMV45A' '4003',

' ' 'BDC_OKCODE' '=BACK',

'X' 'SAPLKACB' '0002',

' ' 'COBL-PS_PSP_PNR' IVBAP-WBS,

' ' 'BDC_OKCODE' '=ENTE'.

else.

PERFORM DYNPRO USING :

' ' 'BDC_OKCODE' '=BACK'.

ENDIF.

  • Input long texts

PERFORM DYNPRO USING :

'X' 'SAPMV45A' '4001',"Overview screen

' ' SELECTION 'X',

' ' 'BDC_OKCODE' '=PTEX',

'X' 'SAPMV45A' '4003',

' ' 'RTEXT-SPRAS(2)' 'EN',

' ' 'RTEXT-SELKZ(2)' 'X',

' ' 'BDC_OKCODE' '/2',

'X' 'SAPLSTXX' '1100'.

perform parse_text_n using ivbap-text. "Load header texts

perform input_long_texts using ivbap-posnr.

PERFORM DYNPRO USING :

'X' 'SAPMV45A' '4003',

' ' 'BDC_OKCODE' '=BACK',

'X' 'SAPMV45A' '4001'.

ENDLOOP.