01-25-2007 12:43 PM
hi,please tell me how to handle the line items i.e the header data and item data in bdc?
provide me a clear vision?
01-25-2007 12:50 PM
Hi,
You will have the ful data in the internal table. first loop, we need to trigger only the header data with the help o\f Flag, and the second time, we use the same flag not to trigger the Header data, and trigger only the ITEM data. we can also use the Flag to trigger the item data in the loop, after the end of the item data for a record, we need to initial that Header falg, and when the loop start then we need to trigger the header data not the item data, and the next loop we we trigger only the item data not the header data, like wise we post the BDC data.
See the below link for an example Program ..
http://www.sap-img.com/abap/upload-the-pricing-condtion-records-for-materials.htm
Regards
Sudheer
01-25-2007 12:54 PM
go with this sample code
REPORT zsowja NO STANDARD PAGE HEADING LINE-SIZE 255.
DATA: bdcdat LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF record OCCURS 0,
data element: ELIFN
lifnr(010),
data element: EKORG
ekorg(004),
data element: BKGRP
ekgrp(003),
data element: EMATNR
ematn(018),
data element: BSTMG
menge(017),
data element: EWERK
werks(004),
END OF record.
DATA : BEGIN OF head_itab OCCURS 0,
data element: ELIFN
lifnr(010),
data element: EKORG
ekorg(004),
data element: BKGRP
ekgrp(003),
END OF head_itab.
DATA : BEGIN OF item_itab OCCURS 0,
data element: ELIFN
lifnr(010),
data element: EMATNR
ematn(018),
data element: BSTMG
menge(017),
data element: EWERK
werks(004),
END OF item_itab.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
filename = 'c:/hello.txt'
filetype = 'ASC'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = record
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 <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT record.
ON CHANGE OF record-lifnr.
head_itab-lifnr = record-lifnr.
head_itab-ekorg = record-ekorg.
head_itab-ekgrp = record-ekgrp.
APPEND head_itab.
CLEAR head_itab.
ENDON.
TO HAVE LINK BETWEEN HEADER AND ITEM TABLE USE LIFNR AS LINKER
item_itab-lifnr = record-lifnr.
item_itab-ematn = record-ematn.
item_itab-menge = record-menge.
item_itab-werks = record-werks.
APPEND item_itab.
CLEAR item_itab.
ENDLOOP.
*TO CHECH THE DATA IN HEADET ITAB AND DETAIL/ITEM ITAB
*
*loop at head_itab.
*write 😕 head_itab.
*endloop.
*skip 2.
*loop at item_itab.
*write:/ item_itab.
*endloop.
SORT head_itab BY lifnr ekorg ekgrp.
SORT item_itab BY lifnr.
DATA linecount TYPE i.
START-OF-SELECTION.
LOOP AT head_itab.
ON CHANGE OF head_itab-lifnr.
REFRESH bdcdat.
CLEAR bdcdat.
PERFORM bdc_dynpro USING 'SAPMM06E' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'EKKO-LIFNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'EKKO-LIFNR'
head_itab-lifnr.
PERFORM bdc_field USING 'EKKO-EKORG'
head_itab-ekorg.
PERFORM bdc_field USING 'EKKO-EKGRP'
head_itab-ekgrp.
linecount = 0.
<b>
LOOP AT item_itab WHERE lifnr = head_itab-lifnr.
linecount = linecount + 1.
IF linecount = 1.</b>
PERFORM bdc_dynpro USING 'SAPMM06E' '0120'.
PERFORM bdc_field USING 'BDC_CURSOR'
'EKPO-WERKS(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'EKPO-EMATN(01)'
item_itab-ematn.
PERFORM bdc_field USING 'EKPO-MENGE(01)'
item_itab-menge.
PERFORM bdc_field USING 'EKPO-WERKS(01)'
item_itab-werks.
PERFORM bdc_dynpro USING 'SAPMM06E' '0120'.
ELSE.
PERFORM bdc_field USING 'BDC_CURSOR'
'EKPO-WERKS(02)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=NP'.
PERFORM bdc_field USING 'EKPO-EMATN(02)'
item_itab-ematn.
PERFORM bdc_field USING 'EKPO-MENGE(02)'
item_itab-menge.
PERFORM bdc_field USING 'EKPO-WERKS(02)'
item_itab-werks.
PERFORM bdc_dynpro USING 'SAPMM06E' '0120'.
ENDIF.
AT END OF lifnr.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
ENDAT.
ENDLOOP.
ENDON.
CALL TRANSACTION 'ME21' USING bdcdat MODE 'A'.
REFRESH bdcdat.
ENDLOOP.
FORM bdc_dynpro USING value(a) value(b).
bdcdat-program = a.
bdcdat-dynpro = b.
bdcdat-dynbegin = 'X'.
APPEND bdcdat.
CLEAR bdcdat.
ENDFORM.
FORM bdc_field USING value(c) value(d).
bdcdat-fnam = c.
bdcdat-fval = d.
APPEND bdcdat.
CLEAR bdcdat.
ENDFORM.