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

Update Forecast values



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



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Sep 26, 2007 7:37 pm    Post subject: Update Forecast values Reply with quote

There is no BAPI or FM to update forecase values.
See the below program, it used MD61 transaction.
Code:

************************************************************************
* Report : ZMPPC015
* Type : Data upload
* Author : Seshu Maramreddy
* Description: This ABAP/4 Program to Create Planned Independent
* Requirement for SMI plants using MD61 Transaction.
* It accepts tab-delimited spreadsheet input and
* creates BDC sessions.
*
************************************************************************
report zmppc015 no standard page heading
line-size 120
line-count 55
message-id zz.


* Constants
constants : c_x type c value 'X'," Dynbegin
c_tcode type tstc-tcode value 'MD61'." Transaction Code

* Variables
data : v_lines_in_xcel like sy-tabix,
l_tabix like sy-tabix,
v_trans_in_ssn type i,
v_ssnnr(4) type n," Counter
v_ssnname like apqi-groupid,
v_matnr(18) type c. " Material Number


* Internal Tables
* Internal table for file
data : begin of t_file occurs 0,
matnr(18) type c, " Material Number
berid(10) type c, " MRP Area
PLNMG01(17) type n, " Forecast Month -01
PLNMG02(17) type n, " Forecast Month -02
PLNMG03(17) type n, " Forecast Month -03
PLNMG04(17) type n, " Forecast Month -04
PLNMG05(17) type n, " Forecast Month -05
PLNMG06(17) type n, " Forecast Month -06
PLNMG07(17) type n, " Forecast Month -07
PLNMG08(17) type n, " Forecast Month -08
PLNMG09(17) type n, " Forecast Month -09
PLNMG10(17) type n, " Forecast Month -10
PLNMG11(17) type n, " Forecast Month -11
PLNMG12(17) type n, " Forecast Month -12
WERKS(4) TYPE C, " Plant
end of t_file.

* Internal table for BDCDATA Structure
data : begin of itab_bdc_tab occurs 0.
include structure bdcdata.
data : end of itab_bdc_tab.


* Selection-screen
selection-screen: skip 3.
selection-screen: begin of block id1 with frame.
*
parameters: p_name like rlgrap-filename
default 'C:\My Documents\InputFile.txt'
obligatory,
* bdc session name prefix
p_bdcpfx(6) default 'ZPIRCT'
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 c_x,
* user who will be executing BDC session
p_uname like apqi-userid
default sy-uname
obligatory.
selection-screen : skip 1.
* Requirement type
parameters : p_bedae like t459u-bedae,
* From Date
p_date like sy-datum default sy-datum obligatory.

selection-screen: end of block id1.

at selection-screen on value-request for p_name.

* F4 value for Input file
perform filename_get.

* main processing

start-of-selection.

* To get the data from file to Internal table
perform getdata_fromfile.

loop at t_file.

* hang on to xcel line num
l_tabix = sy-tabix.

* 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 prod.version maintenance screens
perform bdc_build_script.

* 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.
clear t_file.
endloop.

top-of-page.
call function 'Z_HEADER'
* EXPORTING
* FLEX_TEXT1 =
* FLEX_TEXT2 =
* FLEX_TEXT3 =
.

*&---------------------------------------------------------------------*
*& Form filename_get
*&---------------------------------------------------------------------*
* F4 Value for input file
*----------------------------------------------------------------------*
FORM filename_get.

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = 'C:\Temp\ '
MASK = ',*.*,*.*.'
MODE = 'O'
TITLE = 'Select File '(007)
IMPORTING
FILENAME = p_name
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.


ENDFORM. " filename_get
*&---------------------------------------------------------------------*
*& Form getdata_fromfile
*&---------------------------------------------------------------------*
* Upload the data from file to Internal table
*----------------------------------------------------------------------*
FORM getdata_fromfile.

CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_name
FILETYPE = 'DAT'
TABLES
DATA_TAB = t_file
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.

if sy-subrc eq 0.

sort t_file by matnr .
delete t_file where matnr = ''.

clear v_lines_in_xcel.
describe table t_file lines v_lines_in_xcel.
if v_lines_in_xcel is initial.
write: / 'No data in input file'.
stop.
endif.
else.
write:/ 'Error reading input file'.
stop.
endif.

ENDFORM. " getdata_fromfile
*&---------------------------------------------------------------------*
*& Form bdc_session_open
*&---------------------------------------------------------------------*
* BDC_OPEN_GROUP
*----------------------------------------------------------------------*
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.

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.
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. " bdc_session_open
*&---------------------------------------------------------------------*
*& Form bdc_build_script
*&---------------------------------------------------------------------*
* BDC Script
*----------------------------------------------------------------------*
FORM bdc_build_script.
* Local Variables

DATA : l_frdat(8) type c, " From Date
l_todat(8) type c, " To Date
l_frdat1(4) type c, " Year
l_frdat2(2) type c, " Month
l_frdat3(2) type c, " Day
l_tdate like sy-datum, " Subtract date(1)
l_todat1(4) type c, " Year
l_todat2(2) type c, " Month
l_todat3(3) type c. " Day

* Get the material number from tables ZMSMI_FERR_RAW,
* ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
perform get_matnr.

* Screen 0100.

perform bdc_screen using 'SAPMM60X' '0100'.
perform bdc_field using 'BDC_OKCODE' '/EBDPT'.
perform bdc_field using 'AM60X-MATAW' 'X'.
perform bdc_field using 'AM60X-MATNR' T_FILE-MATNR.
perform bdc_field using 'AM60X-PRGRP' SPACE.
perform bdc_field using 'AM60X-PBDNR' SPACE.
perform bdc_field using 'RM60X-BERID' T_FILE-BERID.
perform bdc_field using 'AM60X-WERKS' SPACE.
perform bdc_field using 'RM60X-VERSB' '00'.

* Converted the date as per MD61 Transaction.
* From date
l_frdat1 = p_date+0(4).
l_frdat2 = p_date+4(2).
l_frdat3 = p_date+6(2).
concatenate l_frdat2 l_frdat3 l_frdat1 into l_frdat.

* To Date
l_tdate = p_date - 1.

l_todat1 = l_tdate+0(4) + 1.
l_todat2 = l_tdate+4(2).
l_todat3 = l_tdate+6(2).

concatenate l_todat2 l_todat3 l_todat1 into l_todat.

perform bdc_field using 'RM60X-DATVE' l_frdat.
perform bdc_field using 'RM60X-DATBE' l_todat.
perform bdc_field using 'RM60X-ENTLU' 'M'.

* Screen 0127
perform bdc_screen using 'SAPMM60X' '0127'.
perform bdc_field using 'BDC_OKCODE' '=WEIT'.
if p_bedae is initial.
perform bdc_field using 'T459U-BEDAE' space.
else.
perform bdc_field using 'T459U-BEDAE' P_BEDAE.
endif.

* Screen 0100.

perform bdc_screen using 'SAPMM60X' '0100'.
perform bdc_field using 'BDC_OKCODE' '/00'.
perform bdc_field using 'AM60X-MATAW' 'X'.
perform bdc_field using 'AM60X-MATNR' T_FILE-MATNR.
perform bdc_field using 'AM60X-PRGRP' SPACE.
perform bdc_field using 'AM60X-PBDNR' SPACE.
perform bdc_field using 'RM60X-BERID' T_FILE-BERID.
perform bdc_field using 'AM60X-WERKS' SPACE.
perform bdc_field using 'RM60X-VERSB' '00'.
perform bdc_field using 'RM60X-DATVE' l_frdat.
perform bdc_field using 'RM60X-DATBE' l_todat.
perform bdc_field using 'RM60X-ENTLU' 'M'.

* Screen 0200

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG01.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG02.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG03.


perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG04.


perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG05.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG06.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG07.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG08.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG09.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG10.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=S+'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG11.

perform bdc_screen using 'SAPLM60E' '0200'.
perform bdc_field using 'BDC_OKCODE' '=SICH'.
perform bdc_field using 'RM60X-PLN01(01)' T_FILE-PLNMG12.


ENDFORM. " bdc_build_script
*&---------------------------------------------------------------------*
*& Form get_matnr
*&---------------------------------------------------------------------*
* Get the material number from tables ZMSMI_FERR_RAW,
* ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
*----------------------------------------------------------------------*
FORM get_matnr.

clear v_matnr.
case t_file-werks.

when '0101'.

select single cmatnr from zmsmi_simp_raw
into v_matnr where matnr = t_file-matnr.

if sy-subrc eq 0.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.

when '0103'.

select single cmatnr from zmsmi_ferr_raw
into v_matnr where matnr = t_file-matnr.

if sy-subrc eq 0.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.

when '0102' or '0110' or '0111' or '0112' or '0113'
or '0114' or '0115' or '0116' or '0117'.

select single cmatnr from zmsmi_snap_raw
into v_matnr where matnr = t_file-matnr.

if sy-subrc eq 0.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.

endcase.


ENDFORM. " get_matnr

*&---------------------------------------------------------------------*
*& Form bdc_screen
*&---------------------------------------------------------------------*
* BDC Script for Screen fields
*----------------------------------------------------------------------*
* -->P_PROG Program name
* -->P_SCRN Screen Number
*----------------------------------------------------------------------*
FORM bdc_screen USING p_prog
p_scrn.

clear itab_bdc_tab.
itab_bdc_tab-program = p_prog.
itab_bdc_tab-dynpro = p_scrn.
itab_bdc_tab-dynbegin = c_x.
append itab_bdc_tab.

ENDFORM. " bdc_screen

*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* BDC Script for Screen fileds
*----------------------------------------------------------------------*
* -->P_NAM Field name
* -->P_VAL Field value
*----------------------------------------------------------------------*
FORM bdc_field USING p_nam
p_val.
clear itab_bdc_tab.
itab_bdc_tab-fnam = p_nam.
itab_bdc_tab-fval = p_val.
append itab_bdc_tab.

ENDFORM. " bdc_screen
*&---------------------------------------------------------------------*
*& Form bdc_submit_transaction
*&---------------------------------------------------------------------*
* BDC_INSERT Function Module
*----------------------------------------------------------------------*
FORM bdc_submit_transaction.

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

IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

refresh itab_bdc_tab.

ENDFORM. " bdc_submit_transaction
*&---------------------------------------------------------------------*
*& Form bdc_session_close
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM bdc_session_close.

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. " bdc_session_close
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 -> FI 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.