SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create Rate Routing using CA21 with BDC



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Sep 29, 2007 4:45 pm    Post subject: Create Rate Routing using CA21 with BDC Reply with quote

Code:
EPORT zmppc010 NO STANDARD PAGE HEADING LINE-SIZE 120 LINE-COUNT 55
MESSAGE-ID zz.

* pool of form routines
INCLUDE ZMPPN001.

* Define BDC Table Structure
DATA: BEGIN OF itab_bdc_tab OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END OF itab_bdc_tab.

* Input record layout of Leagcy File
DATA: BEGIN OF itab_xcel OCCURS 0,
matnr(18) TYPE c,
werks(4) TYPE c,
datuv(10) TYPE c,
verwe(3) TYPE c,
statu(3) TYPE c,
slwbez(3) TYPE c,
vornr(4) TYPE n,
arbpl(8) TYPE c,
steus(4) TYPE c,
ltxa1(40) TYPE c,
bmsch LIKE PLPOD-BMSCH,
meinh(3) TYPE c,
lar01(6) TYPE c,
vgw01 LIKE PLPOD-VGW01,
vge01(3) TYPE c,
lar02(6) TYPE c,
vgw02 LIKE PLPOD-VGW02,
vge02(3) TYPE c,
lar03(6) TYPE c,
vgw03 LIKE PLPOD-VGW03,
vge03(3) TYPE c,
lar04(6) TYPE c,
vgw04 LIKE PLPOD-VGW04,
vge04(3) TYPE c,
lar05(6) TYPE c,
vgw05 LIKE PLPOD-VGW05,
vge05(3) TYPE c,
lar06(6) TYPE c,
vgw06 LIKE PLPOD-VGW06,
vge06(3) TYPE c,
anzma LIKE PLPOD-ANZMA,
zlmax LIKE PLPOD-ZLMAX,
zeilm(3) TYPE c,
zwnor LIKE PLPOD-ZWNOR,
zeiwn(3) TYPE c,
ztnor LIKE PLPOD-ZTNOR,
zeitn(3) TYPE c,
sortl(10) TYPE c,
lifnr(10) TYPE c,
plifz LIKE PLPOD-PLIFZ,
preis LIKE PLPOD-PREIS,
peinh LIKE PLPOD-PEINH,
sakto(10) TYPE c,
waers(5) TYPE c,
infnr(10) TYPE c,
ekorg(4) TYPE c,
ekgrp(3) TYPE c,
matkl(9) TYPE c,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
qpart(8) TYPE c,
ckselkz(1) TYPE c,
rsanz LIKE PLPOD-RSANZ,
END OF itab_xcel.

DATA: v_ssnnr(4) TYPE n,
v_lines_in_xcel LIKE sy-tabix,
v_ssnname LIKE apqi-groupid,
v_trans_in_ssn TYPE i,
wa_xcel LIKE itab_xcel,
l_tabix like sy-tabix,
v_tcode LIKE sy-tcode VALUE 'CA21'.

* Parameters
SELECTION-SCREEN: SKIP 3.
SELECTION-SCREEN: BEGIN OF BLOCK 1 WITH FRAME.
*
PARAMETERS: p_name LIKE rlgrap-filename
DEFAULT 'C:\My Documents\InputFile.txt'
OBLIGATORY,
* bdc session name prefix
p_bdcpfx(6) DEFAULT 'ZRTCRT'
OBLIGATORY,
* number for transction per BDC session
p_trnssn TYPE i
DEFAULT 2000 OBLIGATORY,
* retain the BDC session after successfull execution
p_keep LIKE apqi-qerase
DEFAULT 'X',
* user who will be executing BDC session
p_uname LIKE apqi-userid
DEFAULT sy-uname
OBLIGATORY.
*
SELECTION-SCREEN: END OF BLOCK 1.
*
********************************************************
********************************************************
*
* possible entry list (F4 dropdown) for input file name
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.

*-SELECT FILE FROM USERS LOCAL PC
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
* DEF_FILENAME = ' '
def_path = 'C:\Temp\'
mask = ',*.*,*.*.'
mode = 'O'
title = 'Select File '(007)
IMPORTING
filename = p_name
* RC =
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.

IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*
********************************************************
********************************************************
*
* begin the show :-)
*
START-OF-SELECTION.

* read data from input file
PERFORM transfer_xcel_to_itab.
*
*
LOOP AT itab_xcel.

* load data in work area, used inside 'at new' block
wa_xcel = itab_xcel.
l_tabix = sy-tabix.

* each unique part-plant combn marks begining of new routing defn
AT NEW werks.
* if num-of-trnas-in-session = 0, create new BDC session
IF v_trans_in_ssn IS INITIAL.
PERFORM BDC_SESSION_OPEN.
ENDIF.
* begin new bdc script for rtg create trans
* fill in bdc-data for rtg header screens
PERFORM BDC_BUILD_SCRIPT_FOR_HDR.
ENDAT.

* fill in bdc-data for each opertion in the routing
PERFORM BDC_BUILD_SCRIPT_FOR_OPS.

* end of all recs corresponding to the unique part-plant combn, marks
* the end of routing defn.
AT END OF werks.

* fill in the bdc-data to save the routing defn
PERFORM BDC_BUILD_SCRIPT_FOR_TEND.
* insert the bdc script as a BDC transaction
PERFORM BDC_SUBMIT_TRANSACTION.

* keep track of how many BDC transactions were inserted in the BDC
* session
ADD 1 TO v_trans_in_ssn.
* if the user-specified num of trans in BDC session is reached OR
* if end of input file is reached, close the BDC session
IF v_trans_in_ssn = p_trnssn or
l_tabix = v_lines_in_xcel.
PERFORM BDC_SESSION_CLOSE.
CLEAR v_trans_in_ssn.
ENDIF.

ENDAT.

ENDLOOP.

Top-of-page.
CALL FUNCTION 'Z_HEADER'
* EXPORTING
* FLEX_TEXT1 =
* FLEX_TEXT2 =
* FLEX_TEXT3 =
.

*---------------------------------------------------------------------*
* FORM TRANSFER_XCEL_TO_ITAB *
*---------------------------------------------------------------------*
* Transfer Xcel Spreadsheet to SAP Internal Table *
*---------------------------------------------------------------------*
FORM transfer_xcel_to_itab.
*
* Read the tab-delimited file into itab
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_name
filetype = 'DAT'
* IMPORTING
* filelength = flength
TABLES
data_tab = itab_xcel
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 = 0.
* sort the data
SORT itab_xcel BY matnr werks.
CLEAR v_lines_in_xcel.
* if no data in the file - error out
DESCRIBE TABLE itab_xcel LINES v_lines_in_xcel.
IF v_lines_in_xcel IS INITIAL.
WRITE: / 'No data in input file'.
STOP.
ENDIF.
else.
* if file upload failed - error out
WRITE: / 'Error reading input file'.
STOP.
endif.

ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_SESSION_OPEN *
*---------------------------------------------------------------------*
* Open BDC Session *
*---------------------------------------------------------------------*
FORM BDC_SESSION_OPEN.

* create bdc session name = prefix-from-selectn-screen + nnnn
ADD 1 TO v_ssnnr.
CONCATENATE p_bdcpfx v_ssnnr INTO v_ssnname.

* open new bdc session
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = v_ssnname
keep = p_keep
user = p_uname
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.

ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_BUILD_SCRIPT_FOR_HDR *
*---------------------------------------------------------------------*
* Build BDC *
*---------------------------------------------------------------------*
FORM bdc_build_script_for_hdr.

DATA: l_sttag LIKE rc271-sttag,
l_matnr LIKE rc27m-matnr,
l_mapl LIKE mapl.


* clear bdc-data itab - begin of new bdc transaction
CLEAR itab_bdc_tab.
REFRESH itab_bdc_tab.
*
* read material cross reference tables to determine sap part#
PERFORM read_matnr_cross_ref USING wa_xcel-matnr
wa_xcel-werks
CHANGING l_matnr.
*
* read any existing rtg group counters from MAPL table
clear l_mapl.
select * into l_mapl
from mapl up to 1 rows
where matnr = l_matnr and
werks = wa_xcel-werks and
plnty = 'R' and
loekz = space.
endselect.
*
* bdc script for routing header screens
PERFORM BDC_BUILD_SCRIPT_RECORD
*
* initial screen
USING: 'X' 'SAPLCPDI' '1010',
' ' 'BDC_OKCODE' '/00',
' ' 'RC27M-MATNR' l_matnr,
' ' 'RC27M-WERKS' wa_xcel-werks,
' ' 'RC271-VBELN' space,
' ' 'RC271-POSNR' space,
' ' 'RC271-PSPNR' space,
' ' 'RC271-PLNNR' space,
' ' 'RC271-AENNR' space,
' ' 'RC271-STTAG' wa_xcel-datuv,
' ' 'RC271-REVLV' space,
' ' 'RC271-PROFIDNETZ' space.

* overview screen (lists all existing group counters)
* the following screen will be included in bdc only if there was atleast
* one good group counter defined already for this part-plant combn
if not l_mapl is initial.
PERFORM BDC_BUILD_SCRIPT_RECORD
USING: 'X' 'SAPLCPDI' '5200',
' ' 'BDC_OKCODE' '=ANLG'.

endif.

* header details screen
PERFORM BDC_BUILD_SCRIPT_RECORD
USING: 'X' 'SAPLCPDA' '1200',
' ' 'BDC_OKCODE' '/00',
' ' 'PLKOD-VERWE' wa_xcel-VERWE,
' ' 'PLKOD-STATU' wa_xcel-STATU,
' ' 'PLKOD-SLWBEZ' wa_xcel-SLWBEZ,

* header details screen, goto operations overview screen
'X' 'SAPLCPDA' '1200',
' ' 'BDC_OKCODE' '=VOUE'.
*

ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_BUILD_SCRIPT_FOR_OPS *
*---------------------------------------------------------------------*
* Build BDC *
*---------------------------------------------------------------------*
FORM BDC_BUILD_SCRIPT_FOR_OPS.


* bdc script for routing operations
PERFORM BDC_BUILD_SCRIPT_RECORD

* operaions overview screen, insert new line for the operaion
USING: 'X' 'SAPLCPDI' '5400',
' ' 'BDC_CURSOR' 'PLPOD-VORNR(01)',
' ' 'BDC_OKCODE' '=EINF',

* operation overview screen, goto operation detail screen
'X' 'SAPLCPDI' '5400',
' ' 'BDC_CURSOR' 'PLPOD-VORNR(01)',
' ' 'BDC_OKCODE' '=PICK',
' ' 'PLPOD-VORNR(01)' wa_xcel-VORNR,
' ' 'PLPOD-ARBPL(01)' wa_xcel-ARBPL,

* operation detail screen,
'X' 'SAPLCPDO' '1200',
' ' 'BDC_OKCODE' '/00',
' ' 'PLPOD-STEUS' wa_xcel-STEUS,
' ' 'PLPOD-LTXA1' wa_xcel-LTXA1,
' ' 'PLPOD-BMSCH' wa_xcel-BMSCH,
' ' 'PLPOD-MEINH' wa_xcel-MEINH,
' ' 'PLPOD-VGW01' wa_xcel-VGW01,
' ' 'PLPOD-VGE01' wa_xcel-VGE01,
' ' 'PLPOD-VGW02' wa_xcel-VGW02,
' ' 'PLPOD-VGE02' wa_xcel-VGE02,
' ' 'PLPOD-VGW03' wa_xcel-VGW03,
' ' 'PLPOD-VGE03' wa_xcel-VGE03,
' ' 'PLPOD-VGW04' wa_xcel-VGW04,
' ' 'PLPOD-VGE04' wa_xcel-VGE04,
' ' 'PLPOD-VGW05' wa_xcel-VGW05,
' ' 'PLPOD-VGE05' wa_xcel-VGE05.
*
* if no fields in the inputfile for activity#6 (on the screen)
* are given then do not include it in the bdc script as they
* MIGHT NOT be available on the operation detail screen at all
if not wa_xcel-VGW06 is initial or
not wa_xcel-VGE06 is initial or
not wa_xcel-LAR06 is initial.
PERFORM BDC_BUILD_SCRIPT_RECORD
USING: ' ' 'PLPOD-VGW06' wa_xcel-VGW06,
' ' 'PLPOD-VGE06' wa_xcel-VGE06.
endif.
*
* continue with operation detail screen,
PERFORM BDC_BUILD_SCRIPT_RECORD
*
USING: ' ' 'PLPOD-ZLMAX' wa_xcel-ZLMAX,
' ' 'PLPOD-ZEILM' wa_xcel-ZEILM,
' ' 'PLPOD-ZWNOR' wa_xcel-ZWNOR,
' ' 'PLPOD-ZEIWN' wa_xcel-ZEIWN,
' ' 'PLPOD-ZTNOR' wa_xcel-ZTNOR,
' ' 'PLPOD-ZEITN' wa_xcel-ZEITN,
' ' 'PLPOD-RSANZ' wa_xcel-RSANZ,
' ' 'PLPOD-ANZMA' wa_xcel-ANZMA,
' ' 'PLPOD-CKSELKZ' wa_xcel-CKSELKZ,
' ' 'PLPOD-INFNR' wa_xcel-INFNR,
' ' 'PLPOD-EKORG' wa_xcel-EKORG,
' ' 'PLPOD-EBELN' wa_xcel-EBELN,
' ' 'PLPOD-EBELP' wa_xcel-EBELP,
' ' 'PLPOD-SORTL' wa_xcel-SORTL,
' ' 'PLPOD-MATKL' wa_xcel-MATKL,
' ' 'PLPOD-EKGRP' wa_xcel-EKGRP,
' ' 'PLPOD-LIFNR' wa_xcel-LIFNR,
' ' 'PLPOD-PLIFZ' wa_xcel-PLIFZ,
' ' 'PLPOD-PEINH' wa_xcel-PEINH,
' ' 'PLPOD-SAKTO' wa_xcel-SAKTO,
' ' 'PLPOD-PREIS' wa_xcel-PREIS,
' ' 'PLPOD-WAERS' wa_xcel-WAERS,
' ' 'PLPOD-QPART' wa_xcel-QPART,

* operation detail screen, go to the op overview scrn to add another op
'X' 'SAPLCPDO' '1200',
' ' 'BDC_OKCODE' '=BACK'.
*
ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_BUILD_SCRIPT_FOR_TEND *
*---------------------------------------------------------------------*
* Build BDC *
*---------------------------------------------------------------------*
FORM BDC_BUILD_SCRIPT_FOR_TEND.

* operatin detail screen, save the routing defn
PERFORM BDC_BUILD_SCRIPT_RECORD
*
USING: 'X' 'SAPLCPDI' '5400',
' ' 'BDC_OKCODE' '=BU'.
*
ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_SUBMIT_TRANSACTION *
*---------------------------------------------------------------------*
* Submit BDC Session *
*---------------------------------------------------------------------*
FORM BDC_SUBMIT_TRANSACTION.

** Load BDC script as a trqansction in BDC session
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = v_tcode
TABLES
dynprotab = itab_bdc_tab
EXCEPTIONS
internal_error = 01
not_open = 02
queue_error = 03
tcode_invalid = 04.

ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_BUILD_SCRIPT_RECORD *
*---------------------------------------------------------------------*
FORM BDC_BUILD_SCRIPT_RECORD USING dynbegin name value.

CLEAR itab_bdc_tab.
IF dynbegin = 'X'.
MOVE: name TO itab_bdc_tab-program,
value TO itab_bdc_tab-dynpro,
'X' TO itab_bdc_tab-dynbegin.
ELSE.
MOVE: name TO itab_bdc_tab-fnam,
value TO itab_bdc_tab-fval.
SHIFT itab_bdc_tab-fval LEFT DELETING LEADING SPACE.
ENDIF.

APPEND itab_bdc_tab.

ENDFORM.

*---------------------------------------------------------------------*
* FORM BDC_SESSION_CLOSE *
*---------------------------------------------------------------------*
* Close BDC Session *
*---------------------------------------------------------------------*
FORM BDC_SESSION_CLOSE.

* close the session
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.

SKIP 2.
IF sy-subrc NE 0.
WRITE: / 'Error Closing BDC Session ' , 'RETURN CODE: ', sy-subrc.
ELSE.
WRITE : / 'Session created:', v_ssnname,
50 '# of transactions:', v_trans_in_ssn.
ENDIF.

ENDFORM.


************************************************************************
* Report : ZMPPN001
* Type : Include
* Author : Chetan Shah
* Date : 05/05/2005
* Transport : DV3K919472
* Transaction: ??
* Description: Common miscelleneous form routines used in more then
* one program
*
************************************************************************
* Modification Log
* Date Programmer Request # Description
************************************************************************
* 05/05/2005 Chetan Shah DV3K919472 Initial coding
************************************************************************
*----------------------------------------------------------------------*
* INCLUDE ZMPPN001 *
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form read_matnr_cross_ref
*&---------------------------------------------------------------------*
FORM read_matnr_cross_ref USING pi_matnr "SMI legacy part#
pi_werks "SMI plant
CHANGING pe_matnr. "SAP part#

DATA: l_tablename(20) TYPE c.

* pi_matnr = SMI legacy part#
* pi_werks = SMI plant
* pe_matnr = SAP part#

* based in given plant#, decide which cross-reference
* table is to be used
CASE pi_werks.
WHEN '0101'.
l_tablename = 'ZMSMI_SIMP_RAW'.
WHEN '0103'.
l_tablename = 'ZMSMI_FERR_RAW'.
WHEN OTHERS.
* this is basically snapper plant (0102) and all its related
* warehouse-plants. Plant 0110 which is a warehouse-plant for
* snapper can have production parts.
l_tablename = 'ZMSMI_SNAP_RAW'.
ENDCASE.

* read the cross-reference
CLEAR pe_matnr.
SELECT SINGLE cmatnr INTO pe_matnr
FROM (l_tablename)
WHERE matnr = pi_matnr.

* if the cross-reference table had SAP-part# as blank OR
* if the cross-reference read failed,
* return back the SMI part#
IF pe_matnr IS INITIAL OR
sy-subrc NE 0.
pe_matnr = pi_matnr.
ENDIF.


ENDFORM. " read_matnr_cross_ref
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.