Skip to Content
1
Former Member
Dec 16, 2012 at 03:38 AM

Problem in BDC FOr CA02

285 Views

Dear All,

i had develop BDC for ca02 to changes in routing data. doce i below shown. when i excute BDC that time changes only in first line but i want to directly changes in second or any other line. please give me solution ASAP. thanks in advance.

*&---------------------------------------------------------------------*
*& Report ZROUTING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZROUTING.


DATA: bdcdata_wa TYPE bdcdata,
bdcdata_tab TYPE TABLE OF bdcdata,
opt TYPE ctu_params.


DATA: it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

*----- Messages of call transaction
DATA: it_bdcmsgcoll LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.


*----- Local Variable to Capture the G/L Account Data
DATA: lv_koart LIKE bseg-koart, "Account Type
lv_umskz LIKE bseg-umskz, "Special G/L Account Indicator.
lv_poskey LIKE bseg-bschl, "Posting Key
lv_buvar LIKE t001-buvar, "Transaction (Screen) Variant
lv_umsks LIKE bseg-umsks, "Special G/L Ind. Type
lv_buzid LIKE bseg-buzid, "Identification of the Line Item
lv_buzei LIKE bsed-buzei, "Line Item Within Accounting Document
lv_bstat LIKE bkpf-bstat, "Document Status
lv_dynnr LIKE t019-dynnr, "Screen Number
lv_winfk LIKE t019w-winfk, "Window Function Code
lv_winnr LIKE t019w-winnr, "Window Number
lv_mpool LIKE t019w-mpool, "Module Pool
lv_opt LIKE ctu_params. "Screen Mode

*----- To Capture the File Path into the string
DATA: lv_file_string TYPE string,
lv_messg TYPE string,
lv_ok_code(5) TYPE c. " OK-Code

*----------------------------------------------------------------------*
* Constants Declaration
*----------------------------------------------------------------------*
CONSTANTS: c_bukrs TYPE t001-bukrs VALUE '1000',
c_ctum TYPE ctu_params-dismode VALUE 'N',
c_cupd TYPE ctu_params-updmode VALUE 'A',
c_delim TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
c_nodata VALUE ' ',
c_char_a TYPE c VALUE 'A',
c_char_d TYPE c VALUE 'D',
c_char_f TYPE c VALUE 'F',
c_char_k TYPE c VALUE 'K',
c_char_o TYPE c VALUE 'O',
c_char_p TYPE c VALUE 'P',
c_char_m TYPE c VALUE 'M',
c_char_s TYPE c VALUE 'S',
c_char_w TYPE c VALUE 'W',
c_char_x TYPE c VALUE 'x'.
* DATA: xserial TYPE c LENGTH 2,
* yserial TYPE bdcdata-fval,
* XITEM TYPE C LENGTH 2,
* yitem type c LENGTH 4,
* count type i,
* flag.

TYPES : BEGIN OF ty_final,
matnr TYPE matnr,
WERKS TYPE WERKS,
sttag TYPE sttag,
ENTRY_ACT TYPE ENTRY_ACT,
ARBPL TYPE ARBPL,
LTXA1 TYPE LTXA1,
VGW01 TYPE VGW01,
END OF ty_final.
DATA : it_final TYPE STANDARD TABLE OF ty_final,
wa_final TYPE ty_final.
daTA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA :V_COUNT1 TYPE I.

DATA: V_COUNT(3) TYPE C.

DATA: V_CHAR(16).

PARAMETERS: P_FILE TYPE LOCALFILE DEFAULT 'D:\ROUTING.TXT'.
START-OF-SELECTION.
DATA: W_FILE TYPE STRING.

W_FILE = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = W_FILE
FILETYPE = 'DAT'
* HAS_FIELD_SEPARATOR = ' '
* 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_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 'BDC_OPEN_GROUP'
* EXPORTING
* CLIENT = SY-MANDT
** DEST = FILLER8
* GROUP = FILLER12
** HOLDDATE = FILLER8
** KEEP = FILLER1
** USER = FILLER12
** RECORD = FILLER1
** PROG = SY-CPROG
** DCPFM = '%'
** DATFM = '%'
** IMPORTING
** QID =
** EXCEPTIONS
** CLIENT_INVALID = 1
** DESTINATION_INVALID = 2
** GROUP_INVALID = 3
** GROUP_IS_LOCKED = 4
** HOLDDATE_INVALID = 5
** INTERNAL_ERROR = 6
** QUEUE_ERROR = 7
** RUNNING = 8
** SYSTEM_LOCK_ERROR = 9
** USER_INVALID = 10
** OTHERS = 11
* .
*IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.





*PERFORM getdata.
PERFORM bdc.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form BDC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC .
*SAPLCPDI 1010 X

* BDC_CURSOR RC27M-WERKS
* BDC_OKCODE /00
* RC27M-MATNR SRT400-26CAM
* RC27M-WERKS ta02
* RC271-STTAG 15.12.2012
*SAPLCPDI 1400 X

*

* CONCATENATE 'RF05L-ANZDT' '(' XITEM ')' INTO yserial.
LOOP at it_final INTO wa_final.
PERFORM bdc_dynpro USING 'SAPLCPDI' '1010'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC27M-WERKS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RC27M-MATNR'
WA_FINAL-MATNR.
PERFORM bdc_field USING 'RC27M-WERKS'
WA_FINAL-WERKS.
* PERFORM bdc_field USING 'RC271-STTAG'
* WA_FINAL-sttag.

* BDC_CURSOR PLPOD-VGW01(01)
* BDC_OKCODE =BU
* RC27X-ENTRY_ACT 1
* PLPOD-ARBPL(01) WC900
* PLPOD-LTXA1(01) FITTING02
* PLPOD-VGW01(01) 2.50

* do count times.
PERFORM bdc_dynpro USING 'SAPLCPDI' '1400'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'
'PLPOD-VGW01(01)' .

PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
* enddo.
*do count times.


*LOOP AT IT_fINAL INTO WA_FINAL.
BREAK 10115.
V_COUNT1 = V_COUNT1 + 1.

V_COUNT = V_COUNT1.

CONDENSE V_COUNT.

CONCATENATE 'WA_FINAL-ENTRY_ACT' '(' V_COUNT ')' INTO V_CHAR.

DO v_count TIMES.
BREAK 10115.
* PERFORM bdc_field USING 'RC27X-ENTRY_ACT'
* WA_FINAL-ENTRY_ACT.
* CLEAR V_CHAR.
CONCATENATE 'WA_FINAL-ARBPL' '(' V_COUNT' )' INTO V_CHAR.

PERFORM bdc_field USING 'PLPOD-ARBPL(01)'
WA_FINAL-ARBPL.
CLEAR V_CHAR.

CONCATENATE 'WA_FINAL-LTXA1' '(' V_COUNT ')' INTO V_CHAR.
PERFORM bdc_field USING 'PLPOD-LTXA1(01)'
WA_FINAL-LTXA1.
CLEAR V_CHAR.

CONCATENATE 'WA_FINAL-VGW01' '(' V_COUNT ')' INTO V_CHAR.
PERFORM bdc_field USING 'PLPOD-VGW01(01)'
WA_FINAL-VGW01.
CLEAR V_CHAR.
ENDDO.
*
*IF V_COUNT1 = 24.
*
* V_COUNT1 = 1.

perform bdc_field using 'BDC_OKCODE'
'=BU'.

*ENDIF.
*ENDLOOP.
BREAK 10115.
*CALL FUNCTION 'BDC_INSERT'
* EXPORTING
* TCODE = 'CA02'
** POST_LOCAL = NOVBLOCAL
** PRINTING = NOPRINT
** SIMUBATCH = ' '
** CTUPARAMS = ' '
* TABLES
* DYNPROTAB = it_BDCDATA
** EXCEPTIONS
** INTERNAL_ERROR = 1
** NOT_OPEN = 2
** QUEUE_ERROR = 3
** TCODE_INVALID = 4
** PRINTING_INVALID = 5
** POSTING_INVALID = 6
** OTHERS = 7
* .
*IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.





*
* lv_opt-defsize = 'X'.
* lv_opt-dismode = c_ctum.
** lv_opt-RACOMMIT = 'X'.
* lv_opt-updmode = c_cupd.

*------ Call the Tcode for the data upload
CALL TRANSACTION 'CA02'
USING it_bdcdata
OPTIONS FROM lv_opt
MESSAGES INTO it_bdcmsgcoll.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

REFRESH it_bdcdata.
ENDLOOP.




COMMIT WORK.
*------ Looping at BDCMSGCOLL to Track the Errors
LOOP AT it_bdcmsgcoll.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_bdcmsgcoll-msgid
lang = it_bdcmsgcoll-msgspra
no = it_bdcmsgcoll-msgnr
v1 = it_bdcmsgcoll-msgv1
v2 = it_bdcmsgcoll-msgv2
v3 = it_bdcmsgcoll-msgv3
v4 = it_bdcmsgcoll-msgv4
IMPORTING
msg = lv_messg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0. "#EC
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE:/ it_bdcmsgcoll-msgtyp, lv_messg.
ENDIF.
ENDLOOP.





ENDFORM. " BDC
*&---------------------------------------------------------------------*
**& Form BDC_DYNPRO
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->P_0323 text
** -->P_0324 text
**----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
* value(p_0324).
CLEAR it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0328 text
* -->P_0329 text
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
" value(p_0328)
"value(p_0329).
IF fval <> c_nodata.
CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDIF.




**
** CALL FUNCTION 'BDC_CLOSE_GROUP'
** EXCEPTIONS
** NOT_OPEN = 1
** QUEUE_ERROR = 2
** OTHERS = 3
** .
**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. " BDC_FIELD