Skip to Content
0
Former Member
Jan 05, 2008 at 06:45 AM

BDC for CJ20N

365 Views

Hi Sapgurus,

I written one bdc program for CJ20N. My requirement is to create project defination by using existing project defination.

In recording iam clicking network overview buttton but

that ok-code is not capturing what might be the reason.

Iam also atta ching the code please have look and let me know the changes required.

Thanks & regards

Rahul

==========================================

report ZTESTPS4

no standard page heading line-size 255.

include ymm_bdcrecx1.

start-of-selection.

DATA : BEGIN OF IT_DATA OCCURS 0,

VSPSPID1(24), "Project Defination

POST1(40) , "PS Short Description

PLFAZ(10), "Project planned Start Date

PLSEZ(10), "Project Planned finish Date

VORLAGE(24), "Reference Project Defination

SUCHEN(24), "Character String to be Searched

ERSETZEN(24), "character String to be Inserted

AUFNR1(12), "NetWork Number

AUFNR2(12), "NetWork Number

POST2(40), "PS Short Description

END OF IT_DATA.

start-of-selection.

*********************************************************************

  • Internal Table T_BDCDATA to store BDC data

*********************************************************************

  • Batchinputdata of single transaction

DATA: T_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

*********************************************************************

  • Internal Table T_BDC_MSG to store BDC messages

*********************************************************************

DATA: T_BDC_MSG LIKE STANDARD TABLE OF BDCMSGCOLL INITIAL

SIZE 0 WITH HEADER LINE.

DATA: V_FILE LIKE RLGRAP-FILENAME ,

V_COUNT(5) TYPE C,

V_MESSAGE_CNT(5) TYPE C .

START-OF-SELECTION.

PERFORM OPEN_GROUP.

PERFORM DATA_UPLOAD.

PERFORM CALL_TRANSACTION.

PERFORM CLOSE_GROUP.

PERFORM WRITE_ERROR.

&----


*& Form DATA_UPLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DATA_UPLOAD.

*call function ws_upload to retrieve data from a flat file in the

*presentation server into an internal table

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = V_FILE

FILETYPE = 'DAT'

TABLES

DATA_TAB = IT_DATA

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

  • if ws_upload fails then display appropriate message

IF SY-SUBRC <> 0.

  • MESSAGE E000 WITH 'Data not Uploaded into internal table'.

ENDIF.

ENDFORM. " DATA_UPLOAD

&----


*& Form CALL_TRANSACTION

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CALL_TRANSACTION.

DATA : V_IVDAT(10) TYPE C,

V_AKTIV(10) TYPE C,

V_MESSAGE(404) TYPE C.

REFRESH T_BDCDATA.

CLEAR T_BDCDATA.

V_COUNT = 0.

V_MESSAGE_CNT = 0.

LOOP AT IT_DATA .

V_COUNT = V_COUNT + 1.

perform bdc_dynpro using 'SAPLCNPB_M' '1000'.

perform bdc_field using 'BDC_OKCODE'

'=COPY_PRJ'.

perform bdc_dynpro using 'SAPLCJWB' '0110'.

perform bdc_field using 'BDC_CURSOR'

'RCWKP-VORLAGE'.

perform bdc_field using 'BDC_OKCODE'

'=LETC'.

perform bdc_field using 'RCWKP-VSPSPID'

IT_DATA-VSPSPID1.

perform bdc_field using '*PROJ-POST1'

IT_DATA-POST1.

perform bdc_field using '*PROJ-PLFAZ'

IT_DATA-PLFAZ.

perform bdc_field using '*PROJ-PLSEZ'

IT_DATA-PLSEZ.

perform bdc_field using 'RCWBS-PROFL'

''.

perform bdc_field using 'RCWKP-VORLAGE'

IT_DATA-VORLAGE.

perform bdc_field using 'RCWBT-INCLA'

'X'.

perform bdc_field using 'RC62C-COPY_MAT'

'X'.

perform bdc_field using 'RC62C-COPY_AOB'

'X'.

perform bdc_field using 'RC62C-COPY_PST'

'X'.

perform bdc_field using 'RC62C-COPY_MLS'

'X'.

perform bdc_field using 'RC62C-COPY_DOCL'

'X'.

perform bdc_dynpro using 'SAPLCJWB' '0900'.

perform bdc_field using 'BDC_CURSOR'

'PROJ-PSPID'.

perform bdc_field using 'BDC_OKCODE'

'=NUM2'.

perform bdc_dynpro using 'SAPLCJWB' '0560'.

perform bdc_field using 'BDC_CURSOR'

'RCWKP-ERSETZEN'.

perform bdc_field using 'BDC_OKCODE'

'=NUM2'.

perform bdc_field using 'RCWKP-SUCHEN'

IT_DATA-SUCHEN.

perform bdc_field using 'RCWKP-ERSETZEN'

IT_DATA-ERSETZEN.

perform bdc_dynpro using 'SAPLCJWB' '0900'.

perform bdc_field using 'BDC_OKCODE'

'/ENEB'.

perform bdc_field using 'BDC_CURSOR'

'PROJ-PSPID'.

perform bdc_field using 'PROJ-POST1'

'Unit Testing'.

perform bdc_dynpro using 'SAPLSPO3' '0100'.

perform bdc_field using 'BDC_CURSOR'

'SPOP-VARVALUE1'.

perform bdc_field using 'BDC_OKCODE'

'=PICK'.

perform bdc_field using 'SPOP-VARVALUE1'

IT_DATA-AUFNR1.

perform bdc_dynpro using 'SAPLSPO3' '0100'.

perform bdc_field using 'BDC_CURSOR'

'SPOP-VARVALUE1'.

perform bdc_field using 'BDC_OKCODE'

'=PICK'.

perform bdc_field using 'SPOP-VARVALUE1'

IT_DATA-AUFNR2.

perform bdc_dynpro using 'SAPLCNPB_M' '1000'.

perform bdc_field using 'BDC_OKCODE'

'=LTCT'.

*perform bdc_field using 'BDC_CURSOR'

  • 'PROJ-PSPID'.

*perform bdc_field using 'PROJ-PSPID'

  • 'TESTESTSANG8'.

*perform bdc_field using 'PROJ-POST1'

  • 'Unit Testing'.

*perform bdc_field using 'PROJ-VERNR'

  • '762001'.

*perform bdc_field using 'PROJ-VBUKR'

  • '7620'.

*perform bdc_field using 'PROJ-WERKS'

  • 'SPI'.

*perform bdc_field using 'PROJ-PLFAZ'

  • '01.01.2008'.

*perform bdc_field using 'PROJ-PLSEZ'

  • '31.10.2008'.

*perform bdc_field using 'PROJ-FUNC_AREA'

  • '600'.

*perform bdc_field using 'PROJ-PRCTR'

  • '76201-CH'.

*perform bdc_field using 'PROJ-SPROG'

  • '01.01.2008'.

*perform bdc_field using 'PROJ-EPROG'

  • '31.01.2008'.

perform bdc_dynpro using 'SAPLCNPB_M' '1000'.

perform bdc_field using 'PROJ-PSPID'

IT_DATA-VSPSPID1.

perform bdc_field using 'PROJ-POST1'

IT_DATA-POST2.

perform bdc_field using 'BDC_OKCODE'

'=SAVE'.

perform bdc_transaction using 'CJ20N'.

perform close_group.

perform close_group.

LOOP AT T_MESSTAB WHERE REC_NO IS INITIAL.

AT FIRST.

V_MESSAGE_CNT = V_MESSAGE_CNT + 1.

T_MESSTAB-REC_NO = V_COUNT.

ENDAT.

MODIFY T_MESSTAB TRANSPORTING REC_NO.

ENDLOOP.

REFRESH T_BDCDATA.

CLEAR T_BDCDATA.

ENDLOOP.

SKIP.

WRITE : /10 'Record Number ', 30 'Error Message'.

SKIP.

endform.

&----


*& Form WRITE_ERROR

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM WRITE_ERROR.

LOOP AT T_MESSTAB.

WRITE : /10 T_MESSTAB-REC_NO , 30 T_MESSTAB-MESSAGE.

ENDLOOP.

ULINE /10(100).

WRITE : /10 'No of Records : ' , V_COUNT.

WRITE : /10 'No of Erroneous Records : ' , V_MESSAGE_CNT.

ULINE /10(100).

ENDFORM. " WRITE_ERROR

&----


*& Form CHECK_BDC

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHECK_BDC.

DATA: L_CHECK LIKE YMMT_CHECK_BDC-YCHECK.

SELECT SINGLE YCHECK INTO L_CHECK FROM YMMT_CHECK_BDC

WHERE PROGRAMM EQ SY-REPID

AND YCHECK EQ 'X'.

IF SY-SUBRC NE 0.

MESSAGE S000(YM) WITH 'Execution not possible'.

STOP.

ENDIF.

ENDFORM. " CHECK_BDC

=================================

Include Program

----


  • INCLUDE YMM01_BDCRECX1 *

----


***INCLUDE BDCRECX1.

  • for programs doing a data transfer by creating a batch-input session

  • and

  • for programs doing a data transfer by CALL TRANSACTION USING

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS SESSION RADIOBUTTON GROUP CTU. "create session

SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.

selection-screen position 45.

PARAMETERS CTU RADIOBUTTON GROUP CTU default 'X'. "call

"transaction

SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.

selection-screen position 25.

PARAMETERS GROUP(12). "group name of session

SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.

selection-screen position 70.

PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.

"A: show all dynpros

"E: show dynpro on error only

"N: do not display dynpro

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.

selection-screen position 25.

PARAMETERS: USER(12) DEFAULT SY-UNAME. "user for session in batch

SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.

selection-screen position 70.

PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.

"S: synchronously

"A: asynchronously

"L: local

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.

selection-screen position 25.

PARAMETERS: KEEP AS CHECKBOX. "' ' = delete session if finished

"'X' = keep session if finished

SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.

selection-screen position 70.

parameters E_GROUP(12). "group name of error-session

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.

selection-screen position 25.

PARAMETERS: HOLDDATE LIKE SY-DATUM.

SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.

selection-screen position 70.

PARAMETERS: E_USER(12) DEFAULT SY-UNAME. "user for error-session

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.

selection-screen position 70.

PARAMETERS: E_KEEP AS CHECKBOX. "' ' = delete session if finished

"'X' = keep session if finished

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.

selection-screen position 70.

PARAMETERS: E_HDATE LIKE SY-DATUM.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.

PARAMETERS: NODATA DEFAULT '/' LOWER CASE. "nodata

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(33) FOR FIELD SMALLLOG.

PARAMETERS: SMALLLOG as checkbox. "' ' = log all transactions

"'X' = no transaction logging

SELECTION-SCREEN END OF LINE.

----


  • data definition

----


  • Batchinputdata of single transaction

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF T_MESSTAB OCCURS 0,

REC_NO(5) TYPE C,

MESSAGE(250) TYPE C,

END OF T_MESSTAB.

  • messages of call transaction

DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

  • error session opened (' ' or 'X')

DATA: E_GROUP_OPENED.

  • message texts

TABLES: T100.

----


  • at selection screen *

----


AT SELECTION-SCREEN.

  • group and user must be filled for create session

IF SESSION = 'X' AND

GROUP = SPACE OR USER = SPACE.

MESSAGE E613(MS).

ENDIF.

----


  • open dataset *

----


FORM OPEN_DATASET USING P_DATASET.

OPEN DATASET P_DATASET IN TEXT MODE.

IF SY-SUBRC <> 0.

WRITE: / TEXT-E00, SY-SUBRC.

STOP.

ENDIF.

ENDFORM.

----


  • close dataset *

----


FORM CLOSE_DATASET USING P_DATASET.

CLOSE DATASET P_DATASET.

ENDFORM.

----


  • create batchinput session *

  • (not for call transaction using...) *

----


FORM OPEN_GROUP.

IF SESSION = 'X'.

SKIP.

WRITE: /(20) 'Create group'(I01), GROUP.

SKIP.

  • open batchinput group

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING CLIENT = SY-MANDT

GROUP = GROUP

USER = USER

KEEP = KEEP

HOLDDATE = HOLDDATE.

WRITE: /(30) 'BDC_OPEN_GROUP'(I02),

(12) 'returncode:'(I05),

SY-SUBRC.

ENDIF.

ENDFORM.

----


  • end batchinput session *

  • (call transaction using...: error session) *

----


FORM CLOSE_GROUP.

IF SESSION = 'X'.

  • close batchinput group

CALL FUNCTION 'BDC_CLOSE_GROUP'.

WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),

(12) 'returncode:'(I05),

SY-SUBRC.

ELSE.

IF E_GROUP_OPENED = 'X'.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

WRITE: /.

WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).

ENDIF.

ENDIF.

ENDFORM.

----


  • Start new transaction according to parameters *

----


FORM BDC_TRANSACTION USING TCODE.

DATA: L_MSTRING(480).

DATA: L_SUBRC LIKE SY-SUBRC.

  • batch input session

IF SESSION = 'X'.

CALL FUNCTION 'BDC_INSERT'

EXPORTING TCODE = TCODE

TABLES DYNPROTAB = BDCDATA.

IF SMALLLOG <> 'X'.

WRITE: / 'BDC_INSERT'(I03),

TCODE,

'returncode:'(I05),

SY-SUBRC,

'RECORD:',

SY-INDEX.

ENDIF.

  • call transaction using

ELSE.

REFRESH MESSTAB.

CALL TRANSACTION TCODE USING BDCDATA

MODE CTUMODE

UPDATE CUPDATE

MESSAGES INTO MESSTAB.

L_SUBRC = SY-SUBRC.

IF SMALLLOG <> 'X'.

WRITE: / 'CALL_TRANSACTION',

TCODE,

'returncode:'(I05),

L_SUBRC,

'RECORD:',

SY-INDEX.

LOOP AT MESSTAB WHERE MSGTYP = 'E'.

SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA

AND ARBGB = MESSTAB-MSGID

AND MSGNR = MESSTAB-MSGNR.

IF SY-SUBRC = 0.

L_MSTRING = T100-TEXT.

IF L_MSTRING CS '&1'.

REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.

REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.

REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.

REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.

ELSE.

REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.

ENDIF.

CONDENSE L_MSTRING.

T_MESSTAB-MESSAGE = L_MSTRING(250) .

APPEND T_MESSTAB.

ELSE.

ENDIF.

ENDLOOP.

SKIP.

ENDIF.

  • Erzeugen fehlermappe ************************************************

IF L_SUBRC <> 0 AND E_GROUP <> SPACE.

IF E_GROUP_OPENED = ' '.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING CLIENT = SY-MANDT

GROUP = E_GROUP

USER = E_USER

KEEP = E_KEEP

HOLDDATE = E_HDATE.

E_GROUP_OPENED = 'X'.

ENDIF.

CALL FUNCTION 'BDC_INSERT'

EXPORTING TCODE = TCODE

TABLES DYNPROTAB = BDCDATA.

ENDIF.

ENDIF.

REFRESH BDCDATA.

ENDFORM.

----


  • 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.

==========================================