Delivery Document closing -5002

Hi,
I am closing my delivery document and the document doesn’t close with item with serial number; I get error -5002 and the document doesn’t close.
Is there a special routine to close a delivery document with items with serial number?
Thank you,
Rune

hi Rune,
there's only one way to close a document
the .Close Methode
odocument.close
there's no special way with serial numbers

Similar Messages

  • Delivery Document not getting closed

    Hi Experts,
    I am using 2007 B PL 08. I want to close the delivery document through SDK against which no Invoice or return is booked. it gives me error 'Internal error -5002 occured' when I try to close this document with following code.
    Dim fd As SAPbobsCOM.Documents
      fd = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
             If fd.GetByKey(93) = True Then
                    DelClose = fd.Close
                    If DelClose <> 0 Then
                        oCompany.GetLastError(FErrCode, FErrMsg)
                        MsgBox(FErrMsg)
                    End If
              End If
    i even try following code to loop through the lines collection and close lines instead of closing header.
    it gives me "you can not close rows in this type of document" error:
    Dim fd As SAPbobsCOM.Documents
                fd = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
                If fd.GetByKey(93) = True Then
                    For i = 0 To fd.Lines.Count - 1
                        fd.Lines.SetCurrentLine(i)
                        If fd.Lines.LineStatus <> SAPbobsCOM.BoStatus.bost_Close Then
                            fd.Lines.LineStatus = SAPbobsCOM.BoStatus.bost_Close
                        End If
                    Next
                    DelClose = fd.Update
                    If DelClose <> 0 Then
                        oCompany.GetLastError(FErrCode, FErrMsg)
                        MsgBox(FErrMsg)
                    End If
                End If
    this used to work with 2005 B. Am I doing anything wrong?
    Thanks in advance,
    Binita

    Hi Binita,
    Closing the delivery at the header level works in the DI API in SBO 2007A (though it's not good practice as the correct method, as you know, would be to add a return linked to the delivery to return the goods to stock and update the GL). I can also do this via the SBO client (it warns me that there is no target document but I can choose to continue).
    If you can close the delivery via the SBO client in 2007B then it sounds like a bug in the DI API.
    Kind Regards,
    Owen

  • Delivery Document is closed-Solution required to manage transaction!

    Dear All,
    What could be  the best solution for....
    "A delivery document has been added from a standalone return document and status is closed,Now customer wants to add an invoice for closed delivery and skipping outgoing invoice"
    Pls suggest me,how to manage this out of procedure transaction in SAP B1.
    Thanks....

    Hi Param,
    SAP B1 is quite restrictive in the case of closed documents. What you can do is create a delivery note exactly same as the one which is closed. In the remarks field/or any other suitable field add the 'closed delivery note' document number to maintain the traceability. Create the invoice exactly the one you were going to for 'closed delivery note'.
    Hope this helps.
    Regards,
    IC

  • How to find closing date for a delivery document

    I nedd to fin closing date for a delivery document. I tried with clsdate but didnt work
    If someone can help me with this

    Hi.............
                 Better and simplest way you can get it through a simple qury report. Create a query by joining two tables ODLN and OINV. OINV's docdate means the closing date of delivery challan.
    Regards,

  • Delivery document is still open even already invoiced

    Good day! Could anyone help me on this?
    Here is the scenario:
    A new delivery document was created based in sales order. The delivery undergoes to approval procedure and then approved.
    Upon posting of the delivery doc and after past few days, sales return was requested. So, sales return was processed and successfully posted based in that delivery doc, but later that day another sales return was requested and did same procedure (successful).
    Two sales return was created based in that delivery doc and both SR were 'closed' while the delivery doc is still open, now to close that DR an invoice doc is required. Invoice was made base again in that DR and successfully posted. Expectedly, the DR should close but apparently it doesn't close. Why is that? Or did I miss something that would close that DR?
    Thanks in advance!

    Hi Nagesh,
    Yes your right, all marketing docs undergone with approval procedure are all saved as Draft until it was approved by the approver and then posted by the originator and that is the only time DR or any marketing docs should be called as official/posted transaction.
    Going back to my scenario, what I mentioned was approved and posted meaning the transaction was officially saved and undergone with the normal module flow SO->DR->SR->SI.
    And my concern was focused on why DR is still open even already invoiced.
    Correct me if I'm wrong, DR will still remain 'Open' only if the item total qty was not yet invoiced. For example:
    DR1              QTY            Amount
    Item 1             10              100
    SI
    Item 1              8                80
    Thanks,
    Rhod

  • Delivery document change after PGI ?

    Hi All,
    Is any way can I change the value of the field of "Ext.delivery" in delivery document(Header-->Administration) after PGI and billing process. And the most important thing I have to mention: it was closed in previous period. Somebody can help on this issue would be appreciated.
    Thanks.
    mlai

    Hi,
    You can use the user exit MV45AFZ1 sub routine FORM USEREXIT_SAVE_DOCUMENT.
    Here write a small piece of code.
    if LIKP-LIFEX eq '' .
    Message'External Delivery Number is not Maintained' type 'E' .
    endif .
    I hope this will help you to validate before save the document.
    Regards,
    Murali

  • Copy the Frieght/AdditionalExpenses from SO to Delivery document

    Hi,
    I want to copy the Frieght/AdditionalExpenses from SO to Delivery document. I'm using the following code.
    When I'm adding DL document, I get internal error -5002.
    Please help me.
    Thank you.
                Dim objBaseDoc As SAPbobsCOM.Documents
                        objBaseDoc = objSBOAPI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
                If objBaseDoc.GetByKey(strFirstDocEntry) = True Then
                    Call AddExpensesFromBaseDoc(objDLDoc, objBaseDoc.Expenses)
    Private Function AddExpensesFromBaseDoc(ByRef objDLDoc As SAPbobsCOM.Documents, ByRef objExpenses As SAPbobsCOM.DocumentsAdditionalExpenses)
            Try
                Dim i As Integer, ncnt As Integer, nIndexToStart As Integer
                nIndexToStart = objDLDoc.Expenses.Count
                Try
                    objDLDoc.Expenses.SetCurrentLine(nIndexToStart)
                Catch ex As Exception
                    objDLDoc.Expenses.Add()
                End Try
                ncnt = objExpenses.Count
                For i = 0 To ncnt - 1
                    objExpenses.SetCurrentLine(i)
                    objDLDoc.Expenses.SetCurrentLine(nIndexToStart + i)
                    objDLDoc.Expenses.ExpenseCode = objExpenses.ExpenseCode
                    objDLDoc.Expenses.LineTotal = objExpenses.LineTotal
                    'objDLDoc.Expenses.TaxCode = objExpenses.TaxCode
                    If (i + 1) < ncnt Then
                        objDLDoc.Expenses.Add()
                    End If
                Next
            Catch ex As Exception
                Call objSBOAPI.SBO_Appln.MessageBox("AddExpensesFromBaseDoc " & ex.Message)
            End Try
        End Function

    Hi Geetha,
    The most likely reason for that error message is that there's a blank expenses line in the delivery. If you put a break point just before you try and add the delivery, check to see if every expenses line in the delivery has an expense code.
    I suspect the problem is that the document object will automatically have a Expenses.Count value of 1, even if no expenses have been added. Therefore, if you've just created a new instance of a delivery document your following code will add a new expenses line but leave the first line empty:
    nIndexToStart = objDLDoc.Expenses.Count
    Try
    objDLDoc.Expenses.SetCurrentLine(nIndexToStart)
    Catch ex As Exception
    objDLDoc.Expenses.Add()
    End Try
    You need to add logic to this, if Count is 1, then check to see if an expenses code has been set for this line. If not, then you need to overwrite the values in the first expenses line. If the count is 1 and there is an expenses code set on this line then you need to add a new expenses line.
    Kind Regards,
    Owen

  • Delivery status Closed

    Hi all,
    How to return closed delivery document.
    Eg.
    By mistake clinet closed the delivery document before return document.
    Thanks,
    Rupinder

    Rupinder,
    I believe you are looking to create a Return based on a Delivery but the delivery is closed.   My thinking would be to create a Standalone Return document.
    Open the Return doc, pick the customer and items and add. 
    I am not sure if I missed something but Goods Receipts is obviously not needed to do RETURN.
    Suda

  • Cancellation of Delivery Document

    Hi everyone,
    I would like to ask if there is a way to correct a posted Delivery document without having to re-create the reference Sales Order document. Here's the scenario: Upon creation of a Delivery document, the user has forgot to change the delivery quantity before posting it. (human error)
    Example:
    Sales Order Qty = 10
    Delivery Qty = 8 (Partial Delivery)
    The Delivery Document has been posted in B1 with 10 as the quantity. If we try to create a Return Document for the 2 quantity which was not served, we cannot anymore create a new Delivery Document for the remaining 2 because the reference Sales Order document is already closed. Is there a way we can serve the remaining 2 without having  to create a new Sales Order and just used the same Sales Order? Any suggestions will be appreaciated (either thru SDK or thru a workaround)
    Thanks in advance.
    Malu

    Hi Malu,
    There is no workaround either you make a return of 2 and again delivered 2 directly or return 10 and create a new sales order of 10 quantity a better option will be to return 10 and create new sales order.
    I hope SAP will come up with solution on this as these is a commen scenerio required.
    Thanks
    Kamlesh

  • Report of cancelled Delivery Document, Billing Document & Shipment Document

    Hi,
    How can I get list of cancelled Delivery Document, Billing Document & Shipment Document.
    Regards,
    VK

    Hi,
    Good Day,
    Cancelled Delivery will available in Table CDPOS
    Pass below parameter
    OBJECTCLAS    LIEFERUNG              
    OBJECTID       Delivery Number
    TABNAME       LIKP                   
    CHNGIND       D                      
    Cancelled Invoice available in Table VBRK Pass Below Parameter
    FKSTO = 'X'
    Shipment Document Once you delete i don't thinks will get the details.
    May we can use Userexist and maintain customized table to track the deleted shipment number.
    Best Regards,
    KSK

  • Unable to capture condition type in delivery document

    There are deliveries in production server, for the same destination zone, in which, for some deliveries, the condition Z52L is not determined and for some other deliveries, the condition Z52L is determined although the condition record for its plant with its corresponding destination zone is maintained in VK13.
    For example, if we take 2 documents with the same Ship-To-Party, same Plant, and same Destination Zone:
    1 delivery document, condition Z52L is properly determined while the other
    delivery document, condition Z52L is not determined.
    Another good representative example if we take 2 delivery documents with the same Ship-To-Party, same Plant and same destination zone: 
    1 delivery document, condition Z52L is properly determined while the other
    delivery document, condition Z52L is not determined.
    But in the analysis pricing of the delivery document, there is no destination zone found but still it captures the condition Z52L by just referring to the transportation zone of the ship to party while the other delivery document cannot able to capture it since there is no maintained condition record for those with blank destination zone in VK13.
    Another point that we want to clarify is even the user update the pricing in the delivery document, still the condition was not yet updated even it is already maintained in VK13.
    Please help and explain this issue to us.
    Thank you in advance. Hoping for your assistance on this matter.
    Reyna Agustin

    hi,
    for the first errot check if you have maintained the item level copy control (from sales order to del). if yes check the settings against the field 'pos/- qty'. put a + here. for the second issue check in the item level copy ctrl from sales order to billing maintain 'd' in the price type.
    saurabh

  • Regarding- Packing Line Item Not Displayed in the Delivery Document.

    Hi,
    I have 2 queries
    1) Have  created separate Material Type Packaging for my packing material and the item category group used is VERP, my Orginal Material is getting packed in the Delivery Document, however the packed item is not coming as a separate line item in the Delivery document, I have maintained the item category settings for the Delivery Packing Material and also the packing Material contains stock,
    2) The Plant and Storage Location for my handling unit need to get defaulted autmatically in the delivery document what settings should I configure for the same.
    Kind Regards
    Atul Keshav

    Hi,
       Find the below threads, which is explained in context with returnable packaging, same will be useful for you.
    [Re: returnable packaging]
    [Returnable packaging process;
    Regards,
    Reazuddin MD

  • Item number in billing document not matching with delivery document-reg

    Hi All,
    In the billing document the item number is coming from Shipment document. ie., there are three deliveries in a shipment. Each delivery has got one line item, ie., 10. These three deliveries are assigned to a shipment, the order in which the deliveries are attached if we take as 10 for first delivery, 20 for th esecond and 30 for the third, In billing document the billing from first delivery is getting the item number as 10, the second delivery's billing document is getting the item number as 20 and the third as 30.
    Can someone please reply where and how this is configured?
    Thanks and regards,
    Tajudeen S.

    Hi,
    first look at IMG/Sales and Distribution/ Billing / Maintain Copying Control For Billing Documents / Copying control: Delivery document to billing document
    There is a field "Copy item number from reference"
    Maybe it helps.
    regards
    Wojciech

  • Open Sales order, Delivery docuement, Billing document, Item

    Hi Gurus,
    Kindly help to view the following items for a particular customer.
    1) Open sales order value
    2) Open Delivery docuement value
    3) Open Billing document value
    4) Open item.
    I presume for viewing open sales order VA05N and to view Open item FBL5N would suffice. Please correct me if i am wrong and let me know about points 2 and 3.
    This is required because, my client is facing some figure mismatch while executing F.35 tcode. I am trying to analyze the differnce of figures while doing a Static and dynamic credit check.
    Thanking you in advance
    ficoguy.

    Dear ficoguy,
    1) Open sales order value
    Tcode: VA05 (select OPEN SALES ORDERS)
    optional method: SE11/ TABLE VBAK/ INPUT customer code as KUNNR, fetch the list.
    Input the VBELN in VBUK and filter with RFSTK='A'
    2) Open Delivery document value
    Tcode: VF04 (OUTPUT DATA FOR BATCH PROCESSING-->CHECK LIST DISPLAY)
    DOCUMENT TO BE SELECTED = DELIVERY RELATED
    optional method:(same as above except the FIRST TABLE)
    SE11/ TABLE LIKP/ INPUT customer code as KUNNR, fetch the list.
    Input the VBELN in VBUK and filter with RFSTK='A'
    3) Open Billing document value
    TCode: VF05
    Selection criteria : OPEN BILLING DOCUMENTS
    4) Open item.
    Tcode : FBL5N
    Check and revert back.
    Thanks & Regards,
    Hegal K Charles

  • How 2 creat report for displaying the details of a Delivery Document using

    how to create report for displaying the details of a Delivery Document using the tables LIKP, LIPS
    thank you
    regards,
    jagrut bharatkumar shukla
    points will be rewarded

    HI
    I AM GIVING YOU MY DELIVERY DOCUMENT CODE...MODIFY IT ACCORDING TO YOUR REQUIREMENT
    *& Report  ZDELIVERY                                *
    report  zdelivery  message-id z9bhu          .
    types: begin of t_likp,
               vbeln type likp-vbeln,      "Delivery
               erdat type likp-erdat,      "Date for rec creation
    *           LFDAT TYPE LIKP-LFDAT,      "Delevery Date
    *           WAERK TYPE LIKP-WAERK,      "Currency
               kunnr type likp-kunnr,      "Ship-To Party
               kunag type likp-kunag,      "Sold-to party
               traty type likp-traty,      "Means-of-Transport
           end of t_likp.
    types: begin of t_lips,
               vbeln type lips-vbeln,      "Delivery
               posnr type lips-posnr,      "Delivery item
               matnr type lips-matnr,      "Material Number
               arktx type lips-arktx,      "Short Text for Sales Order Item
               lfimg type lips-lfimg,      "Actual quantity delivered
               netpr type lips-netpr,
    *           MEINS TYPE LIPS-MEINS,      "Base Unit of Measure
               vgbel type lips-vgbel,      "Doc no of the reference document
            end of t_lips.
    types: begin of t_vbpa,
               vbeln type vbpa-vbeln,      "SD DocumenT Number
               posnr type vbpa-posnr,      "Item number
               parvw type vbpa-parvw,      "Partner function
               kunnrb type vbpa-kunnr,      "Customer Number 1
           end of t_vbpa.
    types: begin of t_kna1,
               kunnr type kna1-kunnr,      "Customer Number 1
               name1 type kna1-name1,      "Name 1
               ort01 type kna1-ort01,      "City
               adrnr type kna1-adrnr,      "Address
           end of t_kna1.
    types: begin of t_li_vbpa,
               vbeln type likp-vbeln,      "Delivery
               erdat type likp-erdat,      "Date for rec creation
    *           LFDAT TYPE LIKP-LFDAT,      "Delevery Date
    *           WAERK TYPE LIKP-WAERK,      "Currency
               kunnr type likp-kunnr,      "Ship-To Party
               kunag type likp-kunag,      "Sold-to party
               traty type likp-traty,      "Means-of-Transport
               vbeln1 type lips-vbeln,      "Delivery
               posnr type lips-posnr,      "Delivery item
               matnr type lips-matnr,      "Material Number
               arktx type lips-arktx,      "Short Text for Sales Order Item
               lfimg type lips-lfimg,      "Actual quantity delivered
               netpr type lips-netpr,      "Net Price
    *           MEINS TYPE LIPS-MEINS,      "Base Unit of Measure
               vgbel type lips-vgbel,      "Doc no of the reference document
               vbeln3 type vbpa-vbeln,     "SD DocumenT Number
               parvw type vbpa-parvw,      "Partner function
               kunnrb type vbpa-kunnr,      "Customer Number 1
           end of t_li_vbpa.
    types: begin of t_final,
               vbeln type likp-vbeln,      "Delivery
               erdat type likp-erdat,      "Date for rec creation
               kunnr type likp-kunnr,      "Ship-To Party
               kunag type likp-kunag,      "Sold-to party
               traty type likp-traty,      "Means-of-Transport
               vbeln1 type lips-vbeln,      "Delivery
               posnr type lips-posnr,      "Delivery item
               matnr type lips-matnr,      "Material Number
               arktx type lips-arktx,      "Short Text for Sales Order Item
               lfimg type lips-lfimg,      "Actual quantity delivered
               netpr type lips-netpr,      "Net Price
               vgbel type lips-vgbel,      "Doc no of the reference document
               vbeln3 type vbpa-vbeln,     "SD DocumenT Number
               parvw type vbpa-parvw,      "Partner function
               kunnrb type vbpa-kunnr,     "Customer Number 1
               name1 type kna1-name1,      "Name 1
               ort01 type kna1-ort01,      "City
               adrnr1 type kna1-adrnr,     "Address
               name2 type kna1-name1,      "Name 1
               ort02 type kna1-ort01,      "City
               adrnr2 type kna1-adrnr,     "Address
               name3 type kna1-name1,      "Name 1
               ort03 type kna1-ort01,      "City
               adrnr3 type kna1-adrnr,     "Address
           end of t_final.
    *            D A T A  D E C L A R A T I O N
    *&*********Internal Table Declaration****************&*
    data: it_likp type standard table of t_likp.
    data: it_lips type standard table of t_lips.
    data: it_vbpa type standard table of t_vbpa.
    data: it_kna1 type standard table of t_kna1.
    data: it_li_vbpa type standard table of t_li_vbpa.
    data: it_li_vbpa_temp type standard table of t_li_vbpa.
    data: it_final type standard table of t_final.
    *&*********Work Area Declaration********************&*
    data: wa_likp type t_likp.
    data: wa_lips type t_lips.
    data: wa_vbpa type t_vbpa.
    data: wa_kna1 type t_kna1.
    data: wa_li_vbpa type t_li_vbpa.
    data: wa_li_vbpa_temp type t_li_vbpa.
    data: wa_final type t_final.
    *&*********Data Declaration************************&*
    data: d_vbeln type likp-vbeln.
    data: flag type i value 0.
    *           S E L E C T I O N  S C R E E N   D E C L A R A T I O N
    selection-screen begin of block block2 with frame title text-001.
    select-options: s_vbeln for d_vbeln obligatory.    "Delivery no
    selection-screen end of block block2.
    *            A T  S E L E C T I O N - S C R E E N   E V E N T S
    *AT SELECTION-SCREEN.
    *PERFORM VALIDATE_DATA.
    *            S T A R T   O F  S E L E C T I O N     E V E N T S
    start-of-selection.
    perform fetch_data.
    perform merge_data_kna1.
    *INCLUDE Z9BT_SH_***4_FORMS.
    call function 'OPEN_FORM'
    exporting
    *   APPLICATION                       = 'TX'
    *   ARCHIVE_INDEX                     =
    *   ARCHIVE_PARAMS                    =
        device                            = 'PRINTER'
    *   DIALOG                            = 'X'
    *   FORM                              = ' '
       language                          = sy-langu
    *   OPTIONS                           =
    *   MAIL_SENDER                       =
    *   MAIL_RECIPIENT                    =
    *   MAIL_APPL_OBJECT                  =
    *   RAW_DATA_INTERFACE                = '*'
    *   SPONUMIV                          =
    * IMPORTING
    *   LANGUAGE                          =
    *   NEW_ARCHIVE_PARAMS                =
    *   RESULT                            =
    exceptions
       canceled                          = 1
       device                            = 2
       form                              = 3
       options                           = 4
       unclosed                          = 5
       mail_options                      = 6
       archive_error                     = 7
       invalid_fax_number                = 8
       more_params_needed_in_batch       = 9
       spool_error                       = 10
       codepage                          = 11
       others                            = 12
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    sort it_final by vbeln.
    loop at it_final into wa_final.
    call function 'START_FORM'
    exporting
    *   ARCHIVE_INDEX          =
       form                   = 'Z9BT_DELIVERY'
       language               = sy-langu
    *   STARTPAGE              = ' '
    *   PROGRAM                = ' '
    *   MAIL_APPL_OBJECT       =
    * IMPORTING
    *   LANGUAGE               =
    exceptions
       form                   = 1
       format                 = 2
       unended                = 3
       unopened               = 4
       unused                 = 5
       spool_error            = 6
       codepage               = 7
       others                 = 8
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    call function 'WRITE_FORM'
    exporting
       element                        = 'ITEM_LIST'
       function                       = 'SET'
       type                           = 'BODY'
       window                         = 'MAIN'
    * IMPORTING
    *   PENDING_LINES                  =
    * EXCEPTIONS
    *   ELEMENT                        = 1
    *   FUNCTION                       = 2
    *   TYPE                           = 3
    *   UNOPENED                       = 4
    *   UNSTARTED                      = 5
    *   WINDOW                         = 6
    *   BAD_PAGEFORMAT_FOR_PRINT       = 7
    *   SPOOL_ERROR                    = 8
    *   CODEPAGE                       = 9
    *   OTHERS                         = 10
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    call function 'END_FORM'
    * IMPORTING
    *   RESULT                         =
    exceptions
       unopened                       = 1
       bad_pageformat_for_print       = 2
       spool_error                    = 3
       codepage                       = 4
       others                         = 5
    if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    endloop.
    call function 'CLOSE_FORM'
    * IMPORTING
    *   RESULT                         =
    *   RDI_RESULT                     =
    * TABLES
    *   OTFDATA                        =
    exceptions
       unopened                       = 1
       bad_pageformat_for_print       = 2
       send_error                     = 3
       spool_error                    = 4
       codepage                       = 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.
    endif.
    *&      Form  VALIDATE_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form validate_data .
    select single vbeln into wa_likp-vbeln
                        from likp where vbeln in s_vbeln.
    append wa_likp to it_likp.
    if sy-subrc <> 0.
    flag = 1.
    endif.
    endform.                    " VALIDATE_DATA
    *&      Form  FETCH_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form fetch_data .
    select a~vbeln
           a~erdat
           a~kunnr
           a~kunag
           a~traty
           b~vbeln
           b~posnr
           b~matnr
           b~arktx
           b~lfimg
           b~netpr
           b~vgbel
           c~vbeln
           c~parvw
           c~kunnr
             into table it_li_vbpa
                    from likp as a
                    left outer join lips as b on a~vbeln = b~vbeln
                    inner join vbpa as c on b~vgbel = c~vbeln
                    where a~vbeln in s_vbeln and
                    c~parvw = 'RE'.
    endform.                    " FETCH_DATA
    *&      Form  MERGE_DATA_KNA1
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form merge_data_kna1 .
    if it_li_vbpa[] is not initial.
    it_li_vbpa_temp[] = it_li_vbpa[].
    sort it_li_vbpa_temp by kunnr.
    delete adjacent duplicates from it_li_vbpa_temp comparing kunnr.
    loop at it_li_vbpa into wa_li_vbpa.
    read table it_li_vbpa_temp into wa_li_vbpa_temp with key kunnr =
    wa_li_vbpa-kunag.
    if sy-subrc <> 0.
    wa_li_vbpa_temp = wa_li_vbpa.
    append wa_li_vbpa_temp to it_li_vbpa_temp.
    endif.
    read table it_li_vbpa_temp into wa_li_vbpa_temp with key kunnr =
    wa_li_vbpa-kunnrb.
    if sy-subrc <> 0.
    wa_li_vbpa_temp = wa_li_vbpa.
    append wa_li_vbpa_temp to it_li_vbpa_temp.
    endif.
    endloop.
    endif.
    if it_li_vbpa_temp[] is not initial.
    select  kunnr
            name1
            ort01
            adrnr into table it_kna1 from kna1
                        for all entries in it_li_vbpa_temp
                        where kunnr = it_li_vbpa_temp-kunnr.
    endif.
    loop at it_li_vbpa into wa_li_vbpa .
    wa_final-vbeln = wa_li_vbpa-vbeln.
    wa_final-erdat = wa_li_vbpa-erdat.
    *it_final-LFART = it_li_vbpa-LFART.
    wa_final-kunnr = wa_li_vbpa-kunnr.
    wa_final-kunag = wa_li_vbpa-kunag.
    *it_final-VSTEL = it_li_vbpa-VSTEL.
    wa_final-traty = wa_li_vbpa-traty.
    wa_final-vbeln1 = wa_li_vbpa-vbeln.
    wa_final-posnr = wa_li_vbpa-posnr.
    wa_final-matnr = wa_li_vbpa-matnr.
    wa_final-arktx = wa_li_vbpa-arktx.
    wa_final-lfimg = wa_li_vbpa-lfimg.
    wa_final-netpr = wa_li_vbpa-netpr.
    *wa_final-GEWEI = it_li_vbpa-GEWEI.
    *it_final-VOLUM = it_li_vbpa-VOLUM.
    *it_final-VOLEH = it_li_vbpa-VOLEH.
    wa_final-vgbel = wa_li_vbpa-vgbel.
    wa_final-vbeln3 = wa_li_vbpa-vbeln.
    *wa_final-PARVW = wa_li_vbpa-PARVW.
    wa_final-kunnrb = wa_li_vbpa-kunnrb.
    read table it_kna1 into wa_kna1 with key kunnr = wa_li_vbpa-kunnr.
    if sy-subrc = 0.
    wa_final-name1 = wa_kna1-name1.
    wa_final-ort01 = wa_kna1-ort01.
    wa_final-adrnr1 = wa_kna1-adrnr.
    endif.
    read table it_kna1 into wa_kna1 with key kunnr = wa_li_vbpa-kunag.
    if sy-subrc = 0.
    wa_final-name2 = wa_kna1-name1.
    wa_final-ort02 = wa_kna1-ort01.
    wa_final-adrnr2 = wa_kna1-adrnr.
    endif.
    read table it_kna1 into wa_kna1 with key kunnr = wa_li_vbpa-kunnrb.
    if sy-subrc = 0.
    wa_final-name3 = wa_kna1-name1.
    wa_final-ort03 = wa_kna1-ort01.
    wa_final-adrnr3 = wa_kna1-adrnr.
    endif.
    append wa_final to it_final.
    clear wa_final.
    endloop.
    endform.

Maybe you are looking for