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 FM

Former Member
0 Likes
1,021

Hi all!

Can any one provide me the pseudo code of writing a new FM for an OUTBOUND and INBOUND IDoc.

Thanks in advance

Kumar

Hi all!

Can any one provide me the pseudo code of writing a new FM for an OUTBOUND and INBOUND IDoc.

Thanks in advance

Kumar

4 REPLIES 4
Read only

manuel_bassani
Contributor
0 Likes
834

Hi Praneeth,

for inbound idocs try to have a look at FM IDOC_INPUT_*

for outbound FM : IDOC_OUTPUT_*

Regards, Manuel

Read only

Former Member
0 Likes
834

Hi,

just check the standard Inbound/outbound FM's .

they will serve the purpose, you can get idea how to proceed.

regards

vijay

Read only

Former Member
0 Likes
834

Hi Praneeth,

Create new segments -- WE31

Create new IDOCs -- WE30

Create a new message type -- WE81

Link message type with IDOC type -- WE82

Outbound program LOGIC

Select data from application tables

Fill data into IDOC

Pass IDOC to ALE layer

(Call function MASTER_IDOC_DISTRIBUTE)

Commit Work

REPORT zale_example.

  • Parameter for material number for getting related information

PARAMETER : s_matnr TYPE matnr.

  • Internal table for populating the control information for the IDOC

DATA : i_edidc TYPE STANDARD TABLE OF edidc INITIAL SIZE 0

WITH HEADER LINE.

  • Internal table for the communication control record

DATA : i_c_edidc TYPE STANDARD TABLE OF edidc INITIAL SIZE 0

WITH HEADER LINE.

  • Internal table for the populating the data record

DATA : i_edidd TYPE STANDARD TABLE OF edidd INITIAL SIZE 0

WITH HEADER LINE.

  • Structure for the storing material related information

DATA : struct_mara TYPE mara.

  • Structure for the storing the material description

DATA : struct_makt TYPE makt.

  • Structure for the segment to populate the record in the data record

DATA : struct_e1maram TYPE e1maram.

DATA : struct_e1maktm TYPE e1maktm.

  • Constants for the segment names.

DATA : c_e1maram TYPE edilsegtyp.

DATA : c_e1maktm TYPE edilsegtyp.

START-OF-SELECTION.

  • Get the application data from the tables MARA and MAKT

PERFORM get_app_data.

  • Populate the idoc.

PERFORM pop_idoc.

&----


*& Form GET_APP_DATA

&----


  • Get the Application data from the MARA and MAKT

----


FORM get_app_data .

  • Get the Material related information from the mara.

SELECT SINGLE *

FROM mara

INTO struct_mara

WHERE matnr = s_matnr.

  • Check for the sy-subrc value

IF sy-subrc NE 0.

  • Sy-subrc is not equal to zero go out of the program.

EXIT.

ENDIF.

  • Get the material description from the makt by using matnr

SELECT SINGLE *

FROM makt INTO struct_makt

WHERE matnr = s_matnr.

  • Check for the sy-subrc value

IF sy-subrc NE 0.

  • Sy-subrc is not equal to zero go out of the program.

EXIT.

ENDIF.

ENDFORM. " GET_APP_DATA

&----


*& Form MOVE_TO_E1MARAM

&----


  • populate the segment E!MARAM

----


FORM move_mara_to_e1maram .

  • Clear the segment

CLEAR struct_e1maram.

  • Pass the message type related information into the segment.

MOVE: "STRUCT_MARA-MSGFN TO STRUCT_E1MARAM-MSGFN,

struct_mara-matnr TO struct_e1maram-matnr,

struct_mara-ersda TO struct_e1maram-ersda,

struct_mara-ernam TO struct_e1maram-ernam,

struct_mara-meins TO struct_e1maram-meins.

  • Populate the internal table for the data record by passing the

  • Segment name and application data.

PERFORM pop_idoc_edidd USING c_e1maram struct_e1maram.

ENDFORM. " MOVE_TO_E1MARAM

&----


*& Form MOVE_MAKT_TO_E1MAKTM

&----


  • Populate the segment E1MAKTM

----


FORM move_makt_to_e1maktm .

  • Clear the segment

CLEAR struct_e1maktm.

  • Pass the message type related information into the segment.

MOVE : "STRUCT_MAKT-MSGFN TO STRUCT_E1MAKTM-MSGFN,

struct_makt-spras TO struct_e1maktm-spras,

struct_makt-maktx TO struct_e1maktm-maktx.

  • Populate the internal table for the data record by passing the

  • Segment name and application data.

PERFORM pop_idoc_edidd USING c_e1maktm struct_e1maktm.

ENDFORM. " MOVE_MAKT_TO_E1MAKTM

&----


*& Form POP_IDOC_EDIDD

&----


  • Populate the data record by passing the segement data

----


  • -->P_C_E1MAKTM segment name

  • -->P_STRUCT_E1MAKTM Application data

----


FORM pop_idoc_edidd USING p_c_e1maktm

p_struct_e1maktm.

  • Clear the work area for the data record internaltable I_edidd

CLEAR i_edidd.

  • Move the segment name

MOVE: p_c_e1maktm TO i_edidd-segnam,

  • Pass the application data

p_struct_e1maktm TO i_edidd-sdata.

  • Append the internaltable.

APPEND i_edidd.

ENDFORM. " POP_IDOC_EDIDD

&----


*& Form POP_IDOC

&----


  • Populate the Idoc with related information

----


FORM pop_idoc .

  • populate the control record

PERFORM pop_con_data.

  • populate the data record by first populating the header segment

PERFORM move_mara_to_e1maram.

  • Populate the data record by populate the data segment

PERFORM move_makt_to_e1maktm.

  • call the fM master idoc distribute for creating master idoc

PERFORM create_mat_idoc.

ENDFORM. " POP_IDOC

&----


*& Form POP_CON_DATA

&----


  • Populate the control record

----


FORM pop_con_data .

  • Variable for the logical system name

DATA: l_logsys TYPE edi_sndprn.

  • Get the logical system name.

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

own_logical_system = l_logsys

EXCEPTIONS

own_logical_system_not_defined = 1

OTHERS = 2.

  • Check for the sy-subrc value

IF sy-subrc NE 0.

  • Sy-subrc is not equal to zero go out of the program.

EXIT.

ENDIF.

  • Clear the work area of the control record

CLEAR i_edidc.

  • Move the partener type to the control record

MOVE : 'LS' TO i_edidc-sndprt,

  • Populate the sending system name

l_logsys TO i_edidc-sndprn,

  • Populate the type system partener used

'LS' TO i_edidc-rcvprt,

  • Populate the partner number

l_logsys TO i_edidc-rcvprn,

  • Populate message type

'MATMAS' TO i_edidc-mestyp,

  • Populate the idoc type.

'MATMAS03' TO i_edidc-idoctp.

  • Append the control record data.

APPEND i_edidc.

ENDFORM. " POP_CON_DATA

&----


*& Form CREATE_MAT_IDOC

&----


  • Call the FM MASTER_IDOC_DISTRIBUTE

----


FORM create_mat_idoc .

  • Call the FM MASTER_IDOC_DISTRIBUTE for passing the IDOC to ALE layer.

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'

EXPORTING

master_idoc_control = i_edidc

TABLES

communication_idoc_control = i_c_edidc

master_idoc_data = i_edidd

EXCEPTIONS

error_in_idoc_control = 1

error_writing_idoc_status = 2

error_in_idoc_data = 3

sending_logical_system_unknown = 4

OTHERS = 5.

  • Check for the sy-subrc value

IF sy-subrc NE 0.

  • Sy-subrc is not equal to zero go out of the program.

EXIT.

ENDIF.

ENDFORM. " CREATE_MAT_IDOC

Inbound program development

Name: Z_IDOC_INPUT_<Msgtype>

FUNCTION MODULE

Interface:

ImportInput_Method process in dialog or not?

Mass_Processing used for WF programming

Export

In_Update_Task Was update ‘in update task’ used ?

Call_Transaction_done Was a Call Transaction used ?

Workflow_Result Workflow events for errors ?

Application_Variable Workflow parameter

Tables

Idoc_Contrl one entry for each IDOC control record

Idoc_Data one entry for each IDOC data segment

Docnum IDOC number

Segnam Segment name

Sdata Segment data

Idoc_Status Status of the IDOC

Return_Variables created/changed application objects

Serialization_Info used for serialization check

Exceptions

Wrong_Function_called

Logic:

Check, if IDOC contains the correct message type; if not raise exception WRONG_FUNCTION_MODULE_CALLED

Initialize any global variables/tables.

Convert the character data in table IDOC_DATA to internal format in internal tables:

character -> numbers

ISO codes -> SAP codes

Check data

If O.k., post data

If Not: return error message to ALE

No Commit Work !

Return variables for successfully processed IDOCs:Workflow_Result: ‘0’

Idoc_Status: 1 record with following fields

Docnum IDOC number

Status ‘53’

Return_Variables: table must contain following entries:

Entry Wf_param Doc_number

1 ‘Processed IDoc’ Idoc number

2 ‘Appl_Objects’ Appl.Object number

Thanks

Eswar

Read only

0 Likes
834

Hi,

The sudo code for inbound one is as follows


FUNCTION Z_IDOC_INPUT_EMPMAST.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(INPUT_METHOD) LIKE  BDWFAP_PAR-INPUTMETHD
*"     REFERENCE(MASS_PROCESSING) LIKE  BDWFAP_PAR-MASS_PROC
*"  EXPORTING
*"     REFERENCE(WORKFLOW_RESULT) LIKE  BDWFAP_PAR-RESULT
*"     REFERENCE(APPLICATION_VARIABLE) LIKE  BDWFAP_PAR-APPL_VAR
*"     REFERENCE(IN_UPDATE_TASK) LIKE  BDWFAP_PAR-UPDATETASK
*"     REFERENCE(CALL_TRANSACTION_DONE) LIKE  BDWFAP_PAR-CALLTRANS
*"  TABLES
*"      IDOC_CONTRL STRUCTURE  EDIDC
*"      IDOC_DATA STRUCTURE  EDIDD
*"      IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"      RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"      SERIALIZATION_INFO STRUCTURE  BDI_SER
*"  EXCEPTIONS
*"      WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

  DATA: S_EMPMAST LIKE ZEMPMASTHEADERSEG.
  DATA: T_EMPMAST LIKE ZEMPMASTSEG OCCURS 0 WITH HEADER LINE.
  DATA: WA_EMPMAST LIKE ZEMPMAST.

  DATA: L_FLAG VALUE 'Y'.
  CLEAR S_EMPMAST.
  REFRESH T_EMPMAST.


* check if the function is called correctly                            *
  IF IDOC_CONTRL-MESTYP <> 'ZEMPMSG'.
    RAISE WRONG_FUNCTION_CALLED.
  ENDIF.

  WORKFLOW_RESULT = 0.

* Unpacking the IDoc
  LOOP AT IDOC_DATA.
    CASE IDOC_DATA-SEGNAM.
      WHEN 'ZEMPMASTHEADERSEG'.
        MOVE IDOC_DATA-SDATA TO S_EMPMAST.
      WHEN 'ZEMPMASTSEG'.
        MOVE IDOC_DATA-SDATA TO T_EMPMAST.
        APPEND T_EMPMAST.
    ENDCASE.
  ENDLOOP.


  IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
  IDOC_STATUS-MSGV1 = IDOC_CONTRL-IDOCTP.
  IDOC_STATUS-MSGID = '00'.
  IDOC_STATUS-MSGNO = '398'.

  LOOP AT T_EMPMAST.
    MOVE-CORRESPONDING  T_EMPMAST TO WA_EMPMAST.
    INSERT INTO ZEMPMAST VALUES WA_EMPMAST.
    G_OKCODE = SY-SUBRC.


    IF G_OKCODE <> 0.
      L_FLAG = 'N'.

      IDOC_STATUS-STATUS = '51'.
      IDOC_STATUS-MSGTY = 'E'.
      IDOC_STATUS-MSGV2 = 'Employee & already exists'.
      REPLACE '&' WITH WA_EMPMAST-EMPNO INTO IDOC_STATUS-MSGV2.
      IDOC_STATUS-SEGNUM = SY-TABIX + 1.
      APPEND IDOC_STATUS.

    ENDIF.

    AT LAST.

    ENDAT.
  ENDLOOP.



  IF L_FLAG <> 'Y'.
    CLEAR RETURN_VARIABLES.
    RETURN_VARIABLES-WF_PARAM   = 'Error_IDOCs'.
    RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
    APPEND RETURN_VARIABLES.
    WORKFLOW_RESULT = '99999'.

    ROLLBACK WORK.
  ELSE.
    IDOC_STATUS-STATUS = '53'.
    IDOC_STATUS-MSGTY = 'S'.
    IDOC_STATUS-MSGV2 = 'Employee Info inserted'.
    APPEND IDOC_STATUS.

  ENDIF.

ENDFUNCTION.