SAP SD BAPI VA01

From SapWiki

Ejemplo 1

FORM f_pedido_venta USING i_kunnr
                          i_werks
                 CHANGING p_documento TYPE vbak-vbeln
                          o_datos_pedido LIKE gt_datos_pedido[].
  DATA: ls_header TYPE bapisdhd1,
        lt_partners TYPE STANDARD TABLE OF bapiparnr,
        ls_partner TYPE bapiparnr,
        lt_items TYPE STANDARD TABLE OF bapisditm,
        ls_item TYPE bapisditm,
        lt_schedule TYPE STANDARD TABLE OF bapischdl,
        ls_schedule TYPE bapischdl,
        lt_condiciones TYPE STANDARD TABLE OF bapicond,
        ls_condicion TYPE bapicond,
        lt_return TYPE STANDARD TABLE OF bapiret2,
        ls_return TYPE bapiret2,
        posicion(6) TYPE n.
  DATA detalle LIKE LINE OF o_datos_pedido.
  CLEAR: ls_header,
         lt_items[],
         lt_condiciones[],
         lt_partners[],
         lt_schedule[],
         lt_return[].

  ls_header-doc_type = 'PSER'.
  ls_header-sales_org = 'PTG'.
  ls_header-distr_chan = 'PT'.
  ls_header-division =  'PT'.
  ls_header-req_date_h = sy-datlo.
 
  ls_partner-partn_role = 'AG'.
  ls_partner-partn_numb = i_kunnr.
  APPEND ls_partner TO lt_partners.
  posicion = '0'.
  
  LOOP AT o_datos_pedido INTO detalle.
    CLEAR: ls_item,
           ls_condicion,
           ls_schedule.
    posicion = posicion + 10.
    ls_item-itm_number = posicion.
    ls_item-material = detalle-matnr.
    ls_item-short_text = detalle-maktx.
    ls_item-plant = i_werks.
    
    APPEND ls_item TO lt_items.
    ls_condicion-itm_number = posicion.
    ls_condicion-cond_type = 'PCOND'.

    DATA ld_monto LIKE bapicurr-bapicurr.
    CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
      EXPORTING
        currency        = detalle-waerk
        amount_internal = detalle-kwert
      IMPORTING
        amount_external = ld_monto.
    ls_condicion-cond_value = ld_monto.
    ls_condicion-currency = detalle-waerk.
    APPEND ls_condicion TO lt_condiciones.
    ls_schedule-itm_number = posicion.
    ls_schedule-req_qty = detalle-menge.
    APPEND ls_schedule TO lt_schedule.
  ENDLOOP.

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
    order_header_in               = ls_header
     behave_when_error             = space
   IMPORTING
     salesdocument                 = p_documento
  TABLES
    return                        = lt_return
    order_items_in                = lt_items
    order_partners                = lt_partners
    order_schedules_in            = lt_schedule
    order_conditions_in           = lt_condiciones.

  IF p_documento IS NOT INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = ls_return.

* Pedido de Venta grabado
    MESSAGE ID 'V1' TYPE 'S' NUMBER '311'
    WITH 'Pedido de Venta'(s01)
          p_documento.
  ELSE.
    LOOP AT lt_return INTO ls_return WHERE type = 'E'.
      MESSAGE ID ls_return-id TYPE ls_return-type NUMBER ls_return-number
      WITH ls_return-message_v1
           ls_return-message_v2
           ls_return-message_v3
           ls_return-message_v4.
      EXIT.
    ENDLOOP.
  ENDIF.

ENDFORM.                    "f_pedido_venta

Crear pedido con referencia a factura

En SAP no existe una BAPI para crear una orden de venta con referencia a otros documentos, como otros pedidos, ofertas, etc. Solución ver Nota SAP 370988

FUNCTION Z_SD_CREA_PEDIDO_CON_REF_FACT.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     REFERENCE(I_AUART) LIKE  VBAK-AUART DEFAULT 'ZFIN'
*"     REFERENCE(I_VBELN) LIKE  VBRK-VBELN
*"     REFERENCE(I_MONTO) TYPE  ACBTR
*"     REFERENCE(I_WAERS) TYPE  WAERS
*"     REFERENCE(I_COMMIT) TYPE  CHAR1 DEFAULT SPACE
*"     REFERENCE(I_VERSION) TYPE  VSNMR_V OPTIONAL
*"  EXPORTING
*"     REFERENCE(O_SALESDOCUMENT) LIKE  BAPIVBELN-VBELN
*"  TABLES
*"      I_T_SALESDOCUMENTS STRUCTURE  SALES_KEY OPTIONAL
*"      O_T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
 ls_bapi_view-header       = 'X'.
 ls_bapi_view-item         = 'X'.
 ls_bapi_view-sdschedule   = 'X'.
 ls_bapi_view-sdcond       = 'X'.
 ls_bapi_view-partner      = 'X'.
 ls_bapi_view-BUSINESS     = 'X'.
 select single aubel into ls_salesdocuments
                          from vbrp where vbeln = i_vbeln.
 append ls_salesdocuments to lt_salesdocuments.
 CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
   EXPORTING
     i_bapi_view                   = ls_bapi_view
*   I_MEMORY_READ                 =
   TABLES
     sales_documents               = lt_salesdocuments
     order_headers_out             = lt_order_headers_out
     order_items_out               = lt_order_items_out
     order_schedules_out           = lt_order_schedules_out
     order_partners_out            = lt_order_partners_out
     order_conditions_out          = lt_order_conditions_out
     order_business_out            = lt_order_business_out
           .
************************************************************************
** PREPARE DATA
 clear lt_order_items_in[].
 clear lt_order_partners[].
 clear lt_order_schedules_in[].
 clear lt_order_conditions_in[].
* fill header data
 IF NOT lt_order_headers_out[] IS INITIAL.
   READ TABLE lt_order_headers_out INTO ls_header_out INDEX 1.
* fill header data
   perform fill_header using i_auart
                             i_vbeln
                             i_version.
* fill header business data
   perform fill_header_business.
* fill partner data
   perform fill_partners.
 endif.
* ORDER_ITEMS_IN
 select single matnr werks zterm from ZSD_MAT_INTERES
                   into (ls_order_items_in-material,
                         ls_order_items_in-plant,
                         ls_order_header_in-PMNTTRMS)
                   where vkorg = ls_header_out-SALES_ORG.
 ls_order_items_in-po_itm_no  = '0010'.
*  ls_order_items_in-material   = '000000000000040383'.
*  ls_order_items_in-plant      = '700P'.
 APPEND ls_order_items_in TO lt_order_items_in.
* ORDER_SCHEDULE_IN
 ls_order_schedules_in-itm_number = '0010'.
 ls_order_schedules_in-req_qty    = '1'.
 APPEND ls_order_schedules_in TO lt_order_schedules_in.
* ORDER_CONDITIONS_IN
 ls_order_conditions_in-itm_number = '0010'.
 ls_order_conditions_in-cond_type  = 'ZFIN'.
 ls_order_conditions_in-cond_value = i_monto.
 ls_order_conditions_in-currency  =  i_waers.
 APPEND ls_order_conditions_in TO lt_order_conditions_in.

*fill logic switch
*  lv_logic_switch-pricing = i_prart.
 clear o_t_return[].
 CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
   EXPORTING
*   SALESDOCUMENTIN               =
     order_header_in               = ls_order_header_in
     logic_switch                  = lv_logic_switch
   IMPORTING
     salesdocument                 = o_salesdocument
   TABLES
     return                        = o_t_return
     order_items_in                = lt_order_items_in
     order_partners                = lt_order_partners
     order_schedules_in            = lt_order_schedules_in
     order_conditions_in           = lt_order_conditions_in
           .
 if o_salesdocument is not initial.
   if i_commit = 'X'.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
     EXPORTING
        WAIT          = 'X'
*   IMPORTING
*     RETURN        =
               .
   endif.
 endif.
ENDFUNCTION.

FORM add_schedules using i_qty.         "add schedules to item
 LOOP AT lt_order_schedules_out INTO ls_schedules_out
                  WHERE itm_number = ls_item_out-itm_number
                    and DOC_NUMBER = ls_item_out-DOC_NUMBER
   .
*    ls_order_schedules_in-itm_number = ls_schedules_out-itm_number.
   ls_order_schedules_in-itm_number = ld_item_number.
   IF NOT i_qty IS INITIAL AND NOT ls_schedules_out-req_qty = 0.
     ls_order_schedules_in-req_qty = i_qty.
   ELSE.
     ls_order_schedules_in-req_qty = ls_schedules_out-req_qty.
   ENDIF.
   ls_order_schedules_in-sched_line = ls_schedules_out-sched_line.
   APPEND  ls_order_schedules_in TO lt_order_schedules_in.
 ENDLOOP.
 IF sy-subrc <> 0.
   ls_order_schedules_in-itm_number = ls_item_out-itm_number.
   ls_order_schedules_in-sched_line = '001'.
   ls_order_schedules_in-req_qty = i_qty.
   APPEND  ls_order_schedules_in TO lt_order_schedules_in.
 ENDIF.
ENDFORM.                    " add_schedules
*&---------------------------------------------------------------------*
*&      Form  add_items
*&---------------------------------------------------------------------*
FORM add_items .
 CONSTANTS:
       kzvbr_e TYPE c VALUE 'E',        " Einzelfertigung
       vkgru_rep_reparaturanfo LIKE vbap-vkgru VALUE 'I01'.
*  ls_order_items_in-itm_number = ls_item_out-itm_number.
* MOVE-CORRESPONDING ls_item_out to ls_order_items_in.
 ls_order_items_in-itm_number = ld_item_number.
 ls_order_items_in-material = ls_item_out-material.
*  ls_order_items_in-ref_doc  = pa_key.
 ls_order_items_in-ref_doc  = ls_item_out-DOC_NUMBER.
 ls_order_items_in-ref_doc_it = ls_item_out-itm_number.
 ls_order_items_in-ref_doc_ca = ls_header_out-sd_doc_cat.
 ls_order_items_in-PLANT   = ls_item_out-PLANT.         "centro
 ls_order_items_in-STore_LOC  = ls_item_out-STGE_LOC.   "almacen
 ls_order_items_in-MAT_ENTRD  = ls_item_out-MAT_ENTRD.   "material introducido     ;
 ls_order_items_in-MATL_GROUP = ls_item_out-MATL_GROUP.    "grupo de articulos;
 ls_order_items_in-SHORT_TEXT = ls_item_out-SHORT_TEXT."Texto breve posición de pedido de cliente;
 ls_order_items_in-VAL_TYPE   = ls_item_out-VAL_TYPE ."clase de valoración;
 ls_order_items_in-PROD_HIERa  = ls_item_out-PROD_HIER."jerarquía de productos;
 ls_order_items_in-PR_REF_MAT = ls_item_out-PR_REF_MAT.    "Material determinante del precio;
* ls_order_items_in-BASE_UOM   = ls_item_out-BASE_UOM."Unidad de medida base;
 ls_order_items_in-SALES_UNIT = ls_item_out-SALES_UNIT .   "Cantidad de pedido acumulada (en unidades de venta);
 ls_order_items_in-SALQTYNUM = ls_item_out-SALES_QTY1.   "Numerador (factor) p.conversión cantidad venta en UMA;
 ls_order_items_in-SALQTYDEN = ls_item_out-SALES_QTY2.  "Denominador (divisor) p.conversión ctd.venta en UMA;
*  IF NOT ls_item_out-REPAIR_PRO EQ VKGRU_REP_REPARATURANFO.
*    ls_order_items_in-REPAIR_PRO = ls_item_out-REPAIR_PRO.  "Gestión de reparaciones: Clasificación de posiciones;
*  ENDIF.
 ls_order_items_in-dlvschduse = ls_item_out-DLVSCHEDUS. "Indicador de utilización;
 IF NOT ls_item_out-DLV_GROUP IS INITIAL.
   ls_order_items_in-DLV_GROUP = ls_item_out-DLV_GROUP . "Grupo de entrega (las pos.se entregan conjuntamente);
 ENDIF.
 ls_order_items_in-FIXED_QUAN = ls_item_out-FIXED_QUAN .  "Cantidad fija;
*    ls_order_items_in-REPLACE_PT = ls_item_out-REPLACE_PT.  "Pieza de recambio;
*   ls_order_items_in-METH_BILL = ls_item_out-METH_BILL.  "Forma de facturación para órdenes RK/PPS;
 ls_order_items_in-DIVISION = ls_item_out-DIVISION.  "sector;
 ls_order_items_in-CURRENCY = ls_item_out-CURRENCY.  "Moneda de documento comercial;
 IF NOT ls_item_out-PROFIT_CTR IS INITIAL.
   ls_order_items_in-PROFIT_CTR = ls_item_out-PROFIT_CTR.     "Centro de beneficio;PROFIT_CTR
 ENDIF.
 ls_order_items_in-ORDERID = ls_item_out-ORDERID.             "Orden
 if ls_item_out-WBS_ELEM is NOT INITIAL.
*    ls_order_items_in-WBS_ELEM = ls_item_out-WBS_ELEM .          "Elemento PEP
   CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
     EXPORTING
       INPUT         = ls_item_out-WBS_ELEM
    IMPORTING
      OUTPUT        = ls_order_items_in-WBS_ELEM
             .
 endif.
*   ls_order_items_in-NO_OF_SERI = ls_item_out-NO_OF_SERI.  "Cantidad de números de serie;
*   ls_order_items_in-SERNO_PROF = ls_item_out-SERNO_PROF.  "Perfil de números de serie;
 APPEND ls_order_items_in TO lt_order_items_in.
ENDFORM.                    " add_items
*&---------------------------------------------------------------------*
*&      Form  add_conditions
*&---------------------------------------------------------------------*
FORM add_conditions.          " add conditions to item
 LOOP AT lt_order_conditions_out INTO ls_conditions_out
                      WHERE itm_number = ls_item_out-itm_number
                       and sd_doc  = ls_item_out-DOC_NUMBER
                     AND NOT cond_type IS INITIAL
   .
   CLEAR ls_order_conditions_in.
   MOVE-CORRESPONDING ls_conditions_out TO ls_order_conditions_in.
   ls_order_conditions_in-itm_number = ld_item_number.
   ls_order_conditions_in-cond_unit = ls_conditions_out-cond_d_unt.
   APPEND ls_order_conditions_in TO lt_order_conditions_in.
 ENDLOOP.
ENDFORM.                    " add_conditions
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FILL_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILL_HEADER using i_auart
                      i_vbeln
                      i_version.

 ls_order_header_in-doc_type   = i_auart.
 ls_order_header_in-sales_org  = ls_header_out-sales_org.
 ls_order_header_in-distr_chan = ls_header_out-distr_chan.
 ls_order_header_in-division   = ls_header_out-division.
*  ls_order_header_in-ref_doc = ls_header_out-DOC_NUMBER.
*  ls_order_header_in-purch_no_c = i_purno.
*  ls_order_header_in-refdoc_cat = ls_header_out-sd_doc_cat.
 ls_order_header_in-sales_off = ls_header_out-sales_off. "oficina de ventas
 ls_order_header_in-sales_grp = ls_header_out-sales_grp. "grupo de vendedores
 ls_order_header_in-WAR_DATE	= ls_header_out-WAR_DATE.	"Fecha límite de garantía
 if ls_header_out-WBS_ELEM is not initial
   and ls_header_out-WBS_ELEM ne '000000000'.
 ls_order_header_in-WBS_ELEM  = ls_header_out-WBS_ELEM. "Elemento del plan de estructura de proyecto (elemento PEP)
endif.
ls_order_header_in-COLLECT_NO	= ls_header_out-SD_COL_NUM.	"Nº de licitación (SD)
ls_order_header_in-DLV_BLOCK  = ls_header_out-DLV_BLOCK.  "Bloqueo de nota de entrega cabecera de documento
ls_order_header_in-ORD_REASON	= ls_header_out-ORD_REASON.	"Motivo de pedido (motivo de la operación)
ls_order_header_in-BILL_BLOCK	= ls_header_out-BILL_BLOCK.	"Bloqueo de clases de facturas para documento comercial
ls_order_header_in-CURRENCY	= ls_header_out-CURRENCY.	"Moneda de documento comercial
ls_order_header_in-COMPL_DLV  = ls_header_out-COMPL_DLV.  "¿Entrega completa por pedido? 
if ls_header_out-REQ_DATE_H is not INITIAL.
 ls_order_header_in-REQ_DATE_H	= ls_header_out-REQ_DATE_H.	"Fecha preferente de entrega
 ls_order_header_in-DATE_TYPE  = ls_header_out-DATE_TYPE.  "Período propuesto para la fecha
endif.
ls_order_header_in-CUST_GRP1  = ls_header_out-CUST_GRP1.  "Grupo de clientes 1
ls_order_header_in-CUST_GRP2  = ls_header_out-CUST_GRP2.  "Grupo de clientes 2
ls_order_header_in-CUST_GRP3  = ls_header_out-CUST_GRP3.  "Grupo de clientes 3
ls_order_header_in-CUST_GRP4  = ls_header_out-CUST_GRP4.  "Grupo de clientes 4
ls_order_header_in-CUST_GRP5  = ls_header_out-CUST_GRP5.  "Grupo de clientes 5
ls_order_header_in-REF_DOC_L  = ls_header_out-REF_DOC_L.  "Número de documento de referencia
ls_order_header_in-REF_DOC    = i_vbeln.
select SINGLE vbtyp into ls_order_header_in-refdoc_cat from vbrk
                                          where vbeln = i_vbeln.
ls_order_header_in-ASS_NUMBER	= ls_header_out-ASS_NUMBER.	"Número de asignación
ls_order_header_in-ALTTAX_CLS	= ls_header_out-ALT_TAX_CL.	"Diferente clasificación fiscal
ls_order_header_in-TAX_CLASS2	= ls_header_out-TAX_CLASS2.	"Clasificación fiscal cliente 2
ls_order_header_in-TAX_CLASS3	= ls_header_out-TAX_CLASS3.	"Clasificación fiscal cliente 3
ls_order_header_in-TAX_CLASS4	= ls_header_out-TAX_CLASS4.	"Clasificación fiscal cliente 4
ls_order_header_in-TAX_CLASS5	= ls_header_out-TAX_CLASS5.	"Clasificación fiscal cliente 5
ls_order_header_in-TAX_CLASS6	= ls_header_out-TAX_CLASS6.	"Clasificación fiscal cliente 6
ls_order_header_in-TAX_CLASS7	= ls_header_out-TAX_CLASS7.	"Clasificación fiscal cliente 7
ls_order_header_in-TAX_CLASS8	= ls_header_out-TAX_CLASS8.	"Clasificación fiscal cliente 8
ls_order_header_in-TAX_CLASS9	= ls_header_out-TAX_CLASS9.	"Clasificación fiscal cliente 9
ls_order_header_in-EUTRI_DEAL = ls_header_out-EU_TRIANG.  "Indicador: ¿operación triangular dentro de la UE?
ls_order_header_in-TAXDEP_CTY	= ls_header_out-TAX_DEPART.	"País de salida para la  determinación de impuestos
ls_order_header_in-TAXDST_CTY = ls_header_out-TAX_DEST_CT.  "País receptor fiscal
ls_order_header_in-DLVSCHDUSE	= ls_header_out-DLVSCHEDUS.	"Indicador de utilización
ls_order_header_in-version    = i_version.
ls_ORDER_HEADER_IN-PURCH_NO_C = i_vbeln.
ls_ORDER_HEADER_IN-CUST_GROUP = '01'.
ENDFORM.                    " FILL_HEADER
*&---------------------------------------------------------------------*
*&      Form  FILL_HEADER_BUSINESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILL_HEADER_BUSINESS .
* fill business data
 IF NOT lt_order_business_out[] IS INITIAL.
   READ TABLE lt_order_business_out INTO ls_business_out INDEX 1.
   ls_order_header_in-ACCNT_ASGN	= ls_business_out-ACCNT_ASGN.	"Cuenta contrato
   ls_order_header_in-FKK_CONACCT  = ls_business_out-FKK_CONACCT.  "grupo de Imputación
   ls_order_header_in-PYMT_METH  = ls_business_out-PAYMETHODE. "Vía de Pago
* = ls_business_out-POSTPERIOD  Periodo Contable
*	= ls_business_out-FISC_YEAR	Ejercicio
   ls_order_header_in-EXRATE_FI  = ls_business_out-EXCHRATEFI. "Tipo de Cambio
   ls_order_header_in-DUNN_KEY	= ls_business_out-DUNN_KEY.	"Clave de Reclamación
   ls_order_header_in-DUNN_BLOCK	= ls_business_out-DUNN_BLOCK.	"Bloqueo de reclamación
 ENDIF.
 ENDFORM.                    " FILL_HEADER_BUSINESS
*&---------------------------------------------------------------------*
*&      Form  FILL_PARTNERS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILL_PARTNERS .
 data ld_pn(10) type n.
 loop at lt_order_partners_out INTO ls_order_partners_out
                             where SD_DOC = ls_header_out-doc_number
                              .
   ls_order_partners-partn_role = ls_order_partners_out-partn_role.
     ls_order_partners-partn_numb   = ls_order_partners_out-customer.
     if ls_order_partners_out-PERSON_NO is not INITIAL.
       move ls_order_partners_out-PERSON_NO to ld_pn.
       move   ld_pn to ls_order_partners-partn_numb.
     endif.
   APPEND ls_order_partners TO lt_order_partners.
 ENDloop.
ENDFORM.                    " FILL_PARTNERS
**********************************************************************************
include ZSSO_RVADOR01_SIM_TOP.
DATA  ls_bapi_view            TYPE order_view.
DATA  lt_salesdocuments       TYPE TABLE OF sales_key.
DATA  lt_order_headers_out    TYPE TABLE OF bapisdhd.
DATA  lt_order_items_out      TYPE TABLE OF bapisdit.
DATA  lt_order_schedules_out  TYPE TABLE OF bapisdhedu.
DATA  lt_order_conditions_out TYPE TABLE OF bapisdcond.
DATA  lt_order_partners_out   TYPE TABLE OF bapisdpart.
data  lt_order_business_out   type table of BAPISDBUSI.
DATA: lv_logic_switch         TYPE bapisdls.
DATA  lv_salesdocument        TYPE bapivbeln-vbeln.
DATA  lt_return               TYPE TABLE OF bapiret2.
DATA  lt_order_items_in       TYPE TABLE OF bapisditm.
DATA  lt_order_schedules_in   TYPE TABLE OF bapischdl.
DATA  lt_order_partners       TYPE TABLE OF bapiparnr.
DATA  lt_order_conditions_in  TYPE TABLE OF bapicond.
data ls_salesdocuments type sales_key.
DATA: ls_return               TYPE bapiret2.
DATA: ls_header_out           TYPE bapisdhd.
DATA  ls_order_header_in      TYPE bapisdhd1.
DATA: ls_item_out             TYPE bapisdit.
DATA: ls_order_items_in       TYPE bapisditm.
DATA: ls_order_schedules_in   TYPE bapischdl.
DATA: ls_schedules_out        TYPE bapisdhedu.
DATA: ls_order_partners_out   TYPE bapisdpart.
DATA: ls_order_partners       TYPE bapiparnr.
DATA  ls_order_conditions_in  TYPE bapicond.
DATA: ls_conditions_out       TYPE bapisdcond.
data  ls_business_out         type BAPISDBUSI.
data ld_item_number like ls_item_out-itm_number.
data ld_sales_key type sales_key.
**********************************************************************
*&---------------------------------------------------------------------*
*&  Include           ZSSO_RVADOR01_SIM_TOP
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
*   DATA DECLARATION
*----------------------------------------------------------------------*
**CONSTANTS**
 CONSTANTS: c_sapmv45a_xvbkd TYPE char40   VALUE '(SAPMV45A)XVBKD[]',
            c_sapmv45a_xvbap TYPE char40   VALUE '(SAPMV45A)XVBAP[]',
            c_initial        TYPE posnr    VALUE '000000',
            c_end_date       TYPE auszdat  VALUE '99991231',
            c_formname       TYPE tdsfname VALUE 'ZSSO_RVADOR01_SIM',
            c_waerk          TYPE waerk    VALUE 'CLP',
            c_skfbt          TYPE acfbt    VALUE '0.00',
            c_valtg          TYPE valtg    VALUE '00',
            c_valdt          TYPE valdt    VALUE space,
            c_true           TYPE char1    VALUE 'X',
            c_as01           TYPE dzterm   VALUE 'AS01',
            c_ts01           TYPE dzterm   VALUE 'TS01',
            c_id_z001        TYPE tdid     VALUE 'Z001',
            c_es             TYPE spras    VALUE 'S',
            c_konp           TYPE tdobject VALUE 'KONP',
            c_01             TYPE char2    VALUE '01',
            c_zint           TYPE kscha    VALUE 'ZINT'.
 constants: c_sapmv45a_xKOMV TYPE char40   VALUE '(SAPMV45A)XKOMV[]'.
**TYPES**
 TYPES: ty_sim       TYPE zsso_sim_st,
        ty_sim_hdr   TYPE zsso_sim_hdr_st,
        ty_sim_pos   TYPE zsso_sim_pos_st,
        ty_sim_ftr   TYPE zsso_sim_ftr_st,
        ty_vbdka     TYPE vbdka,
        ty_xvbkd     TYPE vbkdvb,
        ty_xvbap     TYPE vbapvb,
        ty_te418     TYPE te418.
 TYPES: BEGIN OF ty_t052s,
          ratnr TYPE ratnr,
          ratpz TYPE ratpz,
          ratzt TYPE ratzt,
        END OF   ty_t052s.
**TYPE TABLE**
 TYPES: ty_t_sim_pos TYPE STANDARD TABLE OF ty_sim_pos,
        ty_t_xvbkd   TYPE STANDARD TABLE OF ty_xvbkd,
        ty_t_xvbap   TYPE STANDARD TABLE OF ty_xvbap,
        ty_t_t052s   TYPE STANDARD TABLE OF ty_t052s,
        ty_t_tline   TYPE STANDARD TABLE OF tline.
 types: ty_t_xkomv TYPE STANDARD TABLE OF KOMV.
**DATA**
 DATA: gt_xvbap   TYPE ty_t_xvbap,
       gt_t052s   TYPE ty_t_t052s,
       ga_sim     TYPE ty_sim,
       ga_xvbkd   TYPE ty_xvbkd.
 data gt_xkomv type ty_t_xkomv.
**********************************************************************