Register Login

BDC Call Transaction-PO with Items

Updated May 18, 2018

REPORT ZPO_BDC.

TYPES: BEGIN OF STR_FINAL,

FIELD1 TYPE CHAR18,
FIELD2 TYPE CHAR18,
FIELD3 TYPE CHAR18,
END OF STR_FINAL.

TYPES : BEGIN OF STR_HEADER,

EBELN TYPE ZBC2_DVG_PO1-EBELN,
LIFNR TYPE ZBC2_DVG_PO1-LIFNR,
BEDAT TYPE ZBC2_DVG_PO1-BEDAT,
END OF STR_HEADER.

TYPES : BEGIN OF STR_ITEM,

EBELN TYPE ZBC2_DVG_PO1-EBELN,
MATNR(13), "TYPE ZBC2_DVG_PO2-MATNR,
MENGE(13),
END OF STR_ITEM.

DATA : TD_FINAL TYPE STANDARD TABLE OF STR_FINAL,

TD_HEADER TYPE STANDARD TABLE OF STR_HEADER,
TD_ITEM TYPE STANDARD TABLE OF STR_ITEM,
TD_BDCDATA TYPE STANDARD TABLE OF BDCDATA,
TD_MESSAGE TYPE STANDARD TABLE OF BDCMSGCOll.

DATA : WA_FINAL TYPE STR_FINAL,

WA_HEADER TYPE STR_HEADER,
WA_ITEM TYPE STR_ITEM,
WA_BDCDATA TYPE BDCDATA,
WA_MESSAGE TYPE BDCMSGCOLL,
WA_TEMP TYPE STR_FINAL.

PARAMETERS: MAIN TYPE localfile.

Data: F_NAME TYPE string,

F_NAME1 TYPE string,
L_MSG TYPE string,
VAL TYPE N,
V_MATNR TYPE STRING,
V_MENGE TYPE STRING.

AT SELECTION-SCREEN on VALUE-REQUEST FOR MAIN.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = MAIN.

F_NAME = MAIN.

AT SELECTION-SCREEN on VALUE-REQUEST FOR ITEM.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = ITEM.
F_NAME1 = ITEM.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = F_NAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = TD_FINAL
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.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = F_NAME1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'

HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = TD_ITEM
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.
LOOP AT TD_FINAL INTO WA_FINAL.
MOVE-CORRESPONDING WA_FINAL TO WA_TEMP.
AT NEW FIELD1.
WA_HEADER-EBELN = WA_TEMP-FIELD1.
WA_HEADER-LIFNR = WA_TEMP-FIELD2.
WA_HEADER-BEDAT = WA_TEMP-FIELD3.
APPEND WA_HEADER TO TD_HEADER.
CONTINUE.
ENDAT.
WA_ITEM-EBELN = WA_TEMP-FIELD1.
WA_ITEM-MATNR = WA_TEMP-FIELD2.
WA_ITEM-MENGE = WA_TEMP-FIELD3.
APPEND WA_ITEM TO TD_ITEM.
CLEAR WA_ITEM.
CLEAR WA_TEMP.
ENDLOOP.
loop at TD_HEADER INTO WA_HEADER.
refresh TD_BDCDATA.
PERFORM GET_BDCDATA.

CALL TRANSACTION 'ZPO' USING TD_BDCDATA mode 'A' MESSAGES INTO TD_MESSAGE.

ENDLOOP.

IF NOT TD_MESSAGE IS INITIAL.

LOOP AT TD_MESSAGE INTO WA_MESSAGE.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = WA_MESSAGE-MSGID
LANG = SY-LANGU
NO = WA_MESSAGE-MSGNR
V1 = WA_MESSAGE-MSGV1
V2 = WA_MESSAGE-MSGV2
V3 = WA_MESSAGE-MSGV3
V4 = WA_MESSAGE-MSGV4
IMPORTING
MSG = L_MSG
EXCEPTIONS
NOT_FOUND = 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.

WRITE :/ L_MSG.
ENDIF.
ENDLOOP.
ENDIF.
&---------------------------------------------------------------------
& Form GET_BDCDATA
&---------------------------------------------------------------------
text

--> p1 text
<-- p2 text

FORM GET_BDCDATA .

perform bdc_dynpro using 'ZBC2_DVG_PO' '9000'.
perform bdc_field using 'BDC_CURSOR'
'WA_FINAL-MENGE(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'WA_PO1-EBELN' wa_header-ebeln.
perform bdc_field using 'WA_PO1-LIFNR' wa_header-lifnr.
perform bdc_field using 'WA_PO1-BEDAT' wa_header-bedat.
val = 0.
loop at TD_item into wa_item
where ebeln = wa_header-ebeln.
val = val + 1.

CONCATENATE 'WA_FINAL-MATNR(' VAL' )' INTO V_MATNR.
perform bdc_field using V_MATNR WA_ITEM-MATNR.

CONCATENATE 'WA_FINAL-MENGE(' VAL' )' INTO V_MENGE.
perform bdc_field using V_MENGE WA_ITEM-MENGE.

perform bdc_dynpro using 'ZBC2_DVG_PO' '9000'.
perform bdc_field using 'BDC_CURSOR'
'WA_FINAL-MENGE(02)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
ENDLOOP.
perform bdc_field using 'BDC_OKCODE'
'=CREATE'.
perform bdc_dynpro using 'ZBC2_DVG_PO' '9000'.
perform bdc_field using 'BDC_CURSOR'
'WA_PO1-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=EXIT'.

ENDFORM. " GET_BDCDATA

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM.
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO TD_BDCDATA.
ENDFORM.

Insert field

FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> NODATA.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO TD_BDCDATA.
ENDIF.
ENDFORM.

Flat File

4001 5003 02042011
4001 5001 50
4001 5003 80
4002 5001 02042011
4002 5001 60
4002 5003 80
4002 5004 50
4002 5005 80


×