Вы находитесь на странице: 1из 5

report ZPP_TEST_BDC

no standard page heading line-size 255.

include bdcrecx1.

parameters: dataset(132) lower case.


*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
* data element: AUFNR
AUFNR_001(012),
* data element: FLG_OVIEW
FLG_OVIEW_002(001),
* data element:
FILTER_BOX_003(020),
* data element:
SORT_BOX_004(020),
* data element: APOSN
POSNR_005(004),
* data element:
FILTER_BOX_006(020),
* data element:
SORT_BOX_007(020),
* data element: FLG_SEL
FLG_SEL_01_008(001),
* data element:
FILTER_BOX_009(020),
* data element:
SORT_BOX_010(020),
end of record.

*** End generated data section ***

start-of-selection.

perform open_dataset using dataset.


perform open_group.

do.

read dataset dataset into record.


if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPLCOKO1' '0110'.


perform bdc_field using 'BDC_CURSOR'
'CAUFVD-AUFNR'.
perform bdc_field using 'BDC_OKCODE'
'=KPU2'.
perform bdc_field using 'CAUFVD-AUFNR'
record-AUFNR_001.
perform bdc_field using 'R62CLORD-FLG_OVIEW'
record-FLG_OVIEW_002.
perform bdc_dynpro using 'SAPLCOMK' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RESBD-MATNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=AUFS'.
perform bdc_field using 'FILTER_BOX'
record-FILTER_BOX_003.
perform bdc_field using 'SORT_BOX'
record-SORT_BOX_004.
perform bdc_dynpro using 'SAPLCO05' '0110'.
perform bdc_field using 'BDC_CURSOR'
'RCOSU-POSNR'.
perform bdc_field using 'BDC_OKCODE'
'=MORE'.
perform bdc_field using 'RCOSU-POSNR'
record-POSNR_005.
perform bdc_dynpro using 'SAPLCOMK' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RESBD-POSNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=DEL'.
perform bdc_field using 'FILTER_BOX'
record-FILTER_BOX_006.
perform bdc_field using 'SORT_BOX'
record-SORT_BOX_007.
perform bdc_field using 'RC27X-FLG_SEL(01)'
record-FLG_SEL_01_008.
perform bdc_dynpro using 'SAPLCOMK' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RESBD-MATNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'FILTER_BOX'
record-FILTER_BOX_009.
perform bdc_field using 'SORT_BOX'
record-SORT_BOX_010.
perform bdc_transaction using 'CO02'.

enddo.

perform close_group.
perform close_dataset using dataset.

*&---------------------------------------------------------------------*
*& Report ZTEST5
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZTEST5.
*http://sap-abapworld.blogspot.com/2014/07/bdc-using-call-transaction-method-
in.html
*REPORT SSS.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
TYPES : BEGIN OF ty_excel,
EKORG TYPE EKORG,
KTOKK TYPE KTOKK,
NAME1 TYPE NAME1,
LAND1 TYPE LAND1,
END OF ty_excel.

*RF02K-EKORG
*RF02K-KTOKK
*LFA1-NAME1
*LFA1-LAND1

TYPES: BEGIN OF ty_mes_res,


message TYPE string,
END OF ty_mes_res.
DATA:
gv_name TYPE rlgrap-filename,
git_upl TYPE STANDARD TABLE OF ty_excel,
gwa_upl TYPE ty_excel,
git_mess TYPE STANDARD TABLE OF bdcmsgcoll,
gwa_mess TYPE bdcmsgcoll,
git_mes_res TYPE STANDARD TABLE OF ty_mes_res,
gwa_mes_res TYPE ty_mes_res,
gv_msg TYPE string,
gv_row_num TYPE char2.

TYPES: FS_STRUCT(4096) TYPE C OCCURS 0.


DATA: G_DAT TYPE FS_STRUCT .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file TYPE ibipparms-path.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'


EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = p_file.

AT SELECTION-SCREEN.

gv_name = p_file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = G_DAT
I_FILENAME = p_file
TABLES
I_TAB_CONVERTED_DATA = git_upl
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

start-of-selection.

LOOP AT git_upl INTO gwa_upl.


MOVE sy-tabix TO gv_row_num .
REFRESH bdcdata.
perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-EKORG'
gwa_upl-EKORG."record-MTART_001.
'icfc'.
perform bdc_field using 'RF02K-KTOKK'
gwa_upl-KTOKK."record-MTART_002.
'v005'.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-NAME1'
gwa_upl-NAME1."record-MTART_003.
'ppp'.
perform bdc_field using 'LFA1-LAND1'
gwa_upl-LAND1."record-MTART_003.
'in'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.

REFRESH : git_mess,git_mes_res.
CALL TRANSACTION 'MK01'
USING bdcdata
MODE 'A' "N E
UPDATE 'S' "A
MESSAGES INTO git_mess.

LOOP AT git_mess INTO gwa_mess.


CLEAR gv_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = gwa_mess-msgid
lang = '-D'
no = gwa_mess-msgnr
v1 = gwa_mess-msgv1
* V2 = SY-MSGV2
* V3 = SY-MSGV3
v4 = gwa_mess-msgv4
IMPORTING
msg = gv_msg.
MOVE gv_msg TO gwa_mes_res-message.
APPEND gwa_mes_res TO git_mes_res.
CLEAR : gwa_mes_res,gwa_mess.
ENDLOOP.
CONDENSE gv_row_num.
LOOP AT git_mes_res INTO gwa_mes_res.
WRITE : / 'Record -', gv_row_num,'|', gwa_upl-EKORG HOTSPOT ON, '|',
gwa_mes_res-message COLOR 3.
HIDE gwa_upl-EKORG.
ENDLOOP.
CLEAR :gv_row_num,gwa_upl.
ENDLOOP.

*perform close_group.
*perform close_dataset using dataset.
* ----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ''.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. "BDC_FIELD

Вам также может понравиться