Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

IDoc Creation:

Former Member
0 Likes
939

Dear all,

i have a requirement on ALE-IDoc for creation of sales order .

the following is the requirement, we get the data in excel or through the EDI, this is uploaded and the IDoc is generated.

Once this is generated it has to automate the process of SO creation.

can anyone provide with a sample code for the following:

i have the idoc segment and everything, i need the sample code for the generation of the idoc and the further process.

1 ACCEPTED SOLUTION
3 REPLIES 3
Read only

Former Member
0 Likes
784

helpful answer

Read only

Former Member
0 Likes
784

Hello,

Here is the Process for Handling the Inbound IDoc with the PO Details.

1. The general Scenario would be that you'll receive all the

Purchase Order Information in the Inbound IDoc.

2. If it is Just the Creation of the Standard Order, all you have

to do is to identify the Inbound IDoc Type (ORDERS05 per

say) in WE30.

3. If you have your own segments to be added to the Existing

Idoc and create an IDoc extension, you can do so by

a) First Creating the Custom Segments for adding the Fields

in WE31 Transaction.

b) Adding the Custom Segment(s) to the IDoc Extension

in WE30 Transaction.

4. Identify the Process Code (ORDE) in WE42 Transaction.

5. Assign the Message Type and IDoc Extension (WE82).

6. Maitain Partner Profiles for the Interface in WE20 T-Code.

7. Write Code in one of the Customer-Exits for Sales Orders

to populate the Custom Fields / Segments.

If the above Configuration / settings are in Place then, whenever an Inbound IDoc is received, it will automatically Create a Sales Order without you having to do anything.

SAMPLE CODE

*******************

The Standard Posting Program for Creating Sales Order is IDOC_INPUT_ORDERS. The Name of the Enhancement is VEDA0001 in which we'll find the Customer Function EXIT_SAPVEDA_001 where the Logic for Populating the Custom Fields / Segments are to be written. Here is the Sample Code.

ws_c_segnam = segment-segnam.

  • Checking the Segment E1EDKA1

CASE ws_c_segnam.

WHEN 'Z1EDK02'.

CLEAR: wa_z1edk02.

MOVE segment-sdata TO wa_z1edk02.

    • Populating SDABW in sales order.

EXPORT wa_z1edk02 TO MEMORY ID 'ZSDABW'. " added 09/10/2007

WHEN 'E1EDKA1'.

ws_c_indx1 = sy-tabix.

CLEAR: e1edka1.

MOVE segment-sdata TO e1edka1.

EXPORT e1edka1 TO MEMORY ID 'Z1EDKKA1'.

  • Validation for Sold-To Party

IF e1edka1-parvw = 'AG'.

IF NOT e1edka1-partn IS INITIAL.

CLEAR ws_c_sldto.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = e1edka1-partn

IMPORTING

output = ws_c_sldto.

IF NOT ws_c_sldto IS INITIAL.

CLEAR: ws_c_vbeln,ws_vbeln.

  • Check if there is a Sales Order exists for the Sold-To Party

  • get the sold to party.

SELECT SINGLE kunnr FROM vbpa INTO ws_c_parnr WHERE

( parvw EQ 'AG' OR parvw EQ 'SP') AND

  • kunnr EQ e1edka1-partn.

kunnr EQ ws_c_sldto.

IF sy-subrc EQ 0.

  • Get all the contracts that are present for the customer.

SELECT vbeln FROM vbak INTO TABLE ws_vbeln

WHERE ( vbtyp = 'G' OR vbtyp = 'E') AND

kunnr = ws_c_parnr AND

gueen GE sy-datlo.

ENDIF.

ELSE.

  • If Sold-To customer is not found then error

MESSAGE i006(z1) WITH text-001

space

space

space RAISING user_error.

ENDIF. "NOT ws_c_sldto IS INITIAL

ELSE.

  • If Sold-To customer is not found then error

MESSAGE i006(z1) WITH text-001

space

space

space RAISING user_error.

ENDIF. "NOT e1edka1-partn IS INITIAL.

  • Validation for Ship-To Party

ELSEIF e1edka1-parvw = 'WE'.

IF NOT e1edka1-partn IS INITIAL.

CLEAR ws_c_shpto.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = e1edka1-partn

IMPORTING

output = ws_c_shpto.

IF NOT ws_c_shpto IS INITIAL.

CLEAR: ws_c_kunnr, ws_c_adrnr.

  • Check if the Ship-To Party is a One-Time Account (KNA1-XCPDK)

SELECT SINGLE kunnr adrnr FROM kna1 INTO (ws_c_kunnr,ws_c_adrnr)

  • WHERE kunnr EQ e1edka1-partn AND xcpdk = 'X' AND loevm NE 'X'.

WHERE kunnr EQ ws_c_shpto AND xcpdk = 'X' AND loevm NE 'X'.

  • If it is, then Get ADRNR for the Ship-To from KNA1 and populate Address

  • from ADRC table based on ADDRNUMBER.

IF sy-subrc = 0.

CLEAR: wa_adrc.

SELECT SINGLE country

name1

city1

post_code1

region

street

FROM adrc INTO wa_adrc WHERE addrnumber = ws_c_adrnr.

IF sy-subrc = 0.

APPEND wa_adrc TO i_adrc.

  • Update the Corresponding address fields of Segment E1EDKA1.

MOVE-CORRESPONDING wa_adrc TO wa_e1edka1.

EXPORT wa_e1edka1 TO MEMORY ID 'Z1EDKA1'.

ENDIF.

CLEAR: ws_c_subrc.

ws_c_subrc = sy-subrc.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

WHEN 'E1EDK02'.

MOVE segment-sdata TO wa_e1edk02.

IF wa_e1edk02-qualf = '001'.

IF wa_e1edk02-belnr IS INITIAL.

EXPORT wa_e1edk02-qualf TO MEMORY ID 'ZPONUM'.

sy-subrc = 4.

ENDIF.

ENDIF.

WHEN 'E1EDKT1'.

MOVE segment-sdata TO wa_e1edkt1.

EXPORT wa_e1edkt1 TO MEMORY ID 'Z1EDKT1'.

wa_e1edkt1_1 = wa_e1edkt1.

WHEN 'E1EDKT2'.

MOVE segment-sdata TO wa_e1edkt2.

EXPORT wa_e1edkt2 TO MEMORY ID 'Z1EDKT2'.

*Addition Parag 12/27/2007 - Contract- Customer - material relation.

When 'E1EDP01'.

MOVE segment-sdata TO wa_e1edp01.

ws_s_posnr = wa_e1edp01-posex.

WHEN 'E1EDP19'.

MOVE segment-sdata TO wa_e1edp19.

CLEAR: ws_c_matnr, ws_c_kdmat, ws_c_posnr.

if wa_e1edp19-qualf = '001'.

ws_c_kdmat = wa_e1edp19-idtnr.

ws_c_posnr = ws_s_posnr.

ELSEIF wa_e1edp19-qualf = '002'.

ws_c_matnr = wa_e1edp19-idtnr.

ws_c_posnr = ws_s_posnr.

endif.

*If the customer has any contracts

IF ws_vbeln IS NOT INITIAL.

*for each Contract check if the corresponding material in the IDOC is present.

LOOP AT ws_vbeln INTO ws_c_vbeln.

*Check if an item in the contract for the material is present.

CLEAR ws_tmp_matnr.

IF wa_e1edp19-qualf = '002'.

SELECT SINGLE matnr

INTO ws_tmp_matnr FROM vbap

WHERE vbeln EQ ws_c_vbeln

AND matnr = ws_c_matnr.

ELSEIF wa_e1edp19-qualf = '001'.

SELECT SINGLE matnr

INTO ws_tmp_matnr FROM vbap

WHERE vbeln EQ ws_c_vbeln

AND kdmat = ws_c_kdmat.

ENDIF.

IF NOT ws_tmp_matnr IS INITIAL.

*if material is found add a line to the text.

  • IF sy-subrc EQ 0.

CLEAR ws_c_sotxt.

CONCATENATE 'CONTRACT ' ws_c_vbeln ' EXISTS FOR ITEM '

  • ws_c_posnr '(MATERIAL ' ws_c_matnr+10(8)')' INTO

ws_c_posnr '(MATERIAL ' ws_tmp_matnr+10(8)')' INTO

ws_c_sotxt RESPECTING BLANKS.

APPEND ws_c_sotxt TO i_sotxt.

  • ENDIF.

ENDIF." matnr

ENDLOOP.

CLEAR: ws_c_posnr,ws_c_matnr.

IF i_sotxt[] IS NOT INITIAL.

EXPORT i_sotxt TO MEMORY ID 'ZSOTXT'.

ENDIF.

ENDIF.

ENDCASE.

Hope it was helpful.

Thanks and Regards,

Venkat Phani Prasad Konduri