Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Following list of scenarios are supported by this reusable component

  • If a subscription order already exist which expired , so this RFC provides an opportunity to create new subscription order with reference to existing one and update customer fields also .If a customer would like to create a new subscription with reference to an existing subscription which already exist for charities other welfare organizations but expired so in IS-Media there is no such utility / tool  exist which can allow customer / media company to renew the subscription
  • Another case is where a customer on the web portal would like to place a new subscription order or renew existing subscription then instead of re-entering all related details and then creating a new subscription, it is always an easier task for  him/her to subscribe to a media-publication for the duration requested for by copying an existing one and also update customer fields  .
FUNCTION ZTEST_CREATEREF .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_CAMPAIGN) TYPE  ISM_MARKETING_CAMPAIGN_GENERIC OPTIONAL
*"     VALUE(I_VBELN_VL) TYPE  AVNR_VL
*"     VALUE(I_POSNR_UR_VL) TYPE  APNR_VL
*"     VALUE(I_ORDER_ADDITION) TYPE  RJKIF_S_REF_ORDER_ADDITION
*"     VALUE(XTEST) TYPE  XFELD OPTIONAL
*"     VALUE(XUPDATE_TASK) TYPE  XFELD OPTIONAL
*"     VALUE(XMESSAGING) TYPE  XFELD OPTIONAL
*"     VALUE(IM_HEAD_EXT_ADDITION) TYPE  ZAJKAK OPTIONAL
*"     VALUE(IM_ITEM_EXT_ADDITION) TYPE  ZAJKAP OPTIONAL
*"  EXPORTING
*"     VALUE(E_VBELN) LIKE  JKAK-VBELN
*"     VALUE(EX_RETURN) TYPE  BAPIRET2_T
*"     VALUE(EX_RETURN_CODE) TYPE  I
*"  CHANGING
*"     VALUE(CT_RETURN) TYPE  BAPIRET2_T
*"----------------------------------------------------------------------
*FUNCTION /gdt/ism_salesorder_createref .
  TYPE-POOLS : jksi.

  CONSTANTS: con_msg_extern  TYPE symsgty VALUE '*'.        "#EC NEEDED
  CONSTANTS: con_error       TYPE symsgty VALUE 'E'.        "#EC NEEDED
  DATA: msg LIKE rjmsg.
  DATA: ls_tvta      LIKE tvta.
  DATA: ls_head      TYPE jksi_head.
  DATA: ls_item      TYPE jksi_item.
  DATA: lt_item      TYPE jksi_t_item.
  DATA: lv_vkont LIKE jkkd-vkont.
  DATA: lv_startdate LIKE jkap-gueltigvon.
  DATA : ls_exreturn          TYPE bapiret2.
  data : lv_msgv1             TYPE sy-msgv1.

* Additional Data Declaration
  DATA ls_return TYPE bapiret2.
*  DATA ls_header_ext_new TYPE zajkak.
  DATA ls_header_new TYPE zjk_s_ism_order_head.

  DATA lt_item_new TYPE zjk_tt_ism_order_item.

* Initialize export parameters
  REFRESH ex_return.
  CLEAR ex_return_code.

* Validate the custom fields
*  PERFORM validate_addl_fields_2 USING im_head_ext_addition
*                                       im_item_ext_addition
*                               CHANGING ex_return_code
*                                        ex_return.

  IF ex_return_code <> 0.
    RETURN.
  ENDIF.

* initialization
* ==============
  CLEAR: ls_head, ls_item.
  REFRESH: lt_item.
  CALL FUNCTION 'ISP_GP_BUFFER_REFRESH'.
  CALL FUNCTION 'ISM_BUPA_BK_REFRESH'.
  CALL FUNCTION 'ISM_BUPA_CC_REFRESH'.

* pre-checks
* ==========
* template data
  PERFORM check_template USING    i_campaign
                         CHANGING i_vbeln_vl
                                  i_posnr_ur_vl
                                  ct_return.
* customer
  IF i_order_addition-gpag IS INITIAL.

    CLEAR ls_return.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
      EXPORTING
        type       = 'E'
        cl         = 'JK'
        number     = '080'
        par1       = ''
        par2       = ''
        par3       = ''
        par4       = ''
*       LOG_NO     = ' '
*       LOG_MSG_NO = ' '
*       PARAMETER  = ' '
*       ROW        = 0
*       FIELD      = ' '
      IMPORTING
        return     = ls_return.

    APPEND ls_return TO ex_return.
    ex_return_code = 4.
    RETURN.

  ENDIF.

* process
* =======
  lv_startdate = i_order_addition-gueltigvon.
  IF lv_startdate IS INITIAL.
    lv_startdate = sy-datum.
  ENDIF.

* lock reference order
* ====================
  IF xtest IS INITIAL.
    PERFORM ejkak_sperren USING i_vbeln_vl
                                con_msg_extern
                       CHANGING msg.
    IF NOT msg-msgno IS INITIAL.
      CLEAR ls_return.
      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type       = con_error
          cl         = msg-msgid
          number     = msg-msgno
          par1       = msg-msgv1
          par2       = msg-msgv2
          par3       = msg-msgv3
          par4       = msg-msgv4
*         LOG_NO     = ' '
*         LOG_MSG_NO = ' '
*         PARAMETER  = ' '
*         ROW        = 0
*         FIELD      = ' '
        IMPORTING
          return     = ls_return.

      APPEND ls_return TO ex_return.
      ex_return_code = 4.
      RETURN.
    ENDIF.
  ENDIF.

* read reference order
* ====================
  CALL FUNCTION 'ISM_SALES_ITEM_EXTRACT_ORIGIN'
    EXPORTING
      i_vbeln    = i_vbeln_vl
      i_posnr_ur = i_posnr_ur_vl
    IMPORTING
      e_head     = ls_head
      e_items    = lt_item
    EXCEPTIONS
      OTHERS     = 4.
  IF sy-subrc <> 0.

    CLEAR ls_return.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
      EXPORTING
        type       = sy-msgty
        cl         = sy-msgid
        number     = sy-msgno
        par1       = sy-msgv1
        par2       = sy-msgv2
        par3       = sy-msgv3
        par4       = sy-msgv4
*       LOG_NO     = ' '
*       LOG_MSG_NO = ' '
*       PARAMETER  = ' '
*       ROW        = 0
*       FIELD      = ' '
      IMPORTING
        return     = ls_return.

    APPEND ls_return TO ex_return.
    ex_return_code = 4.
    RETURN.

  ENDIF.
* unlock reference order
* ======================
  IF xtest IS INITIAL.
    PERFORM ejkak_entsperren USING i_vbeln_vl.
  ENDIF.

*  IF xtest IS INITIAL.
*   check if customer is available in sales area
    PERFORM check_sold_to_party USING i_order_addition
                                      ls_head
                             CHANGING ls_tvta.
*   check if customer is available in sales area
    PERFORM check_payment_method USING i_order_addition
                                       ls_tvta.
*   check/create contract account
    READ TABLE lt_item INTO ls_item INDEX 1.
    PERFORM check_contract_account USING i_order_addition
                                         ls_head
                                         ls_item
                                CHANGING lv_vkont.
*  ENDIF.

* merge document with variable data
* =================================
  PERFORM merge_document USING i_order_addition
                               lv_vkont
                               lv_startdate
                      CHANGING ls_head
                               lt_item.
*                               LS_RJKBANK
*                               LS_RJKAPCC.

* Merge the custom fields of Order Header and Item
  PERFORM z_merge_custom_fields USING i_vbeln_vl
                                      ls_head
                                      im_head_ext_addition
                                      im_item_ext_addition
                                      lt_item
                                CHANGING ls_header_new
                                         lt_item_new.

* Create new order with Z-fields data as well
  CALL FUNCTION 'ISM_SALESORDER_CREATE'
    EXPORTING
      abo_kopf            = ls_header_new
*     XEXTERNAL_NUMBERING = ' '
      xtest               = xtest
      xupdate_task        = xupdate_task
      xmessaging          = xmessaging
    IMPORTING
      vbeln               = e_vbeln
      ex_return           = ex_return
      ex_return_code      = ex_return_code
    CHANGING
      ch_abo_pos          = lt_item_new
*     CH_POS_LIST         =
    .

ENDFUNCTION.

Below include will be added for Custom Subroutines :

*----------------------------------------------------------------------*
**INCLUDE LZTESTF01
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CHECK_CONTRACT_ACCOUNT
*&---------------------------------------------------------------------*
*       check and create contract account
*----------------------------------------------------------------------*
TYPE-POOLS : jksi, jfca , jkext , jkd , jdbz.
INCLUDE          mj000m00.
INCLUDE          mj_symsgty.
INCLUDE          mjg00tro.
INCLUDE          mj_sydatum.
INCLUDE          mjk00feq.
INCLUDE          mjk0tfkt.
CONSTANTS :  con_gp_satzart_anlegen_gp     LIKE rjgau-gp_satzart VALUE '01'.

*&---------------------------------------------------------------------*
*&      Form  check_contract_account
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->VALUE(ORDER_ADDITION)  text
*      -->VALUE(HEAD)            text
*      -->VALUE(ITEM)            text
*      -->VALUE(VKONT)           text
*----------------------------------------------------------------------*
FORM check_contract_account
             USING order_addition TYPE rjkif_s_ref_order_addition
                   head TYPE jksi_head
*                   value(
  item ")
   TYPE jksi_item
          CHANGING "value
            vkont LIKE jkkd-vkont.
  DATA: ls_rjkbank LIKE rjkbank,
        ls_rjkapcc LIKE rjkapcc.
  DATA: lv_gpnr_rg TYPE gpnr_rg.
*  DATA: ls_tvko LIKE tvko.

*  DATA: lv_lines LIKE sy-tfill,
*        ls_vkont TYPE jfca_vkont_struc,
*        lt_vkont TYPE jfca_vkont_tab.
*
  CLEAR vkont.

* determine BP
  lv_gpnr_rg = order_addition-gpnr_rg.
  IF lv_gpnr_rg IS INITIAL.
    lv_gpnr_rg = order_addition-gpag.
  ENDIF.
*
  CALL FUNCTION 'FKK_FICA_FOR_SD_ACTIVE'
    EXPORTING
      customer   = lv_gpnr_rg
    EXCEPTIONS
      not_active = 1
      OTHERS     = 0.
*
  CHECK sy-subrc = 0.
* fill paymode, bank data, credit card data
  item-zlsch = order_addition-zlsch.
  MOVE-CORRESPONDING order_addition TO ls_rjkbank.
  MOVE-CORRESPONDING ls_rjkbank TO item.
  MOVE-CORRESPONDING order_addition TO ls_rjkapcc.
  MOVE-CORRESPONDING ls_rjkapcc TO item.

* Determine or create contract account (incl. user-exit)
  CALL FUNCTION 'ISM_FICA_VKONT_DETERMINE'
    EXPORTING
      i_gpnr               = order_addition-gpag
      i_abo_kopf           = head
      i_abo_pos            = item
      i_with_creation      = jpsd_x
      i_with_paymode_check = jpsd_x
    IMPORTING
      e_vkont              = vkont
    EXCEPTIONS
      warning              = 0
      OTHERS               = 4.
* contract account is saved, (rollback not possible)
  IF sy-subrc <> 0.
    ROLLBACK WORK.
    $sy_message_raising error.
  ENDIF.

ENDFORM.                    " CHECK_CONTRACT_ACCOUNT

*&---------------------------------------------------------------------*
*&      Form  CHECK_PAYMENT_METHOD
*&---------------------------------------------------------------------*
*       check payment method, create bank data or credit card data
*----------------------------------------------------------------------*
FORM check_payment_method
            USING value(order_addition) TYPE rjkif_s_ref_order_addition
                  value(ps_tvta) LIKE tvta.

  DATA: lv_partner TYPE gpnr_rg.
  DATA: ls_but0bk  TYPE but0bk,
        ls_but0cc  TYPE but0cc,
        ls_ccard   TYPE ccard.

* determine BP
  lv_partner = order_addition-gpnr_rg.
  IF lv_partner IS INITIAL.
    lv_partner = order_addition-gpag.
  ENDIF.
*
  IF NOT order_addition-bankl IS INITIAL.
    CLEAR ls_but0bk.
    MOVE-CORRESPONDING order_addition TO ls_but0bk.
    ls_but0bk-partner = lv_partner.
  ELSEIF NOT order_addition-ccnum IS INITIAL.
    CLEAR ls_but0cc. CLEAR ls_ccard.
    MOVE-CORRESPONDING order_addition TO ls_but0cc.
    ls_but0cc-partner = lv_partner.
    MOVE-CORRESPONDING order_addition TO ls_ccard.
  ELSE.
    EXIT.
  ENDIF.
*
  CALL FUNCTION 'ISM_BP_PAYMENT_TRANSACTION_ADD'
    EXPORTING
      i_partner = lv_partner
      i_vkorg   = ps_tvta-vkorg
      i_vtweg   = ps_tvta-vtwku
      i_spart   = ps_tvta-spaku
      i_but0bk  = ls_but0bk
      i_but0cc  = ls_but0cc
      i_ccard   = ls_ccard
    EXCEPTIONS
      OTHERS    = 4.

  IF sy-subrc <> 0. $sy_message_raising error. ENDIF.

* bank or credit data are saved, (rollback not possible)

ENDFORM.                    " CHECK_PAYMENT_METHOD
*&---------------------------------------------------------------------*
*&      Form  check_sold_to_party
*&---------------------------------------------------------------------*
*       check and create sold_to_party in sales area
*----------------------------------------------------------------------*
FORM check_sold_to_party
             USING value(order_addition) TYPE rjkif_s_ref_order_addition
                   value(head) TYPE jksi_head
          CHANGING ps_tvta LIKE tvta.
*
  DATA: l_sapgp_active TYPE xsapgpactive.
  DATA: ls_abo_ku  TYPE jkext_f_aboku.
  DATA: ls_h_abo TYPE rjgau_ku.
  DATA: ls_rjkbank LIKE rjkbank,
        ls_rjkapcc LIKE rjkapcc.
*  INCLUDE mjg00tc2.

* check bp
*  select count(*) from jgvdb_gp where gpnr eq order_addition-gpag.
  CALL FUNCTION 'ISP_GP_READ'
    EXPORTING
      gpnr_in    = order_addition-gpag
    EXCEPTIONS
      deleted    = 1
      not_exists = 2
      OTHERS     = 3.
  IF sy-subrc <> 0.
    MESSAGE e101(jg) WITH order_addition-gpag RAISING error.
  ENDIF.
* get sales area
  CALL FUNCTION 'ISP_SELECT_SINGLE_TVTA'
    EXPORTING
      vkorg  = head-vkorg
      vtweg  = head-vtweg
      spart  = head-spart
      msgty  = con_dump
    IMPORTING
      tvta_i = ps_tvta
    EXCEPTIONS
      OTHERS = 0.
* check customer
*  select count(*) from jgvdb_ku where gpnr eq order_addition-gpag
*                                and   vkorg eq ps_tvta-vkorg
*                                and   vtweg eq ps_tvta-vtwku
*                                and   spart eq ps_tvta-spaku.
  CALL FUNCTION 'ISP_KU_READ'
    EXPORTING
      gpnr_in           = order_addition-gpag
      vkorg_in          = ps_tvta-vkorg
      vtweg_in          = ps_tvta-vtwku
      spart_in          = ps_tvta-spaku
    EXCEPTIONS
      deleted           = 1
      not_exists        = 2
      not_in_sales_area = 3
      OTHERS            = 4.
  IF sy-subrc <> 0.
*   create customer
    ls_abo_ku-vkorg = ps_tvta-vkorg.
    ls_abo_ku-vtweg = ps_tvta-vtwku.
    ls_abo_ku-spart = ps_tvta-spaku.
    ls_abo_ku-gpnr  = order_addition-gpag.
*   bank data
    MOVE-CORRESPONDING order_addition TO ls_rjkbank.
    MOVE-CORRESPONDING ls_rjkbank TO ls_abo_ku.
*   credit card data
    MOVE-CORRESPONDING order_addition TO ls_rjkapcc.
    MOVE-CORRESPONDING ls_rjkapcc TO ls_abo_ku.
    ls_abo_ku-waers  = order_addition-waerk.
    ls_abo_ku-kurst  = order_addition-kurst.
    ls_abo_ku-kzdeb  = jpsd_x.
    ls_abo_ku-zwels  = order_addition-zlsch.
    ls_abo_ku-jparvw = con_ro_vertriebskunde.
    ls_abo_ku-wdat1  = sy-datum.
    ls_abo_ku-wdat2  = con_time_infinity.
    ls_abo_ku-gp_satzart  = con_gp_satzart_anlegen_gp.
    CALL FUNCTION 'ISM_SAP_GP_STATUS_GET'
      IMPORTING
        e_sapgp_active = l_sapgp_active.
    IF NOT l_sapgp_active IS INITIAL.
      SELECT SINGLE langu_corr FROM but000 INTO ls_abo_ku-spras
                               WHERE partner = ls_abo_ku-gpnr.
      IF ls_abo_ku-spras IS INITIAL.
        ls_abo_ku-spras = sy-langu.
      ENDIF.
    ENDIF.
*   Call User-Exit to attach additional data
    MOVE-CORRESPONDING ls_abo_ku TO ls_h_abo.
    PERFORM customer_function_sapmjk07_002(sapmjk07)
                                         CHANGING ls_h_abo.
    MOVE-CORRESPONDING ls_h_abo TO ls_abo_ku.
*
    CALL FUNCTION 'ISP_PARTNER_SAVE_COMPLETE'
      EXPORTING
        abo_ku = ls_abo_ku
      EXCEPTIONS
        OTHERS = 4.
    IF sy-subrc <> 0.
      ROLLBACK WORK.
      $sy_message_raising error.
    ENDIF.
  ENDIF.

ENDFORM.                    " check_sold_to_party

*&---------------------------------------------------------------------*
*&      Form  check_template
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CAMPAIGN     text
*      -->P_VBELN_VL     text
*      -->P_POSNR_UR_VL  text
*----------------------------------------------------------------------*
FORM check_template USING    p_campaign    TYPE ism_marketing_campaign_generic
                    CHANGING p_vbeln_vl    TYPE avnr_vl
                             p_posnr_ur_vl TYPE apnr_vl
                             ct_return     TYPE bapiret2_t.

  DATA: l_offertab TYPE rjjcamp_msdtab,
        l_offer    TYPE rjjcamp_msd.
  DATA: l_campaign TYPE ism_marketing_campaign_extern.
  DATA : lv_vbeln TYPE vbeln_vl.
  DATA : lv_msgv1             TYPE sy-msgv1.
  DATA : ls_exreturn          TYPE bapiret2.
  IF NOT p_campaign IS INITIAL.
    CALL FUNCTION 'ISM_CAMPAIGN_EXISTANCE_CHECK'
      EXPORTING
        campaign = p_campaign
      EXCEPTIONS
        OTHERS   = 4.
    IF sy-subrc <> 0.
*      $sy_message_raising error.

            CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = sy-msgty
          cl     = sy-msgid
          number = sy-msgno
          par1   = sy-msgv1
          par2   = sy-msgv2
          par3   = sy-msgv3
          par4   = sy-msgv4
        IMPORTING
          return = ls_exreturn.
      APPEND ls_exreturn TO ct_return.
          RETURN.

    ENDIF.
  ENDIF.

  IF p_vbeln_vl IS INITIAL.
*   offer from campaign
    IF p_campaign IS INITIAL.
*      MESSAGE e500(jk1).

*            lv_msgv1 = text-002.

      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = 'E'
          cl     = 'JK1'
          number = '500'
*          par1   = lv_msgv1
        IMPORTING
          return = ls_exreturn.
      APPEND ls_exreturn TO ct_return.
          RETURN.

    ELSE.
*     get offer from campaign
      CALL FUNCTION 'ISM_CRM_MSDOFFERS_TO_CMPGN_GET'
        EXPORTING
          i_campaign     = p_campaign
          i_valid_from   = sy-datum
          i_valid_to     = sy-datum
        IMPORTING
          e_offertab     = l_offertab
        EXCEPTIONS
          no_offer_found = 1
          OTHERS         = 2.
      IF sy-subrc <> 0.
*        $sy_message_raising error.
            CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = sy-msgty
          cl     = sy-msgid
          number = sy-msgno
          par1   = sy-msgv1
          par2   = sy-msgv2
          par3   = sy-msgv3
          par4   = sy-msgv4
        IMPORTING
          return = ls_exreturn.
      APPEND ls_exreturn TO ct_return.
          RETURN.
      ENDIF.
      IF lines( l_offertab ) > 1.
        CALL FUNCTION 'CONVERSION_EXIT_MCMP1_OUTPUT'
          EXPORTING
            input         = p_campaign
          IMPORTING
            output        = l_campaign
          EXCEPTIONS
            error_message = 0.
*        MESSAGE e501(jk1) WITH l_campaign.

        sy-msgv1  = l_campaign.

       CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = 'E'
          cl     = 'JK1'
          number = '501'
          par1   = sy-msgv1
        IMPORTING
          return = ls_exreturn.
      APPEND ls_exreturn TO ct_return.
          RETURN.
      ENDIF.
      READ TABLE l_offertab INTO l_offer INDEX 1.
      p_vbeln_vl = l_offer-templ_doc.
    ENDIF.
  ENDIF.

  IF p_vbeln_vl IS NOT INITIAL.
    SELECT SINGLE vbeln
           FROM jkak
     INTO lv_vbeln
     WHERE vbeln = p_vbeln_vl.

    IF sy-subrc NE 0.

      lv_msgv1 = text-002.

      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = 'E'
          cl     = 'JK'
          number = '000'
          par1   = lv_msgv1
        IMPORTING
          return = ls_exreturn.
      APPEND ls_exreturn TO ct_return.
          RETURN.
    ENDIF.

  ENDIF.

  IF p_posnr_ur_vl IS INITIAL.
    SELECT DISTINCT posnr_ur FROM jkap INTO p_posnr_ur_vl UP TO 1 ROWS
      WHERE vbeln = p_vbeln_vl.
    ENDSELECT.
    IF sy-subrc <> 0.

*      $abbruch.
      lv_msgv1 = text-002.

      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          type   = 'E'
          cl     = 'JK'
          number = '000'
          par1   = lv_msgv1
        IMPORTING
          return = ls_exreturn.
      APPEND ls_exreturn TO ct_return.
      RETURN.
    ENDIF.

  ENDIF.
*  ENDIF.
*
ENDFORM.                    "check_template

**********************************************************************
** Kundenauftrag entsperren                                          *
**********************************************************************
*form ejkak_entsperren using value(jkak_vbeln).              "#EC CALLED
*
*  call function 'DEQUEUE_EJKJKAK'
*    exporting
*      vbeln = jkak_vbeln.
**
*  call function 'ISM_DEQUEUE_DEREG_EJKJKAK'
*    exporting
*      vbeln = jkak_vbeln.
**
*endform.                    "ejkak_entsperren
*&---------------------------------------------------------------------*
*&      Form  MERGE_DOCUMENT
*&---------------------------------------------------------------------*
*       merge document
*----------------------------------------------------------------------*
FORM merge_document  USING    value(ps_order_addition)
                                   TYPE rjkif_s_ref_order_addition
                              value(pv_vkont) LIKE jkkd-vkont
                              value(pv_startdate) LIKE syst-datum
                     CHANGING value(ps_head) TYPE jksi_head
*                              value(
  pt_item TYPE jksi_t_item.
*                              value(ps_rjkbank) type rjkbank
*                              value(ps_rjkapcc) type rjkapcc.
  DATA: ls_tjak      LIKE tjak.
  DATA: ls_item      TYPE jksi_item.
  DATA: lv_startdate LIKE jkap-gueltigvon.
* viability data
  DATA: ls_jkd_address TYPE jkd_address,
        lt_jkd_address TYPE jkd_addresstab,
        ls_delivpar    TYPE jkd_delivpar,
        ls_address        LIKE jgvaddres2.
  DATA: lt_addresses      LIKE jgvaddres2 OCCURS 0.
  DATA: ls_item_viability TYPE jkd_itemadd.
  DATA: lv_xbackdated TYPE xfeld.
  DATA: lv_enddate   LIKE jkap-gueltigbis.
  CONSTANTS: con_vbtyp_angebot TYPE jkak-vbtyp  VALUE 'B'.
*  DATA: ls_rjkaccaddt LIKE rjkaccaddt.                      "Rel.4.72
  DATA: ls_rjkbank TYPE rjkbank,
        ls_rjkapcc TYPE rjkapcc.

* initialization
* ==============
  CLEAR: ls_item_viability, ls_rjkapcc, ls_rjkbank,
         ls_address, ls_delivpar, lv_xbackdated.
  REFRESH: lt_addresses, lt_jkd_address.
* set item period
* ---------------
  lv_startdate = pv_startdate.
  lv_enddate = con_time_infinity.
  IF ps_order_addition-gueltigbis GT con_time_zero AND
     ps_order_addition-gueltigbis LT con_time_infinity.
    lv_enddate = ps_order_addition-gueltigbis.
  ENDIF.
* header data
* -----------
* sold-to party
  ps_head-gpnr_ag = ps_order_addition-gpag.
  IF ps_order_addition-waerk IS INITIAL.
    CLEAR: ps_head-waerk, ps_head-kurst.
*   is determined out of sold-to party
  ELSE.
    ps_head-waerk = ps_order_addition-waerk.
    ps_head-kurst = ps_order_addition-kurst.
  ENDIF.
  IF NOT ps_order_addition-ximmatrik IS INITIAL.
    ps_head-ximmatrik = ps_order_addition-ximmatrik.
    ps_head-immatdat  = ps_order_addition-immatdat.
  ENDIF.
*
* determine follow up order type
  CALL FUNCTION 'ISP_SELECT_SINGLE_TJAK'
    EXPORTING
      auart  = ps_head-auart
      msgty  = con_dump
    IMPORTING
      tjak_i = ls_tjak
    EXCEPTIONS
      OTHERS = 0.
  IF ls_tjak-vbtyp = con_vbtyp_angebot.
    ps_head-auart = ls_tjak-auart_nf.
  ENDIF.
* item data
* ---------
  LOOP AT pt_item INTO ls_item.
*   overwrite partners
*   bill-to party
    IF ps_order_addition-gpnr_re IS INITIAL.
      ls_item-gpnr_re = ps_order_addition-gpag.
    ELSE.
      ls_item-gpnr_re = ps_order_addition-gpnr_re.
    ENDIF.
    CLEAR: ls_item-logadr_re, ls_item-adressvar_re.
*   ship-to party
    IF ps_order_addition-gpnr_we IS INITIAL.
      ls_item-gpnr_we = ps_order_addition-gpag.
    ELSE.
      ls_item-gpnr_we = ps_order_addition-gpnr_we.
    ENDIF.
    CLEAR: ls_item-logadr_we, ls_item-adressvar_we,
           ls_item-beablst, ls_item-land1, ls_item-stceg_l.
*   payer
    IF ps_order_addition-gpnr_rg IS INITIAL.
      ls_item-gpnr_rg = ps_order_addition-gpag.
    ELSE.
      ls_item-gpnr_rg = ps_order_addition-gpnr_rg.
    ENDIF.
    ls_item-zlsch   = ps_order_addition-zlsch.
    ls_item-vkont   = pv_vkont.
*   agent
    IF NOT ps_order_addition-gpverm IS INITIAL.
      ls_item-gpverm = ps_order_addition-gpverm.
    ENDIF.
*   gift
    IF NOT ps_order_addition-matnrwerb IS INITIAL.
      ls_item-matnrwerb = ps_order_addition-matnrwerb.
    ENDIF.
*   billing details
    IF NOT ps_order_addition-konda IS INITIAL.
      ls_item-konda = ps_order_addition-konda.
    ENDIF.
    IF NOT ps_order_addition-perfk IS INITIAL.
      ls_item-perfk = ps_order_addition-perfk.
    ENDIF.
    IF NOT ps_order_addition-fkper IS INITIAL.
      ls_item-fkper = ps_order_addition-fkper.
    ENDIF.
    IF NOT ps_order_addition-rcode IS INITIAL.
      ls_item-rcode = ps_order_addition-rcode.
    ENDIF.
    IF NOT ps_order_addition-dueday IS INITIAL.
      ls_item-dueday = ps_order_addition-dueday.
    ENDIF.
*   schedule line data
    IF NOT ps_order_addition-etmenge IS INITIAL.
      ls_item-etmenge = ps_order_addition-etmenge.
    ENDIF.
*   bank data
    MOVE-CORRESPONDING ps_order_addition TO ls_rjkbank.
    MOVE-CORRESPONDING ls_rjkbank TO ls_item.
*   credit card data
    MOVE-CORRESPONDING ps_order_addition TO ls_rjkapcc.
    MOVE-CORRESPONDING ls_rjkapcc TO ls_item.
*   initialize sub item data
    CLEAR ls_item-t_sub_item. REFRESH ls_item-t_sub_item.
*   viability optimization, (only for the first item)
    IF ls_item_viability-pva IS INITIAL.
      CALL FUNCTION 'ISP_ADDRESSES_READ'
        EXPORTING
          sel_gpnr  = ls_item-gpnr_we
          sel_rolle = con_ro_gp_allg
        TABLES
          iaddres2  = lt_addresses
        EXCEPTIONS
          OTHERS    = 4.
      IF sy-subrc <> 0.
        MESSAGE e138(jg) WITH ls_item-gpnr_we RAISING error.
      ENDIF.
      LOOP AT lt_addresses INTO ls_address.
        MOVE-CORRESPONDING ls_address TO ls_jkd_address.
        ls_jkd_address-gueltigvon = lv_startdate.
        ls_jkd_address-gueltigbis = lv_enddate.
        ls_jkd_address-adressvar  = ls_address-erstadr.
        IF ls_address-wdat1 LE lv_startdate AND
           ls_address-wdat2 GE lv_startdate.
          APPEND ls_jkd_address TO lt_jkd_address.
          EXIT.                   "exit with actual address
        ENDIF.
      ENDLOOP.
*     Fill workarea for deliverablity check
      ls_delivpar-auart          = ps_head-auart.
      ls_delivpar-drerz          = ls_item-drerz.
      ls_delivpar-vkorg          = ps_head-vkorg.
      ls_delivpar-vtweg          = ps_head-vtweg.
      ls_delivpar-bezper         = ls_item-bezper.
      ls_delivpar-gueltigab      = lv_startdate.
      ls_delivpar-gueltigbis     = con_time_infinity.
      ls_delivpar-xclosing_date  = jpsd_x.
      CLEAR: ls_delivpar-pva, ls_delivpar-lieferart,
             ls_delivpar-bezugstyp.
      DATA: l_jkap TYPE jkap.
      DATA: l_etmenge TYPE jkep-etmenge.
      MOVE-CORRESPONDING ls_item TO l_jkap.
      l_etmenge = ls_item-etmenge.
      CALL FUNCTION 'ISM_DELIVERABILITY_USER_PAR'
        EXPORTING
          quantity = l_etmenge
          p_jkap   = l_jkap
        IMPORTING
          user_par = ls_delivpar-user_par.
*
      CALL FUNCTION 'ISM_DELIVERABILITY_PRECHECK'
        EXPORTING
          pt_address        = lt_jkd_address
          ps_delivpar       = ls_delivpar
          pv_poart          = ls_item-poart
        IMPORTING
          ps_item_additions = ls_item_viability
        EXCEPTIONS
          OTHERS            = 1.

      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                RAISING error.
      ENDIF.
*     backdated issue
      IF ps_order_addition-gueltigvon GT con_time_zero AND
         ls_item_viability-vorlaufdat GT ps_order_addition-gueltigvon.
        lv_xbackdated = jpsd_x.
      ENDIF.
    ENDIF.
    ls_item-pva       = ls_item_viability-pva.
    ls_item-bezugstyp = ls_item_viability-bezugstyp.
    ls_item-lieferart = ls_item_viability-lieferart.
    CLEAR: ls_item-heftnumvon, ls_item-heftnumbis.
*   period
    CASE ls_item-funktion.
      WHEN con_funktion_pp_mit_negoption OR
           con_funktion_pp_mit_negopt_rw.
*       adjust function
        IF lv_xbackdated = jpsd_x.
          ls_item-funktion = con_funktion_pp_mit_negopt_rw.
          lv_startdate = ps_order_addition-gueltigvon.
        ELSE.
          ls_item-funktion = con_funktion_pp_mit_negoption.
          IF ls_item_viability-vorlaufdat GT lv_startdate.
            lv_startdate = ls_item_viability-vorlaufdat.
          ENDIF.
        ENDIF.

        PERFORM adjust_start_date
                      USING ls_item-drerz
                            ls_item-pva
                            ls_item-bezugstyp
                            ls_item-bezper
                   CHANGING lv_startdate.

        IF ls_item-gueltigbis LT con_time_infinity AND
           lv_enddate = con_time_infinity.
*         determine end of period out of promotion
          PERFORM determine_end_date
                        USING ls_item-drerz
                              ls_item-pva
                              ls_item-bezugstyp
                              ls_item-bezper
                              ls_item-werbeakt
                              lv_startdate
                     CHANGING lv_enddate.
        ELSE.
          MESSAGE e074(jk) RAISING error.
        ENDIF.
      WHEN con_funktion_kp_mit_negoption OR
           con_funktion_kp_mit_negopt_rw.
*       adjust function
        IF lv_xbackdated = jpsd_x.
          ls_item-funktion = con_funktion_kp_mit_negopt_rw.
          lv_startdate = ps_order_addition-gueltigvon.
        ELSE.
          ls_item-funktion = con_funktion_kp_mit_negoption.
          IF ls_item_viability-vorlaufdat GT lv_startdate.
            lv_startdate = ls_item_viability-vorlaufdat.
          ENDIF.
        ENDIF.
        PERFORM adjust_start_date
                      USING ls_item-drerz
                            ls_item-pva
                            ls_item-bezugstyp
                            ls_item-bezper
                   CHANGING lv_startdate.
        IF ls_item-gueltigbis LT con_time_infinity AND
           lv_enddate = con_time_infinity.
*         determine end of period out of promotion
          PERFORM determine_end_date
                        USING ls_item-drerz
                              ls_item-pva
                              ls_item-bezugstyp
                              ls_item-bezper
                              ls_item-werbeakt
                              lv_startdate
                     CHANGING lv_enddate.
        ELSE.
          MESSAGE e074(jk) RAISING error.
        ENDIF.
      WHEN con_funktion_probe_pos OR con_funktion_probe_pos_rw.
*       adjust function
        IF lv_xbackdated = jpsd_x.
          ls_item-funktion = con_funktion_probe_pos_rw.
          lv_startdate = ps_order_addition-gueltigvon.
        ELSE.
          ls_item-funktion = con_funktion_probe_pos.
          IF ls_item_viability-vorlaufdat GT lv_startdate.
            lv_startdate = ls_item_viability-vorlaufdat.
          ENDIF.
        ENDIF.
        PERFORM adjust_start_date
                      USING ls_item-drerz
                            ls_item-pva
                            ls_item-bezugstyp
                            ls_item-bezper
                   CHANGING lv_startdate.
        IF ls_item-gueltigbis LT con_time_infinity AND
           lv_enddate = con_time_infinity.
*         determine end of period out of promotion
          PERFORM determine_end_date
                        USING ls_item-drerz
                              ls_item-pva
                              ls_item-bezugstyp
                              ls_item-bezper
                              ls_item-werbeakt
                              lv_startdate
                     CHANGING lv_enddate.
        ENDIF.
      WHEN con_funktion_kostenlos_pos    OR
           con_funktion_kostenlos_pos_rw.
*       adjust function
        IF lv_xbackdated = jpsd_x.
          ls_item-funktion = con_funktion_kostenlos_pos_rw.
          lv_startdate = ps_order_addition-gueltigvon.
        ELSE.
          ls_item-funktion = con_funktion_kostenlos_pos.
          IF ls_item_viability-vorlaufdat GT lv_startdate.
            lv_startdate = ls_item_viability-vorlaufdat.
          ENDIF.
        ENDIF.
        PERFORM adjust_start_date
                      USING ls_item-drerz
                            ls_item-pva
                            ls_item-bezugstyp
                            ls_item-bezper
                   CHANGING lv_startdate.
        IF ls_item-gueltigbis LT con_time_infinity AND
           lv_enddate = con_time_infinity.
*         determine end of period out of promotion
          PERFORM determine_end_date
                        USING ls_item-drerz
                              ls_item-pva
                              ls_item-bezugstyp
                              ls_item-bezper
                              ls_item-werbeakt
                              lv_startdate
                     CHANGING lv_enddate.
        ENDIF.
      WHEN con_funktion_normal_pos OR
           con_funktion_normal_pos_rw.
*       adjust function
        IF lv_xbackdated = jpsd_x.
          ls_item-funktion = con_funktion_normal_pos_rw.
          lv_startdate = ps_order_addition-gueltigvon.
        ELSE.
          ls_item-funktion = con_funktion_normal_pos.
          IF ls_item_viability-vorlaufdat GT lv_startdate.
            lv_startdate = ls_item_viability-vorlaufdat.
          ENDIF.
        ENDIF.
*       adjust startdate
        PERFORM adjust_start_date
                      USING ls_item-drerz
                            ls_item-pva
                            ls_item-bezugstyp
                            ls_item-bezper
                   CHANGING lv_startdate.
        IF lv_enddate = con_time_infinity.
          lv_enddate = ls_item-gueltigbis.
        ENDIF.
      WHEN con_funktion_nego_unbefristet.
        lv_startdate = lv_enddate + 1.
        lv_enddate   = con_time_infinity.
      WHEN OTHERS.
*       dump
        MESSAGE e801(jk) RAISING error.
    ENDCASE.
*   set dates, periods
    ls_item-gueltigvon = lv_startdate.
    ls_item-gueltigbis = lv_enddate.
    ls_item-rechbeginn = ls_item-gueltigvon.
    ls_item-rechende   = ls_item-gueltigbis.
    IF ls_item-prsbinddat LT ls_item-rechbeginn.
      CLEAR: ls_item-prsdt, ls_item-prsbinddat.
    ENDIF.
*   fill additional payments                                  "Rel.4.72
    ls_item-t_add_payment[] = ps_order_addition-addpayments[].
*
    MODIFY pt_item FROM ls_item.

  ENDLOOP.

ENDFORM.                    " MERGE_DOCUMENT
*&---------------------------------------------------------------------*
*&      Form  ADJUST_START_DATE
*&---------------------------------------------------------------------*
*       Startdatum auf nächsten Erscheinungstag schieben
*----------------------------------------------------------------------*
FORM adjust_start_date  USING value(drerz)
                              value(pva)
                              value(bezugstyp)
                              value(bezper)
                     CHANGING value(startdate).
  DATA: ls_jdvva LIKE jdvva.
  DATA: lv_nr_of_issues LIKE sy-tabix.
* get next issue
  lv_nr_of_issues = 1.
  CALL FUNCTION 'ISM_N_ISSUES_READ_FORWARD'
       EXPORTING
            publication             = drerz
            edition                 = pva
            mix_type                = bezugstyp
            order_periodicity       = bezper
            key_date                = startdate
            nr_of_issues            = lv_nr_of_issues
            incl_comb_issues        = jdbz_rel_only_invoice
*           alternating ship-to addresses not relevant       "ALTADR4.63
       IMPORTING
            n_th_issue              = ls_jdvva
       EXCEPTIONS
            internal_error          = 1
            not_enough_issues_found = 2
            OTHERS                  = 3.
  IF sy-subrc NE 0.
    MESSAGE e241(jk) WITH startdate drerz pva RAISING error.
  ENDIF.
  startdate = ls_jdvva-erschdat.

ENDFORM.                    " ADJUST_START_DATE
*&---------------------------------------------------------------------*
*&      Form  DETERMINE_END_DATE
*&---------------------------------------------------------------------*
*       Endedatum über Werbeaktion bestimmen
*----------------------------------------------------------------------*
FORM determine_end_date  USING value(drerz)
                               value(pva)
                               value(bezugstyp)
                               value(bezper)
                               value(werbeakt)
                               value(startdate)
                      CHANGING value(enddate).
  DATA: ls_tjwak LIKE tjwak,
        ls_msg LIKE rjmsg,
        ls_jdvva LIKE jdvva.
  DATA: lv_nr_of_issues LIKE sy-tabix.
*
  CALL FUNCTION 'ISP_SELECT_SINGLE_TJWAK'
    EXPORTING
      werbeakt = werbeakt
    IMPORTING
      meldung  = ls_msg
      tjwak_i  = ls_tjwak
    EXCEPTIONS
      OTHERS   = 4.
  IF sy-subrc <> 0 OR ls_msg-msgno <> 0.
    MESSAGE e007(jw) WITH werbeakt RAISING error.
  ENDIF.
  lv_nr_of_issues = ls_tjwak-anzetprobe.
  CALL FUNCTION 'ISM_N_ISSUES_READ_FORWARD'
       EXPORTING
            publication             = drerz
            edition                 = pva
            mix_type                = bezugstyp
            order_periodicity       = bezper
            key_date                = startdate
            nr_of_issues            = lv_nr_of_issues
            incl_comb_issues        = jdbz_rel_only_invoice
*           alternating ship-to addresses not relevant       "ALTADR4.63
       IMPORTING
            n_th_issue              = ls_jdvva
       EXCEPTIONS
            internal_error          = 1
            not_enough_issues_found = 2
            OTHERS                  = 3.
  IF sy-subrc NE 0.
    MESSAGE e241(jk) WITH startdate drerz pva RAISING error.
  ENDIF.
  enddate = ls_jdvva-erschdat.

ENDFORM.                    " DETERMINE_END_DATE
*&---------------------------------------------------------------------*
*&      Form  VALIDATE_ADDL_FIELDS_2
*&---------------------------------------------------------------------*
*       Validate the variable additional fields in Order Header and Items
*       during order creation with reference to an existing order
*----------------------------------------------------------------------*
FORM validate_addl_fields_2  USING    ps_head_ext_addition TYPE zajkak"JKAK"
                                      ps_item_ext_addition TYPE zajkap "JKAP "
                             CHANGING p_return_code TYPE i
                                      pt_return TYPE bapiret2_t.

  p_return_code = 0.
  RETURN.
ENDFORM.                    " VALIDATE_ADDL_FIELDS_2
*&---------------------------------------------------------------------*
*&      Form  Z_MERGE_CUSTOM_FIELDS
*&---------------------------------------------------------------------*
*       Merge the custom fields in Order Header and Item
*----------------------------------------------------------------------*
FORM z_merge_custom_fields  USING    p_vbeln TYPE avnr_vl
                                     ps_head TYPE jksi_head
                                     ps_head_ext_addition "TYPE dref
                                     ps_item_ext_addition" TYPE zajkap
                                     pt_item TYPE jksi_t_item
                            CHANGING ps_header_new TYPE zjk_s_ism_order_head
                                     pt_item_new TYPE zjk_tt_ism_order_item.

* Local Data Declaration
  TYPES: BEGIN OF ty_jkap_ext,
          vbeln             TYPE jkap-vbeln,
          posnr             TYPE jkap-posnr,
          posex             TYPE jkap-posex,
          zz_email_eedtion  TYPE jkap-zz_email_eedtion,
          zz_xdonation      TYPE jkap-zz_xdonation,
          zz_inbound_chl    TYPE jkap-zz_inbound_chl,
          zz_delivery_unit  TYPE jkap-zz_delivery_unit,
          zz_delivery_area  TYPE jkap-zz_delivery_area,
          zz_contpers       TYPE jkap-zz_contpers,
          zz_xdoorslot      TYPE jkap-zz_xdoorslot,
          zz_inv_channel    TYPE jkap-zz_inv_channel,
        END OF ty_jkap_ext.

  DATA ls_header_ext_new        TYPE zajkak.
  DATA : ls_header_ext_new_jkak TYPE jkak.
*  DATA ls_item_ext_new          TYPE zajkap.
  DATA ls_item                  LIKE LINE OF pt_item.
  DATA ls_item_new              LIKE LINE OF pt_item_new.
  DATA ls_jkap_ext              TYPE jkap ."ty_jkap_ext.

  DATA lt_jkap_ext TYPE STANDARD TABLE OF jkap." ty_jkap_ext.

  TYPES : BEGIN OF ts_fields,
            fieldname TYPE fieldname,
          END OF ts_fields.

  DATA :  lt_fields       TYPE TABLE OF ts_fields,
          lt_fields_jkap  TYPE TABLE OF ts_fields.

  FIELD-SYMBOLS : <fs_name> TYPE any.

* Initialize the changing parameters
  CLEAR ps_header_new.
  REFRESH pt_item_new.

*----------------------------------------------------------------------*
* Process Header custom fields
*----------------------------------------------------------------------*
* Read the existing Order header Z-fields
  CLEAR ls_header_ext_new.

*  Start of change made by sachin

  SELECT SINGLE *
    FROM jkak INTO ls_header_ext_new_jkak
    WHERE vbeln = p_vbeln.

  IF sy-subrc = 0.

*    Get Custom field names

    DATA : ls_fields TYPE ts_fields.

    DATA : ls_fnamesrc TYPE char50,
            ls_fnametgt TYPE char50.
    FIELD-SYMBOLS : <fs_value> TYPE any.

    FIELD-SYMBOLS <fs>.
*    go_struct ?= cl_abap_typedescr=>describe_by_data( ls_header_ext_new_jkak ).
*    gt_comp = go_struct->get_components( ).

    SELECT fieldname
      FROM dd03l
      INTO TABLE lt_fields
      WHERE tabname = 'JKAK'
      AND fieldname LIKE 'ZZ%'.

* Check that header extension parameter is supplied with variable data
* Then merge the variable extension data

    IF ps_head_ext_addition IS NOT INITIAL .

      LOOP AT lt_fields INTO ls_fields .

        CONCATENATE 'PS_HEAD_EXT_ADDITION-' ls_fields-fieldname INTO ls_fnamesrc.
        ASSIGN  (ls_fnamesrc) TO <fs_name>.

        IF sy-subrc EQ 0.
          IF  <fs_name> IS NOT INITIAL.
            CONCATENATE 'LS_HEADER_EXT_NEW-' ls_fields-fieldname INTO ls_fnametgt.
            ASSIGN (ls_fnametgt) TO <fs>.
            MOVE <fs_name> TO <fs>.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDIF.  "     IF ( ps_head_ext_addition IS SUPPLIED )
    "     AND ( ps_head_ext_addition IS NOT INITIAL ).
  ENDIF.  "   IF sy-subrc = 0.

* Transfer the final values of standard and Z-fields into the
* Target header structure for update
  MOVE-CORRESPONDING ps_head TO ps_header_new-header_data.
  MOVE-CORRESPONDING ls_header_ext_new TO ps_header_new-header_ext_data.

*----------------------------------------------------------------------*
* Process Item custom fields
*----------------------------------------------------------------------*
  CLEAR ls_jkap_ext.

  SELECT * FROM jkap
         INTO TABLE lt_jkap_ext
         FOR ALL ENTRIES IN pt_item
         WHERE vbeln = p_vbeln
         AND   posex = pt_item-posex.

  SELECT fieldname
     FROM dd03l
     INTO TABLE lt_fields_jkap
     WHERE tabname = 'JKAP'
     AND fieldname LIKE 'ZZ%'.

  LOOP AT pt_item INTO ls_item.
    CLEAR ls_jkap_ext.

    READ TABLE lt_jkap_ext WITH KEY posex = ls_item-posex
    INTO ls_jkap_ext.

    CHECK sy-subrc = 0.

* Check that header extension parameter is supplied with variable data
* Then merge the variable extension data

    IF ps_item_ext_addition IS NOT INITIAL.

      LOOP AT lt_fields INTO ls_fields .
        CLEAR ls_fnamesrc.
        CONCATENATE 'PS_ITEM_EXT_ADDITION-' ls_fields-fieldname INTO ls_fnamesrc.
        ASSIGN  (ls_fnamesrc) TO <fs_name>.

        CLEAR ls_fnametgt.
        IF sy-subrc EQ 0.
          IF  <fs_name> IS NOT INITIAL.
            CONCATENATE 'LS_JKAP_EXT-' ls_fields-fieldname INTO ls_fnametgt.
            ASSIGN (ls_fnametgt) TO <fs>.
            MOVE <fs_name> TO <fs>.
          ENDIF.
        ENDIF.

      ENDLOOP.

    ENDIF.

    CLEAR ls_item_new.
    MOVE-CORRESPONDING ls_item TO ls_item_new.
    MOVE-CORRESPONDING ls_jkap_ext TO ls_item_new.
    CLEAR ls_item_new-vbeln.
    APPEND ls_item_new TO pt_item_new.
  ENDLOOP.
ENDFORM.                    " Z_MERGE_CUSTOM_FIELDS