‎2006 Mar 09 3:01 PM
hello guys i need some help from u
i am having some part of function module
doc_type = 'ED'.
Document Header fields
documentheader-appl_area = 'P'.
documentheader-doc_type = doc_type.
documentheader-currency = comp_code_data-waers.
documentheader-doc_source_key = '01'.
documentheader-post_date = erfpacht-bldat.
documentheader-doc_date = erfpacht-bldat.
documentheader-ref_doc_no = erfpacht-xblnr.
in this functionmodule someone hardcoded at the fields ed, p, 01 i have to replace these with variables
for this i have to build an internal table with these fields all the fields existing in tfk033d table and i ahve to extarct the data from the data base
can anyone guide me how to write the things
i appreciate your help
‎2006 Mar 09 3:05 PM
Hi Naveen,
You can do a single select from the table & pass those values from the header to the fields..
Hi you can do like...
SELECT SINGLE * FROM tfk033d WHERE <CONDITIONS>.
Message was edited by: Phani Kiran Nudurupati
‎2006 Mar 09 3:05 PM
Can you mail the name of function module which has these lines as part of the source code?
‎2006 Mar 09 3:07 PM
hey
the function module name is z_fica_document_create
this is the functin v r using
‎2006 Mar 09 3:11 PM
I don't have that table in my system but you can write a selet on this table and get details instead of hardcoding. Else pass these entries as import parameters. As it belongs to header table - i believe there is only one header record so you can pass it as a structure and remove the hardcoding.
‎2006 Mar 09 3:06 PM
‎2006 Mar 09 3:14 PM
hello rich,
here i am giving the fields that to be changed in that code
doc-type is tfk033d-key05,
in place of p is that is application area ie tfk003d-applk,
in plafe of '01' filed is tfk003d-key06 this is document origin
these values i have to change in the above can u more specific about this answer
i appreciate your help
please help me in this regard
‎2006 Mar 09 3:18 PM
Hi Naveen,
Just do like this..
tables: tfk003d.
SELECT SINGLE * FROM TFK003D.
documentheader-doc-type = tfk033d-key05.
documentheader-appl_area = tfk003d-applk.
documentheader-doc_source_key = tfk003d-key06.
Here you do your rest of coding..
‎2006 Mar 09 3:19 PM
for more info i am pasting the total code in the function module here
FUNCTION z_fica_document_create.
*"----
""Lokale interface:
*" IMPORTING
*" REFERENCE(ERFPACHT) TYPE ZST_ERFPACHT
*" REFERENCE(TESTRUN) TYPE BAPIFLAG OPTIONAL
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRET2
*"----
DATA: documentheader TYPE bapidfkkko,
partnerposition TYPE bapidfkkop,
genledgerposition TYPE bapidfkkopk,
partnerpositions TYPE TABLE OF bapidfkkop,
genledgerpositions TYPE TABLE OF bapidfkkopk,
comp_code TYPE bukrs,
comp_code_data TYPE t001,
cont_acct_data TYPE fkkvkp,
acct_determination TYPE tfk033d,
doc_type TYPE blart_kk,
t100 TYPE t100.
TABLES: tfk001g, tfk033d.
REFRESH: partnerpositions, genledgerpositions.
clear: documentheader, partnerposition, genledgerposition, comp_code, comp_code_data,cont_acct_data,
acct_determination, doc_type.
Get Data From Contract Account - Partner Specific
SELECT SINGLE * FROM fkkvkp
INTO cont_acct_data
WHERE gpart = erfpacht-partner.
AND vkont = assessment-cont_acct.
IF sy-subrc <> 0.
EXIT.
ENDIF.
Get Standard Company Code
IF cont_acct_data-stdbk IS NOT INITIAL.
comp_code = cont_acct_data-stdbk.
ELSE.
Get Paying Company Code from Company Code Group
SELECT SINGLE pybuk FROM tfk001g
INTO comp_code
WHERE opbuk = cont_acct_data-opbuk.
IF sy-subrc <> 0.
return-type = 'E'.
return-id = 'ZTRM'.
return-number = '003'.
return-message_v1 = cont_acct_data-opbuk.
SELECT SINGLE * FROM t100 INTO t100
WHERE sprsl = sy-langu
AND arbgb = return-id
AND msgnr = return-number.
return-message = t100-text.
EXIT.
ENDIF.
ENDIF.
Get Currency and Chart of Accounts
CALL FUNCTION 'COMPANY_CODE_READ'
EXPORTING
i_bukrs = comp_code
IMPORTING
e_t001 = comp_code_data
EXCEPTIONS
country_not_found = 1
no_such_code = 2
space_input = 3
wrong_kkber = 4
OTHERS = 5.
IF sy-subrc <> 0.
return-type = sy-msgty.
return-id = sy-msgid.
return-number = sy-msgno.
return-message_v1 = sy-msgv1.
return-message_v2 = sy-msgv2.
return-message_v3 = sy-msgv3.
return-message_v4 = sy-msgv4.
SELECT SINGLE * FROM t100 INTO t100
WHERE sprsl = sy-langu
AND arbgb = sy-msgid
AND msgnr = sy-msgno.
return-message = t100-text.
EXIT.
ENDIF.
doc_type = 'ED'.
Document Header fields
documentheader-appl_area = 'P'.
documentheader-doc_type = doc_type.
documentheader-currency = comp_code_data-waers.
documentheader-doc_source_key = '01'.
documentheader-post_date = erfpacht-bldat.
documentheader-doc_date = erfpacht-bldat.
documentheader-ref_doc_no = erfpacht-xblnr.
Reconciliation Key
CONCATENATE documentheader-post_date+2(6) '-TXRET'
INTO documentheader-fikey.
CALL FUNCTION 'FKK_FIKEY_CHECK'
EXPORTING
i_fikey = documentheader-fikey
i_open_without_dialog = 'X'
EXCEPTIONS
non_existing = 1
OTHERS = 2.
IF sy-subrc <> 0.
return-type = sy-msgty.
return-id = sy-msgid.
return-number = sy-msgno.
return-message_v1 = sy-msgv1.
return-message_v2 = sy-msgv2.
return-message_v3 = sy-msgv3.
return-message_v4 = sy-msgv4.
SELECT SINGLE * FROM t100
WHERE sprsl = sy-langu
AND arbgb = sy-msgid
AND msgnr = sy-msgno.
return-message = t100-text.
EXIT.
ENDIF.
IF sy-subrc <> 0.
return-type = 'E'.
return-id = 'ZTRM'.
return-number = '002'.
return-message_v1 = erfpacht-psobtyp. "AC01+-
SELECT SINGLE * FROM t100
WHERE sprsl = sy-langu
AND arbgb = return-id
AND msgnr = return-number.
return-message = t100-text.
EXIT.
ENDIF.
partnerposition-item = '0001'.
partnerposition-comp_code = comp_code.
partnerposition-buspartner = erfpacht-partner.
partnerposition-cont_acct = erfpacht-cont_acct.
partnerposition-contract = erfpacht-contract.
partnerposition-appl_area = 'P'.
partnerposition-main_trans = erfpacht-main.
partnerposition-sub_trans = erfpacht-sub.
partnerposition-doc_date = erfpacht-bldat.
partnerposition-post_date = erfpacht-bldat.
CALL FUNCTION 'Z_DUE_DATE_DETERMINE'
EXPORTING
I_BLART = doc_type
I_BLDAT = erfpacht-bldat
I_BUDAT = erfpacht-bldat
I_CPUDT = erfpacht-bldat
IMPORTING
E_FAEDN = partnerposition-net_date
EXCEPTIONS
ERROR_MESSAGE = 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.
partnerposition-net_date = erfpacht-bldat.
partnerposition-disc_due = erfpacht-bldat.
partnerposition-amount = erfpacht-amount.
partnerposition-period_key = erfpacht-persl.
partnerposition-paymnt_grp = erfpacht-bldat+2(2).
Account Determination - Receivables
CLEAR acct_determination.
acct_determination-applk = 'P'.
acct_determination-buber = 'P000'. "Receivables
acct_determination-ktopl = comp_code_data-ktopl.
acct_determination-key01 = comp_code.
acct_determination-key02 = 'EB'. "AC01+-
acct_determination-key03 = erfpacht-main.
acct_determination-key04 = erfpacht-sub.
CALL FUNCTION 'FKK_ACCOUNT_DETERMINE'
EXPORTING
i_tfk033d = acct_determination
IMPORTING
e_tfk033d = acct_determination
EXCEPTIONS
error_in_input_data = 1
nothing_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
EXIT.
ENDIF.
partnerposition-g_l_acct = acct_determination-fun01.
APPEND partnerposition TO partnerpositions.
Offset Item Fields
genledgerposition-item = '0001'.
genledgerposition-comp_code = comp_code.
genledgerposition-amount = partnerposition-amount * -1.
Account Determination - Revenue
CLEAR acct_determination.
acct_determination-applk = 'P'.
acct_determination-buber = 'P001'. "Revenue
acct_determination-ktopl = comp_code_data-ktopl.
acct_determination-key01 = comp_code.
acct_determination-key02 = 'EB'. "AC01+-
acct_determination-key03 = erfpacht-main.
acct_determination-key04 = erfpacht-sub.
CALL FUNCTION 'FKK_ACCOUNT_DETERMINE'
EXPORTING
i_tfk033d = acct_determination
IMPORTING
e_tfk033d = acct_determination
EXCEPTIONS
error_in_input_data = 1
nothing_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
EXIT.
ENDIF.
genledgerposition-g_l_acct = acct_determination-fun01.
APPEND genledgerposition TO genledgerpositions.
BAPI Call
CALL FUNCTION 'BAPI_CTRACDOCUMENT_CREATE'
EXPORTING
testrun = testrun
documentheader = documentheader
IMPORTING
return = return
TABLES
partnerpositions = partnerpositions
genledgerpositions = genledgerpositions.
ENDFUNCTION.
‎2006 Mar 09 3:32 PM
Hi naveen,
I dont find tfk033d in my system,so i cant really tell you the where condition.But you can do a SELECT SINGLE on the table tfk033d & pass the data as required.
‎2006 Mar 09 3:39 PM
Basically you have to select the values from TFK003D as Rich mentioned and then loop at that internal table and prepare your BAPI data and call the BAPI. Here is how
LOOP AT i_tfk003d.
CLEAR: doc_type, documentheader,
partnerposition, partnerpositions[],
genledgerposition, genledgerpositions[].
doc_type = 'ED'.
* Document Header fields
documentheader-appl_area = 'P'.
documentheader-doc_type = doc_type.
documentheader-currency = comp_code_data-waers.
documentheader-doc_source_key = '01'.
documentheader-post_date = erfpacht-bldat.
documentheader-doc_date = erfpacht-bldat.
documentheader-ref_doc_no = erfpacht-xblnr.
* Reconciliation Key
CONCATENATE documentheader-post_date+2(6) '-TXRET'
INTO documentheader-fikey.
CALL FUNCTION 'FKK_FIKEY_CHECK'
EXPORTING
i_fikey = documentheader-fikey
i_open_without_dialog = 'X'
EXCEPTIONS
non_existing = 1
OTHERS = 2.
IF sy-subrc <> 0.
return-type = sy-msgty.
return-id = sy-msgid.
return-number = sy-msgno.
return-message_v1 = sy-msgv1.
return-message_v2 = sy-msgv2.
return-message_v3 = sy-msgv3.
return-message_v4 = sy-msgv4.
SELECT SINGLE * FROM t100
WHERE sprsl = sy-langu
AND arbgb = sy-msgid
AND msgnr = sy-msgno.
IF sy-subrc <> 0.
return-type = 'E'.
return-id = 'ZTRM'.
return-number = '002'.
return-message_v1 = erfpacht-psobtyp. "AC01+-
SELECT SINGLE * FROM t100
WHERE sprsl = sy-langu
AND arbgb = return-id
AND msgnr = return-number.
ENDIF.
return-message = t100-text.
ENDIF.
partnerposition-item = '0001'.
partnerposition-comp_code = comp_code.
partnerposition-buspartner = erfpacht-partner.
partnerposition-cont_acct = erfpacht-cont_acct.
partnerposition-contract = erfpacht-contract.
partnerposition-appl_area = 'P'.
partnerposition-main_trans = erfpacht-main.
partnerposition-sub_trans = erfpacht-sub.
partnerposition-doc_date = erfpacht-bldat.
partnerposition-post_date = erfpacht-bldat.
CALL FUNCTION 'Z_DUE_DATE_DETERMINE'
EXPORTING
i_blart = doc_type
i_bldat = erfpacht-bldat
i_budat = erfpacht-bldat
i_cpudt = erfpacht-bldat
IMPORTING
e_faedn = partnerposition-net_date
EXCEPTIONS
error_message = 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.
* partnerposition-net_date = erfpacht-bldat.
* partnerposition-disc_due = erfpacht-bldat.
partnerposition-amount = erfpacht-amount.
partnerposition-period_key = erfpacht-persl.
partnerposition-paymnt_grp = erfpacht-bldat+2(2).
* Account Determination - Receivables
CLEAR acct_determination.
acct_determination-applk = 'P'.
acct_determination-buber = 'P000'. "Receivables
acct_determination-ktopl = comp_code_data-ktopl.
acct_determination-key01 = comp_code.
acct_determination-key02 = 'EB'. "AC01+-
acct_determination-key03 = erfpacht-main.
acct_determination-key04 = erfpacht-sub.
CALL FUNCTION 'FKK_ACCOUNT_DETERMINE'
EXPORTING
i_tfk033d = acct_determination
IMPORTING
e_tfk033d = acct_determination
EXCEPTIONS
error_in_input_data = 1
nothing_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
EXIT.
ENDIF.
partnerposition-g_l_acct = acct_determination-fun01.
APPEND partnerposition TO partnerpositions.
* Offset Item Fields
genledgerposition-item = '0001'.
genledgerposition-comp_code = comp_code.
genledgerposition-amount = partnerposition-amount * -1.
* Account Determination - Revenue
CLEAR acct_determination.
acct_determination-applk = 'P'.
acct_determination-buber = 'P001'. "Revenue
acct_determination-ktopl = comp_code_data-ktopl.
acct_determination-key01 = comp_code.
acct_determination-key02 = 'EB'. "AC01+-
acct_determination-key03 = erfpacht-main.
acct_determination-key04 = erfpacht-sub.
CALL FUNCTION 'FKK_ACCOUNT_DETERMINE'
EXPORTING
i_tfk033d = acct_determination
IMPORTING
e_tfk033d = acct_determination
EXCEPTIONS
error_in_input_data = 1
nothing_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
EXIT.
ENDIF.
genledgerposition-g_l_acct = acct_determination-fun01.
APPEND genledgerposition TO genledgerpositions.
* BAPI Call
CALL FUNCTION 'BAPI_CTRACDOCUMENT_CREATE'
EXPORTING
testrun = testrun
documentheader = documentheader
IMPORTING
return = return
TABLES
partnerpositions = partnerpositions
genledgerpositions = genledgerpositions.
ENDLOOP.
‎2006 Mar 09 3:50 PM
hey srinivas thanks alot for u r directions
but don't need this stuff
what i need is to put the variables in place of the hardcoded values
for this i have to build an internal table and i have to retreive the data from the datebase table ie tfk033d
so if u can help please i need the help to build the internal table and select statement with condition
inthis table primary key field is ''applk'' ie applicatin area
i appreciate ur help
‎2006 Mar 09 8:14 PM
I don't what you have that you can use in the where clause for this table. I don't know this table because it is not there in my version of R/3. Assuming you need all the values from this table, here is code. If you need to restrict which records need to be selected from this table, you need to add the WHERE clause to the select statement for your conditions.
DATA: i_tfk033d TYPE TABLE OF tfk033d WITH HEADER LINE.
SELECT * INTO TABLE i_tfk033d FROM tfk033d.
LOOP AT i_tfk003d.
CLEAR: doc_type, documentheader,
partnerposition, partnerpositions[],
genledgerposition, genledgerpositions[].
* document header fields
documentheader-appl_area = i_tfk003d-applk.
documentheader-doc_type = i_tfk033d-key05.
documentheader-doc_source_key = i_tfk003d-key06.
*--- do the rest needed for the BAPI call
ENDLOOP.
‎2006 Mar 09 3:10 PM
Hi Naveen,
Things look pretty straight forward by your description of the problem.
Just declare an internal table with variables of the same type (in the LHS side)
for doc_type ,appl_area and source_key say,
v_doc_type, v_appl_area and v_source_key.
get the data from the database(U should know the table name) using a select statement.
and then use these variables in place of the constants.
loop at itab.
doc_type = itab-v_doc_type.
Document Header fields
documentheader-appl_area = itab-v_appl_area.
documentheader-doc_type = doc_type.
documentheader-currency = comp_code_data-waers.
documentheader-doc_source_key = itab-v_source_key.
documentheader-post_date = erfpacht-bldat.
documentheader-doc_date = erfpacht-bldat.
documentheader-ref_doc_no = erfpacht-xblnr.
.
.
.
.
endloop.
‎2006 Nov 14 10:30 PM
Hi Guys
I think the reason you don't have the table in your systems is because it is not a table. I think tfk003d is 'n structure defined local to the FM or program and tfk003 is the corresponding table.
So Naveen, if you do a select off tfk003 to extract the relevant data you can plug it into the code as describe by others in this thread.
Cheers,
Corné
‎2006 Nov 15 1:24 AM
Hi Naveen,
If your issue is still not resolved, please look below...
In order to retrieve the data from table TFK033D, you need to know the business logic for accessing this table. So whatever fields you want to use in the WHERE clause of the SELECT statement on TFK033D, you can add as IMPORT parameters of your Z function module and then get the data from this table.
The table TFK033D has a composite Primary Kay (consisting of 11 fields). I would suggest that you get the data for ALL the KEY fields of TFK033D if possible as that would return you exactly one row from this table which you can then use in your function module...
Hope this helps...
Regards,
Amit
‎2009 Jan 16 4:59 AM
Hi everyone.
Is there other BAPI function module with similar function as BAPI_CTRACDOCUMENT_CREATE?
How do we post credit GL accounts and debit GL accounts?
Thanks in advance.