Thursday, December 9, 2010

Contract Upload Using BAPI_CONTRACT_CREATE

Using BAPI_CONTRACT_CREATE is quite tricky when you want to add customised fields, conditions and header/item texts.

Just sharing my experience for my own future references and to anyone who'll benefit from this as I can't find any specific help on the net on this.


CUSTOMISED FIELDS - LINE ITEMS LEVEL

In my case, it's ZZREGION and ZZTECH fields that were appended to table EKKN.
In ME31K, these fields are located on item level, on 'Account Assignment' tab - 'More' tab - then you'll get region/technology fields.

In BAPI, you have to use structure  BAPI_TE_MEOUTACCOUNT as in the code excerpts below:

*-----------------------------------Customised Field ZZREGION & ZTECH - Item---------------------------------------*

    lt_extensionin-structure = 'BAPI_TE_MEOUTACCOUNT'.
    lt_regiontech-item_no = '00010'.
    lt_regiontech-serial_no = '01'.
    lt_regiontech-zzregion  = 'EAST'.
    lt_regiontech-zztech    = 'C'.
    CONCATENATE lt_regiontech-item_no lt_regiontech-serial_no lt_regiontech-zzregion lt_regiontech-zztech INTO lt_extensionin-valuepart1.
    APPEND lt_extensionin. CLEAR lt_extensionin.

CUSTOMISED FIELDS - HEADER LEVEL

Working With CHECKBOXES:
- If it's standard checkbox field, we can move directly to BAPI contract header data.
- If it's CUSTOMIZED checkbox field, we have to find the structure and use EXTENSIONIN to append data.

Example 1:
Checkbox: 'Notification not required'.
(Field EKKO-WEAKT in ME33K -  Header - Details) - Standard field

In BAPI, use structure BAPI_TE_MEOUTHEADER to move the data as in below:


*-----------------------------------Customised Field ZZSDRO - Header --------------------------------------*

    lt_extensionin-structure = 'BAPI_TE_MEOUTHEADER'.
    PERFORM fill_leading_zero USING lw_ufile-ebeln CHANGING lt_zzsdro-number.
    lt_zzsdro-zzcode    = lc_zzcode.
    lt_zzsdro-zzamount  = lc_zzamount.
    lt_zzsdro-zzsdro    = lw_ufile-zsdro.
    CONCATENATE lt_zzsdro-number lt_zzsdro-zzcode lc_zzamount lt_zzsdro-zzsdro INTO lt_extensionin-valuepart1.
    APPEND lt_extensionin. CLEAR lt_extensionin.


    lt_extensionin-structure = 'BAPI_TE_MEOUTHEADERX'.
    PERFORM fill_x_structure CHANGING lt_zzsdrox.
    PERFORM fill_leading_zero USING lw_ufile-ebeln CHANGING lt_zzsdrox-number.
    CONCATENATE lt_zzsdrox-number lt_zzsdrox-zzcode lt_zzsdrox-zzamount lt_zzsdrox-zzsdro INTO lt_extensionin-valuepart1.
    APPEND lt_extensionin. CLEAR lt_extensionin.

**Remember to concatenate ALL fields BEFORE the fields u need (zzcode & zzamount) in the BAPI structure before moving it to structure field EXTENSIONIN-VALUEPART1.
**Or try to point to the field directly: lt_extensionin-valuepart1+4(2) = lt_zzsdrox-zzcode.



Example 2:

Checkbox: 'Allow Stock To DRO'.
(Field ZZSDRO in ME33K -  Header - Details) - Custom field

- Use BADI


CONDITIONS
- To Be Continued....
... And so the screenshots! Will upload later.


***UPLOAD TO UNIX***
Upload tcode: CG3Z
Check uploaded file in unix: AL11








With Much Love,
The Rookie ABAPer