Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

bdc

Former Member
0 Likes
505

hi frnds,

In transaction fbv3 there is a field "Amt in loc curr"(bseg-dmbtr) that is picking of the values

from "VBSEGS-DMBTR".

I have a session method bdc in which the requirement is to:-

a) the user will pick the values from a flat file for the field "Amt in loc curr"

and if there are values in the flat files it will pick it and display it in the

amt in loc curr field.

if for some rows values are not there it will pick up the values of vbsegs-dmbtr.

note:- in this bdc there is no such field or table decalred as "VBSEGS-DMBTR"

but it picks the values in tcode fbv3 for amt in loc curr field.

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

  • Tables *

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

TABLES:

ZINC1,

CSKS, " Cost Center table

SKB1.

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

DATA:

C_ZERO TYPE P DECIMALS 2 VALUE 0,

C_TRANS_MODE TYPE C VALUE 'N',

C_TRANS_UPDATE TYPE C VALUE 'S' ,

C_TCDE LIKE SY-TCODE VALUE 'F-65',

C_DEBIT(2) TYPE C VALUE '40',

C_CREDIT(2) TYPE C VALUE '50',

C_OFFSET_NUM(3) TYPE C VALUE '998',

C_OFFSET_ACCOUNT(6) TYPE C VALUE '225100',

C_DFLT_TAX_CODE(2) TYPE C VALUE 'I0',

C_DFLT_TAX_JURIS(15) TYPE C VALUE 'CA9513400'.

- Strings----


DATA:

W_HEADER(47), " Holds header data

W_OLD_HEADER(47) VALUE 'XXXXXXXXXX'.

DATA V_LINE_TEXT(50). "syalla 07/11/00

- Variables -


DATA:

V_WORKPATH LIKE ZOUT1-ZWORKPATH,

V_DATASET LIKE V_WORKPATH,

V_DEBIT LIKE BSEG-WRBTR,

V_CREDIT LIKE V_DEBIT,

V_OFFSET_BALANCE_AMOUNT(16) TYPE C,

V_OFFSET_AMOUNT(16) TYPE C,

V_OFFSET_POSTING_KEY(2) TYPE C,

V_OFFSET_BALANCE_POSTING LIKE V_OFFSET_POSTING_KEY,

V_TOT_RECS LIKE SY-TABIX,

V_CURRENT_REC LIKE SY-TABIX,

V_NO_REC_INSERTED TYPE I,

V_POSTDT(10) TYPE C,

V_DATE(10) TYPE C VALUE '05/07/1997'.

- Counters -


DATA:

V_MSG_CNTR TYPE I,

V_COUNTER TYPE I VALUE 1,

V_CNTR TYPE N.

DATA: FLAG1(1) TYPE C.

DATA: ERROR_FLAG TYPE C,

SESSION_ID LIKE APQI-QID.

- Flags -


DATA:

V_FIRST_TIME_FLAG VALUE 'Y', " First time flag

V_NEWDOC_FLAG VALUE 'N',

V_FILE LIKE RLGRAP-FILENAME.

- Structures -


*Structure to hold BDC script

DATA: BEGIN OF T_BDCDATA OCCURS 100.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF T_BDCDATA.

*Table to hold the messages displayed during processing

DATA: BEGIN OF T_MSG OCCURS 20.

INCLUDE STRUCTURE FIMSG.

DATA: END OF T_MSG.

- Internal Tables -


*Table to hold accounting info from desired fields

DATA: BEGIN OF T_INTAB OCCURS 10000,

COMPANY_CODE(4) TYPE C VALUE SPACE,

COST_CNTR(10) TYPE C VALUE SPACE,

POSTING_KEY(2) TYPE C,

GL_ACCNT LIKE BSEG-HKONT,

AMOUNT(16) TYPE C,

  • LINE_DESC(50) TYPE C, "syalla 07/11/00

LINE_DESC(102) TYPE C, "syalla 07/11/00

TAX_CODE(2) TYPE C,

JURIS_CODE(15) TYPE C,

POSID LIKE PRPS-POSID,

PROF_CTR(10) TYPE C,

NETWORK(12) TYPE C,

VORNR(4) TYPE C,

ALLOCATION LIKE BSEG-ZUONR,

ACCTG_DATE(10) TYPE C VALUE SPACE,

  • begin of code added by manasm

AMT_LOC_CURR(20) TYPE C,

  • end of code added by manasm

END OF T_INTAB.

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

  • Input Parameters : *

  • Select Options (S_...) *

  • Parameters (P_...) *

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

PARAMETERS:

P_DOCDT LIKE SY-DATUM OBLIGATORY,

P_POSTDT LIKE SY-DATUM OBLIGATORY,

P_BUKRS LIKE BKPF-BUKRS OBLIGATORY,

P_DT LIKE BKPF-BLART OBLIGATORY,

P_CUR LIKE BKPF-WAERS OBLIGATORY,

P_HDRTXT LIKE BKPF-BKTXT OBLIGATORY,

P_REFDOC LIKE BKPF-XBLNR OBLIGATORY,

P_DFTTXK AS CHECKBOX,

P_BDCNME LIKE APQI-GROUPID,

P_INTID LIKE ZINC1-ZINTID DEFAULT 'JRNL',

P_FILE LIKE IBIPPARMS-PATH DEFAULT 'DRIVE:\PATH\FILE',

P_LOCAL(1) DEFAULT 'X' .

SELECTION-SCREEN SKIP 2.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(76) TEXT-001.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(16) TEXT-002.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK B1.

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

FILE_NAME = P_FILE

EXCEPTIONS

OTHERS = 1.

----


START-OF-SELECTION. "Main processing

----


  • Changed and added by Vijay Chavva on 7/26/00.

  • This report execution will be monitored from now onwards.

  • DV1K921585

INCLUDE ZREPTRAC.

  • upload the flat file from either the local drive or remote server.

MOVE P_FILE TO V_FILE.

PERFORM F_UPLOAD_FILE.

PERFORM F_VALIDATE_INPUT_DATA CHANGING ERROR_FLAG.

CHECK ERROR_FLAG = SPACE.

PERFORM F_BDC_OPEN_GROUP.

  • put the date in correct format.

WRITE P_DOCDT MM/DD/YYYY TO V_DATE.

WRITE P_POSTDT MM/DD/YYYY TO V_POSTDT.

  • total number of records in int tab.

DESCRIBE TABLE T_INTAB LINES V_TOT_RECS.

  • Populate bdc table and call transaction at header change.

PERFORM F_POPULATE_BDC_TABLE.

  • Save at end of header for last rec in loop (on screen 2)

PERFORM F_SAVE_LAST_DATA.

  • call f-65 using the data in t_bdcdata for last record in loop.

PERFORM F_BDC_CALL_TRANSACTION.

  • close bdc group.

PERFORM F_BDC_CLOSE_GROUP.

  • Report on error messages.

PERFORM F_MSG_WRITE_MESSAGES.

IF V_NO_REC_INSERTED = 0.

CALL FUNCTION 'BDC_OBJECT_DELETE'

EXPORTING

QUEUE_ID = SESSION_ID

EXCEPTIONS

NOT_FOUND = 1

INVALID_DATATYPE = 2

OTHERS = 3.

ENDIF.

----


END-OF-SELECTION. "Error handling and clean-up processing

----


----


TOP-OF-PAGE. "Header (Appears always on top of the screen.)

----


PERFORM HEADER USING SY-TITLE SY-REPID '' ''.

----


END-OF-PAGE. "Footer

&----


*& Form f_upload_file

&----


  • Read file from the interface architecture or from a local file *

  • depending on how the "Local file" flag is set. *

----


FORM F_UPLOAD_FILE.

DATA NO_LINES TYPE I.

IF P_LOCAL NE 'X'.

PERFORM F_GET_INBOUND_DIRECTORY.

OPEN DATASET V_DATASET FOR INPUT IN TEXT MODE.

  • read dataset into internal table

DO.

READ DATASET V_DATASET INTO T_INTAB.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND T_INTAB.

ENDDO.

ELSE.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = V_FILE

FILETYPE = 'DAT'

TABLES

DATA_TAB = T_INTAB

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

OTHERS = 6.

If SY-SUBRC NE C_ZERO.

MESSAGE E904 WITH P_FILE.

PERFORM F_MSG_COLLECT.

Stop.

Endif.

ENDIF.

DELETE T_INTAB INDEX 1.

DESCRIBE TABLE T_INTAB LINES NO_LINES.

DELETE T_INTAB INDEX NO_LINES.

ENDFORM. " f_upload_file

&----


*& Form F_BDC_OPEN_GROUP

&----


  • Opens the session to process the transaction *

----


FORM F_BDC_OPEN_GROUP.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = P_BDCNME

USER = SY-UNAME

IMPORTING

QID = SESSION_ID

EXCEPTIONS

CLIENT_INVALID = 01

DESTINATION_INVALID = 02

GROUP_INVALID = 03

HOLDDATE_INVALID = 04

INTERNAL_ERROR = 05

QUEUE_ERROR = 06

RUNNING = 07

USER_INVALID = 08.

IF SY-SUBRC NE C_ZERO.

MESSAGE E904 WITH 'BDC_OPEN_GROUP'.

PERFORM F_MSG_COLLECT.

STOP.

ENDIF.

ENDFORM. " F_BDC_OPEN_GROUP

&----


*& Form F_MSG_COLLECT

&----


  • Stores the message in the internal table T_MSG. *

----


FORM F_MSG_COLLECT.

CLEAR T_MSG.

T_MSG-MSGID = SY-MSGID.

T_MSG-MSGTY = SY-MSGTY.

T_MSG-MSGNO = SY-MSGNO.

T_MSG-MSGV1 = SY-MSGV1.

T_MSG-MSGV2 = SY-MSGV2.

T_MSG-MSGV3 = SY-MSGV3.

T_MSG-MSGV4 = SY-MSGV4.

APPEND T_MSG.

ENDFORM. " F_MSG_COLLECT

&----


*& Form F_BDC_ADD_DYNPRO_DATA

&----


  • Creates script based on internal table *

----


FORM F_BDC_ADD_DYNPRO_DATA USING DYNBEGIN NAME VALUE.

CLEAR T_BDCDATA.

IF DYNBEGIN = 'X'.

MOVE NAME TO T_BDCDATA-PROGRAM.

MOVE VALUE TO T_BDCDATA-DYNPRO.

MOVE 'X' TO T_BDCDATA-DYNBEGIN.

ELSE.

MOVE NAME TO T_BDCDATA-FNAM.

MOVE VALUE TO T_BDCDATA-FVAL.

ENDIF.

APPEND T_BDCDATA.

ENDFORM. "F_BDC_ADD_DYNPRO_DATA

&----


*& Form F_BDC_INSERT_TRANSACTION

&----


  • Places script into SAP session to be processed *

----


FORM F_BDC_INSERT_TRANSACTION.

TRANSLATE C_TCDE TO UPPER CASE.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = C_TCDE

TABLES

DYNPROTAB = T_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 01

NOT_OPEN = 02

QUEUE_ERROR = 03

TCODE_INVALID = 04.

IF V_CURRENT_REC EQ V_TOT_RECS.

MESSAGE S002 WITH P_BDCNME.

ENDIF.

IF SY-SUBRC NE C_ZERO.

MESSAGE E904 WITH 'BDC_INSERT'.

PERFORM F_MSG_COLLECT.

STOP.

ELSE.

V_NO_REC_INSERTED = V_NO_REC_INSERTED + 1.

ENDIF.

ENDFORM. " F_BDC_INSERT_TRANSACTION

&----


*& Form F_BDC_CALL_TRANSACTION

&----


  • This form places the script created by F_BDC_ADD_DYNPRO_Data into the*

  • opened session. It will be processed automatically and leave errors *

  • to be processed by the user in SM35. *

----


FORM F_BDC_CALL_TRANSACTION.

DATA: V_INFO(20) VALUE 'for set # '.

V_CNTR = V_CNTR + 1.

CALL TRANSACTION C_TCDE

Using T_BDCDATA

MODE C_TRANS_MODE

UPDATE C_TRANS_UPDATE.

If Sy-Subrc NE 0.

  • perform f_msg_collect. "syalla 06/07/00 asr#9886

CONCATENATE P_BDCNME V_INFO V_CNTR INTO V_INFO.

MESSAGE S003 WITH V_INFO.

PERFORM F_MSG_COLLECT.

PERFORM F_BDC_INSERT_TRANSACTION.

Else.

Endif.

Refresh T_BDCDATA.

ENDFORM. " F_BDC_CALL_TRANSACTION

&----


*& Form F_BDC_CLOSE_GROUP

&----


  • Closes the session to be processed *

----


FORM F_BDC_CLOSE_GROUP.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 01

QUEUE_ERROR = 02.

IF SY-SUBRC NE C_ZERO.

MESSAGE E904 WITH 'BDC_CLOSE_GROUP'.

PERFORM F_MSG_COLLECT.

STOP.

ELSE.

PERFORM F_MSG_COLLECT.

ENDIF.

ENDFORM. " F_BDC_CLOSE_GROUP

&----


*& Form F_MSG_WRITE_MESSAGES

&----


  • If no error messages were found then it says that the program has *

  • been completed successfully. If there are messages it displays them. *

----


FORM F_MSG_WRITE_MESSAGES.

DESCRIBE TABLE T_MSG LINES V_MSG_CNTR.

IF V_MSG_CNTR LT 1.

MESSAGE I001.

ELSE.

SORT T_MSG BY MSGTY.

WRITE:

/ 'The following',

  • V_MSG_CNTR, "SYALLA 06/07/00 ASR#

'messages were written:'.

SKIP.

PERFORM GET_ERROR_COST_CENTERS. "SYALLA 06/07/00 ASR#9886

ULINE.

IF FLAG1 = 'X'.

WRITE:

/ 'Program completed with errors. Use SM35 to process the BDC session:',

P_BDCNME.

ELSE.

WRITE:

'Program completed Successfully use SM35 to process the BDC session: ',

P_BDCNME.

ENDIF.

  • Begin Of delete SYALLA 07/18/00

  • LOOP AT T_MSG.

  • ON CHANGE OF T_MSG-MSGTY.

  • SKIP.

  • WRITE:

  • / 'Message type','Successful'.

    • T_MSG-MSGTY. "SYALLA 07/18/00

  • ULINE.

  • ENDON.

  • CALL FUNCTION 'WRITE_MESSAGE'

  • EXPORTING

  • MSGID = T_MSG-MSGID

  • MSGNO = T_MSG-MSGNO

  • MSGTY = T_MSG-MSGTY

  • MSGV1 = T_MSG-MSGV1

  • MSGV2 = T_MSG-MSGV2

  • MSGV3 = T_MSG-MSGV3

  • MSGV4 = T_MSG-MSGV4

  • MSGV5 = SPACE

  • IMPORTING

  • MESSG = T_MESSAGE

  • EXCEPTIONS

  • OTHERS = 1.

  • WRITE: / T_MESSAGE-MSGTX.

  • ENDLOOP.

  • End Of delete SYALLA 07/18/00

ENDIF.

ENDFORM. " F_MSG_WRITE_MESSAGES

&----


*& Form F_GET_INBOUND_DIRECTORY

&----


  • text *

----


  • --> p1 text

  • <-- p2 text

----


FORM F_GET_INBOUND_DIRECTORY.

SELECT SINGLE * FROM ZINC1

WHERE ZINTID = P_INTID.

IF SY-SUBRC NE 0.

MESSAGE E903 WITH P_INTID 'INTID' 'ZINC1'.

PERFORM F_MSG_COLLECT.

ENDIF.

IF SY-SUBRC = 0 AND ZINC1-ZPROCESS = 'X'.

V_WORKPATH = ZINC1-ZWORKPATH.

CONCATENATE V_WORKPATH P_FILE INTO V_DATASET.

ENDIF.

ENDFORM. " F_GET_INBOUND_DIRECTORY

&----


*& Form f_fill_all_screens

&----


  • This subroutine populated the bdc table when the header changes*

----


  • --> p1 text

  • <-- p2 text

----


FORM F_FILL_ALL_SCREENS.

IF V_FIRST_TIME_FLAG EQ 'N'. "If not first loop

*save at end of header (on screen 2)

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'bdc_okcode' '/11',

'X' 'SAPLKACB' '0002',

' ' 'bdc_okcode' '/8'.

PERFORM F_BDC_CALL_TRANSACTION.

ENDIF.

V_FIRST_TIME_FLAG = 'N'.

*top of screen 1

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0100',

' ' 'bkpf-bukrs' T_INTAB-COMPANY_CODE,

' ' 'bkpf-bldat' T_INTAB-ACCTG_DATE,

' ' 'bkpf-budat' V_POSTDT,

' ' 'bkpf-blart' P_DT,

' ' 'bkpf-waers' P_CUR,

' ' 'bkpf-bktxt' P_HDRTXT,

' ' 'bkpf-xblnr' P_REFDOC,

*bottom of screen 1

' ' 'rf05v-newko' T_INTAB-GL_ACCNT,

' ' 'rf05v-newbs' T_INTAB-POSTING_KEY,

' ' 'bdc_okcode' '/0'.

V_LINE_TEXT = T_INTAB-LINE_DESC. "syalla 07/11/00

*top of screen 2

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'bseg-wrbtr' T_INTAB-AMOUNT,

    • begin of code added by manasm

*IF T_INTAB-AMT_LOC_CURR NE SPACE.

  • PERFORM F_BDC_ADD_DYNPRO_DATA USING:

  • ' ' 'bseg-dmbtr' T_INTAB-AMT_LOC_CURR,

  • ' ' 'bdc_okcode' '/0'.

  • ELSE.

  • PERFORM F_BDC_ADD_DYNPRO_DATA USING:

  • ' ' 'bdc_okcode' '/0'.

  • ENDIF.

**end of code added by manasm

  • ' ' 'bseg-sgtxt' T_INTAB-LINE_DESC, "syalla 07/11/00

**begin of code added by manas

  • PERFORM F_BDC_ADD_DYNPRO_DATA USING:

  • 'X' 'SAPLF040' '0300',

**end of code added by manas

' ' 'bseg-sgtxt' V_LINE_TEXT, "syalla 07/11/00

' ' 'BSEG-ZUONR' T_INTAB-ALLOCATION.

CLEAR V_LINE_TEXT. "syalla 07/11/00

IF T_INTAB-TAX_CODE NE SPACE. "new

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bseg-mwskz' T_INTAB-TAX_CODE.

IF T_INTAB-JURIS_CODE NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bseg-txjcd' T_INTAB-JURIS_CODE.

ENDIF.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bdc_okcode' '/0'.

ELSE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bdc_okcode' '/0'.

ENDIF.

*

IF T_INTAB-PROF_CTR NE SPACE AND T_INTAB-COST_CNTR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'cobl-prctr' T_INTAB-PROF_CTR,

' ' 'cobl-kostl' T_INTAB-COST_CNTR,

' ' 'bdc_okcode' '/8'.

ELSEIF T_INTAB-COST_CNTR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'cobl-kostl' T_INTAB-COST_CNTR,

' ' 'bdc_okcode' '/8'.

ELSEIF T_INTAB-PROF_CTR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'cobl-prctr' T_INTAB-PROF_CTR,

' ' 'bdc_okcode' '/8'.

ELSEIF T_INTAB-POSID NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'COBL-PS_PSP_PNR' T_INTAB-POSID,

' ' 'bdc_okcode' '/8'.

ELSE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'bdc_okcode' '/8'.

ENDIF.

ENDFORM. " f_fill_all_screens

&----


*& Form f_fill_screen_two

&----


  • This subroutine will post next line items. So it will do the *

  • bottom of screen 2 and it will do the coding block or screen thre*

----


  • --> p1 text

  • <-- p2 text

----


FORM F_FILL_SCREEN_TWO.

*bottom of screen 2

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'rf05v-newko' T_INTAB-GL_ACCNT,

' ' 'rf05v-newbs' T_INTAB-POSTING_KEY,

' ' 'RF05V-NEWBK' T_INTAB-COMPANY_CODE,

' ' 'bdc_okcode' '/0',

'X' 'SAPLKACB' '0002',

' ' 'BDC_OKCODE' '/8'.

V_LINE_TEXT = T_INTAB-LINE_DESC. "syalla 07/11/00

*top of screen 2

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'bseg-wrbtr' T_INTAB-AMOUNT.

*begin of code added by manasm

IF T_INTAB-AMT_LOC_CURR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bseg-dmbtr' T_INTAB-AMT_LOC_CURR,

' ' 'bdc_okcode' '/0'.

ELSE .

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bdc_okcode' '/0'.

ENDIF.

*end of code added by manasm

  • ' ' 'bseg-sgtxt' T_INTAB-LINE_DESC , "syalla07/11/0

*begin of code added by manas

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

*end of code added by manas

' ' 'bseg-sgtxt' V_LINE_TEXT, "syalla 07/11/00

' ' 'BSEG-ZUONR' T_INTAB-ALLOCATION.

CLEAR V_LINE_TEXT.

IF T_INTAB-TAX_CODE NE SPACE. "new

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bseg-mwskz' T_INTAB-TAX_CODE.

IF T_INTAB-JURIS_CODE NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bseg-txjcd' T_INTAB-JURIS_CODE.

ENDIF.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bdc_okcode' '/0'.

ELSE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

' ' 'bdc_okcode' '/0'.

ENDIF.

*

IF T_INTAB-PROF_CTR NE SPACE AND T_INTAB-COST_CNTR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'cobl-prctr' T_INTAB-PROF_CTR,

' ' 'cobl-kostl' T_INTAB-COST_CNTR,

' ' 'bdc_okcode' '/8'.

ELSEIF T_INTAB-COST_CNTR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'cobl-kostl' T_INTAB-COST_CNTR,

' ' 'bdc_okcode' '/8'.

ELSEIF T_INTAB-PROF_CTR NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'COBL-PRCTR' T_INTAB-PROF_CTR,

' ' 'bdc_okcode' '/8'.

ELSEIF T_INTAB-POSID NE SPACE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'COBL-PS_PSP_PNR' T_INTAB-POSID,

' ' 'bdc_okcode' '/8'.

ELSE.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLKACB' '0002',

' ' 'bdc_okcode' '/8'.

ENDIF.

ENDFORM. " f_fill_screen_two

&----


*& Form F_FILL_OFFSET_RECORD

&----


  • This subroutine will post to the offset account and offset *

  • amount and it will be considered another line item but it's *

  • purpose is to balance debits and credits if a document is being*

  • split becuase SAP allows only 999 line items per doc or per *

  • header.

----


  • --> p1 text

  • <-- p2 text

----


FORM F_FILL_OFFSET_RECORD USING V_OFFSET_AMOUNT V_OFFSET_POSTING_KEY.

*bottom of screen 2

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'rf05v-newko' C_OFFSET_ACCOUNT,

' ' 'rf05v-newbs' V_OFFSET_POSTING_KEY,

' ' 'bdc_okcode' '/0',

'X' 'SAPLKACB' '0002',

' ' 'BDC_OKCODE' '/8'.

*top of screen 2

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'bseg-wrbtr' V_OFFSET_AMOUNT,

' ' 'bdc_okcode' '/0',

'X' 'SAPLKACB' '0002',

' ' 'bdc_okcode' '/8'.

  • Here, I am assigning that offset amount into another variable so that

  • when we do another offset entry at the beginning of the next doc,

  • inorder to zero out the offset account, then we can call upon this

  • variable which will store the amount of the offset entry for the

  • previous doc.

V_OFFSET_BALANCE_AMOUNT = V_OFFSET_AMOUNT.

  • This is also a preparation for the offset entry at the beginning of

  • the next doc. We want to store the opposit of the current posting so

  • that we can correctly post a debit or a credit.

IF V_OFFSET_POSTING_KEY = C_CREDIT.

V_OFFSET_BALANCE_POSTING = C_DEBIT.

ELSE.

V_OFFSET_BALANCE_POSTING = C_CREDIT.

ENDIF.

  • Since we already posted to the offset for the current doc, we want to

  • zero out these variable so they can be initialized for the next doc.

V_CREDIT = 0.

V_DEBIT = 0.

  • We want to save the doc and then we want to call the transaction again

  • since that's the only way f-02 will allow you to input new header

  • data.

PERFORM F_SAVE_LAST_DATA.

PERFORM F_BDC_CALL_TRANSACTION.

ENDFORM. " F_FILL_OFFSET_RECORD

&----


*& Form F_SAVE_LAST_DATA

&----


  • save the current doc before you can post to a different header *

----


  • --> p1 text

  • <-- p2 text

----


FORM F_SAVE_LAST_DATA.

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'bdc_okcode' '/11',

'X' 'SAPLKACB' '0002',

' ' 'bdc_okcode' '/8'.

ENDFORM. " F_SAVE_LAST_DATA

&----


*& Form F_POST_CREDIT_DEBIT_BALANCE

&----


  • This subroutine keeps a running tab of the credits and debits *

  • for each document. *

----


  • --> p1 text

  • <-- p2 text

----


FORM F_POST_CREDIT_DEBIT_BALANCE.

IF T_INTAB-POSTING_KEY = C_CREDIT.

V_CREDIT = V_CREDIT + T_INTAB-AMOUNT.

ELSE.

V_DEBIT = V_DEBIT + T_INTAB-AMOUNT.

ENDIF.

ENDFORM. " F_POST_CREDIT_DEBIT_BALANCE

&----


*& Form f_post_to_offset_account

&----


  • This sub posts to the offset account. *

----


  • --> p1 text

  • <-- p2 text

----


FORM F_POST_TO_OFFSET_ACCOUNT.

IF V_DEBIT > V_CREDIT.

V_OFFSET_AMOUNT = V_DEBIT - V_CREDIT.

V_OFFSET_POSTING_KEY = C_CREDIT.

PERFORM F_FILL_OFFSET_RECORD USING V_OFFSET_AMOUNT

V_OFFSET_POSTING_KEY.

ELSEIF V_CREDIT > V_DEBIT.

V_OFFSET_AMOUNT = V_CREDIT - V_DEBIT.

V_OFFSET_POSTING_KEY = C_DEBIT.

PERFORM F_FILL_OFFSET_RECORD USING V_OFFSET_AMOUNT

V_OFFSET_POSTING_KEY.

ENDIF.

ENDFORM. "F_POST_TO_OFFSET_ACCOUNT

&----


*& Form F_CONCAT_HEADER

&----


  • concatenates the fields into one variable for comparison *

----


  • --> p1 text

  • <-- p2 text

----


FORM F_CONCAT_HEADER.

CONCATENATE:" t_intab-company_code SRINIP ASR 15071

P_DT P_REFDOC P_HDRTXT INTO W_HEADER.

ENDFORM. " F_CONCAT_HEADER

&----


*& Form F_BALANCE_OFFSET_ACCOUNT

&----


  • This will be the offset posting with the header info, which is *

  • at the beginning of the next document. It basically zeros out *

  • the offset account.

----


  • --> p1 text

  • <-- p2 text

----


FORM F_BALANCE_OFFSET_ACCOUNT.

*top of screen 1

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0100',

' ' 'bkpf-bukrs' T_INTAB-COMPANY_CODE,

' ' 'bkpf-bldat' T_INTAB-ACCTG_DATE,

' ' 'bkpf-budat' V_POSTDT,

' ' 'bkpf-blart' P_DT,

' ' 'bkpf-waers' P_CUR,

' ' 'bkpf-bktxt' P_HDRTXT,

' ' 'bkpf-xblnr' P_REFDOC,

*bottom of screen 1

' ' 'rf05v-newko' C_OFFSET_ACCOUNT,

' ' 'rf05v-newbs' V_OFFSET_BALANCE_POSTING,

  • ' ' 'RF05V-NEWBK' t_intab-company_code,

' ' 'bdc_okcode' '/0'.

*top of screen 2

PERFORM F_BDC_ADD_DYNPRO_DATA USING:

'X' 'SAPLF040' '0300',

' ' 'bseg-wrbtr' V_OFFSET_BALANCE_AMOUNT,

' ' 'bdc_okcode' '/0',

'X' 'SAPLKACB' '0002',

' ' 'bdc_okcode' '/8'.

  • Since this is actually the first line item in a new doc, then the

  • amount has to be stored so that it won't throw off the balance at the

  • end of the doc.

IF V_OFFSET_BALANCE_POSTING EQ C_CREDIT.

V_CREDIT = V_CREDIT + V_OFFSET_BALANCE_AMOUNT.

ELSE.

V_DEBIT = V_DEBIT + V_OFFSET_BALANCE_AMOUNT.

ENDIF.

ENDFORM. " F_BALANCE_OFFSET_ACCOUNT

&----


*& Form F_POPULATE_BDC_TABLE

&----


  • text *

----


  • --> p1 text

  • <-- p2 text

----


FORM F_POPULATE_BDC_TABLE.

LOOP AT T_INTAB.

SET PARAMETER ID 'PRC' FIELD ' '.

V_CURRENT_REC = SY-TABIX.

  • Hardcode the date to current date, the currency to 'USD'

T_INTAB-ACCTG_DATE = V_DATE.

  • t_intab-company_code = p_bukrs. "SRINIP ASR 15071

T_INTAB-LINE_DESC = T_INTAB-LINE_DESC.

  • Need to keep a running tab of the credits and debits for each document

PERFORM F_POST_CREDIT_DEBIT_BALANCE.

  • loop through internal table and make the five key fields into one

  • variable called header.

PERFORM F_CONCAT_HEADER.

  • populate relevant parts of internal bdc table if the header changes,

  • and when it stays the same

IF V_NEWDOC_FLAG EQ 'Y'.

  • if it's a new doc., meaning there are 999 line items posted already

  • and it's about to save but the debits don't equal the credits then

  • the first thing it'll do in the new doc is post to the offset account

  • the same amount that was posted in the last line item in the previous

  • doc. This offset line item will pull a new header as well and

  • immediately after the offset is posted then the current line item in

  • our loop will post as the next line item. So that's two entries, thus

  • why the counter is incremented by two.

IF V_OFFSET_BALANCE_AMOUNT NE 0.

PERFORM F_BALANCE_OFFSET_ACCOUNT.

PERFORM F_FILL_SCREEN_TWO.

V_COUNTER = 2.

ELSE.

  • if it's a new doc but the entries are balanced then we just continue

  • and enter another line item and increment the counter by one.

PERFORM F_FILL_ALL_SCREENS.

V_COUNTER = 1.

ENDIF.

  • since we did all the offset accounting necessary at the beginning of

  • a new doc then we indicate that it no longer a new doc and we empty

  • out our variable that keeps track of the offset amount.

V_NEWDOC_FLAG = 'N'.

V_OFFSET_BALANCE_AMOUNT = 0.

ELSEIF W_HEADER NE W_OLD_HEADER.

  • If the header has changed then we know right away that it is a new doc

  • until it reaches 999 line items. This will be the first posting so the

  • counter is set to one.

PERFORM F_FILL_ALL_SCREENS.

V_COUNTER = 1.

ELSE.

  • The first 998 line items should be read into the first SAP document

  • Line item number 999 should be offset account whose amount should

  • balance this initial document.

IF ( V_COUNTER EQ C_OFFSET_NUM ).

PERFORM F_FILL_SCREEN_TWO.

  • we post an offset amount only if the debits and credits don't equal

  • out for the current doc., and we indicate that we need to start a new

  • doc because the maximum num of line items has been reached.

IF V_DEBIT NE V_CREDIT.

PERFORM F_POST_TO_OFFSET_ACCOUNT.

ENDIF.

V_NEWDOC_FLAG = 'Y'.

ELSE.

  • If it's not a new doc, and it's not a new header then we know it's

  • just another line item and we post the data in the current header as

  • the next line item.

PERFORM F_FILL_SCREEN_TWO.

ENDIF.

ENDIF.

  • reset the old header with the current header.

MOVE W_HEADER TO W_OLD_HEADER.

V_COUNTER = V_COUNTER + 1.

ENDLOOP.

ENDFORM. " F_POPULATE_BDC_TABLE

&----


*& Form F_VALIDATE_INPUT_DATA

&----


  • text

----


FORM F_VALIDATE_INPUT_DATA CHANGING ERROR_FLAG.

DATA: DOC_TOTAL LIKE BSEG-WRBTR,

CUR_DOC_AMT LIKE BSEG-WRBTR,

NO_ZERO_DOCS TYPE I.

CLEAR ERROR_FLAG.

READ TABLE T_INTAB INDEX 1.

IF SY-SUBRC = 0.

IF T_INTAB-COMPANY_CODE <> P_BUKRS.

WRITE:/'Comp Code on screen must match comp code in first',

'record in input file'.

ERROR_FLAG = 'X'.

ENDIF.

ENDIF.

LOOP AT T_INTAB.

CUR_DOC_AMT = T_INTAB-AMOUNT.

IF CUR_DOC_AMT = 0.

NO_ZERO_DOCS = NO_ZERO_DOCS + 1.

DELETE T_INTAB.

CONTINUE.

ENDIF.

IF T_INTAB-POSTING_KEY = 40.

DOC_TOTAL = DOC_TOTAL + CUR_DOC_AMT.

ELSE.

DOC_TOTAL = DOC_TOTAL - CUR_DOC_AMT.

ENDIF.

  • Check if tax code is needed for this record

IF T_INTAB-TAX_CODE = SPACE AND P_DFTTXK = 'X'.

SHIFT T_INTAB-GL_ACCNT RIGHT DELETING TRAILING SPACE.

TRANSLATE T_INTAB-GL_ACCNT USING ' 0'.

SELECT SINGLE * FROM SKB1 WHERE BUKRS = T_INTAB-COMPANY_CODE

AND SAKNR = T_INTAB-GL_ACCNT

AND MWSKZ <> SPACE.

IF SY-SUBRC = 0.

T_INTAB-TAX_CODE = C_DFLT_TAX_CODE.

T_INTAB-JURIS_CODE = C_DFLT_TAX_JURIS.

MODIFY T_INTAB.

ENDIF.

ENDIF.

ENDLOOP.

  • Check if there is difference in credits and debits.

IF DOC_TOTAL <> 0.

SKIP 3.

WRITE:/ 'Credits and Debits do not equal in the document.',

'The difference is:', DOC_TOTAL CURRENCY P_CUR.

ERROR_FLAG = 'X'.

ENDIF.

IF NO_ZERO_DOCS <> 0.

WRITE: /'No of line with zero amounts deleted:', NO_ZERO_DOCS.

ENDIF.

ENDFORM. " F_VALIDATE_INPUT_DATA

&----


*& Form GET_ERROR_COST_CENTERS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_ERROR_COST_CENTERS.

DATA: V_MSSG(22) TYPE C,V_COSTCTR(10) TYPE C,V_STRLEN(3) TYPE C,

V_SAKNR(10) TYPE C.

DATA TABIND TYPE I.

LOOP AT T_INTAB.

TABIND = SY-TABIX + 1.

IF T_INTAB-GL_ACCNT+0(4) = '0000'.

T_INTAB-GL_ACCNT = T_INTAB-GL_ACCNT+4(6).

ENDIF.

IF T_INTAB-GL_ACCNT >= '600000' AND T_INTAB-GL_ACCNT <= '999999'.

CLEAR: V_COSTCTR,V_SAKNR,V_STRLEN.

CONCATENATE '00000' T_INTAB-COST_CNTR INTO V_COSTCTR.

IF T_INTAB-COST_CNTR = SPACE AND T_INTAB-POSID = SPACE AND

T_INTAB-PROF_CTR = SPACE AND T_INTAB-NETWORK = SPACE.

IF V_MSSG EQ ' '.

SKIP.

V_MSSG = 'Message type: Error'.

WRITE:/ V_MSSG.

ULINE.

ENDIF.

WRITE:/ TABIND, 'G/L Account', T_INTAB-GL_ACCNT,

'requires cost object(i.e WBS, cost center etc)'.

FLAG1 = 'X'.

ELSE.

IF T_INTAB-COST_CNTR <> SPACE.

SELECT SINGLE * FROM CSKS WHERE KOKRS = 'CA01' AND

KOSTL = V_COSTCTR

AND ( DATBI >= P_POSTDT AND

DATAB <= P_POSTDT ) AND BUKRS = T_INTAB-COMPANY_CODE.

IF SY-SUBRC <> 0.

IF V_MSSG EQ ' '.

SKIP.

V_MSSG = 'Message type: Error'.

WRITE:/ V_MSSG.

ULINE.

ENDIF.

WRITE:/ TABIND, 'Cost center CA01 /'.

WRITE: T_INTAB-COST_CNTR NO-ZERO.

WRITE: 'does not exist on ' .

WRITE: V_POSTDT, 'and in company code',

T_INTAB-COMPANY_CODE .

WRITE: '.'.

FLAG1 = 'X'.

ELSE.

IF CSKS-BKZKP = 'X'.

IF V_MSSG EQ ' '.

SKIP.

V_MSSG = 'Message type: Error'.

WRITE:/ V_MSSG.

ULINE.

ENDIF.

WRITE:/ TABIND, 'Cost center CA01 /'.

WRITE: T_INTAB-COST_CNTR NO-ZERO.

WRITE: 'Blocked on'.

WRITE: V_POSTDT, 'and in company code',

T_INTAB-COMPANY_CODE .

WRITE: '.'.

FLAG1 = 'X'.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

CLEAR V_STRLEN. "syalla 07/11/00

V_STRLEN = STRLEN( T_INTAB-LINE_DESC ). "syalla 07/11/00

IF V_STRLEN > 50. "syalla 07/11/00

IF V_MSSG = ' '. "syalla 07/11/00

V_MSSG = 'Message type: Error'."syalla 07/11/00

WRITE:/ V_MSSG. "syalla 07/11/00

ULINE. "syalla 07/11/00

ENDIF. "syalla 07/11/00

IF V_STRLEN > 100. "syalla 07/11/00

WRITE: TABIND,

T_INTAB-LINE_DESC ,'Text exceeds field width shown partial text'.

ELSE. "SYALLA 07/11/00

WRITE: TABIND,

T_INTAB-LINE_DESC ,'Text exceeds field width'. "syalla 07/11/00

FLAG1 = 'X'.

ENDIF. "SYALLA 07/11/00

ENDIF. "syalla 07/11/00

CLEAR: V_STRLEN. "syalla 07/11/00

V_STRLEN = STRLEN( T_INTAB-GL_ACCNT ).

IF V_STRLEN = 1.

CONCATENATE '000000000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 2.

CONCATENATE '00000000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 3.

CONCATENATE '0000000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 4.

CONCATENATE '000000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 5.

CONCATENATE '00000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 6.

CONCATENATE '0000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 7.

CONCATENATE '000' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 8.

CONCATENATE '00' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 9.

CONCATENATE '0' T_INTAB-GL_ACCNT INTO V_SAKNR.

ELSEIF V_STRLEN = 10.

V_SAKNR = T_INTAB-GL_ACCNT .

ENDIF.

SELECT SINGLE * FROM SKB1 WHERE BUKRS = T_INTAB-COMPANY_CODE AND

SAKNR = V_SAKNR AND

XLOEB = ' '.

IF SY-SUBRC <> 0 .

IF V_MSSG EQ ' '.

SKIP.

V_MSSG = 'Message type: Error'.

WRITE:/ V_MSSG.

ULINE.

ENDIF.

WRITE:/ TABIND, 'G/L account'.

FLAG1 = 'X'.

WRITE: T_INTAB-GL_ACCNT NO-ZERO.

WRITE: T_INTAB-COMPANY_CODE NO-ZERO.

WRITE: 'does not exist '.

WRITE: '.'.

ENDIF.

ENDLOOP.

ENDFORM. " GET_ERROR_COST_CENTERS

2 REPLIES 2
Read only

Former Member
0 Likes
380

All you have to do is write a condition where you pass the value to the field VBSEGS-DMBTR... When you dont find the value for this in the flatfile. Do no execute that sepecific statement.. It will automatically pick the default valu..

Regards,

VIjay

Read only

Former Member
0 Likes
380

Dear Daniel,

CAn you tell me the steps in your recording so that I can hekp you better

Regards,

Vijay