TCODE CO02
RECORD Screen for BDC(SHDB)
Important point when recoding
Type order number -> press F6 -> component screen is come -> search for material which you want to update by using CRT+F -> then type your material number you want to update -> After find then again type next in number of material same box ( so that for Update material there is a need for new material number recoding is also come there )
If you are not able to do then copy the below code and submit your object
*&---------------------------------------------------------------------*
*& Report ZAPP_TRY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZPP_BDC_CO02.
TYPES: BEGIN OF TY_STR1,
AUFNR TYPE AUFNR ,
MATNR TYPE MATNR ,
MATNR1 TYPE MATNR,
LGORT(4) TYPE C,
* LGORT1(4) TYPE C,
END OF TY_STR1.
DATA : IT_ITAB TYPE TABLE OF TY_STR1,
WA_ITAB TYPE TY_STR1.
TYPES : BEGIN OF TY_ERROR,
INDEX TYPE C,
AUFNR TYPE AUFNR ,
TEXT(100) TYPE C ,
END OF TY_ERROR.
DATA: IT_ERROR TYPE TABLE OF TY_ERROR,
WA_ERROR TYPE TY_ERROR.
DATA: IT_BDCDATA TYPE TABLE OF BDCDATA,
WA_BDCDATA TYPE BDCDATA,
IT_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL,
WA_BDCMSGCOLL TYPE BDCMSGCOLL,
V_TEXT TYPE STRING .
DATA : V_FILE TYPE STRING,
V_INDEX TYPE I .
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS p_file TYPE FC03TAB-PL00_FILE.
SELECTION-SCREEN END OF BLOCK B1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM PATH_FOR_FILE.
AT SELECTION-SCREEN OUTPUT.
START-OF-SELECTION. " METHOD FOR FETECH DATA FROM PRESENTATION LAYER
V_FILE = P_FILE.
PERFORM UPLOAD_FILE. " METHOD FOR UPLOAD FILE FROM PRESENTATION LAYER
LOOP AT IT_ITAB INTO WA_ITAB .
V_INDEX = SY-TABIX.
REFRESH IT_BDCDATA.
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'
WA_ITAB-AUFNR.
perform bdc_field using 'R62CLORD-FLG_OVIEW'
'X'.
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'
'NO_FIL'.
perform bdc_field using 'SORT_BOX'
'ST_STA'.
perform bdc_dynpro using 'SAPLCO05' '0110'.
perform bdc_field using 'BDC_CURSOR'
'RCOSU-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'=MORE'.
perform bdc_field using 'RCOSU-MATNR'
WA_ITAB-MATNR.
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'
'NO_FIL'.
perform bdc_field using 'SORT_BOX'
'ST_STA'.
perform bdc_field using 'RESBD-MATNR(01)'
WA_ITAB-MATNR1.
perform bdc_field using 'RESBD-LGORT(01)'
WA_ITAB-LGORT.
perform bdc_dynpro using 'SAPLCOMD' '0110'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'RESBD-MATNR'.
perform bdc_field using 'RESBD-MATNR'
WA_ITAB-MATNR1.
*perform bdc_field using 'RESBD-POSNR'
* '0010'.
*perform bdc_field using 'RESBD-LGORT'
* WA_ITAB-LGORT1.
*perform bdc_field using 'RESBD-WERKS'
* 'SHLL'.
*perform bdc_field using 'RESBD-MENGE'
* '40'.
*perform bdc_field using 'RESBD-EINHEIT'
* '001'.
*perform bdc_field using 'RESBD-SANKA'
* 'X'.
*perform bdc_transaction using 'CO02'.
CALL TRANSACTION 'CO02' USING IT_BDCDATA MODE 'A' UPDATE 'A' MESSAGES INTO IT_BDCMSGCOLL .
IF SY-SUBRC <> 0 .
" ERROR MSG CALL
PERFORM ERROR_MSGCOLL.
ENDIF.
CLEAR WA_ITAB.
ENDLOOP.
PERFORM ERROR_CALL.
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_FILE .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = V_FILE
* FILETYPE = 'TEXT'
HAS_FIELD_SEPARATOR = 'T'
* 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 = IT_ITAB
* 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_FILE
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* UPDATES THE SCREEN DATA USING BDCDATA STRUCUTRE
*----------------------------------------------------------------------*
* -->P_0084 text
* -->P_0085 text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM LIKE BDCDATA-PROGRAM
DYNPRO LIKE BDCDATA-DYNPRO
.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM .
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM. " BDC_DYNPRO
" BDC_FIELD
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* UPDATES THE FIELD DATA USING BDCDATA STRUCUTRE
*---------------------------------------------------------------------*
* -->P_0089 text
* -->P_0090 text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING VALUE(P_0089)
VALUE(P_0090).
CLEAR WA_BDCDATA .
WA_BDCDATA-FNAM = P_0089.
WA_BDCDATA-FVAL = P_0090 .
APPEND WA_BDCDATA TO IT_BDCDATA .
ENDFORM. " BDC_FIELD
*&---------------------------------------------------------------------*
*& Form PATH_FOR_FILE
*&---------------------------------------------------------------------*
* PATH OF FILE (FETECH FROM PRESENTATION LAYER )
*----------------------------------------------------------------------*
FORM PATH_FOR_FILE .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
* PROGRAM_NAME = SYST-REPID
* DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'P_FILE'
* STATIC = ' '
* MASK = ' '
* FILEOPERATION = 'R'
CHANGING
FILE_NAME = P_FILE
* LOCATION_FLAG = 'P'
* EXCEPTIONS
* MASK_TOO_LONG = 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.
ENDFORM. " PATH_FOR_FILE
*&---------------------------------------------------------------------*
*& Form ERROR_MSGCOLL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ERROR_MSGCOLL .
LOOP AT IT_BDCMSGCOLL INTO WA_BDCMSGCOLL.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = WA_BDCMSGCOLL-MSGID
LANG = SY-LANGU
NO = WA_BDCMSGCOLL-MSGNR
V1 = WA_BDCMSGCOLL-MSGV1
V2 = WA_BDCMSGCOLL-MSGV2
V3 = WA_BDCMSGCOLL-MSGV3
V4 = WA_BDCMSGCOLL-MSGV4
IMPORTING
MSG = V_TEXT
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
WA_ERROR-INDEX = V_INDEX .
WA_ERROR-TEXT = V_TEXT.
WA_ERROR-AUFNR = WA_ERROR-AUFNR.
ENDIF.
CLEAR WA_BDCDATA.
ENDLOOP.
ENDFORM. " ERROR_MSGCOLL
*&---------------------------------------------------------------------*
*& Form ERROR_CALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ERROR_CALL .
IF NOT IT_ERROR IS INITIAL.
WRITE : /30 ' ERROR RECORDS DETAILS'.
SKIP 1.
WRITE : /5 'RECORD NUMBER ' ,15 SY-VLINE ,
17 'ORDER NUMBER ', 33 SY-VLINE , 36 'ERROR MESSAGE'.
ULINE.
LOOP AT IT_ERROR INTO WA_ERROR .
WRITE :/5 WA_ERROR-INDEX LEFT-JUSTIFIED,
20 SY-VLINE,
22 WA_ERROR-AUFNR,
32 SY-VLINE,
35 WA_ERROR-TEXT.
ENDLOOP.
ELSE.
WRITE : 'SUCEESFULLY UPDATED'.
ENDIF.
ENDFORM. " ERROR_CALL
No comments:
Post a Comment