Adding new segment in IDOC

Hi,
       i have a requirement where based on a condition i need to add a new segment dynamically in Inbound IDOC.
I have written the code in the user exit of the inbound FM. Its adding new segments and process it perfectly.
But when i see the IDOC in we02 or we19, i am not able to see the newly added segment.
Will the newly added segment in FM appear in the We02?
PS: i have changed the idoc_control-maxsegnum.
Regards,
Niyaz

Hi Niyaz,
Check out the below program ....Similar to your requirement
IDoc creation from inbound file
REPORT ZS7BM000006 message-id ZS7.
*/ Program Name: Creation of DESADV & INVOIC IDocs from file E021
*/ Description : This program reads in external file E021 containing
*                shipping and invoice data from internal vendors and
*                creates one DESADV and one INVOIC IDoc per invoice.
*/ Transaction : n/a - run from job Z_ccc_S7B_Annnnn, where
*                'ccc' = 3-digit client and 'nnnnn' = zero-filled
*                sequence number matching the scheduled job for E020.
tables:  lfa1,
         lfm1,
         ekpo,
         eine,
         e1edk01,
         e1edk02,
         e1edk07,
         e1edk08,
         e1edk06,
         e1edk03,
         e1edka1,
         e1edka2,
         e1edp07,
         e1edp09,
         e1edp19,
         e1edp01,
         e1edp02,
         e1edp26,
         e1edp04,
         e1eds01,
         e1eds02,
         zst7f_ty_vendors.
parameters:  p_path like PATH-PATHEXTERN
                   default '/ftp/atac/in/'.
data:  INFILE LIKE PATH-PATHEXTERN,
       back_path(7) type c value 'backup/',
       offset like sy-fdpos,
       p07_ctr like sy-index,
       invoice_total type p decimals 3,
       d_seg_num like sy-index,
       i_seg_num like sy-index.
data:  OUTFILE LIKE PATH-PATHEXTERN,
       today(8)     type c.
data:  begin of uty_vendors occurs 10,
          lifnr like lfa1-lifnr,
          waers like lfm1-waers,
          name_abbr like zst7f_ty_vendors-name_abbr,
          ship_days like zst7f_ty_vendors-ship_days,
       end of uty_vendors.
data:  iZSS7B21 like ZSS7B21.
data:  desadvdata like edi_dd occurs 5 with header line.
data:  invoicdata like edi_dd occurs 5 with header line.
data:  dedidc like edi_dc occurs 1 with header line.
data:  iedidc like edi_dc occurs 1 with header line.
data:  begin of ie021 occurs 10,
        lifnr            like lfa1-lifnr,
        ship_days        like zst7f_ty_vendors-ship_days,
        invoice_no       like e1edk08-vbeln,
        stat             like e1edk01-action,
        po_number(10)    type n,
        po_lineno(5)     type n,
        slip_number      like e1edp09-vbeln,
        shipto_id        like e1edka1-partn,
        vendor_id        like e1edka1-partn,
        endcust_name     like e1edka1-name1,
        cust_partno      like e1edp09-kdmat,  "char 35
        vendor_partno    like e1edp09-matnr,  "char 35
        invoice_qty      like e1edp09-lfimg,
        qty_uom          like e1edp01-menee,
        unit_price       like e1edp01-vprei,
        price_uom        like e1edp01-pmene,
        price_qty        like e1edp01-peinh,
        line_amount      like e1edp26-betrg,
        currency         like e1edk01-curcy,
        etd              like e1edk06-datum, "ship date
        eta              like e1edk06-datum, "delivery date
        ship_id          like e1edk08-traid,
        ship_method      like e1edk08-traty,
        create_date      like e1edk03-datum,
        plant            like ekpo-werks,
       end of ie021.
data: save_po like ie021-po_number,
      save_line like ie021-po_lineno,
      save_stat like ie021-stat,
      save_invoice like ie021-invoice_no.
constants: hun_thou type p decimals 5 value '100000',
           thou type p decimals 3 value '1000'.
*&      DEFINITION:  append_idoc_rec
*       add a data record to the IDoc internal table
define append_idoc_rec.
&1-tabnam = &1-segnam.
&2_seg_num = &2_seg_num + 1.
&1-segnum = &2_seg_num.
shift &1-segnum left deleting leading space.
append &1.
clear &1.
end-of-definition.       " append_idoc_rec
* MAIN PROCESSING LOOP
START-OF-SELECTION.
today = sy-datum.
* find all internal vendors
select a~lifnr
       b~waers
       c~name_abbr  c~ship_days
   into corresponding fields of table uty_vendors
     from lfa1 as a
          inner join lfm1 as b
             on a~lifnr = b~lifnr
          inner join zst7f_ty_vendors as c
             on a~lifnr = c~lifnr
     where a~ktokk = 'ZZTY' and
           b~ekorg = '7100' and
           c~ship_code = ' '.
perform init_desadv.
perform init_invoic.
concatenate 'SAP' sy-sysid(3) into: iedidc-sndpor, dedidc-sndpor.
loop at uty_vendors.
  clear ie021. refresh ie021.
  if not uty_vendors-name_abbr is initial.
* datafiles are received with naming convention:
* E020_<customer name abbreviation>_UTY
    concatenate p_path 'E021_' uty_vendors-name_abbr '_UTY'
        into infile.
    if not sy-subrc is initial.  "pathname too long
* Filename too long: &
      message i016 with infile.
      continue.
    endif.
    condense infile.
    OPEN DATASET INFILE FOR INPUT IN TEXT MODE.
    if not sy-subrc is initial.
*'Cannot open dataset & on &'
      message i013 with infile sy-datum.
      continue.
    else.
      concatenate p_path back_path 'E021_'
          uty_vendors-name_abbr '_UTY' today
                into outfile.
      if not sy-subrc is initial.  "pathname too long
* Filename too long: &
        message i016 with outfile.
        continue.
      endif.
      condense outfile.
      OPEN DATASET OUTFILE FOR OUTPUT IN TEXT MODE.
* if the datestamped file cannot be created, do not process the
* input file, because the input file is deleted after processing,
* and there would be no record of the data.
      if not sy-subrc is initial.
*'ERROR opening file & for output'
        close dataset infile.
        message i033 with outfile.
        continue.  "process next vendor's file
      endif.
      do.
        read dataset infile into izss7b21.
        case sy-subrc.
          when 0.
            transfer izss7b21 to outfile.
            if izss7b21-datacode = 'T'. "trailer rec
              perform process_one_vendor using infile.
              exit.  "process next vendor's file
            endif.
            check: izss7b21-datacode = 'A'. "data rec
            case izss7b21-status.
              when ' '.  "new
                ie021-stat = '000'.
              when 'M'.  "modification
                ie021-stat = '002'.
              when 'D'.  "deletion
                ie021-stat = '003'.
            endcase.
            move-corresponding uty_vendors to ie021.
            move-corresponding izss7b21 to ie021.
            perform convert_po_no using izss7b21-pono_poline
                               changing ie021-po_number
                                        ie021-po_lineno.
            perform convert_dates using ie021-lifnr
                                        izss7b21-etd
                                        izss7b21-eta
                                        izss7b21-ship_method
                                        izss7b21-create_date
                               changing ie021-eta
                                        ie021-ship_days.
            perform quantity_conversion
                                using izss7b21-qty_uom
                                      izss7b21-invoice_qty
                                      izss7b21-unit_price
                                changing ie021-qty_uom
                                         ie021-invoice_qty
                                      izss7b21-line_amount.
            perform money_conversion
                                using izss7b21-currency
                                      izss7b21-unit_price
                                      izss7b21-price_uom
                                      izss7b21-line_amount
                                changing ie021-currency
                                         ie021-price_uom
                                         ie021-price_qty
                                         ie021-unit_price
                                         ie021-line_amount.
            perform SAP_vendor_partno
                                changing ie021-cust_partno.
            append ie021.
          when 4.  "EOF
            perform process_one_vendor using infile.
            exit.  "process next vendor's file
          when others.
*ERROR reading dataset & - &
            message i015 with infile sy-datum.
            exit.
        endcase.
      enddo.
      close dataset: infile, outfile.
      delete dataset infile.
    endif.
  endif.
endloop. "UTY_VENDORS
*&      Form  process_one_vendor
*       Pre-processed records from one vendor file are now in the
*       internal table ie021 - ready to create IDocs
FORM process_one_vendor using value(infile).
  sort ie021 by invoice_no stat po_number po_lineno.
  loop at ie021.
    if ( ie021-invoice_no <> save_invoice or
         ie021-stat <> save_stat ).
      if sy-tabix > 1.
        perform post_idocs using ie021-stat.
      endif.
      perform idoc_header_segs using ie021-stat.
    endif.
    if ( ie021-stat <> save_stat or
         ie021-po_number <> save_po or
         ie021-po_lineno <> save_line or
         ie021-invoice_no <> save_invoice ).
      if ( sy-tabix > 1 and
           ie021-stat = '000' ).
        perform idoc_poheader_segs.
      endif.
    endif.
    perform idoc_item_segs using ie021-stat.
    save_po = ie021-po_number.
    save_line = ie021-po_lineno.
    save_invoice = ie021-invoice_no.
    save_stat = ie021-stat.
  endloop.
  perform post_idocs using ie021-stat.
* File successfully processed: &
  message s035 with infile.
ENDFORM.                    " process_one_vendor
*&      Form  convert_po_no
*       Break the PO number & line field into separate fields
FORM convert_po_no using value(infield)
                   changing po_number like ie021-po_number
                            po_line like ie021-po_lineno.
data:  cpos like sy-fdpos,
       lpos like sy-fdpos,
       cline(6) type c.
* if the infield contains a hyphen, assume that the preceding characters
* represent the po number, if they are numeric. The po line number is
* assumed to be all numeric characters after the hyphen.
  if infield ca '-'.
    if infield(sy-fdpos) co ' 0123456789'.  "numeric
      po_number = infield(sy-fdpos).
      cpos = sy-fdpos + 1.
    endif.
  else.  "no hyphen - PTY
    if infield(2) = '71'.  "SAP number range
      cpos = 10.
    else.                  "SyteLine number
      cpos = 6.
    endif.
    if infield(cpos) co ' 0123456789'.  "numeric
      po_number = infield(cpos).
    endif.
  endif.
  if not po_number is initial.
    while infield+cpos(1) co '0123456789'.
      cline+lpos(1) = infield+cpos(1).
      lpos = lpos + 1.
      cpos = cpos + 1.
    endwhile.
    shift cline left deleting leading '0'.
    if not cline is initial.
      po_line = cline.
    endif.
  endif.
* Put out a warning in the job log, but create the IDoc to save the data
  if ( po_number is initial or
       po_line is initial ).
* PO number - line item conversion failed: &
    message i034 with infield.
  endif.
ENDFORM.                    " convert_po_no
*&      Form  convert_dates
*       Convert ship date to delivery date, if necessary
FORM convert_dates using value(vendor_no)
                         value(i_ship_date)
                         value(i_delivery_date)
                         value(i_ship_code)
                         value(i_create_date)
                changing o_delivery_date
                         ship_days.
data:  ship_date type d.
* if delivery date not sent, calculate it from ship date plus
* ship days.
* Note that this logic could leave delivery date blank,
* if ship date is not numeric.
  if ( i_delivery_date is initial or
       i_delivery_date co ' 0' ).  "no delivery date sent
    if ( i_ship_date co ' 0123456789' and
         i_ship_date cn ' 0' ).    "ship date sent
* move the ship date into a date field to add days
      ship_date = i_ship_date.
    elseif ( i_create_date co ' 0123456789' and
             i_create_date cn ' 0' ).
      ship_date = i_create_date.
    endif.
    if not i_ship_code is initial.
      select single ship_days from zst7f_ty_vendors
               into ship_days
              where lifnr = vendor_no
                and ship_code = i_ship_code.
    endif.
    if not ship_date is initial.
      if ship_days > 0.
        ship_date = ship_date + ship_days.
        o_delivery_date = ship_date.
        shift o_delivery_date left deleting leading ' '.
      endif.
    endif.
  else.  "delivery date sent
    o_delivery_date = i_delivery_date.
  endif.
ENDFORM.                    " convert_dates
*&      Form  quantity_conversion
*       The quantities in the input file are implied 3-decimal,
*       so need to be converted into a "real" number.
*       Also, the unit of measure may be 'KP' indicating that the qty
*       is given in thousands.
FORM quantity_conversion USING    value(i_UOM)
                                  value(i_invoice_qty)
                                  value(i_unit_price)
                    CHANGING o_uom like iE021-qty_UOM
                             o_invoice_qty like IE021-INVOICE_QTY
                             c_LINE_AMOUNT like izss7b21-line_amount.
data:  f_invoice_qty type f.
data:  n_invoice_qty like lips-kcmeng.
data:  f_unit_price type f.
data:  f_line_amt type f.
data:  n_line_amt0 type p decimals 0.
  if ( i_invoice_qty co ' 0123456789' and
       i_invoice_qty cn ' 0' ).
    f_invoice_qty = i_invoice_qty.
* if no extended price is sent, calculate it
    if c_line_amount is initial.
* the qty is implied 3-dec, the price is still implied
* 5-dec, and line amount should be implied 3-dec.
      f_unit_price = i_unit_price.
      f_line_amt = ( f_invoice_qty * f_unit_price ) / 100000.
      n_line_amt0 = f_line_amt.
      c_line_amount = n_line_amt0.
      shift c_line_amount left deleting leading space.
    endif.
* if the invoice qty is per 1000, the implied 3-dec times 1000 equals
* the unconverted value. Otherwise, divide by 1000 to get the PCE qty
    if i_uom = 'KP'.
      n_invoice_qty = f_invoice_qty.
    else.
      n_invoice_qty = f_invoice_qty / thou.
    endif.
  endif.
  o_uom = 'PCE'.
  if not n_invoice_qty is initial.
    o_invoice_qty = n_invoice_qty.
    shift o_invoice_qty left deleting leading space.
  else.
    clear o_invoice_qty.
  endif.
ENDFORM.                    " quantity_conversion
*&      Form  money_conversion
*       Add the implied decimals and store price-per qty, if
*       price per 1,000 is sent.
FORM money_conversion USING    value(I_CURR)
                               value(i_UNIT_PRICE)
                               value(i_UOM)
                               value(i_LINE_AMOUNT)
                      CHANGING o_CURRENCY like ie021-currency
                               o_PRICE_UOM like ie021-price_uom
                               o_PRICE_QTY like ie021-price_qty
                               o_UNIT_PRICE like ie021-unit_price
                               o_LINE_AMOUNT like ie021-line_amount.
data:  n_unit_price type p decimals 5,
       n_line_amount type p decimals 3.
* not all of the vendors send the currency code, so use the vendor
* master default
  case i_curr(2).
    when 'US'.
      o_currency = 'USD'.
    when 'JP'.
      o_currency = 'JPY'.
    when others.
      o_currency = uty_vendors-waers.
  endcase.
* unit price is implied 5-dec
  if ( i_unit_price cn ' 0' and
       i_unit_price co ' 0123456789' ).
    n_unit_price = i_unit_price.
    n_unit_price = n_unit_price / hun_thou.
  endif.
* line price is implied 3-dec
  if ( i_line_amount co ' 0123456789' and
       i_line_amount cn ' 0' ).
    n_line_amount = i_line_amount.
    n_line_amount = n_line_amount / thou.
  endif.
* 'KP' = price per thousand
  if i_uom = 'KP'.
    o_price_qty = '1000'.
  else.
    o_price_qty = '1'.
  endif.
  o_price_uom = 'PCE'.
  if not n_unit_price is initial.
    o_unit_price = n_unit_price.
    shift o_unit_price left deleting leading space.
  else.
    clear o_unit_price.
  endif.
  if not n_line_amount is initial.
    o_line_amount = n_line_amount.
    shift o_line_amount left deleting leading space.
  else.
    clear o_line_amount.
  endif.
ENDFORM.                    " money_conversion
*&      Form  SAP_vendor_partno
*       replace UTY part number sent by vendor with SAP material no.
*       from PO line item.
FORM SAP_vendor_partno changing cust_partno like ie021-cust_partno.
tables: makt.
data: partno_sent like makt-maktx.
  partno_sent = cust_partno.
  clear: makt, cust_partno.
  select single matnr from ekpo into cust_partno
         where ebeln = ie021-po_number and
               ebelp = ie021-po_lineno.
  if sy-subrc is initial.
*compare material description to part number sent by vendor
    select single maktx from makt into makt-maktx
        where matnr = cust_partno.
    if partno_sent <> makt-maktx.
* 'Part No. Mismatch: PO & - &, Part sent &, SAP mat.no. &'
      message i031 with ie021-po_number ie021-po_lineno
                        partno_sent makt-maktx.
    endif.
  else.  "PO line not found
*try to find SAP material number using 20-char catalog no. sent
    select single matnr from makt into cust_partno
        where maktx = partno_sent.
    if not sy-subrc is initial.
* 'SAP material no. not found for & - PO & - &'
      message i032 with partno_sent ie021-po_number ie021-po_lineno.
    endif.
  endif.
*if not found, IDoc will go to workflow for missing material no.
ENDFORM.                    " SAP_vendor_partno
*&      Form  idoc_header_segs
*       create internal table entries for header segments.
*  DESADV:
*          E1EDK07
*          E1EDKA1
*          E1EDK03
*          E1EDK08
*          E1EDKA2
*          E1EDK06
*  INVOIC:
*          E1EDK01
*          E1EDKA1(s)
*          E1EDK02
*          E1EDK03(s)
FORM idoc_header_segs using value(desadv_ok).
* INVOIC
  clear i_seg_num.
  invoicdata-segnam = 'E1EDK01'.
  e1edk01-action = ie021-stat.
  if ie021-currency(2) = 'US'.
    e1edk01-curcy = 'USD'.
  else.
    e1edk01-curcy = 'JPY'.
  endif.
  invoicdata-sdata = e1edk01.
  append_idoc_rec invoicdata i.
  clear e1edka1.
  invoicdata-segnam = 'E1EDKA1'.
  e1edka1-parvw = 'RE'.
  e1edka1-partn = ie021-shipto_id.
  invoicdata-sdata = e1edka1.
  append_idoc_rec invoicdata i.
  clear e1edka1.
  invoicdata-segnam = 'E1EDKA1'.
  e1edka1-parvw = 'LF'.
  e1edka1-partn = ie021-lifnr.
  e1edka1-lifnr = ie021-shipto_id.
  invoicdata-sdata = e1edka1.
  append_idoc_rec invoicdata i.
  if not ie021-endcust_name is initial.
    clear e1edka1.
    invoicdata-segnam = 'E1EDKA1'.
    e1edka1-parvw = 'WE'.
    e1edka1-name1 = ie021-endcust_name.
    invoicdata-sdata = e1edka1.
    append_idoc_rec invoicdata i.
  endif.
  clear e1edk02.
  invoicdata-segnam = 'E1EDK02'.
  e1edk02-qualf = '009'.
  e1edk02-belnr = ie021-invoice_no.
  invoicdata-sdata = e1edk02.
  append_idoc_rec invoicdata i.
  clear e1edk03.
  invoicdata-segnam = 'E1EDK03'.
  e1edk03-iddat = '012'.
  e1edk03-datum = ie021-create_date.
  invoicdata-sdata = e1edk03.
  append_idoc_rec invoicdata i.
  invoicdata-segnam = 'E1EDK03'.
  e1edk03-iddat = '024'.
  invoicdata-sdata = e1edk03.
  append_idoc_rec invoicdata i.
  check desadv_ok = '000'.
* DESADV
  clear d_seg_num.
  desadvdata-segnam = 'E1EDK07'.
  e1edk07-action = ie021-stat.
  e1edk07-bolnr = ie021-invoice_no.
  desadvdata-sdata = e1edk07.
  append_idoc_rec desadvdata d.
  clear e1edka1.
  desadvdata-segnam = 'E1EDKA1'.
  desadvdata-sdata = e1edka1.
  append_idoc_rec desadvdata d.
  clear e1edk03.
  desadvdata-segnam = 'E1EDK03'.
  desadvdata-sdata = e1edk03.
  append_idoc_rec desadvdata d.
  clear e1edk08.
  desadvdata-segnam = 'E1EDK08'.
  e1edk08-vbeln = ie021-invoice_no.
  e1edk08-traid = ie021-ship_id.
  e1edk08-traty = ie021-ship_method.
  desadvdata-sdata = e1edk08.
  append_idoc_rec desadvdata d.
  clear e1edka2.
  desadvdata-segnam = 'E1EDKA2'.
  desadvdata-sdata = e1edka2.
  append_idoc_rec desadvdata d.
  clear e1edk06.
  desadvdata-segnam = 'E1EDK06'.
  e1edk06-iddat = '025'.  "document date
  e1edk06-datum = ie021-create_date.
  desadvdata-sdata = e1edk06.
  append_idoc_rec desadvdata d.
  if not ie021-eta is initial.
    clear e1edk06.
    desadvdata-segnam = 'E1EDK06'.
    e1edk06-iddat = '001'.  "delivery date
    e1edk06-datum = ie021-eta.
    desadvdata-sdata = e1edk06.
    append_idoc_rec desadvdata d.
  endif.
  if not ie021-etd is initial.
    clear e1edk06.
    desadvdata-segnam = 'E1EDK06'.
    e1edk06-iddat = '010'.  "ship date
    e1edk06-datum = ie021-etd.
    desadvdata-sdata = e1edk06.
    append_idoc_rec desadvdata d.
  endif.
ENDFORM.                    " idoc_header_segs
*&      Form  idoc_poheader_segs
*       create internal table entries for DESADV PO/item segments
*          E1EDP07
FORM idoc_poheader_segs.
*DESADV
  clear e1edp07.
  desadvdata-segnam = 'E1EDP07'.
  e1edp07-bstnk = ie021-po_number.
  e1edp07-posex = ie021-po_lineno.
  desadvdata-sdata = e1edp07.
  append_idoc_rec desadvdata d.
  p07_ctr = p07_ctr + 1.
ENDFORM.                    " idoc_poheader_segs
*&      Form  idoc_item_segs
*       create internal table entries for PO item segments:
*          DESADV:   E1EDP09
*          INVOIC:   E1EDP01        Qtys
*                    E1EDP02        ref nos. (PO number / line)
*                    E1EDP19        part numbers
*                    E1EDP26        amounts
*                    E1EDP04        taxes
FORM idoc_item_segs using value(desadv_ok).
data:  n_line_amt  type p decimals 3.
*INVOIC
  clear e1edp01.
  invoicdata-segnam = 'E1EDP01'.
  e1edp01-menee = ie021-qty_uom.
  e1edp01-menge = ie021-invoice_qty.
  e1edp01-vprei = ie021-unit_price.
  e1edp01-pmene = ie021-price_uom.
  e1edp01-peinh = ie021-price_qty.
  e1edp01-netwr = ie021-line_amount.
  invoicdata-sdata = e1edp01.
  append_idoc_rec invoicdata i.
  clear e1edp02.
  invoicdata-segnam = 'E1EDP02'.
  e1edp02-qualf = '001'.
  e1edp02-belnr = ie021-po_number.
  e1edp02-zeile = ie021-po_lineno.
  invoicdata-sdata = e1edp02.
  append_idoc_rec invoicdata i.
  clear e1edp19.
  invoicdata-segnam = 'E1EDP19'.
  e1edp19-qualf = '001'.
  e1edp19-idtnr = ie021-cust_partno.
  invoicdata-sdata = e1edp19.
  append_idoc_rec invoicdata i.
  clear e1edp19.
  invoicdata-segnam = 'E1EDP19'.
  e1edp19-qualf = '002'.
  e1edp19-idtnr = ie021-vendor_partno.
  invoicdata-sdata = e1edp19.
  append_idoc_rec invoicdata i.
  clear e1edp26.
  invoicdata-segnam = 'E1EDP26'.
  e1edp26-qualf = '003'.
  e1edp26-betrg = ie021-line_amount.
  invoicdata-sdata = e1edp26.
  append_idoc_rec invoicdata i.
* dummy tax seg
  clear e1edp04.
  invoicdata-segnam = 'E1EDP04'.
  e1edp04-msatz = '0.00'.
  invoicdata-sdata = e1edp04.
  append_idoc_rec invoicdata i.
  n_line_amt = ie021-line_amount.
  invoice_total = invoice_total + n_line_amt.
  check desadv_ok = '000'.
*DESADV
  clear e1edp09.
  desadvdata-segnam = 'E1EDP09'.
  e1edp09-vbeln = ie021-slip_number.
  e1edp09-matnr = ie021-vendor_partno.
  e1edp09-vrkme = ie021-qty_uom.
  e1edp09-lfimg = ie021-invoice_qty.
  desadvdata-sdata = e1edp09.
  append_idoc_rec desadvdata d.
ENDFORM.                    " idoc_item_segs
*&    Form  post_idocs
*     create database IDocs from the idocdata tables and clear tables.
FORM post_idocs using value(desadv_ok).
*INVOIC
  clear e1eds01.
  invoicdata-segnam = 'E1EDS01'.
  e1eds01-sumid = '010'.
  e1eds01-summe = invoice_total.
  e1eds01-waerq = ie021-currency.
  shift e1eds01-summe left deleting leading space.
  invoicdata-sdata = e1eds01.
  append_idoc_rec invoicdata i.
  CALL FUNCTION 'INBOUND_IDOC_PROCESS'
    TABLES
      IDOC_CONTROL       =  iedidc
      IDOC_DATA          =  invoicdata.
  commit work.
*DESADV
  if desadv_ok = '000'.
    clear e1eds02.
    desadvdata-segnam = 'E1EDS02'.
    e1eds02-sumid = '001'.
    e1eds02-summe = p07_ctr.
    shift e1eds02-summe left deleting leading space.
    desadvdata-sdata = e1eds02.
    append_idoc_rec desadvdata d.
    CALL FUNCTION 'INBOUND_IDOC_PROCESS'
      TABLES
        IDOC_CONTROL       =  dedidc
        IDOC_DATA          =  desadvdata.
    commit work.
  endif.
  refresh: desadvdata,
           invoicdata.
  clear:
    desadvdata,
    invoicdata,
    p07_ctr,
    invoice_total,
    save_stat,
    save_po,
    save_line,
    save_invoice.
ENDFORM.                    " post_idocs
*&      Form  init_desadv
*       add a DESDAV control record and initialize fields
FORM init_desadv.
clear dedidc. refresh dedidc.
* initialize control record:
move:  '2'        to  dedidc-direct,
      'DESADV01'  to  dedidc-doctyp,
      'DESADV'    to  dedidc-mestyp,
      'F'         to  dedidc-std,
      'E021'      to  dedidc-stdmes,
      'LS'        to  dedidc-sndprt,
      'TY_VENDORS' to dedidc-sndprn,
      sy-datlo    to  dedidc-credat,
      sy-timlo    to  dedidc-cretim.
append dedidc.
ENDFORM.              " init_desadv
*&      Form  init_invoic
*       add a INVOIC control record and initialize fields
FORM init_invoic.
clear iedidc. refresh iedidc.
* initialize control record:
move:  '2'        to  iedidc-direct,
      'INVOIC01'  to  iedidc-doctyp,
      'INVOIC'    to  iedidc-mestyp,
      'MM'        to  iedidc-mescod,
      'F'         to  iedidc-std,
      'E021'      to  iedidc-stdmes,
      'LS'        to  iedidc-sndprt,
      'TY_VENDORS' to iedidc-sndprn,
      sy-datlo    to  iedidc-credat,
      sy-timlo    to  iedidc-cretim.
append iedidc.
ENDFORM.              " init_invoic
REWARD POINTS IF HELPFUL
Lakshmiraj.A

Similar Messages

  • Adding new segment to IDoc type DELVRY03

    Hello everybody!
    I just got a request to add two new segments to an Idoc (type DELVRY03) under the segment E1EDL24. (E1EDL43 and E1EDL41).
    They told me to use the userexit EXIT_SAPLV55K_004 to add the new segments using the table IDOC_CONTROL since it is standard. But the problem is that the changes are not been saved.
    I realised that by the time that this exit is called the standard already stored the information on EDID4.
    I appreciate any help!
    Thanks in advance!

    Hi Kumar,
    If we change EDBAS table data and modify my idoc type by adding segment.
    after completing process have to move my object to production.
    Hope it ll through an error...   because it will check with table data also for validation.
    could you please justify your answer kumar?
    Thanks for your helpful information.
    Regards,
    BALAJI.

  • How to generate a new segment in IDoc for multiple occurance of Control Num

    Hi Experts,
    In my scenario, i need to generate a new segment in IDoc(Target Structure) based on  Control Number Field in the Source Structure.
    The segment need to be created for multiple occurance of the Control Number.
    Ex:
    Control Number - 100 appears 5 times in Source Structure.This control Number is mapped to one of the Field in the Segment of  IDoc.
    Now my requirement is to generate the Segment 5 times with respective to this Control Number.
    please help me out to resolve this issue.
    Thanks,
    Kish.

    Hi,
    Here is the XML Structure of my Source:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:GoodsReceipt_MT xmlns:ns0="urn:WOL-com:XI:data:HJ:10">
       <row>
          <CONTROL_NUMBER>111</CONTROL_NUMBER>
          <LINE_NUMBER>1111</LINE_NUMBER>
          <CONTROL_NUMBER_2/>
          <OUTSIDE_ID/>
          <WH_ID>111111</WH_ID>
          <LOCATION_ID/>
          <HU_ID>11111</HU_ID>
          <NUM_ITEMS/>
          <ITEM_NUMBER>111111</ITEM_NUMBER>
          <CONTROL_NUMBER_3>LR</CONTROL_NUMBER_3>
          <LOT_NUMBER>11111</LOT_NUMBER>
          <UOM>11111</UOM>
       </row>
       <row>
          <CONTROL_NUMBER>111</CONTROL_NUMBER>
          <LINE_NUMBER>12222</LINE_NUMBER>
          <CONTROL_NUMBER_2/>
          <OUTSIDE_ID/>
          <WH_ID>12222</WH_ID>
          <LOCATION_ID/>
          <HU_ID>1222</HU_ID>
          <NUM_ITEMS/>
          <ITEM_NUMBER>112222</ITEM_NUMBER>
          <TRAN_QTY>112222</TRAN_QTY>
          <CONTROL_NUMBER_3>LR</CONTROL_NUMBER_3>
          <LOT_NUMBER>12222</LOT_NUMBER>
          <UOM>1122222</UOM>
       </row>
       <row>
          <CONTROL_NUMBER>222</CONTROL_NUMBER>
          <LINE_NUMBER>2222</LINE_NUMBER>
          <CONTROL_NUMBER_2/>
          <OUTSIDE_ID/>
          <WH_ID>22222</WH_ID>
          <LOCATION_ID/>
          <HU_ID>222222</HU_ID>
          <NUM_ITEMS/>
          <ITEM_NUMBER>2222222</ITEM_NUMBER>
          <TRAN_QTY>22222222</TRAN_QTY>
          <LOCATION_ID_2>33333333</LOCATION_ID_2>
          <CONTROL_NUMBER_3>LR</CONTROL_NUMBER_3>
          <LOT_NUMBER>22222</LOT_NUMBER>
          <UOM>22222</UOM>
       </row>
       <row>
          <CONTROL_NUMBER>333</CONTROL_NUMBER>
          <LINE_NUMBER>3333</LINE_NUMBER>
          <CONTROL_NUMBER_2/>
          <OUTSIDE_ID/>
          <WH_ID>33333</WH_ID>
          <LOCATION_ID/>
          <HU_ID>33333</HU_ID>
          <NUM_ITEMS/>
          <ITEM_NUMBER>333333</ITEM_NUMBER>
          <TRAN_QTY>33333333</TRAN_QTY>
          <CONTROL_NUMBER_3>LR</CONTROL_NUMBER_3>
          <LOT_NUMBER>33333</LOT_NUMBER>
          <UOM>333333</UOM>
       </row>
    </ns0:GoodsReceipt_MT>
    Now Control_Number 111 occurs 2 times, 222 & 333 occurs 1 time.
    Now one IDoc for 111,222 & 333 should be generated.
    But Control_number 111 appears 2 times.
    Now the data in the 2 rows should be passed to Single IDoc by repeating the segments inside the IDoc.
    As u said i changed the Occurance of IDoc to 0...unbound and imported as External Definition. I have done upto Generating IDoc for each unique Control_Number.
    I stuck up at repeating the Segments in the IDoc.
    So please help me out.
    Thanks,
    Kish.

  • Regarding new segment in Idoc

    Hi,
        I have created a new segment ZDH_HAZMAT  for hazardous materials for the idoc type ZDH_ORDERS and released it for purchase order. Actually modifying the segment data for already existing Idoc segments (E1EDP01) is possible and i have done it using user exit MM06E001. When a new segment (ZDH_HAZMAT) is added, it's showing a syntax  error . Waiting for earliest reply.
                                                            Thank you.

    Hello,
    You must keep a an IF condition like this in selection program's user exit.
         if Segmetn-Name eq <New segmetn>
             break <user name>
        end.
    It must stop other wise the enhancing the standard Idoc type is wrong. And so you need to check whether it is activate / released the new segment properly.
    All the very best for you.
      - Mohan Vamsi

  • Cut an object with the knife without adding new segment?

    If I use the knife to cut across a closed object, it creates two closed objects. What I would LIKE is to cut the object and have two open objects touching at the points of the cut. E.g., if I cut a square in half, I want two brackets touching at their ends. Obviously, I can go in and delete the added extraneous segments, but it adds extra steps. Thus far, I have not found any way to turn that off, or to toggle it, or anything. I DID do a search in the Adobe support help files and couldn't find anything -- which probably means that every article that mentions the knife has that exact info in billposter type right at the top of the article ; it's the way these things usually run with me...! <ruefulGrin>
    Am I missing something simple?
    (For the sake of completeness, I'm using Illustrator CC 2014.0.0 on OS X Mavericks.)

    Thanks, Jacob. That certainly will work; unfortunately, it's just not as quick and precise as Option-dragging the knife to get a straight cut across an object or, more importantly, across multiple objects.
    Ah, well -- when they finally replaced my old G5 at work last year, I knew it was going to mean giving up Freehand and learning the Adobe way of doing things. After predominantly doing illustrations in Freehand since the Aldus days, though -- somewhere around 25 years ago, now -- it's difficult having to learn a whole new set of reflexes!

  • Authentication failure when adding new 'Segment in Use'

    Hi all!
    I've set up integration between Siebel 8.1.1.9 and OBIEE 11.1.1.5.0. I've applied My Oracle Support article ID 1400715.1, importing the modified SIF and Workflow definitions and re-deployed the SRF to the server.
    When attempting to drill into a folder in the 'Pick Segment' applet, I get the following error:
    Operation 'impersonate' of Web Service 'com.siebel.analytics.web/soap/v1.SAWSessionService' at port 'SAWSessionServiceSoap' failed with the following explanation:
    "Authentication error. An invalid User Name or Password was entered.".(SBL-EAI-04308)
    I cannot for the life of me work out why this is happening. I've followed 1400715.1:
    1. Created a new OBIEE user called 'impersonateuser' and added the 'oracle.bi.server.impersonateUser' permission
    2. In Siebel, Marketing - Administration > Servers, I've set the User Id and Password fields for the 'Default Analytics Web Server' entry, ensuring that the password contains more than 8 characters and contains a number, with the 'impersonateuser' details. The 'impersonateuser' user can successfully log in to OBIEE / Dashboard
    I've checked the Web Service definitions and replaced host name with host:port. The Web Service is definitely getting invoked but there seems to be a problem with the impersonation.
    Any thoughts on how to resolve this?
    Many thanks!
    mroshaw

    DOH - failed to RTFM correctly!
    I'd not followed the instructions for adding the permission correctly - you have to read very cafrefully how to get to the right page to add the permission.
    Working now! :)
    Regards,
    Oli

  • How to add new segment to IDOC in BADI CRMXIF_ORDER_R3_MAP

    Hi All,
    I am creating a DMR in ECC when a service order is created in CRM.
    I am using Basic Type ORDERS05. This Basic Type does not have the segment E1CUCFG populated when it comes to the BADI.
    I want to populate this segment and attach to my IDOC.
    How can i do this?
    Is there any FM which will create the segments?
    Kindly help.
    Thanks in advance.
    Edited by: shanthi v on Mar 29, 2011 3:42 AM

    I have dropped the IDOC solution. I created a enhancement in FM - CRM_SERVICE_BILLING_FILTER which helped me to create DMR as per my need.

  • Adding field in standard IDOC Segment E1EDL24

    Hello Friends,
    I have an urgent requirement that I have to extend IDOC segment E1EDL24 with two fields PABNR and LFSNR.
    When I tries to change the segment in WE31, it shows an error message that you can only modify the segments of customer namespace and cannot modify Standard IDOC Segments.
    Can we modify the standard IDOC segments, and if yes, how can we modify the standard IDOC segments. Please clarify.
    Points will be rewarded generously.
    Regards,
    Navin

    Hi Naveen,
    We cannot Modify the Standard segments. But we have to Create a new Segment and Add these fields.
    Then Create an Extended Idoc type
    Implement User Exits in Outbound And Inbound ..
    This is the Complete Steps and Info on this...with an Example...
    Enhancing ALE
    For example, if in an outbound interface you find that the IDOC type does not contain all the data you need to pass to the other system, you can extend the IDOC to accommodate the additional fields and enhance the ALE function modules to populate the fields. Similarly, if in an inbound interface, there is additional data that needs to be posted to the R/3 application, you can extend the IDOC type to have additional fields populated by the external system or translator or the other R/3 system and then enhance the inbound ALE function modules to post the additional data to the R/3 application.
    let us use the SAP Customer Master application as an example. Specifically, letâs focus on the IDOC extension and ALE function module enhancement of IDOC type DEBMAS02 and message type DEBMAS (Customer Master) and the IDOC reduction of message type MATMAS.
    IDOC EXTENSIONS
    Letâs first look at the concept of IDOC extension. SAP delivers Basic IDOC types such as DEBMAS02, MATMAS02, ORDERS02, and WMMBID01. By extending the Basic IDOC type, you are actually creating a new IDOC type. You create a new segment with the additional fields. This new segment has to be associated with one of the existing Basic IDOC segments. Then you create a new extension type, which is associated with the Basic IDOC type. This results in a new IDOC type. In order for ALE function modules to relate to this new IDOC type, the IDOC type is linked to the corresponding message type.
    Note that you should not add fields to existing segments but should create a new segment and associate it with an existing segment. This, in a nutshell, is the process of creating IDOC extensions.
    In our example, the Basic IDOC type DEBMAS02 is used to communicate Customer Master data to the SAP Customer Master application. Even though the application has a screen to enter and store a contact personâs business address (see Figure 1), DEBMAS02 does not have a segment or fields that communicate the contact personâs business address. If your business requires that this business address be communicated to the other system through the ALE interface for Customer Master, then you have to extend the DEBMAS02 IDOC type, and enhance the corresponding ALE function module.
    In DEBMAS02 the contact person fields are present in segment E1KNVKM and the business address of the contact person is stored on the SADR SAP table. You need to create a new segment, Z1SADRX, that is associated with E1KNVKM. This will be done in the process of creating an extension type ZDEBMASX. This extension type will then be associated with a new IDOC type, ZDEBMASZ. IDOC type ZDEBMASZ will be linked to message type DEBMAS for Customer Master. The final step in the IDOC extension process is to check the new objects. This check also verifies the structural integrity of the IDOC type. Letâs look at each of these steps in more detail.
    1. Create an Extension Type and a New Segment.
    Determine the fields on table SADR that you are going to provide for in the new segment Z1SADRX. You need fields for name, street, city, region, and country to give the business address of the contact person. You also need fields for the address number. ADRNR is a field in SAP tables such as SADR that uniquely identifies the address of an entity. This field is cross-referenced from other tables to the SADR table to obtain the full description of the address. Because this is an IDOC type for master data, the first field of the new segment will be MSGFN. The message function field informs the receiving system of the action to be taken for that particular segment. In the code that you write for populating the new segment, the value of the message function is the same as that of the parent segment E1KNVKM. In all, you will have 12 fields in segment Z1SADRX (see Table 1).
    To create an extension type and new segment:
    • Use transaction WE30 or from WEDI go to Development -> IDOC types.
    • Enter ZDEBMASX for Object Name.
    • Choose Extension Type.
    • Click on Create.
    • You will see a pop-up screen. Choose Create New, and enter a description. For version 4.x, enter DEBMAS02 in the Linked Basic Type field. Enter.
    • You will see a screen with ZDEBMASX and its description in the first line. Click on this line, and press Create. For version 4.x, expand the tree of segments, and place the cursor on E1KNVKM.
    • You will see a pop-up screen. Enter E1KNVKM as the reference segment. Enter.
    • For 4.x, press Create after placing the cursor on segment E1KNVKM.
    • You will see a line appear with E1KNVKM hierarchically below ZDEBMASX, with a description "Customer Master contact person (KNVK)."
    • Click on this line and press Create. You will receive a message indicating that the new segment being created will be a child segment of E1KNVKM. Enter. A pop-up box appears for the new segment.
    • Enter Z1SADRX as the segment type, 1 for Minimum, 1 for Maximum. Leave Mandatory segment unchecked. These entries imply that there is only one Z1SADRX segment for every occurrence of the E1KNVKM segment, and also that this segment is not mandatory. Note that if the parent segment is not mandatory, then the child segment should not be mandatory, because this could result in a syntax error during the creation or processing of the IDOC.
    • For 4.x, you must first create the IDOC segment Z1SADRX (Iâll explain why in a moment) from the menu path WEDI -> IDOC -> Development -> IDOC Segment.
    • Click on Segment Editor.
    • On the next screen, click on Create.
    • Enter a development class for the object. Enter.
    • This will take you to the screen for segment definition. Enter a description for the segment. Enter the field name, data element, and the data element documentation name. In most cases, all three fields may have the same values. If you are using a field in the segment that is not present in the ABAP/4 data dictionary, you must first create the domain, data element, field, and appropriate documentation before using it in the new segment.
    • Enter these three columns for all 12 fields. Save.
    • Click on Generate/Activate, F3 to step back.
    • From screen Maintain Segment, go to Segment Type -> Release. A checkbox now appears beside the segment definition Z1SADRX (see Figure 2). Check this box. Save.
    • Save again to store the descriptions of the segment, F3 to step back.
    • Save the extension type.
    It is possible to have several new segments with relevant Basic IDOC type parent segments in a single extension type. However, you can form only one IDOC type based on a single extension type.
    2. Create an IDOC Type.
    The next step is to create an IDOC type by associating the extension type that you created with the Basic IDOC type. This is a simple process:
    • From transaction WE30 or WEDI go to Development -> IDOC Types.
    • Enter ZDEBMASZ for Object Name.
    • Click on IDOC Type.
    • Click on Create.
    • Enter DEBMAS02 for Basic IDOC type.
    • Enter ZDEBMASX for extension type.
    • Enter a description.
    • Enter.
    • You will see a display of the composite IDOC type with all segments, including Z1SADRX (see Figure 3).
    It is possible to associate only one extension type with a Basic IDOC type for a given IDOC type. However, you can have multiple new segments in an extension type.
    3. Link IDOC Type to Message Type.
    The next step is to link the new IDOC type to its corresponding message type. This is important, because this relationship is referenced in the partner profile parameters where you specify the message type and IDOC type to be used for that particular representative system. To link the message type:
    • Use transaction WE82, or from WE30, go to Environment -> IDOC Type / Message Type, or from WEDI go to Development -> IDOC Type -> Environment Î IDOC Type / Message Type.
    • Click on Display <-> Change.
    • Click on New Entries.
    • Enter DEBMAS for message type.
    • Enter DEBMAS02 for Basic IDOC type.
    • Enter ZDEBMASX for extension type.
    • Enter your SAP R/3 release number for Release.
    • Save.
    This data is stored on the EDIMSG table and is accessed by several ALE processes to relate the message type to the IDOC type.
    4. Check the IDOC Type.
    Before checking the IDOC type for consistency, it is important to perform another step that releases the extension type to the IDOC type:
    • From WEDI go to Development -> IDOC Types -> Extras -> Release Type, or from transaction WE30 go to Extras -> Release Type.
    • For the Object Name ZDEBMASX and radio button Extension Type, click Yes.
    • The extension type has now been "released."
    You canât edit the extension type once itâs released. To cancel the release for further editing or deactivation, go to WE30 Î Extras Î Cancel release. The final step in the IDOC extension process is checking the validity of the IDOC type:
    • From transaction WE30 or WEDI go to Development -> IDOC types.
    • Enter ZDEBMASX for Object name.
    • Click on Extension Type.
    • From the Development Object menu select Check.
    • Repeat the operation for IDOC type ZDEBMASZ.
    • A check log will be generated for each run with details of correctness or errors (see Figure 4).
    In some situations it is possible to receive errors during the check process, especially segment length errors. The incorrect IDOC segment can be repaired and corrected by executing program RSEREPSG. This program checks the formal consistency and repairs incorrect segments. In test mode it will generate a log of formal correctness for the specified segment only. For the program to repair segments in normal mode, the underlying IDOC structures (DDIC structures) must be active. This program rectifies the lengths of the DDIC structures and not the fields themselves. RSEREPSG can also be used to change the person responsible for the object and the release flag.
    Menu paths may vary slightly depending on the release/version of SAP R/3, but the procedures and the principles are the same.
    ALE FUNCTION MODULE ENHANCEMENTS
    Having extended the IDOC type to contain additional fields for an inbound or outbound application, you now want to enhance ALE function modules for populating the additional segment on the outbound or applying the additional segment data on the inbound application.
    The core working code for ALE processes for a given application area is always encapsulated in ABAP/4 function modules. These function modules are associated with such control information as message types and process codes. So the ALE process checks this control information and derives the name of the function module to invoke for that particular IDOC processing from certain database tables. These function modules contain objects known as customer functions, which can be considered SAP Enhanced user exits. A function module is called at a particular point during the processing of the main program or function module, and it can be used to influence data processing at that point by adding code to the customer function. The customer function behaves like a normal function module and has import and export parameters, tables (internal tables) statement, and exception processing. Unlike a conventional user exit, customer functions give you the ability to modify only data available to you by the function moduleâs parameters and internal tables. While most ALE/EDI function modules are supported by customer functions, there are ALE/EDI processes that still use conventional user exits. There are a few ways to determine which function module to enhance for a given message type/process code:
    • For master data distribution, from SALE go to Extensions -> Master data distribution -> Setup additional data for message types. Search for message type DEBMAS in this example. You see an entry for DEBMAS associated with function module MASTERIDOC_CREATE_SMD_DEBMAS. This data is stored on table TBDME. The function module names for all master data message types follow this pattern: MASTERIDOC_CREATE_SMD_messagetype. This function module calls another function module of name MASTERIDOC_CREATE_DEBMAS or MASTERIDOC_CREATE_messagetype. Search for the words customer function, and you find several hits that can be used to add code to the function module.
    • From WEDI got to Control -> Inbound process codes -> Inbound with ALE service -> Processing by function module (transaction WE42), or from WEDI go to Control -> Outbound process codes -> Outbound with ALE service -> With function module (transaction WE41). There will be function modules associated with the process codes. For inbound, the function modules usually follow this pattern: IDOC_INPUT_messagetype: for example, IDOC_INPUT_CHRMAS for inbound characteristics master.
    • Use transaction WE57 or from WEDI go to Development -> Message/Application Object. The entries list the function module, Business Object, message type, and IDOC type that are used for inbound ALE/EDI interfaces.
    Customer functions are not specific only to ALE and EDI but also to all programs/modules in SAP R/3. Customer function is a SAP enhancement component; the other two types are menu and screen enhancements.
    All customer function exits are maintained in SAP enhancements and are found by using transaction SMOD. After executing transaction SMOD, pull down (F4) on the enhancement name field, and execute again. This provides you with a list of all SAP enhancements available. SAP enhancements are grouped by development class pertaining to an application area. Choose Application development R/3 SD master data distribution for development class VSV to lead to a screen that lists VSV00001 as an enhancement (see Figure 5). Press Component +/- to display its function exit components. There are four possible components listed, all of which are function exits (and are function modules) that are called from the ALE function modules in the form Call Customer Function Î001â. This is a special occurrence of the ABAP statement Call. Go to item Exit_SAPLVV01_ 001, which you need to enhance for the Customer Master outbound example of an IDOC extension. In the ALE-function module MASTERIDOC_CREATE_DEBMAS, the statement CALL Customer Function 001 is translated in the background to call component EXIT_SAPLVV01_001. Although this function exit can be edited using transaction SE37, you will use a simpler approach.
    When you use SAP enhancements and their components, you manage them with an SAP object known as a project, which is like an envelope containing the selected enhancements and their components. A project can be used to control the execution of components and to transport them to other clients and instances in SAP. Basically, the process involves creating a project, including enhancements and components that are to be enhanced, editing the components, and then activating the project. The following process creates a project for our example Customer Master IDOC extension:
    • Execute transaction CMOD.
    • Enter name of project, say CSTMAST1.
    • Click on Create.
    • Enter a description of the project.
    • Save.
    • Click on SAP Enhancements.
    • Enter VSV00001 for Enhancement.
    • Save.
    Once youâve created the project, edit the function exit components and activate the project. Remember that the code in the function exit enhancement will execute only if the project is activated. In fact, this is a convenient SAP enhancements feature, whereby the work in progress (developing code in the customer function) will not affect users of that application. When the code is completed, the project can be activated so the enhanced functionality takes effect. It can also be deactivated for maintenance.
    As mentioned earlier, customer functions (function exits) are embedded in ALE function modules and can be used to influence the creation and modification of IDOC data on an outbound application or to post additional or modified IDOC data to an inbound R/3 application. Function exits are similar to regular function modules, with import/export parameters, tables (internal tables), and exceptions.
    The two important factors to consider while developing the customer function are:
    1. The point in the ALE function module where the function exit occurs
    2. The data made available by the customer function that can be modified or posted to the R/3 application, based on the direction.
    Because some function modules have several customer functions, it is critical to choose the function exit best suited for that particular enhancement. Do not attempt to perform activities that the function exit is not designed for. The importance of this point is illustrated by the following description of enhancing function modules for outbound and inbound ALE interfaces.
    Outbound interfaces. In an outbound ALE interface you use function exits (customer functions) to populate additional segments created by an IDOC extension or to modify the existing IDOC data segments as per business requirements. Previously, you identified that enhancement VSV00001 has a component EXIT_SAPLVV01_001 (function exit), which can be used for populating the additional data segment Z1SADRX that you created in the IDOC extension ZDEBMASX (IDOC type ZDEBMASZ, based on Basic IDOC type DEBMAS02). You also learned that the ALE function module that calls this function exit is MASTERIDOC_CREATE_DEBMAS, which has a statement Call Customer Function 001.
    Browse the function module MASTERIDOC_CREATE_DEBMAS using transaction SE37. You will find that this customer function is invoked for every segment of IDOC type DEBMAS02. In fact, the function exit is called soon after the creation of an existing segment has been populated with data and appended to the IDOC data table (internal table). Also, the function exit is exporting the message type, IDOC type, and the segment name and is importing the IDOC extension type. It is also passing the IDOC data internal table. This indicates that the ALE function module is allowing you to populate additional segments for every existing segment and modify the existing segmentâs data.
    Letâs write ABAP/4 code to accomplish the task of populating IDOC segment Z1SADRX with a contact personâs business address:
    • From SE37, display function module MASTERIDOC_CREATE_ DEBMAS.
    • Find Customer Function 001.
    • Double-click on 001.
    • The function EXIT_SAPLVV01_001 will be displayed.
    • Double-click on INCLUDE ZXVSVU01.
    • You will be asked to create a new include object. Proceed as desired.
    • Enter code (as in Listing 1).
    • Be sure to perform a main program check (Function Module -> Check -> main program) and extended program check (Function module -> Check -> Extended check).
    Now that you have extended the IDOC and enhanced the ALE function module based on the requirements for the contact personâs business address on the Customer Master, letâs test the interface. You should create a logical system and define a port for this interface. You should also configure the Customer Distribution Model to indicate that message type DEBMAS is being distributed to this logical system. The only difference in configuration between a regular outbound ALE interface and an enhanced one is the partner profile definition. While maintaining the outbound parameters of the partner profile, make sure the IDOC type is ZDEBMASZ. The fields for Basic IDOC type and extension type are automatically populated with DEBMAS02 and ZDEBMASX, respectively.
    To maintain the contact personâs business address of a customer:
    • Use transaction BD12 or from BALE go to Master Data ->Customer -> Send and send that Customer Master record by executing the transaction after filling in the relevant fields such as customer number, message type, and logical system.
    • Use transaction WE02 or WE05 to verify the IDOC created. You should see the new segment Z1SADRX populated with the correct data.
    With SAP releases below 4.5B, you cannot capture changes to business address through change pointers because a change document object is not available for capturing business address changes, and also earlier releases have not been configured to write change documents for a contact personâs business address. If you would like this functionality, you can either create change document objects, generate function modules to create change documents, and perform ALE configuration to tie it in, or make a cosmetic change to the contact person screen data while changing the contact personâs business address so that it gets captured as a change to the Customer Master. Subsequently, the ALE enhancement that you performed captures the contact personâs business address.
    Inbound interfaces. The process for enhancing inbound ALE interfaces is similar for outbound, with a few exceptions; specifically in the coding of customer functions (function exits) for the ALE/EDI function modules.
    The first step is to create an IDOC extension for the specific Basic IDOC type by adding new segments at the appropriate hierarchy level: that is, associated to the relevant existing segment. Populate the data fields on the new segments with application data by the translator or external system/program before importing them into the R/3 System. Then, find the ALE function module that is invoked by the inbound processing. By browsing through the code or reading the documentation on the function exit enhancements using the SMOD transaction, identify the function exit in which you should place your code. The technique used in the code to post the additional or modified IDOC data to the application can vary based on the application rules and requirements, the data available at that point in processing, and the application function modules available to update the application tables. It is important to search first for application modules that process the data and see if they can be called within the function exit. If the additional data in the extended segments in specific to a custom table or resides in nonkey fields of a single or small set of tables, you may be able to update it directly by SQL statements in the function exit. This approach should be carefully evaluated and is certainly not highly recommended.
    Another option is to use Call Transaction from within the function exit to process the additional data. For example, in the case of message type WMMBXY for inbound goods movements from a warehouse management system, the standard interface creates batches for materials, but does not update its characteristics. In such a case, you can use Call Transaction MSC1 to create the batch and assign characteristic values to it from within the function exit provided.
    Error handling is a very important consideration when making enhancements to inbound ALE/EDI objects. In ALE and EDI inbound processing, workflow is used for handling errors at different levels such as technical and application. If workflow has been configured for the interface, the error messages and workflow items flow to the inbox of the named recipient(s).
    It is also critical to enhance the workflow that handles notifications of the inbound ALE/EDI process. In most scenarios this is not a very difficult task because SAP lets you influence the workflow parameters and messages in function exits (customer functions). You typically do this using flags and message codes to trigger certain workflow actions. If you conform to the status codes and flags stipulated for workflow processing, the enhancement could be error-free and seamless. In the case of an inbound IDOC with an extension, you should populate the EDIDC fields IDOCTYP (new IDOC type) and CIMTYP (extension type) accordingly.
    Reward if Helpful

  • Adding a segment to a Basic IDOC type

    Hi every one,
    How do i add a segment that I have created to an existing Basic Idoc type ?.
    Can some one give me a solution for this.
    Thanks,
    Arul.

    hi ,
    Idoc extension can be done with 4 steps
    1. creation of new extension type and a new segment
    2. creation of a idoc type
    3. link idoc type to message type
    4. check the idoc type.
    1. creation of new extension type and a new segment
    we30--idoc typesobject name-extension type-create-create new-create-place the cursor on the location
    2. step:
    we30----
    3. we82 or we 30
    4. WEDI
    If you find it useful plz mark the points
    Regards,
    Naveen

  • Error when Adding a segment to an IDOC

    Hi I have added one segment to an IDOC through one user exit and it is giving the error with status 26.
    Here I am pasting the error details,
    The segment E1IDT02 does not occur at the current level of the basic type PEXR2001 (extension ).
    This error can have several reasons:
    The segment E1IDT02 is assigned to a group whose header segment does not occur.
    The segment E1IDT02 does not exist in the syntax description of the basic type PEXR2001 (extension ).
    The sequence of segments in the group in which the segment appears is incorrect.
    Previous errors ('mandatory' segment or group missing) may be due to this error.
    Can any body help me, and let me know what can I do to avoid this.
    Thanks,
    Deepak.

    Actually in the basic type of IDOC, there is no segment with this name. But I am adding this directly in an user exit. Can you tell me what is the actual procedure to add a new segment to the basic type of IDOC
    Thanks
    ravi

  • How to include a new segment in FIDCCP02 idoc (OUTBOUND)

    Hi,
    I would like to know in which EXIT or BADI I should append my new segment to the idoc data.  I have created the new segment to add new Z fields that I added before on the BSEG, and I have created the enhancement of the idoc and put the new segment in the correct place.
    Best Regards

    Adrian,
    Isn't the BADI IDOC_DATA_INSERT the correct answer?
    Regards,
    Ashvin

  • To allow to edit existing iDoc segments or to add new segments.

    In order to re-process iDoc's there is necessary forst to manipulate the record. A custom transaction(WE19) is required to allow to edit existing iDoc segments or to add new segments without creatinga new idoc.
    any clue..
    Regrads,
    Ramya

    hi ramya,
        In the test tool WE19 v can able to see the
    copy and existing idoc.
    create an idoc based on an idoc type.
    create an idoc based on a message type.
    but mostly v use the first option. Like modify the existing idoc to suit our requirement
    Regards....
    Arun.
    Reward points if useful.

  • I facing one situtation in mapping  Custmosied IDOC  a new segment is add t

    HI Gurus
    I facing one situtation in mapping  Custmosied IDOC  a new segment is add to that IDOC.... i want to display values in queues in mapping test.. but queue is empty it showing ,,,
    already i have checked IDX2 .. in that it is updated about the segement .. let me know solutiuon y it is not populate in that segemnt ..\
    thanks in advance.

    Hi ,
    Have you imported the IDOC into ESR after the changes were done in the ECC side?
    Is the mapping done for the new segment/fields properly?
    Please check what values are passed in the segment from ECC?Try triggering a message from WE19 with test values and check if you are receiving the same?
    Please explain little more on this...
    Regards,
    Srinivas

  • Determining new segments for an idoc.

    hi guys,
    i have to map data on an idoc. the problem is that in the idoc there can be header and item segments. using an element referred as Id , i must be able to create a new segment for the idoc.
    can anyone please help me.
    thanks in advance

    Hi,
    You can use CreateIf Node function to create the segments based on the condition.
    <Condition>-CreateIf NodeFuction--<Node of the target segment>.
    The target segment will be created only if the condition is true.
    See the below link for more details.
    http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
    Regards,
    Shweta

  • Adding segment to Idoc

    Hello Guys,
    I have an inbound Idoc in my system with 'N' segments. If I need an 'N+1' segment in the idoc, is it possible to add the new segment using the BADI  HRALE00INBOUND_IDOC?
    regards,
    Gergo

    Hi,
    It depens of type of IDOC. Check Note 753153 - FAQ: Customer-functions in IDOC_INPUT_ORDERS for instance for IDOC ORDERSXX.
    Regards,
    Eduardo

Maybe you are looking for