2008 Apr 28 10:14 AM
Hi, I want to create BDC program(in SAP version ecc6.0) for transaction for CS01 (Create Material BOM). where in first screen i have 1st four fields and in second screen(in Material tab) I have many rows of data to be updated in table control where no of rows of data differ from material to material.
Can anybody suggest me with coding.....
thanks.
Hi, I want to create BDC program(in SAP version ecc6.0) for transaction for CS01 (Create Material BOM). where in first screen i have 1st four fields and in second screen(in Material tab) I have many rows of data to be updated in table control where no of rows of data differ from material to material.
Can anybody suggest me with coding.....
thanks.
2008 Apr 28 11:06 AM
Hi,
First get the no of records to be uploaded for a given BOM. i.e. say there are say 10 Raw materials/Packing Materials/SGS to be uplaod in the current BOM. For first 2 items update all details like materials/Qty/UOM's etc etc As normal BDC followed with enter for act record. Now click the 'Position' Button at the bottomm of the window, & give item code as 20, ( Since we have keyed in data for 2 records , First will have item code of 10 & second will have item code of 20 ) , this will bring item code 20 on the first line, now key in next material on line 30 by giving details like Material/Qty/UOM etc etc & aagain click button 'Position' & give item code as 30, This will agin bring Item 30 as the top, on first line, again key in next item on the next line..etc etc till your are finished with all the items. & finally press save button. Please note that if there are only 2 items in a BOM then the procedure of clicking 'Position' button will not be required.
I hope This helps,
Regards
Raju Chitale
2008 Apr 28 11:23 AM
Hi,
Try with the following code
TYPE-POOLS truxs. "#EC *
TYPES: BEGIN OF ty_head, " structure for header file
ind(2) TYPE n,
matnr(18), "#EC *
werks(4), "#EC *
stlan(1), "#EC *
END OF ty_head.
TYPES :BEGIN OF ty_item, "structure for item file
ind(2) TYPE n,
postp(1) , "#EC *
posnr(4) , "#EC *
idnrk(18) , "#EC *
menge(13), "#EC *
potx1(40), "#EC *
END OF ty_item.
TYPES :BEGIN OF ty_flat, " structure for final file
matnr(18) , "#EC *
werks(4) , "#EC *
stlan(1) , "#EC *
postp(1), "#EC *
posnr(4) , "#EC *
idnrk(18) , "#EC *
menge(13), "#EC *
END OF ty_flat.
*----
INTERNAL TABLE DECLARATIONS *
*----
DATA : t_flat TYPE TABLE OF ty_flat,
f_file TYPE string,
t_head TYPE TABLE OF ty_head,
t_item TYPE TABLE OF ty_item,
t_bdcdata TYPE TABLE OF bdcdata,
t_bdcmsg TYPE TABLE OF bdcmsgcoll.
*----
WORK AREA DECLARATIONS *
*----
DATA : st_flat LIKE LINE OF t_flat,
st_head LIKE LINE OF t_head,
st_item LIKE LINE OF t_item,
st_bdcdata LIKE LINE OF t_bdcdata,
st_bdcmsg LIKE LINE OF t_bdcmsg. "#EC NEEDED
*----
VARIABLES *
*----
DATA : v_ind(2) TYPE n, " value 1,
v_fld(20), "#EC *
v_no(2) TYPE n value 1.
*----
SELECTION SCREEN *
*----
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. "selection screen "#EC *
PARAMETERS: p_fnam TYPE rlgrap-filename OBLIGATORY. "#EC *
SELECTION-SCREEN : END OF BLOCK b1.
*----
AT SELECTION SCREEN *
*----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fnam.
*----
F4 FUNCTIONALITY *
*----
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_fnam.
IF p_fnam IS NOT INITIAL.
*VALIDATE FILE TYPE
PERFORM sub_validate_txt_type.
ENDIF.
START-OF-SELECTION.
f_file = p_fnam.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = f_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = t_flat
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc eq 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*----
LOOP THE ITAB *
*----
SORT t_flat BY matnr .
LOOP AT t_flat INTO st_flat.
MOVE :
st_flat-matnr TO st_head-matnr,
st_flat-werks TO st_head-werks,
st_flat-stlan TO st_head-stlan.
move:
st_flat-posnr to st_item-posnr,
st_flat-postp to st_item-postp,
st_flat-idnrk to st_item-idnrk,
st_flat-menge to st_item-menge.
MOVE v_ind TO st_head-ind.
MOVE v_ind TO st_item-ind.
APPEND st_head TO t_head.
APPEND st_item TO t_item.
CLEAR st_head.
CLEAR st_item.
CLEAR v_ind.
ENDLOOP.
SORT t_item BY ind.
SORT t_head BY ind.
DELETE ADJACENT DUPLICATES FROM t_head.
DELETE ADJACENT DUPLICATES FROM t_item.
LOOP AT t_head INTO st_head.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29N-STLAN'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RC29N-MATNR'
st_head-matnr.
PERFORM bdc_field USING 'RC29N-WERKS'
st_head-werks.
PERFORM bdc_field USING 'RC29N-STLAN'
st_head-stlan.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29K-ZTEXT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0111'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29K-LABOR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
v_no = 1.
LOOP AT t_item INTO st_item WHERE ind = st_head-ind.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29P-POSTP'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
on change of st_item-posnr.
CONCATENATE 'RC29P-IDNRK(' v_no ')' INTO v_fld.
PERFORM bdc_field USING v_fld
st_item-idnrk.
CONCATENATE 'RC29P-MENGE(' v_no ')' INTO v_fld.
PERFORM bdc_field USING v_fld
st_item-menge.
CONCATENATE 'RC29P-POSTP(' v_no ')' INTO v_fld.
PERFORM bdc_field USING v_fld
'L'.
*st_item-postp.
endon.
PERFORM bdc_field USING 'BDC_SUBSCR'
'SAPLCSDI'.
v_no = v_no + 1.
ENDLOOP.
CLEAR v_no.
PERFORM bdc_field USING 'BDC_OKCODE'
'=FCBU'.
*----
CALL TRANSACTION *
*----
CALL TRANSACTION 'CS01' USING t_bdcdata MODE 'E'
UPDATE 'A' MESSAGES INTO t_bdcmsg.
REFRESH t_bdcdata.
CLEAR t_bdcdata.
ENDLOOP.
*----
Start new screen *
*----
FORM bdc_dynpro USING program dynpro. "#EC *
CLEAR st_bdcdata.
st_bdcdata-program = program.
st_bdcdata-dynpro = dynpro.
st_bdcdata-dynbegin = 'X'.
APPEND st_bdcdata TO t_bdcdata.
ENDFORM. "BDC_DYNPRO
*----
Insert field *
*----
FORM bdc_field USING fnam fval. "#EC *
CLEAR st_bdcdata.
st_bdcdata-fnam = fnam.
st_bdcdata-fval = fval.
APPEND st_bdcdata TO t_bdcdata.
ENDFORM. "BDC_FIELD
*&----
FORM sub_validate_txt_type .
DATA : str1 TYPE localfile, "#EC NEEDED
str2 TYPE char3.
SPLIT p_fnam AT '.'
INTO str1 str2.
TRANSLATE str2 TO LOWER CASE. "#EC TRANSLANG
IF str2 NE 'txt'.
MESSAGE i001(zmsg). "#EC *
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. "sub_validate_txt_type.
Regards,
Venkat
2008 Apr 28 12:09 PM
Hi,
Use the following LSMW object for loading the BOM:
Object 0030 Material BOM
Method 0004 Create w/lngTxt
Program name RCSBI040
Program type B Batch input
If you need to schedule for repeat steps at regular intervals you could schedule the background job for the Prg: /SAPDMC/SAP_LSMW_INTERFACE for the above LSMW object. Put the data files on the application server.
Hope this helps.
Best Regards, Murugesh
2008 Apr 28 2:29 PM
Try Referring to the below Program
TYPES: BEGIN OF x_output,
matnr TYPE rc29n-matnr, "Material Number
werks TYPE rc29n-werks, "Plant
stlan TYPE rc29n-stlan, "BOM Usage 'Z'
datuv TYPE sy-datum, "Valid From
bmeng TYPE rc29k-bmeng, "Base Quantity
stlst TYPE rc29k-stlst, "BOM Status
idnrk TYPE rc29p-idnrk, "Material Number
menge TYPE rc29p-menge, "Quantity
postp TYPE rc29p-postp, "Item Category (Bill of Material)
rvrel TYPE rc29p-rvrel, "Relevant to Sales
sanfe TYPE rc29p-sanfe, "Relevant to Production
SANKA type RC29P-SANKA, "Indicator for Relevancy to Costing
END OF x_output,
BEGIN OF x_head,
matnr TYPE rc29n-matnr, "Material Number
werks TYPE rc29n-werks, "Plant
stlan TYPE rc29n-stlan, "BOM Usage 'Z'
datuv TYPE sy-datum, "Valid From
bmeng TYPE rc29k-bmeng, "Base Quantity
stlst TYPE rc29k-stlst, "BOM Status
END OF x_head,
BEGIN OF x_item,
matnr TYPE rc29n-matnr, "Material Number
idnrk LIKE rc29p-idnrk, "Material Number
menge LIKE rc29p-menge, "Quantity
postp LIKE rc29p-postp, "Item Category (Bill of Material)
rvrel LIKE rc29p-rvrel, "Relivant to Sales
sanfe LIKE rc29p-sanfe, "Relevant to Production
SANKA type RC29P-SANKA, "Indicator for Relevancy to Costing
END OF x_item.
*Internal Table
DATA :int_output TYPE TABLE OF x_output,
int_head TYPE TABLE OF x_head,
int_item TYPE TABLE OF x_item.
Internal Table for messages during the BDC
DATA: int_msgtab TYPE TABLE OF bdcmsgcoll.
Internal table for BDC transaction data
DATA: int_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
*WORK AREA FOR UPLOAD FILE
DATA: w_output TYPE X_output,
W_ITEM TYPE X_ITEM,
W_HEAD TYPE X_HEAD.
Work Area for messages during the BDC
DATA: w_msgtab TYPE bdcmsgcoll,
w_ctu_params TYPE ctu_params.
DATA: g_v_mode TYPE c VALUE 'A', "BDC Mode
g_v_update TYPE c VALUE 'S', "BDC Update Method
g_v_str_msg(255) TYPE c. "String for Error Msg
DATA: index TYPE i,
counter_line_item TYPE i,
v_idnrk(30) TYPE c, "Variable for procesing Material Number
v_menge(30) TYPE c, "Variable for procesing Quantity
v_postp(30) TYPE c, "Variable for procesing Item Category (Bill of Material)
idx TYPE n LENGTH 2,
idx1 TYPE n LENGTH 2,
flag TYPE i VALUE 0,
g_file TYPE string.
----
START OF SELECTION *
----
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.
PARAMETERS: p_file LIKE cffile-filename DEFAULT 'C:\so.Txt' OBLIGATORY. "File Name
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Browse the path where file is stored
CALL FUNCTION 'F4_FILENAME' "Allows user to select path/file
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'p_file'
IMPORTING
file_name = p_file.
IF sy-subrc NE 0.
write: / 'Error'(002).
EXIT.
ENDIF.
START-OF-SELECTION.
PERFORM upload.
PERFORM DELETE_HEADING.
PERFORM conversion_on_fields .
PERFORM fill_bdcdata .
&----
*& Form upload
&----
text
----
--> p1 text
<-- p2 text
----
FORM upload.
g_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = g_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = int_output
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
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 . " upload
&----
*& Form delete_heading
&----
text
----
--> p1 text
<-- p2 text
----
FORM delete_heading .
Deleting the Headings of the Excel Sheet
DELETE int_output INDEX 1.
ENDFORM. " delete_heading
&----
*& Form conversion_on_fields
&----
text
----
--> p1 text
<-- p2 text
----
FORM conversion_on_fields .
if not int_output[] is initial.
LOOP AT int_output into w_output.
*Material Number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-matnr
IMPORTING
output = w_output-matnr.
*Plant
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-werks
IMPORTING
output = w_output-werks.
*BOM Usage
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-stlan
IMPORTING
output = w_output-stlan.
*Valid From
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-datuv
IMPORTING
output = w_output-datuv.
*BOM Status
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-stlst
IMPORTING
output = w_output-stlst.
*Material Number
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-idnrk
IMPORTING
output = w_output-idnrk.
*Price List
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-postp
IMPORTING
output = w_output-postp.
*Item Category (Bill of Material)
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-sanfe
IMPORTING
output = w_output-sanfe.
*Relivant to Sales
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-rvrel
IMPORTING
output = w_output-rvrel.
*Indicator for Relevancy to Costing
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_output-SANKA
IMPORTING
output = w_output-SANKA.
MODIFY INT_output INDEX sy-tabix
FROM W_OUTPUT TRANSPORTING matnr "Material Number
werks "Plant
stlan "BOM Usage 'Z'
datuv "Valid From
stlst "BOM Status
idnrk "Component Number
postp "Item Category (Bill of Material)
sanfe "Relevant to Production
rvrel "Relevant to Sales
SANKA. "Indicator for Relevancy to Costing
ENDLOOP.
endif.
ENDFORM. " conversion_on_fields
&----
*& Form fill_bdcdata
&----
text
----
--> p1 text
<-- p2 text
----
----
Filling the BDC Table according to the sequence of the screen *
----
FORM fill_bdcdata .
DATA: v_bmeng(13),
v_menge1(13).
w_ctu_params-dismode = g_v_mode.
w_ctu_params-updmode = g_v_update.
w_ctu_params-defsize = 'X'.
IF NOT int_output[] IS INITIAL.
LOOP AT int_output into w_output.
ON CHANGE OF w_output-matnr.
MOVE: W_OUTPUT-MATNR TO W_HEAD-MATNR,
W_OUTPUT-werks TO W_HEAD-werks,
W_OUTPUT-stlan TO W_HEAD-stlan,
W_OUTPUT-datuv TO W_HEAD-datuv,
W_OUTPUT-bmeng TO W_HEAD-bmeng,
W_OUTPUT-stlst TO W_HEAD-stlst.
APPEND w_head TO INT_HEAD.
CLEAR w_head.
ENDON.
*TO HAVE LINK BETWEEN HEADER AND ITEM TABLE USE LIFNR AS LINKER
MOVE-CORRESPONDING w_output TO w_item.
APPEND w_item TO INT_ITEM.
CLEAR w_item.
ENDLOOP.
ENDIF.
IF NOT int_head[] IS INITIAL.
LOOP AT int_head into w_head .
ON CHANGE OF INT_HEAD-MATNR.
CLEAR int_bdcdata.
REFRESH int_bdcdata.
*INITIAL SCREEN
PERFORM bdc_dynpro USING 'SAPLCSDI' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29N-DATUV'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RC29N-MATNR'
w_head-matnr.
PERFORM bdc_field USING 'RC29N-WERKS'
w_head-werks.
PERFORM bdc_field USING 'RC29N-STLAN'
w_head-stlan.
PERFORM bdc_field USING 'RC29N-DATUV'
w_head-datuv.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29K-BMENG'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
MOVE W_head-bmeng TO v_bmeng.
PERFORM bdc_field USING 'RC29K-BMENG'
v_bmeng.
PERFORM bdc_field USING 'RC29K-STLST'
w_head-stlst.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0111'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29K-LABOR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
MOVE 1 TO idx.
counter_line_item = 0.
if not int_item[] is initial.
LOOP AT INT_item INTO W_ITEM WHERE matnr = W_head-matnr.
counter_line_item = counter_line_item + 1.
ENDLOOP.
endif.
*Processing of Line-Items
if not int_item[] is initial.
LOOP AT INT_item INTO W_ITEM WHERE matnr = w_head-matnr.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
*Processing of first 14 Line-Items
IF flag = 0.
CONCATENATE 'RC29P-IDNRK(' idx ')' INTO v_idnrk.
CONCATENATE 'RC29P-MENGE(' idx ')' INTO v_menge.
CONCATENATE 'RC29P-POSTP(' idx ')' INTO v_postp.
PERFORM bdc_field USING v_idnrk
W_item-idnrk. "cOMPONENT Number
MOVE W_item-menge TO v_menge1.
PERFORM bdc_field USING v_menge
v_menge1. "Quantity
PERFORM bdc_field USING v_postp
w_item-postp. "L
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
ELSE.
idx1 = idx + 1.
CONCATENATE 'RC29P-IDNRK(' idx1 ')' INTO v_idnrk.
CONCATENATE 'RC29P-MENGE(' idx1 ')' INTO v_menge.
CONCATENATE 'RC29P-POSTP(' idx1 ')' INTO v_postp.
PERFORM bdc_field USING v_idnrk
w_item-idnrk. "cOMPONENT Number
MOVE W_item-menge TO v_menge1.
PERFORM bdc_field USING v_menge
v_menge1. "Quantity
PERFORM bdc_field USING v_postp
w_item-postp. "L
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
ENDIF.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0130'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'BDC_SUBSCR'
'SAPLCSDI'.
PERFORM bdc_field USING 'BDC_SUBSCR'
'SAPLCSDI'.
PERFORM bdc_field USING 'RC29P-IDNRK'
w_item-idnrk. "cOMPONENT Number
MOVE W_item-menge TO v_menge1.
PERFORM bdc_field USING 'RC29P-MENGE'
v_menge1. "Quantity
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29P-POSNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0131'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'BDC_SUBSCR'
'SAPLCSDI'.
PERFORM bdc_field USING 'BDC_SUBSCR'
'SAPLCSDI'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29P-POTX1'.
PERFORM bdc_field USING 'RC29P-SANFE'
w_item-sanfe. "X
PERFORM bdc_field USING 'RC29P-RVREL'
w_item-rvrel. "X
PERFORM bdc_field USING 'RC29P-SANKA'
w_item-SANKA. "X
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
*First Screen Processing with 14 rows
IF idx = 14.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=FCNP'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29P-POSNR(02)'.
idx = 0.
flag = 1.
ENDIF.
*Second screen onwards processing with 13 rows
*As the first row in the next screen is always filled the last row of the previous row
IF idx = 13.
IF flag = 1.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29P-POSNR(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=FCNP'.
idx = 0.
ENDIF.
ENDIF.
idx = idx + 1.
index = index + 1.
IF index = counter_line_item.
PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC29P-POSTP(02)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=FCBU'.
PERFORM f_elog.
index = 0.
ENDIF.
ENDLOOP.
endif.
ENDLOOP.
ENDIF.
ENDFORM. " fill_bdcdata
----
Form to set error log *
----
----
*Setting the Error log to display Success or Error while creating the Sales Order *
----
FORM f_elog.
DATA len TYPE i.
CLEAR int_msgtab.
Call Transaction
CALL TRANSACTION 'CS01'
USING int_bdcdata
OPTIONS FROM w_ctu_params
MESSAGES INTO int_msgtab.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
Error/Sucess Handling
LOOP AT int_msgtab INTO w_msgtab
WHERE msgtyp = 'E'
OR msgtyp = 'S'.
*Selecting the Text from T100 Table (T100 stores all the messages while running any Transaction)
SELECT SINGLE text
FROM t100
INTO g_v_str_msg
WHERE sprsl EQ w_msgtab-msgspra AND
arbgb EQ w_msgtab-msgid AND
msgnr EQ w_msgtab-msgnr.
If entry found in T100 then the 4 fields MSGV1, MSGV2, MSGV3, MSGV4 are concatenated
IF sy-subrc EQ 0.
IF NOT w_msgtab-msgv1 IS INITIAL.
len = STRLEN( w_msgtab-msgv1 ).
REPLACE '&1' WITH w_msgtab-msgv1(len) INTO g_v_str_msg.
ENDIF.
IF NOT w_msgtab-msgv2 IS INITIAL.
len = STRLEN( w_msgtab-msgv2 ).
REPLACE '&2' WITH w_msgtab-msgv2(len) INTO g_v_str_msg.
ENDIF.
IF NOT w_msgtab-msgv3 IS INITIAL.
len = STRLEN( w_msgtab-msgv3 ).
REPLACE '&3' WITH w_msgtab-msgv3(len) INTO g_v_str_msg.
ENDIF.
IF NOT w_msgtab-msgv4 IS INITIAL.
len = STRLEN( w_msgtab-msgv4 ).
REPLACE '&' WITH w_msgtab-msgv4(len) INTO g_v_str_msg.
ENDIF.
TRANSLATE g_v_str_msg USING '& '.
CONDENSE g_v_str_msg.
ENDIF.
Display with Colour
IF w_msgtab-msgtyp EQ 'E'.
WRITE g_v_str_msg COLOR 6. "Red Colour
ELSE.
WRITE g_v_str_msg COLOR 5. "Green Colour
ENDIF.
ENDLOOP.
ENDFORM. "f_elog
----
*
Start new screen *
*
----
FORM bdc_dynpro USING program dynpro.
CLEAR int_bdcdata.
int_bdcdata-program = program.
int_bdcdata-dynpro = dynpro.
int_bdcdata-dynbegin = 'X'.
APPEND int_bdcdata.
ENDFORM. "bdc_dynpro
----
*
Insert field *
*
----
FORM bdc_field USING fnam fval TYPE any.
CLEAR int_bdcdata.
int_bdcdata-fnam = fnam.
int_bdcdata-fval = fval.
WRITE fval TO int_bdcdata-fval LEFT-JUSTIFIED.
APPEND int_bdcdata.
ENDFORM. "bdc_field
*********************************************************************************
E N D - O F - S E L E C T I O N *
*********************************************************************************
END-OF-SELECTION.
*Free all internal tables
FREE: int_head,
int_item,
int_output.
*********************************************************************************
E N D O F R E P O R T *
2012 Mar 01 11:30 AM
TABLES: MAPL, PLPO, PLAS.
INCLUDE BDCRECX1.
PARAMETERS : P_FILE TYPE STRING.
DATA: G_FILE TYPE IBIPPARMS-PATH.
DATA: LIN_COUNT(02),
X1(20),
X2(20),
X3(20),
X4(20),
X5(20),
X6(20),
X7(20),
FLAG(002), "Flag to select the assignment
CNT TYPE I,
CNT1 TYPE I,
CNT2 TYPE I,
OPNO(4) TYPE N,
SEQUENCE(6) TYPE N,
SET TYPE I.
DATA: BEGIN OF RECORD OCCURS 0,
COUNT(005), "Counter
MATNR_001(018), "Material No
WERKS_002(004), "Plant
STLAN_003(001), "Bom Usage
STLAL_004(002), "Alternative Bom
DATUV_005(010), "Valid-From Date
ZTEXT_006(040), "BOM Text
BMENG_007(017), "Base Quantity
LOSVN(013), "From Lot Size
LOSBS(013), "To Lot Size
STLST_008(002), "BOM Status
POSNR_012(004), "BOM Item Number
IDNRK_01_009(018), "Component
POSTP(001), "Item Category (Bill of Material)
MENGE_01_010(018), "Quantity
END OF RECORD.
**** End generated data section ***
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'P_FILE '
IMPORTING
FILE_NAME = G_FILE.
P_FILE = G_FILE.
START-OF-SELECTION.
PERFORM OPEN_GROUP.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = P_FILE
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = RECORD.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
2012 Mar 01 11:33 AM
code-2
LOOP AT RECORD.
ON CHANGE OF RECORD-COUNT. "record-matnr_001 OR RECORD-STLAL_004.
LIN_COUNT = 1.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC29N-DATUV'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RC29N-MATNR'
RECORD-MATNR_001.
PERFORM BDC_FIELD USING 'RC29N-WERKS'
RECORD-WERKS_002.
PERFORM BDC_FIELD USING 'RC29N-STLAN'
RECORD-STLAN_003.
PERFORM BDC_FIELD USING 'RC29N-STLAL'
RECORD-STLAL_004.
PERFORM BDC_FIELD USING 'RC29N-DATUV'
RECORD-DATUV_005.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0110'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC29K-BMENG'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RC29K-ZTEXT'
RECORD-ZTEXT_006.
PERFORM BDC_FIELD USING 'RC29K-BMENG'
RECORD-BMENG_007.
PERFORM BDC_FIELD USING 'RC29K-STLST'
RECORD-STLST_008.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0111'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC29K-LABOR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
ENDON.
PERFORM CONCAT.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0140'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'X5
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING X1 RECORD-POSNR_012.
PERFORM BDC_FIELD USING X2 "'RC29P-IDNRK(01)'
RECORD-IDNRK_01_009.
PERFORM BDC_FIELD USING X3 "'RC29P-MENGE(01)'
RECORD-MENGE_01_010.
PERFORM BDC_FIELD USING X5 "'RC29P-POSTP(01)'
RECORD-POSTP.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0130'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC29P-AUSCH'.
PERFORM BDC_FIELD USING 'RC29P-POSNR'
RECORD-POSNR_012.
IF RECORD-MATNR_001 EQ RECORD-IDNRK_01_009.
PERFORM BDC_FIELD USING 'RC29P-REKRS'
'X'.
ENDIF.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0131'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC29P-POSNR(01)'.
LIN_COUNT = LIN_COUNT + 1.
AT END OF COUNT. "MATNR_001.
PERFORM BDC_DYNPRO USING 'SAPLCSDI' '0140'.
*perform bdc_field using 'BDC_CURSOR'
* 'RC29P-POSNR(02)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=FCBU'.
PERFORM BDC_TRANSACTION USING 'CS01'.
ENDAT.
ENDLOOP.
PERFORM CLOSE_GROUP.
2012 Mar 01 11:35 AM
code-3.
*&---------------------------------------------------------------------*
*& Form CONCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CONCAT.
IF LIN_COUNT < 50.
CONCATENATE 'RC29P-POSNR(' LIN_COUNT ')' INTO X1.
CONCATENATE 'RC29P-IDNRK(' LIN_COUNT ')' INTO X2.
CONCATENATE 'RC29P-MENGE(' LIN_COUNT ')' INTO X3.
CONCATENATE 'RC29P-MEINS(' LIN_COUNT ')' INTO X4.
CONCATENATE 'RC29P-POSTP(' LIN_COUNT ')' INTO X5.
CONCATENATE 'RC29P-AUSKZ(' LIN_COUNT ')' INTO X6.
ENDIF.
ENDFORM. " CONCAT
all the 3 post wil complete the code,
hope this helps...even at this point of time the code might not be helpful for you.
CODE: For BOM Routing CS01 TCODE
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |