Go on link..

link us with ...

Monday, December 13, 2010

SESSION CALL METHOD BDC Programming

REPORT ZSJ_SESSION_CALL_METHOD
NO STANDARD PAGE HEADING LINE-SIZE 255.

*INCLUDE BDCRECX1.


DATA :IT_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA : BDCDATA TYPE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA : IDX LIKE SY-TABIX.

DATA : BEGIN OF ITAB OCCURS 0 ,

BLDAT(8) TYPE C , " LIKE BKPF-BLDAT,
BLART(2) TYPE C , "LIKE BKPF-BLART,
BUKRS(4) TYPE C, "LIKE BKPF-BUKRS,
XBLNR(16) TYPE C , "LIKE BKPF-XBLNR,
BKTXT(25) TYPE C , "LIKE BKPF-BKTXT,
NEWBS(2) TYPE C , "LIKE RF05A-NEWBS,
NEWKO(17) TYPE C , "LIKE RF05A-NEWKO,
WRBTR(13) TYPE C, " LIKE BSEG-WRBTR,
GSBER(4) TYPE C , " LIKE COBL-GSBER,
PRCTR(10) TYPE C , "LIKE COBL-PRCTR,
KOSTL(10) TYPE C , "LIKE COBL-KOSTL,

END OF ITAB .




*----------------------------------------------------------------------*
SELECTION-SCREEN : BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-001.

PARAMETER : P_IFILE TYPE STRING , " LIKE RLGRAP-FILENAME OBLIGATORY,
GRPID LIKE APQI-GROUPID OBLIGATORY.

SELECTION-SCREEN : END OF BLOCK BL1.




*----------------------------------------------------------------------*
* At Selection-screen *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.
PERFORM F4_HELP_P_FILE.


START-OF-SELECTION.




PERFORM GUI_UPLOAD.


PERFORM BDC_OPEN_GROUP.

PERFORM SESSION_METHOD .


PERFORM CLOSE_GROUP.





*&---------------------------------------------------------------------*
*& Form CALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SESSION_METHOD .




LOOP AT ITAB .

* REFRESH BDCDATA.
* CLEAR BDCDATA.

IDX = SY-INDEX .
IDX = IDX + 1 .


PERFORM BDC_DYNPRO USING 'ZSAPMF05A' '0100'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BKPF-BLDAT'
* '04.12.2008'.
ITAB-BLDAT.
PERFORM BDC_FIELD USING 'BKPF-BLART'
* 'kr'.
ITAB-BLART.
PERFORM BDC_FIELD USING 'BKPF-BUKRS'
* 'TCIL'.
ITAB-BUKRS.
PERFORM BDC_FIELD USING 'BKPF-BUDAT'
'04.12.2008'.
* ITAB-BUDAT.
PERFORM BDC_FIELD USING 'BKPF-MONAT'
'12'.
PERFORM BDC_FIELD USING 'BKPF-WAERS'
'INR'.
PERFORM BDC_FIELD USING 'BKPF-XBLNR'
* 'test'.
ITAB-XBLNR.
PERFORM BDC_FIELD USING 'BKPF-BKTXT'
* 'test'.
ITAB-BKTXT.
PERFORM BDC_FIELD USING 'FS006-DOCID'
'*'.

PERFORM BDC_FIELD USING 'RF05A-NEWBS'
* '40'.
ITAB-NEWBS .
PERFORM BDC_FIELD USING 'RF05A-NEWKO'
* '44630005'.
ITAB-NEWKO.



PERFORM BDC_DYNPRO USING 'ZSAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF05A-NEWKO'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR'
* '500'.
ITAB-WRBTR .
*
DELETE ITAB INDEX IDX.
CLEAR :ITAB.
READ TABLE ITAB .

PERFORM BDC_FIELD USING 'RF05A-NEWBS'
* '50'.
ITAB-NEWBS .
PERFORM BDC_FIELD USING 'RF05A-NEWKO'
* '44640002'.
ITAB-NEWKO.



PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'COBL-PRCTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTE'.
PERFORM BDC_FIELD USING 'COBL-GSBER'
* 'fxrt'.
ITAB-GSBER .
PERFORM BDC_FIELD USING 'COBL-KOSTL'
* 'rt0001ops'.
ITAB-KOSTL.
PERFORM BDC_FIELD USING 'COBL-PRCTR'
* 'rt0001'.
ITAB-PRCTR.


PERFORM BDC_DYNPRO USING 'ZSAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'BSEG-WRBTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR'
* '*'.
ITAB-WRBTR.


PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'COBL-PRCTR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=ENTE'.
PERFORM BDC_FIELD USING 'COBL-GSBER'
* 'fxrt'.
ITAB-GSBER .
PERFORM BDC_FIELD USING 'COBL-KOSTL'
* 'rt0001ops'.
ITAB-KOSTL.
PERFORM BDC_FIELD USING 'COBL-PRCTR'
* 'rt0001'.
ITAB-PRCTR.
* PERFORM BDC_TRANSACTION USING 'ZFB01'.
PERFORM BDC_INSERT.


* CLEAR : BDCDATA .
DELETE ITAB INDEX IDX.
CLEAR :ITAB.
READ TABLE ITAB .



ENDLOOP.

PERFORM BDC_CLOSE.

IF SY-SUBRC EQ 0.

WRITE:/ 'SESSION CREATED'.

ELSE.

WRITE:/ 'SESSION NOT CREATED, ERRORS OCCURED'.

ENDIF.




ENDFORM. " CALL
*&---------------------------------------------------------------------*
*& Form F4_HELP_P_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F4_HELP_P_FILE .




DATA : V_FILE(128) TYPE C . "LIKE P_FILE.
* Display popup with files list to select
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = V_FILE.
CHECK SY-SUBRC EQ 0.

P_IFILE = V_FILE.

ENDFORM. " F4_HELP_P_FILE
*&---------------------------------------------------------------------*
*& Form GUI_UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GUI_UPLOAD .

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = P_IFILE
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 = 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. " GUI_UPLOAD




FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.

ENDFORM. "BDC_DYNPRO

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*

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

























* PERFORM OPEN_GROUP.
*
* PERFORM BDC_DYNPRO USING 'ZSAPMF05A' '0100'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR'
* 'RF05A-NEWKO'.
* PERFORM BDC_FIELD USING 'BDC_OKCODE'
* '/00'.
* PERFORM BDC_FIELD USING 'BKPF-BLDAT'
* '04.12.2008'.
* PERFORM BDC_FIELD USING 'BKPF-BLART'
* 'kr'.
* PERFORM BDC_FIELD USING 'BKPF-BUKRS'
* 'TCIL'.
* PERFORM BDC_FIELD USING 'BKPF-BUDAT'
* '04.12.2008'.
* PERFORM BDC_FIELD USING 'BKPF-MONAT'
* '12'.
* PERFORM BDC_FIELD USING 'BKPF-WAERS'
* 'INR'.
* PERFORM BDC_FIELD USING 'BKPF-XBLNR'
* 'test'.
* PERFORM BDC_FIELD USING 'BKPF-BKTXT'
* 'test'.
* PERFORM BDC_FIELD USING 'FS006-DOCID'
* '*'.
* PERFORM BDC_FIELD USING 'RF05A-NEWBS'
* '40'.
* PERFORM BDC_FIELD USING 'RF05A-NEWKO'
* '44630005'.
* PERFORM BDC_DYNPRO USING 'ZSAPMF05A' '0300'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR'
* 'RF05A-NEWKO'.
* PERFORM BDC_FIELD USING 'BDC_OKCODE'
* '=BU'.
* PERFORM BDC_FIELD USING 'BSEG-WRBTR'
* '500'.
* PERFORM BDC_FIELD USING 'RF05A-NEWBS'
* '50'.
* PERFORM BDC_FIELD USING 'RF05A-NEWKO'
* '44640002'.
* PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR'
* 'COBL-PRCTR'.
* PERFORM BDC_FIELD USING 'BDC_OKCODE'
* '=ENTE'.
* PERFORM BDC_FIELD USING 'COBL-GSBER'
* 'fxrt'.
* PERFORM BDC_FIELD USING 'COBL-KOSTL'
* 'rt0001ops'.
* PERFORM BDC_FIELD USING 'COBL-PRCTR'
* 'rt0001'.
* PERFORM BDC_DYNPRO USING 'ZSAPMF05A' '0300'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR'
* 'BSEG-WRBTR'.
* PERFORM BDC_FIELD USING 'BDC_OKCODE'
* '=BU'.
* PERFORM BDC_FIELD USING 'BSEG-WRBTR'
* '*'.
* PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR'
* 'COBL-PRCTR'.
* PERFORM BDC_FIELD USING 'BDC_OKCODE'
* '=ENTE'.
* PERFORM BDC_FIELD USING 'COBL-GSBER'
* 'fxrt'.
* PERFORM BDC_FIELD USING 'COBL-KOSTL'
* 'rt0001ops'.
* PERFORM BDC_FIELD USING 'COBL-PRCTR'
* 'rt0001'.
* PERFORM BDC_TRANSACTION USING 'ZFB01'.
*
* PERFORM CLOSE_GROUP.
*&---------------------------------------------------------------------*
*& Form BDC_OPEN_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_OPEN_GROUP .


CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = GRPID
KEEP = 'X'
USER = SY-UNAME
* 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.

ENDFORM. " BDC_OPEN_GROUP
*&---------------------------------------------------------------------*
*& Form CLOSE_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CLOSE_GROUP .



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.
* CALL FUNCTION 'BDC_CLOSE_GROUP'


ENDFORM. " CLOSE_GROUP
*&---------------------------------------------------------------------*
*& Form BDC_INSERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_INSERT .


CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'ZFB01'
TABLES
DYNPROTAB = 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.

REFRESH BDCDATA.



ENDFORM. " BDC_INSERT
*&---------------------------------------------------------------------*
*& Form BDC_CLOSE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_CLOSE .



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.
* CALL FUNCTION 'BDC_CLOSE_GROUP'
.


ENDFORM. " BDC_CLOSE

No comments:

link us...

For Visitors

if you want to publish or Add something on ERP, SAP , SAP FUNCTIONAL, SAP ABAP then mail us along with your email-id. contain must be yours

email-id :- avinashkr_raj@yahoo.com(any email)

email-id :- avinaskr_raj.abap@blogger.com ( use only gmail)