‎2007 Jul 03 8:23 PM
Hi Experts,
I have a tricky situation here. We have a program to load the master recipe(tcode C201) into SAP from a file. This was written long time back. Now I have to formulate the input file to make this program work. But honestly I am unable to do this. Can somebody please let me know what is the format of the input file.
I appreciate your help.
Regards.
SK
Here's the program..............
REPORT zvtest1 MESSAGE-ID fb.
DATA: rec_type, "record type 0 = header,
" 1=material allocation
" 2 = operation detail
sv_rec_type,
fcode(4),
first_time_in_op(1),
op_line(2) TYPE n,
scr_line(2) TYPE n,
workspace(200).
DATA: BEGIN OF hdr_rec,
plnnr(8), "planner group
profidnetz(7), "profile id
werks(4), "Plant
ktext(40), " recipe text
verwe(3), " usage
statu(3), " status
losvn(13), " qty from
losbs(13), " qty to
plnme(3), " header uom
END OF hdr_rec.
DATA: BEGIN OF oper_rec,
vornr(4), " activity #
phflg(1), "phase flag
pvznr(4), " superior oper#
phseq(2), " control recipe dest
arbpl(8), " resource
ltxa1(40), " oper short desc
vgw01(11), "duration
vge01(3), "duration units
bmsch(13), "base
steus(4), "control key
END OF oper_rec.
DATA: BEGIN OF mtl_rec,
plnal(2), " recipe #
matnr(18), " bulk material
werks(4), " Plant
verid(4), "production verion#
stlal(2), "Alt BOM
stlan(1), "BOM usage
END OF mtl_rec.
DATA: fld_vornr(15),
fld_phflg(15),
fld_pvznr(15),
fld_phseq(15),
fld_arbpl(15),
fld_ltxa1(15),
fld_flg_sel(17),
fld_prev_flg(17),
fld_steus(17).
DATA: first-rec TYPE c VALUE 'Y',
first-header TYPE c VALUE 'Y'.
PARAMETERS file(70) DEFAULT 'm:\sapc\spf3'.
DATA: wa LIKE workspace OCCURS 0 WITH HEADER LINE,
bdc_tab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
AT SELECTION-SCREEN.
OPEN DATASET file FOR INPUT IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE e002(fb) WITH file.
File & could not be opened
ENDIF.
START-OF-SELECTION.
DO.
READ DATASET file INTO wa.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND wa.
ENDDO.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'RECIPE'
keep = 'X'
user = sy-uname.
LOOP AT wa.
IF first-rec = 'N'.
CASE rec_type.
WHEN '0'.
op_line = 0.
IF first-header = 'N'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'C201'
TABLES
dynprotab = bdc_tab
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
OTHERS = 5.
REFRESH bdc_tab.
ENDIF.
first-header = 'N'.
*
PERFORM generate_hdr_data. " fill bdc_table
WHEN '1'.
PERFORM generate_mtl_alloc_data. " fill bdc_table
WHEN '2'.
op_line = op_line + 1.
PERFORM generate_detail_data.
IF oper_rec-phflg = 'X'.
PERFORM generate_std_data.
ENDIF.
ENDCASE.
ENDIF.
first-rec = 'N'.
sv_rec_type = rec_type.
rec_type = wa(1).
CASE rec_type.
WHEN '0'.
IF first-header <> 'Y'. "last record for group
PERFORM save_recipe.
ENDIF.
MOVE wa+1 TO hdr_rec.
first_time_in_op = 'Y'.
WHEN '1'.
MOVE wa+1 TO mtl_rec.
WHEN '2'.
MOVE wa+1 TO oper_rec.
ENDCASE.
ENDLOOP.
save last record group
CASE rec_type.
WHEN '0'.
PERFORM generate_hdr_data. " fill bdc_table
WHEN '1'.
PERFORM generate_mtl_alloc_data. " fill bdc_table
WHEN '2'.
op_line = op_line + 1.
PERFORM generate_detail_data.
IF oper_rec-phflg = 'X'.
PERFORM generate_std_data.
ENDIF.
ENDCASE.
PERFORM save_recipe.
submit the job to the system, it's completed.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'C201'
TABLES
dynprotab = bdc_tab
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
OTHERS = 5.
End the batch transaction...
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /'Session created'.
END-OF-SELECTION.
&----
*& Form GENERATE_HDR_DATA
&----
Input the header data into the appropriate screen fields.
----
FORM generate_hdr_data.
PERFORM dynpro USING:
'X' 'SAPLCPDI' '4000', " Initial Screen
' ' 'RC271-PLNNR' hdr_rec-plnnr, " recipe group
' ' 'RC271-PROFIDNETZ' hdr_rec-profidnetz, " Document type
' ' 'RC271-WERKS' hdr_rec-werks, " Plant
' ' 'RC271-STTAG' '08111998',
' ' 'BDC_OKCODE' ' ', " set up recipe
'X' 'SAPLCPDA' '4210', "Header general view
' ' 'PLKOD-KTEXT' hdr_rec-ktext, "recipe short desc
' ' 'PLKOD-VERWE' hdr_rec-verwe, "usage
' ' 'PLKOD-STATU' hdr_rec-statu, "recipe status
' ' 'PLKOD-LOSVN' hdr_rec-losvn, "charge from
' ' 'PLKOD-LOSBS' hdr_rec-losbs, "charge to
' ' 'PLKOD-PLNME' hdr_rec-plnme. "header UOM
' ' 'BDC_OKCODE' '/16 '. "go to operations
ENDFORM. " GL_HDR_DATA
&----
*& Form GENERATE_MTL_ALLOC
&----
Input the material allocation.
----
FORM generate_mtl_alloc_data.
PERFORM dynpro USING:
' ' 'BDC_OKCODE' '/16',
'X' 'SAPLCZDI' '4230', " Material alloc screen
' ' 'MAPL-PLNAL(1)' mtl_rec-plnal, " recipe #
' ' 'MAPL-MATNR(1)' mtl_rec-matnr, " Bulk material
' ' 'MAPL-WERKS(1)' mtl_rec-werks, " Plant
' ' 'BDC_OKCODE' '/2 ', " go to prod version
'X' 'SAPLCMFV' '0200', "Prod version screen
' ' 'MKAL-VERID' mtl_rec-verid, "recipe short desc
' ' 'MKAL-STLAL' mtl_rec-stlal, "Alt BOM
' ' 'MKAL-STLAN' mtl_rec-stlan, "BOM usage
' ' 'BDC_OKCODE' ' ', "go back
'X' 'SAPLCZDI' '4230', "back to alloc screen
' ' 'BDC_OKCODE' '/8 ', "go back to hdr
'X' 'SAPLCPDA' '4210'.
' ' 'BDC_OKCODE' '/8 '. "go to oper screen
ENDFORM. " generate_mtl_alloc_data
&----
*& Form generate_detail_data.
&----
Input the detail data into the appropriate screen fields. *
----
FORM generate_detail_data.
IF op_line > 10.
scr_line = ( op_line MOD 9 ).
CASE scr_line.
WHEN 0.
scr_line = 9.
WHEN 1.
scr_line = 10.
WHEN 2.
PERFORM dynpro USING:
' ' 'BDC_OKCODE' '/23 '.
ENDCASE.
ELSE.
scr_line = op_line.
ENDIF.
CONCATENATE 'PLPOD-VORNR(' scr_line ')' INTO fld_vornr.
CONCATENATE 'PLPOD-PHFLG(' scr_line ')' INTO fld_phflg.
CONCATENATE 'PLPOD-PVZNR(' scr_line ')' INTO fld_pvznr.
CONCATENATE 'PLPOD-PHSEQ(' scr_line ')' INTO fld_phseq.
CONCATENATE 'PLPOD-ARBPL(' scr_line ')' INTO fld_arbpl.
CONCATENATE 'PLPOD-LTXA1(' scr_line ')' INTO fld_ltxa1.
CONCATENATE 'PLPOD-STEUS(' scr_line ')' INTO fld_steus.
first time in this screen for a product, we have to set send a
function code to indicate which screen we want to go to. We may
either be coming from the header screen or the material allocation
screen.
IF first_time_in_op = 'Y'.
if sv_rec_type = '0'. " no material allocation record
fcode = '/8'. " header was last screen
else.
fcode = '/16'. " material allocation was last screen
endif.
PERFORM dynpro USING:
' ' 'BDC_OKCODE' '/8'.
first_time_in_op = 'N'.
ENDIF.
PERFORM dynpro USING:
'X' 'SAPLCPDI' '4400', "Operations overview
' ' fld_vornr oper_rec-vornr, "activity
' ' fld_phflg oper_rec-phflg, "phase flag
' ' fld_pvznr oper_rec-pvznr, "superior op#
' ' fld_phseq oper_rec-phseq, "control recipe dest
' ' fld_arbpl oper_rec-arbpl, "resource
' ' fld_steus oper_rec-steus, "control key
' ' fld_ltxa1 oper_rec-ltxa1, "operation description
' ' 'BDC_OKCODE' ' '.
ENDFORM. " GL_G001_DATA
&----
*& Form save_recipe.
&----
Input the save command. *
----
FORM save_recipe.
PERFORM dynpro USING:
' ' 'BDC_OKCODE' '/11 '.
ENDFORM. " GL_G001_DATA
&----
*& Form GENERATE_STD_DATA
&----
Input the header data into the appropriate screen fields.
----
FORM generate_std_data.
CONCATENATE 'RC27X-FLG_SEL(' scr_line ')' INTO fld_flg_sel.
PERFORM dynpro USING:
' ' fld_flg_sel 'X', "mark selected activity
' ' 'BDC_OKCODE' 'ARBD'," go to std values screen
'X' 'SAPLCPDO' '4410', "STD values screen
' ' 'bdc_okcode' ' ',
' ' 'bdc_okcode' '/00',
'X' 'SAPLCPDO' '4410',
' ' 'PLPOD-VGW01' oper_rec-vgw01, "duration
' ' 'PLPOD-VGE01' oper_rec-vge01. "duration units
IF oper_rec-bmsch = ' /'.
PERFORM dynpro USING:
'X' 'SAPLCPDO' '4410',
' ' 'BDC_OKCODE' '/3 '.
ELSE.
PERFORM dynpro USING:
'X' 'SAPLCPDO' '4410',
' ' 'PLPOD-BMSCH' oper_rec-bmsch, "base
' ' 'bdc_okcode' '/3 '. "go back to select screen
ENDIF.
PERFORM dynpro USING:
'X' 'SAPLCPDI' '4400', "Operations screen
' ' fld_flg_sel ' '. "mark selected activity
ENDFORM. " generate_std_data
&----
&----
*& Form DYNPRO
&----
FORM dynpro USING dynbegin name value.
Clean bdc-tab for all processing...
CLEAR bdc_tab.
IF dynbegin = 'X'. " Initialize the first screen.
MOVE: name TO bdc_tab-program,
value TO bdc_tab-dynpro ,
'X' TO bdc_tab-dynbegin.
ELSE. " Perform input into the screen
MOVE: name TO bdc_tab-fnam,
value TO bdc_tab-fval.
ENDIF.
Append bdc_tab for all processing...
APPEND bdc_tab.
ENDFORM. " DYNPRO
‎2007 Jul 03 9:07 PM
Depending on the first character of each record, the rest of the record is read into either structure hdr_rec, oper_rec or mtl_rec.
Rob
‎2007 Jul 03 8:50 PM
Hi,
in your program, the format of the input file is TEXT.
analyse the below code, definetly you will find the solution.
DATA FNAME VALUE myfile.
DATA: TEXT1 VALUE abcdefghijkl,
TEXT2,
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2, LENG.
IF SY-SUBRC 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
The output is:
0 abcde 5
0 fghij 5
4 kl### 2This example fills the file myfile with 12 bytes from the field TEXT1. It is then read into the field TEXT2 in 5-byte portions. Note here that the system fills up the last three bytes of TEXT2 with zeros after the end of the file has been reached. The number of bytes transferred is contained in the field LENG.
If you are working in text mode, you can use the LENGTH addition to find out the length of the current line in the file. The system sets the value of the variable to the length of the line. The system calculates this by counting the number of bytes between the current position and the next end of line marker in the file.
DATA FNAME VALUE myfile.
DATA: TEXT1 VALUE 1234 ,
TEXT2 VALUE 12345678,
TEXT3,
LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE.
TRANSFER: TEXT1 TO FNAME,
TEXT2 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
DO 2 TIMES.
READ DATASET FNAME INTO TEXT3 LENGTH LENG.
WRITE: / TEXT3, LENG.
ENDDO.
CLOSE DATASET FNAME.
The output appears as follows:
12 4
12 8This example writes the strings TEXT1 and TEXT2 to the file myfile in text mode. They are then read into the string TEXT3 (length 2). The amount of memory occupied by the lines is read into the field LENG.
regards,
Ashok Reddy
‎2007 Jul 03 9:07 PM
Depending on the first character of each record, the rest of the record is read into either structure hdr_rec, oper_rec or mtl_rec.
Rob