RM: create document reference by BAPI or class
Hallo,
I'd like to create reference to a document from another document by use of some BAPI or class.
I found class CL_RMPS_LINKS. Is this class suitable for my idea? Can anybody give me some example how to create reference to another document?
Best regards,
Josef Motl
ry this FM BAPI_DELIVERYFREE_PROXY_CREATE. I had done used it earlier, may be it will work.
Re: BAPI to create outbound delivery
Just try for this FM: BAPI_OUTB_DELIVERY_SAVEREPLICA
BAPI_GOODSMVT_CREATE
Check the Function Group V50S for more delivery BAPI's
try using the BAPI BAPI_GOODSMVT_CREATE
Delivery Type with out ref to order is LO. This is used in a scenario where you want to supply some samples to customer. for samples there is no cutsomer order but you want to supply material.
Also there might a scenario where you have already created a order and you want to add some extra item in delivery which is not in order. in this case alos item category gets determined as given below.
To create LO you have to use tcode VL01NO and Shpping point, Delivery type LO, Sales area. Item category would be determined based on standard rule i.e., Delivery type + Item category group + useage. You have make this assignments in IMG for this work.
Lo is used for inbound deliveries which will be routed thru MM .
example if vendor is supplying some goods to ur company and if you want to take inbound delievery in SD for warehouse logistcs purposes for transfer order and also if it is routed thru shipment .this will be used.
usually this del doc type is rarely used
Hope this clarifies your doubts.
Please give me reward point if it is useful.
Thanks
Murali Poli
Similar Messages
-
BAPI Sales Order create with reference Invoice document
Hi
I am using BAPI ''SD_SALESDOCUMENT_CREATE'' to create debit memo request with reference Invoice document.
First time its successfully created with reference Invoice.When i am going to create 2nd time debit memo request with same reference Invoice and item
no its giving following error.
Reference quantity:
10 EA (total referenced:
40 EA)
Error in SALES_ITEM_IN 000010
Condition ZSLS is not allowed as header condition
Sales document was not changed
Please help any one to resolved this issue.
Regards
ShyamSD_SALESDOCUMENT_CREATE is not a BAPI. Is there any specific reason you're using this FM when the actual BAPI exists?
ZSLS is a custom condition. There might as well be some user exit that attempts to add it [possibly incorrectly], how would we know this on SCN? There is enough information in the error message to troubleshoot on your own, it seems. What kind of analysis have you done before posting on SCN? -
Create an order using BAPI with reference to another one.
Hi everybody,
I'm trying to create a new sales order with reference to another one (That's important because of the documents flow).
I'm using 'BAPI_SALESORDER_CREATEFROMDAT2' but I couldn´t do it yet. I've read some ideas about this kind of creation in this forum; but I still haven´t found the solution yet.
Some ideas about the BAPI parameters I nedd to complete?
Thanks in advance!!
Edited by: Ole ES on Sep 11, 2008 12:32 PMHi,
Are you sure you can create a sales order with reference to ANOTHER sales order? The reason I ask is that in the front end, sales orders are created with reference to either quotations or contracts. There are settings known as "copying control" that need to be maintained for this to show up as document flow.
We have been working on a BAPI to create a sales order, but that is without reference to another document, and it works fine.
Could you please elaborate?
Cheers. -
i created boolean references in my main vi block diagram and copied them to my sub vi front panel. when wire my reference in my main vi to one the input node of the sub vi the wire is broken. the error says its a class conflict why?
Expanding and clarifying what BJD said;
After you create the temporary sub-VI that BJD mentioned, open its front panel and copy the reference control that LV created when it created the sub-VI.
This reference control will be correct class etc that you need. Use the control to replace the original control that you were attempting to wire up.
The technique of "create sub-VI...copy" always works for me.
There is one more thing that you should watch out for.
The mechanical action of the boolean can not be set for latch action when attempting to read the value using a value property node.
Trying to help,
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Hi,
When I create a sales order with reference to a Quote, the pricing condition types are duplicating. Same is happening when subsequent documents like Billing, credit memo request and credit memo are created. Particularly, the condition types are doubled/tripled/.... in the subsequent documents. Because of this, pricing net value is calculated wrong. For example, freight charges getting added twice. I searched the forum and found similar issue was discussed at Condition types - Doubling UP raised by forum member Sridhar Vijjhalwar, however there is no solution added in it.
Has any other member came across this issue and resolved?
I have checked the access sequence and exclusive indicators are checked. Copy controls are also checked, looked good and I tested by adding copying type D/G. Checked OSS note also and found one OSS note 1459807 - Invoice has missing/incorrect conditions when created from a sales order.
but it is not solving the problem either. Issue also elevated to SAP for their investigation. Our system is SAP ECC 6.0 - EHP6.
Quote Pricing:
Sales order Pricing:
I appreciate any pointers to resolve the issue.
Regards,what was the scenario, and how did you replicate?
It is a configuration for a new project (France country), however we found that the same issue popping up for existing business processes also. As for replicating, we just tried the same procedures, the issue is found in subsequent documents.
If you have observed one notable thing is - all the condition types which duplicated were Z Conditions, and the standard conditions were never duplicated at least in my case.
In our case even standard condition types like MWST, SKTO, GRWR, VPRS also shows duplicating.
if you can throw about the business process?
As you have mentioned order created with reference to quote was only the straight forward scenario?
I tested other scenario also, like creating a sales order, then delivery and then billing. In this case in billing document, the condition types are duplicating. If I create a credit memo request against the billing document, then it further duplicating.
I am not sure what is causing this. I initially thought it may be copy control settings pertaining to the new project, however other business documents also has the same issue. Other business are using different document types.
Thanks for your follow-up.
Regards, -
How to create an Accounting Document by calling BAPI
Hai friends ,
please tell me how to call this BAPI and fulfill all the parameters .. Please help me , I dont know the head and tail of it ...
create an Accounting Document by calling BAPI BAPI_ACC_DOCUMENT_POST
Below is the step to fill the parameters for BAPI:
Enter company code, invoice no, invoice date, document type, header text into DOCUMENTHEADER
Enter customer, item text, company code, payment term into ACCOUNTRECEIVABLE
Enter offset account, company code, document type, item text into ACCOUNTGL
Enter currency type u201800u2019, currency, exchange rate, amount into CURRENCYAMOUNT. Please note there will be two rows in this table, one positive amount and one negative amount
Call the BAPI to create the AR document. If p_check is checked, call the BAPI only without COMMIT and then do the message processing
If p_check is initial, COMMIT the data to the database tables.
Check the RETURN table after each BAPI, if no u2018Eu2019 message type found, output the document no. Otherwise, output the error messge to the screen with the message type u2018Eu2019.
thanks in advance ...Hi,
Check the link
http://www.sapbrainsonline.com/sapinfo/tutorial.php?artid=617
http://sap.ittoolbox.com/groups/technical-functional/sap-dev/bapi_acc_document_post-error-1973720
http://delaynomore.spaces.live.com/blog/cns!D2BFFB84EDFE4189!528.entry
http://sap4.com/wiki/index.php?title=BAPI_ACC_DOCUMENT_POST
http://www.sapfans.com
Anurodh -
Capturing Idocs created by BAPI Created Documents
Hi guys,
I have a big problem that i could really need some help, i use a BAPI:
BAPI_ACC_DOCUMENT_POST to create documents, in same cases depending on the accounts used there are some CO documents created and their equivalent idocs.
I searched everywhere but i didn't find any way to get the number of the idoc generated by the CO document that is created, does anyone have any suggestions on what to do ???
In regular Documents i use this Function:
SREL_GET_NEXT_RELATIONS
but in this case it doesn't work even after many trials !
I would really aprecciate the help !Hi
If you are trying to find the idoc number that created a document, there is a way you can find it out.
Note down the important field details of the document that would help you identify the idoc that created it.
Go to transaction WE05. Using the date range the document got posted, pull up a list of idocs.
Then click on the List Specific segment, put in the segment name of the idoc and click continue.
It will bring up a table of table. You can find the row that contains the field information you have and by that approach find the idoc that created the document.
Hope this helps
Deepa -
Bapi-salesorder creation error in creating document
hai friends..
iam doing creation of sales order using bapi .-structures..
but error in creating doucment ....
can u send me some example .. abt sales order .creation ..
once u check my code ...
DATA: BEGIN OF HEADER OCCURS 0,
VBELN LIKE BAPIVBELN-VBELN,
AUART LIKE VBAK-AUART,
VKORG LIKE VBAK-VKORG,
VTWEG LIKE VBAK-VTWEG ,
SPART LIKE VBAK-SPART,
VKBUR LIKE VBAK-VKBUR,
KUNNR LIKE BAPIPARNR-PARTN_NUMB ,"vbak-kunnr,
END OF HEADER.
DATA: BEGIN OF ITEM OCCURS 0,
VBELN LIKE BAPIVBELN-VBELN,
POSNR LIKE BAPISDITM-ITM_NUMBER ,"vbap-posnr,
MATNR LIKE VBAP-MATNR,
NETWR LIKE VBAP-NETWR,
KWMENGE LIKE VBAP-KWMENG,
WERKS LIKE VBAP-WERKS,
NETPR LIKE VBAP-NETPR,
END OF ITEM.
DATA: ORDER_HEADER_IN LIKE BAPISDHD1,
ORDER_HEADER_INX LIKE BAPISDHD1X.
DATA: ITAB_HEAD likE order_header_in,
ITAB_HEADX likE ORDER_HEADER_INX.
DATA: ITAB_ITEM TYPE STANDARD TABLE OF BAPISDITM WITH HEADER LINE,
ITAB_ITEMX TYPE STANDARD TABLE OF BAPISDITMX WITH HEADER LINE.
DATA: KUST TYPE STANDARD TABLE OF BAPIPARNR WITH HEADER LINE,
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: VNO LIKE BAPIVBELN-VBELN,
VCNT LIKE VBAP-POSNR.
LOOP AT HEADER.
VCNT = 10.
CLEAR ITAB_HEAD.
ORDER_HEADER_IN-REFOBJTYPE = 'OR'.
ORDER_HEADER_IN-REFOBJKEY = 'OR'.
ORDER_HEADER_IN-REFDOCTYPE = 'OR'.
ORDER_HEADER_IN-DOC_TYPE = HEADER-AUART.
ITAB_HEAD-DOC_TYPE = HEADER-AUART.
ITAB_HEAD-SALES_ORG = HEADER-VKORG.
ITAB_HEAD-DISTR_CHAN = HEADER-VTWEG.
ITAB_HEAD-DIVISION = HEADER-SPART.
ITAB_HEAD-SALES_OFF = HEADER-VKBUR.
KUST-PARTN_NUMB = HEADER-KUNNR.
ITAB_HEADX-DOC_TYPE = 'X'.
ITAB_HEADX-SALES_ORG = 'X'.
ITAB_HEADX-DISTR_CHAN = 'X'.
ITAB_HEADX-DIVISION = 'X'.
ITAB_HEADX-SALES_OFF = 'X'.
LOOP AT ITEM WHERE VBELN = HEADER-VBELN.
REFRESH RETURN.
ITAB_ITEM-ITM_NUMBER = VCNT.
ITAB_ITEM-MATERIAL = ITEM-MATNR.
ITAB_ITEM-NET_WEIGHT = ITEM-KWMENGE.
APPEND ITAB_ITEM.
ITAB_ITEMX-ITM_NUMBER = VCNT.
ITAB_ITEMX-MATERIAL = 'X'.
ITAB_ITEMX-NET_WEIGHT = 'X'.
APPEND ITAB_ITEMX.
VCNT = VCNT + 10 .
ENDLOOP.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
SALESDOCUMENTIN = SALESORDER
ORDER_HEADER_IN = ITAB_HEAD
ORDER_HEADER_INX = ITAB_HEADX
SENDER =
BINARY_RELATIONSHIPTYPE =
INT_NUMBER_ASSIGNMENT =
BEHAVE_WHEN_ERROR =
LOGIC_SWITCH =
TESTRUN =
CONVERT = ' '
IMPORTING
SALESDOCUMENT = VNO
TABLES
RETURN = RETURN
ORDER_ITEMS_IN = ITAB_ITEM
ORDER_ITEMS_INX = ITAB_ITEMX
ORDER_PARTNERS = KUST.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
IMPORTING
RETURN = RETURN.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
WRITE: / 'Error in creating document'.
ELSE.
COMMIT WORK AND WAIT.
ENDIF.
WRITE: / ' Sales Order NO IS: ', VNO.
WRITE: / SPACE.
CLEAR VNO.
WRITE SY-ULINE.
ENDLOOP.
my HEader is 123 OR 1000 30 10 SATYA.
ITem 2 IS 123 10 HAI 15
once u check it ......Hi Satya,
just check this
REPORT Z_STANDARD_SALES_ORDER no standard page heading.
DATA DECLARATION
CONSTANTS : C_X VALUE 'X'.
Structures to hold Sales order header data
DATA : HEADER LIKE BAPISDHD1," OCCURS 0 WITH HEADER LINE,
HEADERX LIKE BAPISDHD1X." OCCURS 0 WITH HEADER LINE.
Internal Tables to hold Sales order ITEM DATA
DATA : ITEM LIKE BAPISDITM OCCURS 0 WITH HEADER LINE,
ITEMX LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE.
Internal Tables to hold Partners ITEM DATA
DATA : PART LIKE BAPIPARNR OCCURS 0 WITH HEADER LINE.
Internal Tables to hold Partners SCHEDULE DATA
DATA: SCHEDULE LIKE BAPISCHDL OCCURS 0 WITH HEADER LINE,
SCHEDULEX LIKE BAPISCHDLX OCCURS 0 WITH HEADER LINE.
Internal table to hold messages from BAPI call
DATA: RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA W_MSG(150).
*DATA: begin of wa_MESSAGE,
message(150),
end of wa_message.
*DATA: itab_msg like table of wa_message with header line.
Data: Begin of Record occurs 0,
Control type i,
DOC_TYPE like HEADER-DOC_TYPE,
SALES_ORG like HEADER-SALES_ORG,
DISTR_CHAN like HEADER-SALES_ORG,
DIVISION like HEADER-DIVISION,
PURCH_NO_C like HEADER-PURCH_NO_C,
PARTN_NUMB like PART-PARTN_NUMB ,
PARTN_ROLE like PART-PARTN_ROLE ,
ITM_NUMBER like ITEM-ITM_NUMBER,
MATERIAL like ITEM-MATERIAL,
TARGET_QTY like item-TARGET_QTY,
REQ_QTY LIKE BAPISCHDL-REQ_QTY,
TARGET_QU like item-TARGET_QU,
PLANT like ITEM-PLANT,
PMNTTRMS like header-PMNTTRMS,
End of record.
data: itab like ALSMEX_TABLINE occurs 0,
wa like ALSMEX_TABLINE.
data: SO like BAPIVBELN-VBELN.
Selection Screen
selection-screen begin of block b1 with frame title text-001.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
selection-screen end of block b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILE USING P_FILE.
Start of Selection
start-of-selection.
DATA: xl type string.
xl = '*.xls'.
IF not P_FILE CP xl.
Message 'Wrong input file format' type 'E'.
ENDIF.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 13
I_END_ROW = 3000
TABLES
INTERN = itab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 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.
DATA POPULATION
loop at itab into wa.
if wa-col = '0001'.
record-Control = wa-value.
elseif wa-col = '0002'.
record-DOC_TYPE = wa-value.
elseif wa-col = '0003'.
record-SALES_ORG = wa-value.
elseif wa-col = '0004'.
record-DISTR_CHAN = wa-value.
elseif wa-col = '0005'.
record-DIVISION = wa-value.
elseif wa-col = '0006'.
record-PURCH_NO_C = wa-value.
elseif wa-col = '0007'.
record-PARTN_NUMB = wa-value.
elseif wa-col = '0008'.
record-PARTN_ROLE = wa-value.
elseif wa-col = '0009'.
record-PMNTTRMS = wa-value.
elseif wa-col = '0010'.
record-ITM_NUMBER = wa-value.
elseif wa-col = '0011'.
record-MATERIAL = wa-value.
elseif wa-col = '0012'.
record-REQ_QTY = wa-value.
elseif wa-col = '0013'.
record-TARGET_QU = wa-value.
elseif wa-col = '0014'.
record-PLANT = wa-value.
endif.
AT END OF row.
APPEND record.
CLEAR: wa, record.
ENDAT.
endloop.
DATA: tot_lines type i,
tot_po type i,
index type i.
describe table record lines tot_lines.
read table record index tot_lines.
tot_po = record-control.
DO tot_po times.
index = index + 1.
clear: HEADER,HEADERX,ITEM[],ITEMX[],RETURN,RETURN[],SCHEDULE[],SCHEDULEX[], PART[],PART.
refresh: ITEM[],ITEMX[],RETURN[],SCHEDULE[],SCHEDULEX[],PART[] .
POPULATE HEADER FLAG.
HEADERX-UPDATEFLAG = c_x.
HEADERX-doc_type = c_x.
HEADERX-SALES_ORG = c_x.
HEADERX-DISTR_CHAN = c_x.
HEADERX-DIVISION = c_x.
HEADERX-PURCH_NO_C = c_X.
HEADERX-PMNTTRMS = c_X.
loop at record where control = index.
POPULATE HEADER DATA FOR PO
HEADER-DOC_TYPE = record-DOC_TYPE.
HEADER-SALES_ORG = record-SALES_ORG.
HEADER-DISTR_CHAN = record-DISTR_CHAN.
HEADER-DIVISION = record-DIVISION.
HEADER-PURCH_NO_C = record-PURCH_NO_C.
HEADER-PMNTTRMS = record-PMNTTRMS.
*POPULATE ITEM DATA.
ITEM-ITM_NUMBER = record-ITM_NUMBER.
ITEM-MATERIAL = record-material.
ITEM-TARGET_QTY = record-TARGET_QTY.
ITEM-TARGET_QU = record-TARGET_QU.
ITEM-PLANT = record-PLANT .
APPEND ITEM.
*POPULATE ITEM FLAG TABLE
ITEMX-ITM_NUMBER = record-ITM_NUMBER.
ITEMX-UPDATEFLAG = C_X.
ITEMX-TARGET_QTY = C_X.
ITEMX-PLANT = C_X .
ITEMX-MATERIAL = C_X .
ITEMX-TARGET_QU = C_X .
APPEND ITEMX.
*POPULATE SCHEDULE TABLE
SCHEDULE-ITM_NUMBER = RECORD-ITM_NUMBER.
SCHEDULE-REQ_QTY = RECORD-REQ_QTY.
APPEND SCHEDULE.
*POPULATE SCHEDULE TABLE
SCHEDULEX-ITM_NUMBER = RECORD-ITM_NUMBER.
SCHEDULEX-REQ_QTY = C_X.
APPEND SCHEDULEX.
endloop.
*POPULATE PARTNER TABLE
PART-PARTN_NUMB = record-PARTN_NUMB.
PART-PARTN_ROLE = record-PARTN_ROLE.
APPEND PART.
*BAPI CALL
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN = HEADER
ORDER_HEADER_INX = HEADERX
SENDER =
BINARY_RELATIONSHIPTYPE =
INT_NUMBER_ASSIGNMENT =
BEHAVE_WHEN_ERROR =
LOGIC_SWITCH =
TESTRUN =
CONVERT = ' '
IMPORTING
SALESDOCUMENT = SO
TABLES
RETURN = RETURN
ORDER_ITEMS_IN = ITEM
ORDER_ITEMS_INX = ITEMX
ORDER_PARTNERS = PART
ORDER_SCHEDULES_IN = SCHEDULE
ORDER_SCHEDULES_INX = SCHEDULEX
ORDER_CONDITIONS_IN =
ORDER_CONDITIONS_INX =
ORDER_CFGS_REF =
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CFGS_BLOB =
ORDER_CFGS_VK =
ORDER_CFGS_REFINST =
ORDER_CCARD =
ORDER_TEXT =
ORDER_KEYS =
EXTENSIONIN =
PARTNERADDRESSES =
loop at return where type = 'E' and ID NE 'MEPO' and ID NE 'BAPI'.
WRITE:/ Return-message.
endloop.
*Confirm the document creation by calling database COMMIT
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
*Messages
loop at return where type = 'S' and number ne '233'.
WRITE:/ Return-message.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = return-ID
LANG = SY-LANGU
NO = return-NUMBER
IMPORTING
MSG = W_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
WRITE W_MSG.
itab_msg-message = w_msg.
append itab_msg.
clear: W_MSG.
ENDLOOP.
enddo.
-->P_W_FILE text
FORM GET_FILE USING P_W_FILE.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
FILE_NAME = P_W_FILE
EXCEPTIONS
MASK_TOO_LONG = 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.
ENDFORM. "GET_FILE
Regards,
Sachin -
Bapi for creating documents in cv03n
hi!
i am looking for a bapi to create document in cv03n and open an objectlink tab.
I need to transfer the following parameters:
document type = 'ENG'
tables:
objectlink: objecttype = 'AENR'
objectkey = change number field.
regards
yifathi!
i used the create item to open document and that was o.k,
but i also wanted to open objectlink tab and it didnt work.
i transfered documentdata-doctype = 'ENG'.
objectlinks-OBJECTTYPE = 'AENR'
objectlinks-OBJECTKEY = value of change
number
the system grants documentnumber internally and automatically.
regards
yifat -
Need no document flow update for sales order create with reference
Dear All.
We would like to have the ability to create a sales order with reference to another sales order, and have the document flow of the sales order not updated.
Unlike the case of a standard create with reference where the documents are linked, in this case there is no relationship between the documents. The first document is just acting like a template for the remaining documents, to save time during order entry.
We have turned off update of document flow at the line item level.
But I don't see a way for us to turn this off at the header (document level). So wondering if there's another way to turn this off, or possibly through user-exit or VOFM requirement?
Has anyone else done this?
I think that CRM has this functionality, but we're still entering orders through ERP-SD.
Many Thanks!Hello Colleague;
The issue you have reported is SAP standard. The checkbox "Update Document Flow" (V_TVCPAAP-UPFLU) controls document flow at item level. If this checkbox is set to blank, there will be no document flow at item level.
However, the document flow cannot be completely turned off - if the 'update document flow' indicator is blank, you will still see an entry in the document flow, but there will be no update to table VBFA (Sales Document Flow) and the document flow of the predecessor will not be updated at item level (no record in VBFA at item level).
The reason is that the system checks VBAP (Sales Document: Item Data) for fields VGBEL (Document number of the reference document) and VGPOS (Item number of the reference item) for values. You will always have document flow information on header and item level in the successor because it stores this information in table VBAP.
Related with this issue, you can find a Note 53383 for your review.
I hope it can clarify the case.
Regards
Ruy Castro -
Create with reference where original document is incomplete
Hi Guys
We use variant configuration as part of our sales order process. Within the VC we have 'discontinued' validation i.e. a component of the configuration may be discontinued and therefore unavailable. In this case, we would want to lock the configuration, reject the order item and create a new order item for a different component. We do not wish to delete the order item because of the effect this has on BI sales reporting.
However, if we later wish to create another document (such as a FOC replacement) with reference to this document we receive an error message to the effect that the document being referenced is incomplete and cannot be used as a reference.
Does anyone know of a way of being able to copy complete items only during create with reference or being able to set the status of an incomplete ('being processed') item to complete."Incomplete" and "being processed" are two different things. If document is "incomplete", there are some fields that are required and must be filled in before the document may be processed any further. As correctly pointed out above, such fields will appear in the incompletion log.
There is no way to work around the incompletion procedure. If you need to make the field required only in certain situations, you might want to take it out of the incompletion procedure and add a user exit instead.
If an order is displayed as "being processed", this means that one of the statuses (see Status tab on header and item level) is "partially processed". Normally setting the rejection reason updates the overall item's status (not to be confused with the header's status) to "complete", but I've heard of some cases when for some reason this does not happen. Unfortunately, I don't recall if there was any solution.
Hope this helps. -
Create sales order with reference via BAPI
Hi all,
I would like to know if is it possible to create a sales order with reference using BAPI, that is, I want to create an order from a contract, for example, referencing one or more contract itens. If so, what variable or table should I use?
I think that the most suitable function is
'BAPI_SALESORDER_CREATEFROMDAT2' or should I use another to do this?
I am using release SAP ECC 6.0.
Thanks for any help.
Pauloyes, you are using right BAPI i.e. BAPI_SALESORDER_CREATEFROMDAT2
You will have to provide ORDER_HEADER_IN in that, Others are optional, even then if you have data for them, Provide it for better performance.
For any confusion related to chosing BAPI : You may go to BAPI transaction and find out the correct BAPI according to ur need. for example sales order relatd BAPI's are
BAPI_SALESORDER_CHANGE :Change Sales Order
BAPI_SALESORDER_CREATEFROMDAT2: Create Sales Order
BAPI_SALESDOCU_CREATEWITHDIA: Create Data Container with Dialog
BAPI_SALESORDER_GETLIST:List of all Orders for Customer
and so on.
Reward if helpful.. -
Create contract with Purchase Requisition reference using BAPI
Hi friends! I need some help here to create a contract with reference to some purshase requisition. I found BAPI_CONTRACT_CREATE to do this, but I have no idea how to do to create with reference to pruchase requisition.
Anyone can give me a sample code or an idea how I can do this?
Thanks in advance for any help.Thanks friend. I filled Header, Headerx, item e itemx but I'm getting this error:
No instance of object type PurchasingContract has been created. External reference: # 1
Item category 9 not supported
I need fill something else? -
Creating Vendor Master through Bapi
Hi All,
Please help me out in creating vendor master using Bapi and also send me the program logic.
Thanks in Advance,
Sridhar ChHi Sridhar,
Refer to the following and award points if useful.BAPI is like using standard function modules.We will populate the parameters and handle errors from that.See the code below which is vendor debit posting.You can get an idea by the following code.
See the start of selection if this is confusing to you and understand the usage
* TABLES
TABLES: VBAK,
ADR6,
TRDYSE01CM.
* INCLUDE
INCLUDE ZZUTI_STD_HEADER_FOOTER. "Standard header and footer
* TYPES DECLARATION
TYPES:
BEGIN OF T_CRMEMO,
VBELN TYPE VBAK-VBELN,
POSNR TYPE VBAP-POSNR,
ERDAT TYPE VBAK-ERDAT,
AUART TYPE VBAK-AUART,
AUGRU TYPE VBAK-AUGRU,
WAERK TYPE VBAK-WAERK,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
VDATU TYPE VBAK-VDATU,
BSTNK TYPE VBAK-BSTNK,
BSARK TYPE VBAK-BSARK,
BSTDK TYPE VBAK-BSTDK,
AEDAT TYPE VBAK-AEDAT,
BUKRS_VF TYPE VBAK-BUKRS_VF,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
ZIEME TYPE VBAP-ZIEME,
END OF T_CRMEMO,
BEGIN OF T_CRMEMO_CHANGE,
VBELN(90) TYPE C,
POSNR TYPE VBAP-POSNR,
ERDAT TYPE VBAK-ERDAT,
AUART TYPE VBAK-AUART,
AUGRU TYPE VBAK-AUGRU,
WAERK TYPE VBAK-WAERK,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
VDATU TYPE VBAK-VDATU,
BSTNK TYPE VBAK-BSTNK,
BSARK TYPE VBAK-BSARK,
BSTDK TYPE VBAK-BSTDK,
AEDAT TYPE VBAK-AEDAT,
BUKRS_VF TYPE VBAK-BUKRS_VF,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
ZIEME TYPE VBAP-ZIEME,
END OF T_CRMEMO_CHANGE,
BEGIN OF T_MVKE,
MATNR TYPE MVKE-MATNR,
VKORG TYPE MVKE-VKORG,
VTWEG TYPE MVKE-VTWEG,
MTPOS TYPE MVKE-MTPOS,
END OF T_MVKE,
BEGIN OF T_ORDERS,
VBELV TYPE VBFA-VBELV,
POSNV TYPE VBFA-POSNV,
VBELN TYPE VBFA-VBELN,
POSNN TYPE VBFA-POSNN,
VBTYP_N TYPE VBFA-VBTYP_N,
END OF T_ORDERS,
BEGIN OF T_EKPO,
EBELN TYPE EKKO-EBELN,
EBELP TYPE EKPO-EBELP,
WAERS TYPE EKKO-WAERS,
MENGE TYPE EKPO-MENGE,
MEINS TYPE EKPO-MEINS,
NETPR TYPE EKPO-NETPR,
PEINH TYPE EKPO-PEINH,
mwskz TYPE EKPO-mwskz,
TXJCD TYPE EKPO-TXJCD,
END OF T_EKPO,
BEGIN OF T_EKBE,
EBELN TYPE EKBE-EBELN,
EBELP TYPE EKBE-EBELP,
ZEKKN TYPE EKBE-ZEKKN,
VGABE TYPE EKBE-VGABE,
GJAHR TYPE EKBE-GJAHR,
BELNR TYPE EKBE-BELNR,
BUZEI TYPE EKBE-BUZEI,
END OF T_EKBE,
BEGIN OF T_RBKP,
BELNR TYPE RBKP-BELNR,
GJAHR TYPE RBKP-GJAHR,
BLDAT TYPE RBKP-BLDAT,
BUDAT TYPE RBKP-BUDAT,
XBLNR TYPE RBKP-XBLNR,
LIFNR TYPE RBKP-LIFNR,
RMWWR TYPE RBKP-RMWWR,
WMWST1 TYPE RBKP-WMWST1,
XRECH TYPE RBKP-XRECH,
STBLG TYPE RBKP-STBLG,
END OF T_RBKP,
BEGIN OF T_CDHDR,
OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
OBJECTID TYPE CDHDR-OBJECTID,
CHANGENR TYPE CDHDR-CHANGENR,
UDATE TYPE CDHDR-UDATE,
UTIME TYPE CDHDR-UTIME,
END OF T_CDHDR,
BEGIN OF T_CDPOS,
OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
OBJECTID TYPE CDHDR-OBJECTID,
CHANGENR TYPE CDHDR-CHANGENR,
TABNAME TYPE CDPOS-TABNAME,
TABKEY TYPE CDPOS-TABKEY,
FNAME TYPE CDPOS-FNAME,
CHNGIND TYPE CDPOS-CHNGIND,
VALUE_NEW TYPE CDPOS-VALUE_NEW,
VALUE_OLD TYPE CDPOS-VALUE_OLD,
END OF T_CDPOS,
BEGIN OF T_CHANGE_DOCS,
OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
OBJECTID TYPE CDHDR-OBJECTID,
CHANGENR TYPE CDHDR-CHANGENR,
UDATE TYPE CDHDR-UDATE,
UTIME TYPE CDHDR-UTIME,
TABNAME TYPE CDPOS-TABNAME,
TABKEY TYPE CDPOS-TABKEY,
FNAME TYPE CDPOS-FNAME,
CHNGIND TYPE CDPOS-CHNGIND,
VALUE_NEW TYPE CDPOS-VALUE_NEW,
VALUE_OLD TYPE CDPOS-VALUE_OLD,
END OF T_CHANGE_DOCS,
BEGIN OF T_SUCCESS,
crmemo TYPE VBAK-vbeln,
cmemo TYPE VBAK-vbeln,
orders TYPE VBAK-vbeln,
po TYPE VBAK-vbeln,
miro_no TYPE VBAK-vbeln,
text(20) TYPE C,
END OF T_SUCCESS,
BEGIN OF T_ERROR,
crmemo TYPE VBAK-vbeln,
cmemo TYPE VBAK-vbeln,
orders TYPE VBAK-vbeln,
po TYPE VBAK-vbeln,
miro_no TYPE VBAK-vbeln,
text(100) TYPE C,
END OF T_ERROR.
* WORKAREA DECLARATION
DATA:
WA_CRMEMO TYPE T_CRMEMO,
WA_CRMEMO_CHANGE TYPE T_CRMEMO_CHANGE,
WA_MVKE TYPE T_MVKE,
WA_ORDERS TYPE T_ORDERS,
WA_CMEMO TYPE T_ORDERS,
WA_PO TYPE T_ORDERS,
WA_EKPO TYPE T_EKPO,
WA_EKBE TYPE T_EKBE,
WA_EKBE_TEMP TYPE T_EKBE,
WA_RBKP TYPE T_RBKP,
WA_RBKP_TMP TYPE T_RBKP,
WA_CDHDR TYPE T_CDHDR,
WA_CDPOS TYPE T_CDPOS,
WA_CHANGE_DOCS TYPE T_CHANGE_DOCS,
WA_CRMEMO_MR8M TYPE T_CRMEMO,
WA_SUCCESS TYPE T_SUCCESS,
WA_ERROR TYPE T_ERROR,
WA_SUCCESS_MR8M TYPE T_SUCCESS,
WA_ERROR_MR8M TYPE T_ERROR.
*--Work area for all the internal tables used for Sending Mail
DATA :
WA_OBJPACK TYPE SOPCKLSTI1,
WA_OBJHEAD TYPE SOLISTI1,
WA_OBJBIN TYPE SOLISTI1,
WA_OBJTXT TYPE SOLISTI1,
WA_RECLIST TYPE SOMLRECI1 .
DATA:
*-- Structure to hold Invoice Header Data
x_docheader LIKE bapi_incinv_create_header,
*-- Structure to hold Reversal Posting Data
x_rev_post LIKE BAPI_INCINV_FLD.
* INTERNAL TAABLE DECLARATION
DATA:
IT_CRMEMO TYPE STANDARD TABLE OF T_CRMEMO WITH HEADER LINE,
IT_CRMEMO_CHANGE TYPE STANDARD TABLE OF T_CRMEMO_CHANGE WITH HEADER LINE,
IT_MVKE TYPE STANDARD TABLE OF T_MVKE WITH HEADER LINE,
IT_CRMEMO_MIRO TYPE STANDARD TABLE OF T_CRMEMO WITH HEADER LINE,
IT_CRMEMO_MR8M TYPE STANDARD TABLE OF T_CRMEMO WITH HEADER LINE,
IT_ORDERS TYPE STANDARD TABLE OF T_ORDERS WITH HEADER LINE,
IT_CMEMO TYPE STANDARD TABLE OF T_ORDERS WITH HEADER LINE,
IT_PO TYPE STANDARD TABLE OF T_ORDERS WITH HEADER LINE,
IT_EKPO TYPE STANDARD TABLE OF T_EKPO WITH HEADER LINE,
IT_EKBE TYPE STANDARD TABLE OF T_EKBE WITH HEADER LINE,
IT_EKBE_TEMP TYPE STANDARD TABLE OF T_EKBE WITH HEADER LINE,
IT_RBKP TYPE STANDARD TABLE OF T_RBKP WITH HEADER LINE,
IT_CDHDR TYPE STANDARD TABLE OF T_CDHDR WITH HEADER LINE,
IT_CDPOS TYPE STANDARD TABLE OF T_CDPOS WITH HEADER LINE,
IT_CHANGE_DOCS TYPE STANDARD TABLE OF T_CHANGE_DOCS WITH HEADER LINE,
IT_SUCCESS TYPE STANDARD TABLE OF T_SUCCESS WITH HEADER LINE,
IT_ERROR TYPE STANDARD TABLE OF T_ERROR WITH HEADER LINE,
IT_SUCCESS_MR8M TYPE STANDARD TABLE OF T_SUCCESS WITH HEADER LINE,
IT_ERROR_MR8M TYPE STANDARD TABLE OF T_ERROR WITH HEADER LINE.
*-- Internal table to hold Invoice Item Data
DATA:BEGIN OF it_itemdata OCCURS 0.
INCLUDE STRUCTURE bapi_incinv_create_item.
DATA:END OF it_itemdata.
*-- Internal table to hold Invoice Acct Assignment Data
DATA:BEGIN OF it_ACCOUNTingdata OCCURS 0.
INCLUDE STRUCTURE BAPI_INCINV_CREATE_ACCOUNT.
DATA:END OF it_accountingdata.
*-- Internal table to hold BAPI return data
DATA: BEGIN OF it_return OCCURS 0.
INCLUDE STRUCTURE bapiret2. "Return Parameter.
DATA: END OF it_return.
*-- Internal table to hold BAPI return data
DATA: BEGIN OF it_return_mr8m OCCURS 0.
INCLUDE STRUCTURE bapiret2. "Return Parameter.
DATA: END OF it_return_mr8m.
*--MAIL related Internal tables
DATA: X_DOC_CHNG TYPE SODOCCHGI1, " document attributes
IT_OBJPACK TYPE STANDARD TABLE OF SOPCKLSTI1, " attachment table
IT_OBJHEAD TYPE STANDARD TABLE OF SOLISTI1, " object header table
IT_OBJBIN TYPE STANDARD TABLE OF SOLISTI1, " binary table
IT_OBJTXT TYPE STANDARD TABLE OF SOLISTI1, " object text
IT_RECLIST TYPE STANDARD TABLE OF SOMLRECI1, " mail recipients
it_compressed_list TYPE STANDARD TABLE OF SOLI,
it_pdf_list TYPE STANDARD TABLE OF TLINE,
it_pdf TYPE tline OCCURS 10 WITH HEADER LINE,
it_html TYPE solisti1 OCCURS 10 WITH HEADER LINE,
*-- Internal table for MIME data (in CHAR format)
it_temp TYPE bapiqcmime OCCURS 10 WITH HEADER LINE,
*-- Internal table for storing data
it_mime(255) TYPE c OCCURS 10 WITH HEADER LINE.
* GLOBAL VARIABLES *
DATA: V_PGM_ID TYPE SY-REPID, " Program id
v_zterm TYPE lfb1-zterm, " Payment Terms
v_text(75) TYPE c, " To store error or success text
v_itemno(6) TYPE n, " To Increment Item No. for BAPI
v_docnr LIKE bapi_incinv_fld-inv_doc_no, " For MIRO document number
v_year1 LIKE bapi_incinv_fld-fisc_year, " For MIRO Fiscal year
v_spono type TSP01-RQIDENT, " For Spool No.
v_type type SOODK-OBJTP, " For Spool Type
V_CRMEMO_QTY TYPE VBAP-ZMENG, " For CR Memo Qty.
V_LINE_AMOUNT TYPE EKPO-NETPR, " For CR Memo Item Qty.
V_GROSSAMT TYPE EKPO-NETPR, " For CR Memo Grand Qty.
v_tax_per(3) type n, " For CR Memo Tax amount %
v_tax_amt TYPE EKPO-NETPR, " For CR Memo Tax amount
v_flag(1) type c, " Flag to process fruther
v_tot_s_mr8m TYPE i, " For MR8M Success Records
v_tot_e_mr8m TYPE i, " For MR8M Error Records
V_DATE TYPE SY-DATUM, " For Sel. Screen Date
V_DATE2(10) TYPE C, " For EMail Date
V_TIME(10) TYPE C, " For EMail Time
V_TIME2(10) TYPE C, " For EMail Time
V_INFO(100) TYPE C, " For EMail Body Text
V_TABLE_LINES TYPE SY-TABIX, " To Increment Email Count
V_TEXT2 TYPE STRING , " For EMail Id text
v_lines TYPE i, " To Store PDF Lines
v_temp(500) TYPE c, " To Convert to 255 char format
v_offset TYPE p, " To Convert to 255 char format
v_lineslen TYPE i, " To Convert to 255 char format
v_mimelen TYPE i, " To Convert to 255 char format
v_tabix type sy-tabix. " To Convert to 255 char format
* CONSTANTS *
CONSTANTS:
C_X(1) TYPE C VALUE 'X', " Constant X or Flag
C_E(1) TYPE C VALUE 'E', " For Error check
c_v(1) TYPE C VALUE 'V', " For PO Docs
c_o(1) TYPE C VALUE 'O', " For Order Docs
c_c(1) TYPE C VALUE 'C', " For Credit Memo Docs
c_k(1) TYPE C VALUE 'K', " For CR Memo Docs
c_u(1) TYPE C VALUE 'U', " For Change tables Update
c_ali(3) TYPE C VALUE 'ALI', " For ALI Format
c_vbak(4) TYPE C VALUE 'VBAK', " For Change docs table
C_01(2) TYPE C VALUE '01', " For Serial No. & Reversal Reason
C_02(2) TYPE C VALUE '02', " For Reversal Reason
c_blart TYPE bkpf-blart VALUE 'RE', " Document type
C_MTPOS TYPE MVKE-MTPOS VALUE 'BANS', " Item Category group
C_AUGRU(5) TYPE C VALUE 'AUGRU', " Reason Code
C_0000500205(10) TYPE C VALUE '0000500205', " GL Account #
C_VERKBELEG(9) TYPE C VALUE 'VERKBELEG'. " For Object Class
*-- Horizontal tab & line feed constants
CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
CONSTANTS:
C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
C_CR_LF TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF .
* SELECTION SCREEN
*-- Select Optons
SELECTION-SCREEN: BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_AUART FOR VBAK-AUART OBLIGATORY NO INTERVALS,
" Sales Document Type
S_AUGRU FOR VBAK-AUGRU OBLIGATORY NO INTERVALS,
" Order reason
S_ERDAT FOR VBAK-ERDAT OBLIGATORY.
" Date on which the record was created
SELECTION-SCREEN: END OF BLOCK B01.
*-- Mail Sending Options
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-004.
PARAMETERS:P_EMAIL AS CHECKBOX DEFAULT SPACE USER-COMMAND V_COM .
PARAMETERS : P_MODE TYPE SO_ESCAPE default 'U' MODIF ID US1.
SELECT-OPTIONS: S_EMAIL FOR ADR6-SMTP_ADDR
NO INTERVALS MODIF ID US2.
* SELECT-OPTIONS: S_EMAIL FOR TRDYSE01CM-USERNAME
* NO INTERVALS MODIF ID US2.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 55(40) TEXT-019 MODIF ID US2.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
* WORK AREA for SELECT-OPTIONS
DATA : X_EMAIL LIKE S_EMAIL. "Work area for EMAIL select-options
* INITIALIZATION
INITIALIZATION.
*-- Default values for Sales Document Type
CLEAR S_AUART[].
S_AUART-SIGN = 'I'.
S_AUART-OPTION = 'EQ'.
S_AUART-LOW = 'CR'.
APPEND S_AUART.
CLEAR S_AUART.
*-- Default values for Date on which the record was created
V_DATE = ( SY-DATUM - 1 ).
CLEAR S_ERDAT[].
S_ERDAT-SIGN = 'I'.
S_ERDAT-OPTION = 'EQ'.
S_ERDAT-LOW = SY-DATUM.
S_ERDAT-HIGH = SY-DATUM.
APPEND S_ERDAT.
CLEAR S_ERDAT.
* TOP OF PAGE *
TOP-OF-PAGE.
*-- Displaying standard header.
PERFORM std_top_of_page USING sy-title.
* A T S E L E C T I O N S C R E E N O U T P U T
*-- For modifying the selection screen layout
AT SELECTION-SCREEN OUTPUT.
PERFORM F_MODIFY_SCREEN.
* AT SELECTION SCREEN. *
AT SELECTION-SCREEN.
*-- Subroutine to Validate selection screen fields
PERFORM f_validate.
* START-OF-SELECTION *
*START-OF-SELECTION.*
**-- Fetch the Credit Memo Requests documents*
*PERFORM F_GET_CREDIT_MEMO_REQUEST.*
*IF NOT IT_CRMEMO[] IS INITIAL.*
**-- Fetch Item Category Group*
*PERFORM F_GET_MVKE_DOCS.*
**-- Fetch Sales Order documents, PO Documents and Credit Memos*
*PERFORM F_GET_SO_PO_DOCS.*
*ENDIF.*
**-- If Credit memo request internal table have an change records then*
** fetch the change documents from CDHDR and CDPOS*
*IF NOT IT_CRMEMO_CHANGE[] IS INITIAL.*
**-- Fetch Change Documents for CR Memos from CDHDR and CDPOS tables*
*PERFORM F_GET_CHANGED_DOCS.*
*ENDIF.*
**-- Fetch Purchasing Document Item Details*
*IF NOT IT_PO[] IS INITIAL.*
*PERFORM F_GET_EKPO.*
*ENDIF.*
**-- Fetch MIRO Vendor based on the PO Details*
*IF NOT IT_EKPO[] IS INITIAL.*
*PERFORM F_GET_VENDOR.*
*ENDIF.*
* END-OF-SELECTION *
if v_flag is initial.
*-- Process Vendor Debit Postings
PERFORM F_PROCESS_MIRO.
*-- Process Reversal Postings of Vendor Automatic Debits using TCODE MR8M
PERFORM F_PROCESS_MR8M.
*-- Send mail,if user enters Email id's and Email Mode is not initial
IF P_EMAIL = C_X AND P_MODE IS NOT INITIAL AND S_EMAIL[] IS NOT INITIAL.
*-- Get spool id
perform f_spool_id.
*-- EMail Logic
PERFORM F_MAIL_LOGIC.
ENDIF.
*-- display the EMail RSCONN01 and Sussess and Error records of MIRO and MR8M
perform f_display_report.
else.
*-- Else exit the process
exit.
endif.
*& Form F_MODIFY_SCREEN
* A Form routine to modify the screen
FORM F_MODIFY_SCREEN .
*-- To Modify Mail Sending Options
LOOP AT SCREEN.
IF P_EMAIL = C_X.
IF SCREEN-GROUP1 = 'US1' .
SCREEN-INVISIBLE = 0.
SCREEN-ACTIVE = 1.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
IF SCREEN-GROUP2 = 'US2' .
SCREEN-INVISIBLE = 0.
SCREEN-ACTIVE = 1.
MODIFY SCREEN.
ENDIF.
ELSEIF P_EMAIL = SPACE.
IF SCREEN-GROUP1 = 'US1' .
SCREEN-INVISIBLE = 1.
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
IF SCREEN-GROUP1 = 'US2' .
SCREEN-INVISIBLE = 1.
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " F_MODIFY_SCREEN
*& Form f_validate
* Validation of Selection-Screen Inputs
FORM f_validate .
*-- Validate Sales Document Type
if not s_AUART[] is initial.
select AUART
into s_AUART-low
from TVAK up to 1 rows
where AUART in s_AUART.
endselect.
if sy-subrc <> 0.
message E000 with 'Invalid Sales Document Type'(e01) .
endif.
ENDIF.
*-- Validate Order reason (reason for the business transaction)
if not s_AUGRU[] is initial.
select AUGRU
into s_AUGRU-low
from TVAU up to 1 rows
where AUGRU in s_AUGRU.
endselect.
if sy-subrc <> 0.
message E000 with 'Invalid Order reason'(e02) .
endif.
endif.
ENDFORM. " f_validate
*& Form F_GET_CREDIT_MEMO_REQUEST
* Fetch Credit memo requests from VBAK & VBAP
FORM F_GET_CREDIT_MEMO_REQUEST .
SELECT A~VBELN
B~POSNR
A~ERDAT
A~AUART
A~AUGRU
A~WAERK
A~VKORG
A~VTWEG
A~SPART
A~VDATU
A~BSTNK
A~BSARK
A~BSTDK
A~AEDAT
A~BUKRS_VF
B~MATNR
B~ZMENG
B~ZIEME
INTO TABLE IT_CRMEMO
FROM ( VBAK AS A
INNER JOIN VBAP AS B ON A~VBELN = B~VBELN )
WHERE ( A~ERDAT IN S_ERDAT
OR A~AEDAT IN S_ERDAT )
AND A~AUART IN S_AUART.
IF SY-SUBRC = 0.
SORT IT_CRMEMO BY VBELN POSNR.
ELSE.
MESSAGE I000 WITH 'No Credit Memo Request selected'(002).
v_flag = C_X.
stop.
ENDIF.
ENDFORM. " F_GET_CREDIT_MEMO_REQUEST
*& Form F_GET_MVKE_DOCS
* Fetch Sales Data for Material
FORM F_GET_MVKE_DOCS .
DATA: LV_TABIX TYPE SY-TABIX.
*-- Fetch Sales Data for Material
SELECT MATNR " Material Number
VKORG " Sales Organization
VTWEG " Distribution Channel
MTPOS " Item category group from material master
FROM MVKE " Sales Data for Material
INTO TABLE IT_MVKE
FOR ALL ENTRIES IN IT_CRMEMO
WHERE MATNR = IT_CRMEMO-MATNR
AND VKORG = IT_CRMEMO-VKORG
AND VTWEG = IT_CRMEMO-VTWEG.
IF SY-SUBRC = 0.
SORT IT_MVKE BY MATNR VKORG VTWEG MTPOS.
ENDIF.
*-- Validate Item category group if MVKE-MTOPS <> 'BANS' then ignore CM Request line item
LOOP AT IT_CRMEMO INTO WA_CRMEMO.
LV_TABIX = SY-TABIX.
READ TABLE IT_MVKE INTO WA_MVKE WITH KEY MATNR = WA_CRMEMO-MATNR
VKORG = WA_CRMEMO-VKORG
VTWEG = WA_CRMEMO-VTWEG
MTPOS = C_MTPOS
BINARY SEARCH.
IF SY-SUBRC <> 0.
DELETE IT_CRMEMO INDEX LV_TABIX. " Delete CR memo records
ELSE.
*-- Else check for credit memo request change date is not initial, and
* append those records to IT_CRMEMO_CHANGE internal table to retrive
* change documents
IF NOT WA_CRMEMO-AEDAT IS INITIAL.
WA_CRMEMO_CHANGE-VBELN = WA_CRMEMO-VBELN.
WA_CRMEMO_CHANGE-POSNR = WA_CRMEMO-POSNR.
WA_CRMEMO_CHANGE-ERDAT = WA_CRMEMO-ERDAT.
WA_CRMEMO_CHANGE-AUART = WA_CRMEMO-AUART.
WA_CRMEMO_CHANGE-AUGRU = WA_CRMEMO-AUGRU.
WA_CRMEMO_CHANGE-WAERK = WA_CRMEMO-WAERK.
WA_CRMEMO_CHANGE-VKORG = WA_CRMEMO-VKORG.
WA_CRMEMO_CHANGE-VTWEG = WA_CRMEMO-VTWEG.
WA_CRMEMO_CHANGE-SPART = WA_CRMEMO-SPART.
WA_CRMEMO_CHANGE-VDATU = WA_CRMEMO-VDATU.
WA_CRMEMO_CHANGE-BSTNK = WA_CRMEMO-BSTNK.
WA_CRMEMO_CHANGE-BSARK = WA_CRMEMO-BSARK.
WA_CRMEMO_CHANGE-BSTDK = WA_CRMEMO-BSTDK.
WA_CRMEMO_CHANGE-AEDAT = WA_CRMEMO-AEDAT.
WA_CRMEMO_CHANGE-BUKRS_VF = WA_CRMEMO-BUKRS_VF.
WA_CRMEMO_CHANGE-MATNR = WA_CRMEMO-MATNR.
WA_CRMEMO_CHANGE-ZMENG = WA_CRMEMO-ZMENG.
WA_CRMEMO_CHANGE-ZIEME = WA_CRMEMO-ZIEME.
APPEND WA_CRMEMO_CHANGE TO IT_CRMEMO_CHANGE.
CLEAR WA_CRMEMO_CHANGE.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " F_GET_MVKE_DOCS
*& Form F_GET_SO_PO_DOCS
* Fetch the Sales Order documents, PO documents, & Credit Memo
FORM F_GET_SO_PO_DOCS.
*-- Fetch Preceding sales orders based on the credit memo request
SELECT VBELV
POSNV
VBELN
POSNN
VBTYP_N
FROM VBFA
INTO TABLE IT_ORDERS
FOR ALL ENTRIES IN IT_CRMEMO
WHERE VBELN = IT_CRMEMO-VBELN
AND POSNN = IT_CRMEMO-POSNR
AND VBTYP_N = C_K
AND VBTYP_V = C_C.
IF SY-SUBRC = 0.
SORT IT_ORDERS BY VBELV POSNV.
*-- Fetch Subsequent PO documents & Credit Memo based on the sales orders
SELECT VBELV
POSNV
VBELN
POSNN
VBTYP_N
FROM VBFA
INTO TABLE IT_PO
FOR ALL ENTRIES IN IT_ORDERS
WHERE VBELV = IT_ORDERS-VBELV
AND POSNV = IT_ORDERS-POSNV
AND VBTYP_N IN (C_V,C_O)
AND VBTYP_V = C_C.
IF SY-SUBRC = 0.
SORT IT_PO BY VBTYP_N.
*-- Copy the IT_PO internal table contents to IT_CMEMO internal table
IT_CMEMO[] = IT_PO[].
*-- Delete PO documents from IT_CMEMO internal table
DELETE IT_CMEMO WHERE VBTYP_N = C_V.
SORT IT_CMEMO BY VBELN POSNN.
IF IT_CMEMO[] IS INITIAL.
MESSAGE I000 WITH 'No Credit Memo are available for CM Request'(003).
* v_flag = c_x.
* stop.
ENDIF.
*-- Delete Credit Memo documents from IT_PO internal table
DELETE IT_PO WHERE VBTYP_N = C_O.
SORT IT_PO BY VBELN POSNN.
ENDIF.
ENDIF.
ENDFORM. " F_GET_SO_PO_DOCS
*& Form F_GET_CHANGED_DOCS
* Fetch Change Documents for CR Memos from CDHDR and CDPOS tables
FORM F_GET_CHANGED_DOCS .
*-- Fetch Change Documents for CR Memos from CDHDR
SELECT OBJECTCLAS
OBJECTID
CHANGENR
UDATE
UTIME
FROM CDHDR
INTO TABLE IT_CDHDR
FOR ALL ENTRIES IN IT_CRMEMO_CHANGE
WHERE OBJECTCLAS = C_VERKBELEG
AND OBJECTID = IT_CRMEMO_CHANGE-VBELN
* AND UDATE = IT_CRMEMO_CHANGE-AEDAT
IF SY-SUBRC = 0.
SORT IT_CDHDR BY OBJECTCLAS OBJECTID CHANGENR.
*-- Fetch Change Documents for CR Memos from CDPOS
SELECT OBJECTCLAS
OBJECTID
CHANGENR
TABNAME
TABKEY
FNAME
CHNGIND
VALUE_NEW
VALUE_OLD
FROM CDPOS
INTO TABLE IT_CDPOS
FOR ALL ENTRIES IN IT_CDHDR
WHERE OBJECTCLAS = C_VERKBELEG
AND OBJECTID = IT_CDHDR-OBJECTID
AND CHANGENR = IT_CDHDR-CHANGENR
AND TABNAME = C_VBAK
AND FNAME = C_AUGRU
AND CHNGIND = C_U.
IF SY-SUBRC = 0.
SORT IT_CDPOS BY OBJECTCLAS OBJECTID CHANGENR.
ENDIF.
ENDIF.
ENDFORM. " F_GET_CHANGED_DOCS
*& Form F_GET_EKPO
* Fetch Purchasing Document Item Details
FORM F_GET_EKPO .
*-- Fetch Purchasing Document Item Details
SELECT A~EBELN
B~EBELP
A~WAERS
B~MENGE
B~MEINS
B~NETPR
B~PEINH
B~mwskz
B~TXJCD
INTO TABLE IT_EKPO
FROM ( EKKO AS A
INNER JOIN EKPO AS B ON A~EBELN = B~EBELN )
FOR ALL ENTRIES IN IT_PO
WHERE A~EBELN = IT_PO-VBELN
AND B~EBELP = IT_PO-POSNN+1(5).
IF SY-SUBRC = 0.
SORT IT_EKPO BY EBELN EBELP.
ENDIF.
ENDFORM. " F_GET_EKPO
*& Form F_GET_VENDOR
* Fetch MIRO Vendor details based on the PO Details
FORM F_GET_VENDOR .
DATA: LV_TABIX TYPE SY-TABIX.
*-- Fetch History per Purchasing Document records for all the PO records
SELECT EBELN
EBELP
ZEKKN
VGABE
GJAHR
BELNR
BUZEI
FROM EKBE
INTO TABLE IT_EKBE
FOR ALL ENTRIES IN IT_EKPO
WHERE EBELN = IT_EKPO-EBELN
AND EBELP = IT_EKPO-EBELP
AND VGABE = '2'.
* and STBLG = space.
IF SY-SUBRC = 0.
SORT IT_EKBE BY BELNR GJAHR.
*-- Fetch the vendor details based on table IT_EKBE internal table
SELECT BELNR
GJAHR
BLDAT
BUDAT
XBLNR
LIFNR
RMWWR
WMWST1
XRECH
STBLG
FROM RBKP
INTO TABLE IT_RBKP
FOR ALL ENTRIES IN IT_EKBE
WHERE BELNR = IT_EKBE-BELNR
AND GJAHR = IT_EKBE-GJAHR.
IF SY-SUBRC = 0.
SORT IT_RBKP BY BELNR GJAHR.
ENDIF.
ENDIF.
*-- Sort PO History documents based on PO # and PO Item
SORT IT_EKBE BY EBELN EBELP.
*-- Copy the PO History documents into IT_EKBE_TEMP internal table
IT_EKBE_TEMP[] = IT_EKBE[].
*-- Delete PO History documents from IT_EKBE_TEMP internal table
* comparing with IT_RBKP where (STBLG) Reversal document number
* is initial
LOOP AT IT_EKBE_TEMP INTO WA_EKBE_TEMP.
LV_TABIX = SY-TABIX.
READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
GJAHR = WA_EKBE_TEMP-GJAHR
* XRECH = SPACE
STBLG = SPACE.
IF SY-SUBRC <> 0.
DELETE IT_EKBE_TEMP INDEX LV_TABIX.
ENDIF.
CLEAR: WA_EKBE_TEMP, WA_RBKP.
ENDLOOP.
ENDFORM. " F_GET_VENDOR
*& Form F_PROCESS_MIRO
* Process MIRO
FORM F_PROCESS_MIRO .
DATA:
lv_itemno TYPE i,
lv_tabix type sy-index,
lc_check(1) TYPE c VALUE 'X',
V_FILL_ITEM,
lv_rbkp_bldat type sy-datum.
clear : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
refresh : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
*-- Copy all the CR Memo Docs and delete order reason not in S_AUGRU
IT_CRMEMO_MR8M[] = IT_CRMEMO[].
*-- Delete Reversal postings which are not in S_AUGRU
DELETE IT_CRMEMO_MR8M WHERE AUGRU IN S_AUGRU.
*-- Delete Reversal postings where AEDAT is initial
DELETE IT_CRMEMO_MR8M where aedat is initial.
*-- Delete order reason which are not in S_AUGRU
DELETE IT_CRMEMO WHERE AUGRU NOT IN S_AUGRU.
*-- Loop through the credit memo request records
LOOP AT IT_CRMEMO INTO WA_CRMEMO.
lv_tabix = sy-tabix.
*-- If credit memo request change date is not initial then
* send change date (AEDAT) to lv_rbkp_bldat
if not WA_CRMEMO-aedat is initial.
lv_rbkp_bldat = WA_CRMEMO-aedat.
else.
*-- If credit memo request change date is initial then
* send create date (ERDAT) to lv_rbkp_bldat
lv_rbkp_bldat = WA_CRMEMO-erdat.
endif.
READ TABLE IT_ORDERS INTO WA_ORDERS WITH KEY VBELN = WA_CRMEMO-VBELN
POSNN = WA_CRMEMO-POSNR.
IF SY-SUBRC = 0.
READ TABLE IT_PO INTO WA_PO WITH KEY VBELV = WA_ORDERS-VBELV
POSNV = WA_ORDERS-POSNV.
IF SY-SUBRC = 0.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_PO-VBELN
EBELP = WA_PO-POSNN.
IF SY-SUBRC = 0.
*-- Read IT_EKBE_TEMP internal table which contains records which are not reversed
READ TABLE IT_EKBE_TEMP INTO WA_EKBE_TEMP WITH KEY EBELN = WA_EKPO-EBELN
EBELP = WA_EKPO-EBELP.
IF SY-SUBRC = 0.
*-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = 'X' ,
* check for invoice records for the correspnding CR Memo records
READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
GJAHR = WA_EKBE_TEMP-GJAHR
XRECH = C_X.
IF SY-SUBRC = 0.
*-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = SPACE,
* and document date = CR Memo creation date
* and reference document number = PO number
READ TABLE IT_RBKP INTO WA_RBKP_TMP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
GJAHR = WA_EKBE_TEMP-GJAHR
BLDAT = WA_CRMEMO-ERDAT
XRECH = ' '
XBLNR+0(10) = WA_EKBE_TEMP-ebeln.
* STBLG = SPACE.
IF SY-SUBRC = 0.
CONTINUE.
ELSE.
*-- Quantity Conversion (Get the Credit Memo Quantity by passing CMR unit per one PO unit)
perform f_quantity_conv.
*-- Filling the Line items data
*-- Incrementing the item no
lv_itemno = lv_itemno + 1.
v_itemno = lv_itemno.
it_itemdata-invoice_doc_item = v_itemno.
it_itemdata-po_number = WA_ekPO-ebeln.
it_itemdata-po_item = WA_EKPO-EBELP.
it_itemdata-tax_code = WA_ekpo-mwskz.
it_itemdata-TAXJURCODE = WA_ekpo-TXJCD.
*-- Converting SAP amount to BAPI format by passing line item amount and currency
PERFORM f_currency_amount_sap_to_bapi USING WA_EKPO-waers
V_LINE_AMOUNT
CHANGING it_itemdata-item_amount .
it_itemdata-quantity = ( WA_CRMEMO-ZMENG * V_CRMEMO_QTY ).
it_itemdata-po_unit = WA_EKPO-MEINS.
APPEND it_itemdata.
*-- Populate Account Assignment data
IT_ACCOUNTINGDATA-INVOICE_DOC_ITEM = v_itemno.
IT_ACCOUNTINGDATA-XUNPL = space.
IT_ACCOUNTINGDATA-SERIAL_NO = C_01.
IT_ACCOUNTINGDATA-TAX_CODE = it_itemdata-tax_code.
IT_ACCOUNTINGDATA-TAXJURCODE = it_itemdata-TAXJURCODE.
IT_ACCOUNTINGDATA-ITEM_AMOUNT = it_itemdata-item_amount.
IT_ACCOUNTINGDATA-QUANTITY = it_itemdata-quantity.
IT_ACCOUNTINGDATA-PO_UNIT = it_itemdata-po_unit.
IT_ACCOUNTINGDATA-GL_ACCOUNT = C_0000500205.
append IT_ACCOUNTINGDATA.
clear IT_ACCOUNTINGDATA.
CLEAR it_itemdata.
endif.
endif.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
*-- At end of each credit memo request fill the header details of BAPI FM and
*-- post the BAPI
AT END OF VBELN.
read table it_crmemo into wa_crmemo index lv_tabix.
*-- Populate the document Header
*-- Getting the header data for invoice
x_docheader-invoice_ind = space.
x_docheader-doc_type = c_blart.
x_docheader-doc_date = lv_rbkp_bldat.
x_docheader-pstng_date = lv_rbkp_bldat.
x_docheader-ref_doc_no = WA_RBKP-XBLNR.
x_docheader-comp_code = WA_CRMEMO-BUKRS_VF.
x_docheader-CURRENCY = WA_CRMEMO-WAERK.
x_docheader-calc_tax_ind = lc_check.
*-- Logic to find the Tax %
v_tax_per = ( WA_RBKP-WMWST1 / ( WA_RBKP-RMWWR - WA_RBKP-WMWST1 ) ) * 100.
v_tax_amt = ( V_GROSSAMT * v_tax_per ) / 100.
V_GROSSAMT = ( V_GROSSAMT + v_tax_amt ).
x_docheader-gross_amount = V_GROSSAMT.
CLEAR:v_docnr, v_year1.
*-- Calling BAPI to create PO invoice document
CHECK NOT IT_ITEMDATA[] IS INITIAL.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = x_docheader
IMPORTING
invoicedocnumber = v_docnr
fiscalyear = v_year1
TABLES
itemdata = it_itemdata[]
ACCOUNTingDATA = it_ACCOUNTingDATA[]
* GLACCOUNTDATA =
* taxdata =
return = it_return.
*-- Commit work
IF NOT v_docnr IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*-- Move the data to Success Internal Table
wa_success-crmemo = wa_crmemo-vbeln.
wa_success-cmemo = wa_cmemo-vbeln.
wa_success-orders = wa_orders-vbelv.
wa_success-po = wa_po-vbeln.
wa_success-miro_no = v_docnr.
wa_success-text = 'MIRO is Posted'.
append wa_success TO it_success.
clear wa_success.
ENDIF.
*-- Read the values in the table IT_RETURN.
CLEAR it_return.
READ TABLE it_return INDEX 1.
* If message type is error then roll back the work
IF it_return-type = C_E.
*-- Roll back
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
*-- Move the data to Error Internal Table
wa_error-crmemo = wa_crmemo-vbeln.
wa_error-cmemo = wa_cmemo-vbeln.
wa_error-orders = wa_orders-vbelv.
wa_error-po = wa_po-vbeln.
wa_error-text = it_return-MESSAGE.
append wa_error TO it_error.
clear wa_error.
ENDIF.
refresh: it_return, it_itemdata, it_accountingdata.
clear: V_GROSSAMT, it_return, it_itemdata, wa_crmemo, wa_orders, wa_po,
wa_ekpo, WA_EKBE_TEMP, wa_rbkp, wa_rbkp_tmp, v_docnr, v_year1, WA_SUCCESS,
WA_ERROR, it_accountingdata, v_tax_per, v_tax_amt, V_FILL_ITEM, lv_rbkp_bldat.
ENDAT.
ENDLOOP.
ENDFORM. " F_PROCESS_MIRO
*& Form f_quantity_conv
* Quantity Conversion
FORM f_quantity_conv .
*-- Quantity Conversion (Get the Credit Memo Quantity by passing CMR unit per one PO unit)
CLEAR: V_LINE_AMOUNT, V_CRMEMO_QTY.
call function 'MC_UNIT_CONVERSION'
EXPORTING
MATNR = WA_CRMEMO-MATNR
nach_meins = WA_EKPO-MEINS
von_meins = WA_CRMEMO-ZIEME
IMPORTING
UMREF = V_CRMEMO_QTY
EXCEPTIONS
CONVERSION_NOT_FOUND = 1
MATERIAL_NOT_FOUND = 2
NACH_MEINS_MISSING = 3
OVERFLOW = 4
VON_MEINS_MISSING = 5
OTHERS = 6.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
V_LINE_AMOUNT = ( V_CRMEMO_QTY * WA_CRMEMO-ZMENG * WA_EKPO-peinh * WA_EKPO-NETPR ).
V_GROSSAMT = V_GROSSAMT + V_LINE_AMOUNT.
ENDIF.
ENDFORM. " f_quantity_conv
*& Form f_currency_amount_sap_to_bapi
* SAP Amount to BAPI Amount
FORM f_currency_amount_sap_to_bapi USING p_waers
p_kbetr
CHANGING p_amt_doccur.
DATA : lv_waers LIKE tcurc-waers,
lv_sapamount LIKE bapicurr-bapicurr,
lv_bapi_amount LIKE bapicurr-bapicurr.
lv_waers = p_waers.
lv_sapamount = p_kbetr.
CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_BAPI'
EXPORTING
currency = lv_waers
sap_amount = lv_sapamount
IMPORTING
bapi_amount = lv_bapi_amount.
p_amt_doccur = lv_bapi_amount.
ENDFORM. " f_currency_amount_sap_to_bapi
*& Form f_display_report
* Display Report
FORM f_display_report .
*-- Success Report
IF NOT IT_SUCCESS[] IS INITIAL.
ULINE AT /1(129).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'MIRO Number',
99 sy-vline, 'Text',
129 sy-vline.
ULINE AT /1(129).
LOOP AT it_success into wa_success.
WRITE:/1 sy-vline, wa_success-crmemo,
19 sy-vline, wa_success-cmemo,
39 sy-vline, wa_success-orders,
59 sy-vline, wa_success-po,
79 sy-vline, wa_success-miro_no,
99 sy-vline, wa_success-text,
129 sy-vline.
ENDLOOP.
ULINE AT /1(129).
SKIP 2.
ENDIF.
*-- Error Report
IF NOT IT_ERROR[] IS INITIAL.
ULINE AT /1(179).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'Error Text',
179 sy-vline.
ULINE AT /1(179).
LOOP AT IT_ERROR into WA_ERROR.
WRITE:/1 sy-vline, WA_ERROR-crmemo,
19 sy-vline, WA_ERROR-cmemo,
39 sy-vline, WA_ERROR-orders,
59 sy-vline, WA_ERROR-po,
79 sy-vline, WA_ERROR-text,
179 sy-vline.
ENDLOOP.
ULINE AT /1(179).
ENDIF.
IF NOT IT_SUCCESS_MR8M[] IS INITIAL.
ULINE AT /1(129).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'Reversal Posting No.',
99 sy-vline, 'Text',
129 sy-vline.
ULINE AT /1(129).
LOOP AT it_success_mr8m into wa_success_mr8m.
WRITE:/1 sy-vline, wa_success_mr8m-crmemo,
19 sy-vline, wa_success_mr8m-cmemo,
39 sy-vline, wa_success_mr8m-orders,
59 sy-vline, wa_success_mr8m-po,
79 sy-vline, wa_success_mr8m-miro_no,
99 sy-vline, wa_success_mr8m-text,
129 sy-vline.
ENDLOOP.
ULINE AT /1(129).
SKIP 2.
ENDIF.
*-- Error Report
IF NOT IT_ERROR_MR8M[] IS INITIAL.
ULINE AT /1(179).
WRITE:/1 sy-vline, 'CR Memo',
19 sy-vline, 'Credit Memo',
39 sy-vline, 'Sales Order',
59 sy-vline, 'Purchase Order',
79 sy-vline, 'Error Text',
179 sy-vline.
ULINE AT /1(179).
LOOP AT IT_ERROR_MR8M into WA_ERROR_MR8M.
WRITE:/1 sy-vline, WA_ERROR_MR8M-crmemo,
19 sy-vline, WA_ERROR_MR8M-cmemo,
39 sy-vline, WA_ERROR_MR8M-orders,
59 sy-vline, WA_ERROR_MR8M-po,
79 sy-vline, WA_ERROR_MR8M-text,
179 sy-vline.
ENDLOOP.
ULINE AT /1(179).
ENDIF.
ENDFORM. " f_display_report
*& Form F_PROCESS_MR8M
* Process Reversal postings
FORM F_PROCESS_MR8M .
clear: wa_CRMEMO_MR8M.
LOOP AT IT_CRMEMO_MR8M into WA_CRMEMO_MR8M.
read table it_cdpos into wa_cdpos with key OBJECTID = WA_CRMEMO_MR8M-VBELN.
if sy-subrc <> 0.
CONTINUE.
ELSE.
if wa_cdpos-value_old in s_augru.
READ TABLE IT_ORDERS INTO WA_ORDERS WITH KEY VBELN = wa_CRMEMO_MR8M-VBELN
POSNN = wa_CRMEMO_MR8M-POSNR.
IF SY-SUBRC = 0.
* READ TABLE IT_CMEMO INTO WA_CMEMO WITH KEY VBELV = WA_ORDERS-VBELV
* POSNV = WA_ORDERS-POSNV.
* IF SY-SUBRC = 0.
READ TABLE IT_PO INTO WA_PO WITH KEY VBELV = WA_ORDERS-VBELV
POSNV = WA_ORDERS-POSNV.
IF SY-SUBRC = 0.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_PO-VBELN
EBELP = WA_PO-POSNN.
IF SY-SUBRC = 0.
* READ TABLE IT_EKBE INTO WA_EKBE WITH KEY EBELN = WA_EKPO-EBELN
* EBELP = WA_EKPO-EBELP.
* IF SY-SUBRC = 0.
LOOP AT IT_EKBE into WA_EKBE WHERE EBELN = WA_EKPO-EBELN
AND EBELP = WA_EKPO-EBELP.
READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE-BELNR
GJAHR = WA_EKBE-GJAHR
* BLDAT = WA_CRMEMO_MR8M-AEDAT
XBLNR+0(10) = WA_EKBE-EBELN
XRECH = SPACE
STBLG = SPACE.
IF SY-SUBRC = 0.
move: WA_RBKP-BELNR TO X_REV_POST-INV_DOC_NO,
WA_RBKP-GJAHR TO X_REV_POST-FISC_YEAR,
WA_RBKP-BUDAT TO X_REV_POST-PSTNG_DATE.
IF WA_RBKP-BUDAT+4(2) = SY-DATUM+4(2).
X_REV_POST-REASON_REV = C_01.
ELSE.
X_REV_POST-REASON_REV = C_02.
ENDIF.
ENDIF.
ENDLOOP.
*-- Call the FM for MIRO reversal
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CANCEL'
EXPORTING
INVOICEDOCNUMBER = X_REV_POST-INV_DOC_NO
FISCALYEAR = X_REV_POST-FISC_YEAR
REASONREVERSAL = X_REV_POST-REASON_REV
POSTINGDATE = X_REV_POST-PSTNG_DATE
IMPORTING
INVOICEDOCNUMBER_REVERSAL = X_REV_POST-INV_DOC_NO
FISCALYEAR_REVERSAL = X_REV_POST-FISC_YEAR
TABLES
RETURN = it_return_mr8m.
*-- Commit work
IF NOT X_REV_POST-INV_DOC_NO IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*-- Move the data to Success Internal Table
wa_success_mr8m-crmemo = wa_crmemo-vbeln.
wa_success_mr8m-cmemo = wa_cmemo-vbeln.
wa_success_mr8m-orders = wa_orders-vbelv.
wa_success_mr8m-po = wa_po-vbeln.
wa_success_mr8m-text = 'MR8M Done'.
append wa_success_mr8m TO it_success_mr8m.
clear wa_success_mr8m.
ENDIF.
*-- Read the values in the table IT_RETURN.
CLEAR it_return_mr8m.
READ TABLE it_return_mr8m INDEX 1.
*-- If message type is error then roll back the work
IF it_return_mr8m-type = 'E' .
*-- Roll back
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
*-- Move the data to Error Internal Table
wa_error_mr8m-crmemo = wa_crmemo-vbeln.
wa_error_mr8m-cmemo = wa_cmemo-vbeln.
wa_error_mr8m-orders = wa_orders-vbelv.
wa_error_mr8m-po = wa_po-vbeln.
wa_error_mr8m-text = it_return_mr8m-MESSAGE.
append wa_error_mr8m TO it_error_mr8m.
clear wa_error_mr8m.
ENDIF.
* ENDIF.
* ENDIF.
ENDIF.
ENDIF.
* ENDIF.
ENDIF.
ENDIF.
ENDIF.
CLEAR: wa_error_mr8m, wa_SUCCESS_mr8m, X_REV_POST, wa_CRMEMO_MR8M,
wa_orders, wa_po, wa_ekpo, wa_ekbe, wa_rbkp, wa_cmemo.
REFRESH: IT_RETURN_MR8M.
endloop.
ENDFORM. " F_PROCESS_MR8M
*& Form F_spool_id
* Create a new spool ID
FORM F_spool_id .
*-- Create a new spool from the data in data_tab
*-- new-page line-size sy-linsz print on
new-page line-size 255 print on
destination 'LOCL'(p19) "<<== my printer
*-- receiver 'TJOSVOB'
cover text 'Spool title'(p20) " <<== Title or Spool req. name
list name 'List name'(p21)
list dataset 'List Dataset'(p22)
immediately ' ' " X means print now
keep in spool c_x " X means keep spool
new list identification c_x
no dialog .
*-- Writing Report
*-- In this perform you will write the code for displaying the list
perform f_display_report.
*-- new-page print off
new-page print off.
ENDFORM. " F_spool_id
*& Form F_MAIL_LOGIC
* Logic to send a mail for the given Email ID's
FORM F_MAIL_LOGIC .
data : wa_tsp01sys type tsp01sys.
clear v_spono.
v_spono = sy-spono.
* v_attach_desc = sy-title.
*-- Convert the Spool ID into PDF format
perform f_pdf_conversion tables it_compressed_list
it_pdf_list
using v_spono.
*-- Send the Mail in PDF Format
perform f_send_mail.
ENDFORM. " F_MAIL_LOGIC
*& Form f_pdf_conversion
* Read the spool and convert into PDF format
* -->P_ITAB_COMPRESSED_LIST text
* -->P_ITAB_PDF_LIST text
* -->P_V_SPONO text
FORM f_pdf_conversion TABLES it_compressed_list structure soli
it_pdf_list structure tline
using lv_spooln type tsp01-rqident.
clear: it_compressed_list, it_pdf_list.
refresh: it_compressed_list, it_pdf_list.
*-- Call the FM "RSPO_RETURN_SPOOLJOB" to read the spool by passing the spool number
call function 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = lv_spooln
desired_type = v_type
importing
real_type = v_type
tables
buffer = it_compressed_list
buffer_pdf = it_pdf_list
exceptions
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
others = 8.
if sy-subrc <> 0.
message I000 with 'Error in spool reading'(017).
endif.
*-- If the List type is ALI call the FM "CONVERT_ABAPSPOOLJOB_2_PDF"
* to convert list into PDF Format
if v_type = c_ali. " for List it is ALI
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = lv_spooln
tables
pdf = it_pdf
exceptions
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others = 12.
if sy-subrc <> 0.
message e000
with'Error in convertion of list into PDF format'(018).
endif.
*-- Logic to convert the given format into 255 character format in IT_PDF
describe table it_pdf lines v_lines.
describe field it_pdf length v_lineslen IN character MODE.
describe field it_temp length v_mimelen IN character MODE.
LOOP AT it_pdf.
v_tabix = sy-tabix.
MOVE it_pdf TO v_temp+v_offset.
IF v_tabix = v_lines.
v_lineslen = strlen( it_pdf ).
ENDIF.
v_offset = v_offset + v_lineslen.
IF v_offset GE v_mimelen.
CLEAR it_temp.
it_temp = v_temp(v_mimelen).
APPEND it_temp.
SHIFT v_temp BY v_mimelen PLACES.
v_offset = v_offset - v_mimelen.
ENDIF.
IF v_tabix = v_lines.
IF v_offset GT 0.
CLEAR it_temp.
it_temp = v_temp(v_offset).
APPEND it_temp.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT it_temp.
it_mime(255) = it_temp-line.
APPEND it_mime.
ENDLOOP.
*-- Final Data to send to EMail
it_html[] = it_mime[].
endif.
ENDFORM. " f_pdf_conversion
*& Form f_send_mail
* Send EMail Logic
FORM f_send_mail .
data : wa_tsp01sys type tsp01sys.
*-- Populate Mail Id's
WA_RECLIST-REC_TYPE = P_MODE.
WA_RECLIST-EXPRESS = C_X.
*-- Loop through the Emial select options
LOOP AT S_EMAIL INTO X_EMAIL.
WA_RECLIST-RECEIVER = X_EMAIL-LOW.
*-- append receiver table
APPEND WA_RECLIST TO IT_RECLIST.
ENDLOOP.
*-- If receiver table is not initial
CHECK IT_RECLIST[] IS NOT INITIAL.
*--To check Mail ID's internal table should not be Empty.
*--populate document attributes
*-- Mail subject line
CLEAR: X_DOC_CHNG.
X_DOC_CHNG-OBJ_NAME = 'HEADING'.
CONCATENATE 'Automatic Vendor Dedit Postings'(005)
SY-DATUM
INTO X_DOC_CHNG-OBJ_DESCR SEPARATED BY SPACE.
*-- Mail body
CONCATENATE 'Automatic Vendor Dedit Postings'(005)
' is attached.'(006)
INTO WA_OBJTXT SEPARATED BY SPACE.
APPEND WA_OBJTXT TO IT_OBJTXT.
*-- Append Date and Time into Body of em -
Not able to create sales order using BAPI - BAPI_SALESORDER_CREATEFROMDAT2
Hi Experts,
I am not able to create sales order . I am using BAPI - BAPI_SALESORDER_CREATEFROMDAT2
to create sales order .I am passing external sales order number to the parameter
SALESDOCUMENTIN.
I am getting following error.
"524 |Only quantity 1 EA is allowed (Item 00001"
Here EA is UOM(Unit of measurement).
Below is the sample program through which i am trying to create the sales order.
*& Report ZSDC_SALES_TEST
report zsdc_sales_test.
*DATA: wa_bapi_header TYPE bapisdhd1.
Include Name - ZSDC_SALES_ORD_UPLOAD_TOP
Program Name - ZSDC_SALES_ORD_UPLOAD_1393
Program Title - Include for Data Declaration and selection screen
Created by - Lalitha W
Created on - 18-Nov-2008
Object ID - SD_C_1393_SALES_ORDER_UPLOAD
Request Id - SD3K905579
Description - This is a common INCLUDE for data declarations and
*selection screen details.
HISTORY
Date |Developer |Req by | Description |Reference ID
| | | |
| | | |
TYPE-POOLS
*TYPE-POOLS: truxs, abap, slis.
TABLES
*TABLES: t100.
TYPES
types:begin of ty_header,
auart(4) type c, " Sales Order Type
vkorg(4) type c, " Sales Organization
vtweg(2) type c, " Distrubution Channel
spart(2) type c, " Division
kunnr_1(10) type c, " Sold to Party
kunnr_2(10) type c, " Ship to Party
augru(3) type c, " Order Reason
bstkd(35) type c, " PO Number
bstdk(10) type c, " PO Date
ketdat(10) type c, " Required Delivery Date
zterm(4) type c, " Payment Terms
inco1(3) type c, " Inco Terms -1
inco2(28) type c, " Inco Terms -2
prsdt(10) type c, " pricing date
waerk(5) type c, " Document Currency
vkbur(4) type c, " Sales Office
vkgrp(3) type c, " Sales group
pltyp(2) type c, " Price List type
kdgrp(2) type c, " Customer Group
bstkd_e(35) type c, " Ship-to-party PO number
submi(10) type c, " Collective Number
bname(35) type c, " Name
ihrez(12) type c, " Your Reference
kschl_1(4) type c, " Condition Type
kbetr_1(11) type c, " Amount
kschl_2(4) type c, " Condition Type
kbetr_2(11) type c, " Amount
kschl_3(4) type c, " Condition Type
kbetr_3(11) type c, " Amount
partner_1(25) TYPE c, " Partner(Bill To Party Number)
partner_2(25) TYPE c, " Partner(Payer Number)
partner_3(25) TYPE c, " Partner(Sales Responsible Number)
partner_4(25) TYPE c, " Partner(Order admin)
partner_5(25) TYPE c, " Partner(Contact person)
partner_1(10) type c, " Partner(Bill To Party Number)
partner_2(10) type c, " Partner(Payer Number)
partner_3(10) type c, " Partner(Sales Responsible Number)
partner_4(10) type c, " Partner(Order admin)
partner_5(10) type c, " Partner(Contact person)
tdspras_1(2) type c,
text_1(500) type c, " Text Before Items Z012
tdspras_2(2) type c,
text_2(500) type c, " Invocie Up Z034
tdspras_3(2) type c,
text_3(500) type c, " Invocie Down Z035
tdspras_4(2) type c,
text_4(500) type c, " Customer Reference Continue Z018
tdspras_5(2) type c,
text_5(500) type c, " Dispatch Marks/ Order Z019
tdspras_6(2) type c,
text_6(500) type c, " Ordered By Z003
tdspras_7(2) type c,
text_7(500) type c, " Sales Parameters Z002
kvgr1(3) type c, " Industry
kvgr2(3) type c, " customer BU
end of ty_header.
types: begin of ty_item,
bstkd(35) type c, " PO Number
bstdk(10) type c, " PO Date
bstkd_e(35) type c, " Ship-to-party PO number
posnr(6) type c, " POSTION NUMBER
matnr(18) type c, " Material Number
kwmeng(18) type c, " Order Quantity
pstyv(4) type c, " Sales doc. item categ
kursk(18) type c, " EXCHANGE RATE****
ffprf(8) type c, " DIP PROFILE
werks(4) type c, " Delivering Plant
vstel(4) type c, " SHIPPING POINT
lgort(4) type c, " STORAGE LOCATION
route(6) type c, " Route
kurrf(18) type c, " EXCHANGE RATE-FI
ntgew(18) type c, " Net Weight
brgew(18) type c, " Gross Weight
gewei(3) type c, " Weight Unit
prctr(10) type c, " profit center
abgrs(6) type c, " RESULT ANALYSIS KEY
kalsm_k(4) type c, " COSTING SHEET
kschl_1(4) type c, " Condition Type
kbetr_1(11) type c, " Amount
kschl_2(4) type c, " Condition Type
kbetr_2(11) type c, " Amount
kschl_3(4) type c, " Condition Type
kbetr_3(11) type c, " Amount
text_1(500) type c, " material Text 0001
tdspras_1(1) type c,
text_2(500) type c, " Pr Text 9001
tdspras_2(1) type c,
end of ty_item.
types: begin of ty_schedule_line,
bstkd(35) type c, "PO number
bstdk(10) type c, "PO date
bstkd_e(35) type c, "Ship-to-party PO number
posnr(6) type c, "sales doc.Item
etdat(10) type c, "Schedule line date
wmeng(2) type c, "Order Quantity
end of ty_schedule_line.
types: begin of ty_err ,
auart(4) type c, " Sales Order Type
vkorg(4) type c, " Sales Organization
vtweg(2) type c, " Distrubution Channel
spart(2) type c, " Division
kunnr_1(10) type c, " Sold to Party
kunnr_2(10) type c, " Ship to Party
augru(3) type c, " Order Reason
bstkd(35) type c, " PO Number
bstdk(10) type c, " PO Date
ketdat(10) type c, " Required Delivery Date
zterm(4) type c, " Payment Terms
inco1(3) type c, " Inco Terms -1
inco2(28) type c, " Inco Terms -2
prsdt(10) type c, " pricing date
waerk(5) type c, " Document Currency
vkbur(2) type c, " Sales Office
vkgrp(3) type c, " Sales group
pltyp(2) type c, " Price List type
kdgrp(2) type c, " Customer Group
bstkd_e(35) type c, " Ship-to-party PO number
submi(10) type c, " Collective Number
bname(35) type c, " Name
ihrez(12) type c, " Your Reference
kschl_1(4) type c, " Condition Type
kbetr_1(11) type c, " Amount
kschl_2(4) type c, " Condition Type
kbetr_2(11) type c, " Amount
kschl_3(4) type c, " Condition Type
kbetr_3(11) type c, " Amount
partner_1(25) type c, " Partner(Bill To Party Number)
partner_2(25) type c, " Partner(Payer Number)
partner_3(25) type c, " Partner(Sales Responsible Number)
partner_4(25) type c, " Partner(Order admin)
partner_5(25) type c, " Partner(Contact person)
tdspras_1(2) type c,
text_1(500) type c, " Text Before Items Z012
tdspras_2(2) type c,
text_2(500) type c, " Invocie Up Z034
tdspras_3(2) type c,
text_3(500) type c, " Invocie Down Z035
tdspras_4(2) type c,
text_4(500) type c, " Customer Reference Continue Z018
tdspras_5(2) type c,
text_5(500) type c, " Dispatch Marks/ Order Z019
tdspras_6(2) type c,
text_6(500) type c, " Ordered By Z003
tdspras_7(2) type c,
text_7(500) type c, " Sales Parameters Z002
kvgr1(3) type c, " Industry
kvgr2(3) type c, " customer BU
message(600) type c,
end of ty_err.
types: begin of ty_t685a,
kschl type kschl,
krech type krech,
end of ty_t685a.
INTERNAL TABLES
***header
data: g_krech_1(4) type c, " Calculation type for condition
g_krech_2(4) type c, " Calculation type for condition
g_krech_3(4) type c. " Calculation type for condition
g_krech_4(4) TYPE c, " Calculation type for condition
g_krech_5(4) TYPE c, " Calculation type for condition
g_krech_6(4) TYPE c, " Calculation type for condition
g_krech_7(4) TYPE c, " Calculation type for condition
g_krech_8(4) TYPE c, " Calculation type for condition
g_krech_9(4) TYPE c, " Calculation type for condition
g_krech_10(4) TYPE c, " Calculation type for condition
g_krech_11(4) TYPE c, " Calculation type for condition
g_krech_12(4) TYPE c, " Calculation type for condition
g_krech_13(4) TYPE c, " Calculation type for condition
g_krech_14(4) TYPE c, " Calculation type for condition
g_krech_15(4) TYPE c, " Calculation type for condition
g_krech_16(4) TYPE c, " Calculation type for condition
g_krech_17(4) TYPE c, " Calculation type for condition
g_krech_18(4) TYPE c, " Calculation type for condition
g_krech_19(4) TYPE c, " Calculation type for condition
g_krech_20(4) TYPE c. " Calculation type for condition
Items
data: g_krech_item_1(4) type c, " Calculation type for condition
g_krech_item_2(4) type c, " Calculation type for condition
g_krech_item_3(4) type c. " Calculation type for condition
g_krech_item_4(4) TYPE c, " Calculation type for condition
g_krech_item_5(4) TYPE c, " Calculation type for condition
g_krech_item_6(4) TYPE c, " Calculation type for condition
g_krech_item_7(4) TYPE c, " Calculation type for condition
g_krech_item_8(4) TYPE c, " Calculation type for condition
g_krech_item_9(4) TYPE c, " Calculation type for condition
g_krech_item_10(4) TYPE c, " Calculation type for condition
g_krech_item_11(4) TYPE c, " Calculation type for condition
g_krech_item_12(4) TYPE c, " Calculation type for condition
g_krech_item_13(4) TYPE c, " Calculation type for condition
g_krech_item_14(4) TYPE c, " Calculation type for condition
g_krech_item_15(4) TYPE c, " Calculation type for condition
g_krech_item_16(4) TYPE c. " Calculation type for condition
data: it_t685a type standard table of ty_t685a.
data: wa_bapi_header type bapisdhd1,
wa_bapi_headerx TYPE bapisdhd1x,
it_bapi_item type table of bapisditm,
it_bapi_itemx TYPE TABLE OF bapisditmx,
it_bapi_cond type table of bapicond,
it_bapi_condx TYPE TABLE OF bapicondx,
it_bapi_partner type table of bapiparnr,
it_bapi_shdl type table of bapischdl,
it_bapi_shdlx TYPE TABLE OF bapischdlx,
it_bapi_order_text type TABLE OF BAPISDTEXT,
it_bapireturn type table of bapiret2.
data: wa_bapi_item like line of it_bapi_item,
wa_bapi_itemx LIKE LINE OF it_bapi_itemx,
wa_bapi_cond like line of it_bapi_cond,
wa_bapi_condx LIKE LINE OF it_bapi_condx,
wa_bapi_partner like line of it_bapi_partner,
wa_bapi_shdl like line of it_bapi_shdl,
wa_bapi_shdlx LIKE LINE OF it_bapi_shdlx,
wa_bapi_order_text like LINE OF it_bapi_order_text,
wa_bapireturn like line of it_bapireturn.
*DATA: zmode(1) VALUE 'N'.
data: it_header type standard table of ty_header.
*DATA: it_temp_header TYPE STANDARD TABLE OF ty_header.
data: it_item type standard table of ty_item.
*DATA: it_temp_item TYPE STANDARD TABLE OF ty_item.
data: it_err type standard table of ty_err.
data: it_fline1 type standard table of tline,
wa_fline1 type tline.
data: it_thead1 type thead.
data: it_fline2 type standard table of tline,
wa_fline2 type tline.
data: it_thead2 type thead.
data: it_fline3 type standard table of tline,
wa_fline3 type tline.
data: it_thead3 type thead.
data: it_fline4 type standard table of tline,
wa_fline4 type tline.
data: it_thead4 type thead.
data: it_fline5 type standard table of tline,
wa_fline5 type tline.
data: it_thead5 type thead.
data: wa_header like line of it_header,
wa_item like line of it_item,
wa_err type ty_err,
wa_bill LIKE LINE OF it_bill,
wa_bill1 LIKE LINE OF it_bill,
wa_iterr like line of it_err,
wa_t685a like line of it_t685a.
wa_bill_item TYPE ty_bill_item.
data: it_schedule_line type standard table of ty_schedule_line,
wa_schedule_line type ty_schedule_line.
data: sales_order_no type bapivbeln-vbeln.
data: ext_sales_order_no type bapivbeln-vbeln.
Variable to be used to separate the fields which are concatenated by a
runtime character
*DATA: g_tabchar(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
*DATA: wa_truxs_t_text_data TYPE truxs_t_text_data.
*DATA: g_filename TYPE string,
g_path TYPE string,
g_fullpath TYPE string,
g_user_action TYPE i,
g_file_encoding TYPE abap_encoding.
*DATA : g_text(8192),
data : g_mstring1(100) type c,
g_mstring2(100) type c,
g_mstring3(100) type c,
g_mstring4(100) type c,
g_mstring5(100) type c.
data: g_count1 type ebelp,
g_str_count1(6) type c.
data: g_count type ebelp,
g_str_count(6) type c.
*DATA: f_subrc LIKE sy-subrc,
f_subrc1 LIKE sy-subrc,
f_error(500) TYPE c,
item1(27) TYPE c,
item2(27) TYPE c,
item3(27) TYPE c,
item4(27) TYPE c,
i TYPE ekpo-ebelp.
*DATA: g_billplan_header TYPE c,
g_billplan_item TYPE c.
data : g_external_so type vbak-vbeln. "SO
SELECTION-SCREEN
selection-screen begin of block frame1 with frame title text-001 .
parameters:p_file1 type rlgrap-filename, "OBLIGATORY, "Header data.
p_file2 type rlgrap-filename, "OBLIGATORY, "Item Data.
p_file3 type rlgrap-filename, "Schedule line.
p_file4 type rlgrap-filename ."OBLIGATORY. "Error file.
selection-screen end of block frame1.
start-of-selection.
wa_bapi_header-doc_type = 'Z0MX'. "order type
wa_bapi_header-sales_org = '0130'."sales org
wa_bapi_header-distr_chan = '13'. "distr channel
wa_bapi_header-division = '13'. "division
Old code from copied program
wa_bapi_header-purch_no_s = wa_header-kunnr_2. " Ship to party
New code as required in Finland project
We are using to Header ->Order Tab -> Ship to Party -> Purchase order no (BSTKD_E) to store Old legacy SO number
wa_bapi_header-purch_no_s = 'MX100443'. "External SO i.e Old legacey SO number
wa_bapi_header-ref_1_s = '0000666666'. "Sold to party
wa_bapi_header-ord_reason = wa_header-augru.
wa_bapi_header-purch_no_c = 'ddr1234'. " PO number
wa_bapi_header-purch_date = sy-datum. " PO date
wa_bapi_header-req_date_h = sy-datum. " Required Delivery Date
wa_bapi_header-pmnttrms = '01'. " Payment Terms
wa_bapi_header-incoterms1 = wa_header-inco1.
wa_bapi_header-incoterms2 = wa_header-inco2.
wa_bapi_header-price_date = wa_header-prsdt. " Pricing date
wa_bapi_header-currency = wa_header-waerk. " Document Currency
wa_bapi_header-sales_grp = wa_header-vkgrp. " Sales group
wa_bapi_header-price_list = wa_header-pltyp. " Price list type
wa_bapi_header-cust_group = wa_header-kdgrp. " Cust Group
wa_bapi_header-ship_type = wa_header-vsart. " Shipping Type
wa_bapi_header-purch_no_s = wa_header-bstkd_e. " Ship-to-party po number
wa_bapi_header-collect_no = wa_header-submi. " Collective No.
wa_bapi_header-name = wa_header-bname. " Name
wa_bapi_header-ref_1 = wa_header-ihrez. " Your Reference
wa_bapi_header-cust_grp1 = wa_header-kvgr1. " Industry
wa_bapi_header-cust_grp2 = wa_header-kvgr2. " Customer BU
*ENDFORM. " f_header
IF wa_header-partner_1 IS NOT INITIAL.
wa_bapi_partner-partn_role = 'AG'.
wa_bapi_partner-partn_numb = '0000666666'.
wa_bapi_partner-itm_number = '000000'.
append wa_bapi_partner to it_bapi_partner.
clear wa_bapi_partner.
ENDIF.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_header-partner_2
importing
output = wa_header-partner_2.
IF wa_header-partner_2 IS NOT INITIAL.
wa_bapi_partner-partn_role = 'WE'.
wa_bapi_partner-partn_numb = '0000666666'.
wa_bapi_partner-itm_number = '000000'.
append wa_bapi_partner to it_bapi_partner.
clear wa_bapi_partner.
ENDIF.
perform f_item.
data : order_items_inx type table of bapisditmx with header line.
order_items_inx-material = 'X'. "
order_items_inx-target_qty = 'X'. "
order_items_inx-comp_quant = 'X'. "
order_items_inx-trgqty_den = 'X'.
order_items_inx-rnddlv_qty = 'X'.
order_items_inx-updateflag = 'I'.
order_items_inx-target_qu = 'X'.
order_items_inx-plant = 'X'. "
append order_items_inx.
call function 'BAPI_SALESORDER_CREATEFROMDAT2'
exporting
salesdocumentin = 'MX11111152'
order_header_in = wa_bapi_header
order_header_inx = wa_bapi_headerx
importing
salesdocument = sales_order_no
tables
return = it_bapireturn
order_items_in = it_bapi_item
order_items_inx = order_items_inx
order_partners = it_bapi_partner
order_conditions_in = it_bapi_cond.
if sy-subrc is initial.
commit work.
endif.
*& Form f_item
text
form f_item .
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_item-posnr
importing
output = wa_item-posnr.
wa_item-posnr = '000010'.
IF sy-subrc EQ 0. "IS INITIAL.
move wa_item-posnr to g_str_count."commented out by shakti
ENDIF.
wa_bapi_item-itm_number = wa_item-posnr. " Line item
WA_BAPI_ITEM-PO_ITM_NO = WA_ITEM-EBELP.
wa_bapi_item-division = wa_item-spart.
wa_bapi_item-purch_no_c = 'ddr1234'. " po number
wa_bapi_item-purch_date = sy-datum. " po date
wa_bapi_item-purch_no_s = 'MX11111112'. " Ship-to-party po number
wa_item-matnr = 'MAXIMO_SERVICE'.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = wa_item-matnr
importing
output = wa_item-matnr
exceptions
length_error = 1
others = 2.
if sy-subrc is initial.
wa_bapi_item-material = wa_item-matnr. "material
endif.
wa_bapi_item-target_qty = '1'. " Order qty
wa_bapi_item-comp_quant = '1'.
wa_bapi_item-target_qu = 'EA'.
wa_bapi_item-fixed_quan = '1'.
wa_bapi_item-comp_quant = wa_item-kwmeng.
wa_bapi_item-trgqty_den = '1'.
wa_bapi_item-rnddlv_qty = wa_item-kwmeng.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_item-ps_psp_pnr
IMPORTING
output = wa_item-ps_psp_pnr.
IF sy-subrc = 0.
wa_bapi_item-wbs_elem = wa_item-ps_psp_pnr.
ENDIF.
wa_bapi_item-item_categ = 'ZMAX'.
wa_bapi_item-ex_rate_fi = wa_item-kurrf.
wa_bapi_item-dli_profil = wa_item-ffprf. " Dynamic item processor profile
wa_bapi_item-route = wa_item-route. " route
wa_bapi_item-exchg_rate = wa_item-kursk.
wa_bapi_item-plant = '2090'. " Plant
wa_bapi_item-ship_point = 'FN11'. " Shipping point
wa_bapi_item-store_loc = wa_item-lgort. " stg loc
REPLACE ALL OCCURRENCES OF ',' IN wa_item-ntgew WITH '.'.
REPLACE ALL OCCURRENCES OF ',' IN wa_item-brgew WITH '.'.
wa_bapi_item-net_weight = wa_item-ntgew. "
wa_bapi_item-gross_wght = wa_item-brgew. "
call function 'CONVERSION_EXIT_CUNIT_INPUT'
exporting
input = wa_item-gewei
language = sy-langu
importing
output = wa_item-gewei.
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
wa_bapi_item-untof_wght = 'KG'. " weight unit
replace all occurrences of ',' in wa_item-kursk with '.'.
replace all occurrences of ',' in wa_item-kurrf with '.'.
wa_bapi_item-profit_ctr = wa_item-prctr. " Profit center
wa_bapi_item-resanalkey = wa_item-abgrs. " RESULT ANALYSIS KEY
wa_bapi_item-cstg_sheet = wa_item-kalsm_k. " COSTING SHEET
append wa_bapi_item to it_bapi_item.
endform. " f_item
Thanks & regards,
Chetansee the following to create sales order:-
*& Report ZSALESORDER
*&DEVELOPED BY JANI KRUPA 4.10.2008
REPORT ZSALESORDER.
Parameters
Sales document type
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
PARAMETERS: p_auart TYPE auart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Sales organization
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Distribution channel
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Division.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
PARAMETERS: p_spart TYPE spart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SKIP 1.
Sold-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
PARAMETERS: p_sold TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Ship-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
PARAMETERS: p_ship TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SKIP 1.
Material
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
PARAMETERS: p_matnr TYPE matnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Quantity.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Plant
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
PARAMETERS: p_plant TYPE werks_d .
SELECTION-SCREEN END OF LINE.
Complete Deliver
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text10 FOR FIELD p_autlf.
PARAMETERS: p_autlf TYPE autlf DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
Data declarations.
DATA: v_vbeln LIKE vbak-vbeln.
DATA: header LIKE bapisdhead1.
DATA: headerx LIKE bapisdhead1x.
DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx
WITH HEADER LINE.
DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl
WITH HEADER LINE.
DATA: lt_schedules_ink TYPE STANDARD TABLE OF bapisdhead1
WITH HEADER LINE.
Initialization.
INITIALIZATION.
v_text = 'Order type'.
v_text1 = 'Sales Org'.
v_text2 = 'Distribution channel'.
v_text3 = 'Division'.
v_text4 = 'Sold-to'.
v_text5 = 'Ship-to'.
v_text6 = 'Material'.
v_text7 = 'Quantity'.
v_text9 = 'Plant'.
v_text10 = 'Complete delivery'.
Start-of-selection.
START-OF-SELECTION.
Header data
Sales document type
header-doc_type = p_auart.
headerx-doc_type = 'X'.
Sales organization
header-sales_org = p_vkorg.
headerx-sales_org = 'X'.
Distribution channel
header-distr_chan = p_vtweg.
headerx-distr_chan = 'X'.
Division
header-division = p_spart.
headerx-division = 'X'.
headerx-updateflag = 'I'.
*Complete delivery
header-COMPL_DLV = p_autlf.
header-COMPL_DLV = 'X'.
Partner data
Sold to
partner-partn_role = 'AG'.
partner-partn_numb = p_sold.
APPEND partner.
Ship to
partner-partn_role = 'WE'.
partner-partn_numb = p_ship.
APPEND partner.
ITEM DATA
itemx-updateflag = 'I'.
Line item number.
item-itm_number = '000010'.
itemx-itm_number = 'X'.
Material
item-material = p_matnr.
itemx-material = 'X'.
Plant
item-plant = p_plant.
itemx-plant = 'X'.
Quantity
item-target_qty = p_menge.
itemx-target_qty = 'X'.
item category
itemx-ITEM_CATEG = 'X'.
APPEND item.
APPEND itemx.
ITEM DATA
itemx-updateflag = 'I'.
Line item number.
item-itm_number = '000020'.
itemx-itm_number = 'X'.
Material
item-material = p_matnr.
itemx-material = 'X'.
Plant
item-plant = p_plant.
itemx-plant = 'X'.
Quantity
item-target_qty = p_menge.
itemx-target_qty = 'X'.
APPEND item.
APPEND itemx.
Fill schedule lines
lt_schedules_in-itm_number = '000010'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.
Fill schedule line flags
lt_schedules_inx-itm_number = '000010'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.
Fill schedule lines
lt_schedules_in-itm_number = '000020'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.
Fill schedule line flags
lt_schedules_inx-itm_number = '000020'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.
Call the BAPI to create the sales order.
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = header
sales_header_inx = headerx
IMPORTING
salesdocument_ex = v_vbeln
TABLES
return = return
sales_items_in = item
sales_items_inx = itemx
sales_schedules_in = lt_schedules_in
sales_schedules_inx = lt_schedules_inx
sales_partners = partner.
Check the return table.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
WRITE: / 'Error in creating document'.
ELSE.
Commit the work.
COMMIT WORK AND WAIT.
WRITE: / 'Document ', v_vbeln, ' created'.
ENDIF.
Maybe you are looking for
-
My Ipod Touch Won't Show as a device in iTunes
Hope you can help, I'm running all the latest software (ie 10.5.6) on my iMac 2.GHz Intel Core 2 Duo. When I connect my iPod Touch, iPhoto automatically opens and the device is shown but my iTunes remains un-opened. When I manually open it and re-try
-
How to create ITS for a R/3 Transaction?
Hi All, I am new to ITS. Can somebody please let me know how to create a ITS for a R/3 transaction. I tried from SE80 but not able to get the result. I even checked in SICF. Whatever the service that I am created, it is not visible in SICF. Please he
-
How to Mark Radio Channels as Favorite in Apple TV 3rg Generation?
I dont see an option to mark my radio channels as Favourite on my 3rd Gen Apple TV. Please provide me the steps to perform this step. Thanks!
-
ORA-03137: TTC protocol internal error
Hi We created a new database and trying to connect from this database to Oracle access manager at AS400.We added the new instance on oracel access manager Tnsnames. The connection is failing and the error I see in alert log file is ORA-03137: TTC pro
-
Getting VoiceOver to read text
I have just begun to use VoiceOver. My real issue is that while I am able to navigate the cursor around my screen, I am not able to get VoiceOver to speak in the text or html content areas. I know that I have missed something very basic, but it has e