Requirement

There is a need to send Material movement, in my example Goods Receipt(101) to external system. Usually it’s third party WMS/MES system.

Prerequisite

Developer key/somebody who can develop the “semi” part for you. Knowledge of distribution model maintenace. Basic BAPI knowledge. Understanding of TA NACE – setup of output types for the applications, here specificly for ME.

Solution

I’ve searched like many others(i guess) google and scn network and I’ve soon realized that there is no standard procedure to send out GR. However I’ve learned semi-standard way to implementing it using standard BAPI and custom trigger/print program. This is my post, hope you’ll like it 😉


First there we need to generate IDOC type and message type out of standard BAPI BAPI_GOODSMVT_GETDETAIL.

BAPI Explorer GoodsMovement.GetDetail 01.png

Open from menu ‘Environment’ and select Generate ALE interface:

BAPI Explorer GoodsMovement.GetDetail 02.png

Transaction BDBG with prefilled screen parameters will open:

BAPI Explorer GoodsMovement.GetDetail 03.png

Press/select ‘Create(F5)’ and wizard popup will open:

BAPI Explorer GoodsMovement.GetDetail 04.png

Rename or at least add custom namespace Z/Y or your own registered one in fields:

IDoc type

Package(development class)

(Outbound) Function Module

(Outbound) Function Group

(Inbound) Function Module

(Inbound) Function Group(I recommend to use the same as for Outbound)

Additionally decide if you want to allow “Data Filtering” from distribution model.

Check boxes in Inbound part of popup are not relevant for this specific case and we keep them in default state. They may be however interesting for somebody who wants to use BAPI ALE interface for receiving IDOC’s. That’s usually not the case for any “Get” method/BAPI but rather for some “Create/Change/Post” etc. methods.

If everything went well, you have generated your IDOC type and message type and function module to fill and send the IDOC. Easy right? Let’s setup distribution model for it(BD64):

BAPI Explorer GoodsMovement.GetDetail 05.png

Now the semi-auto part from my post title – little bit of Abap is required.

Create a copy of program RSNASTED called e.g. ZRSNASTED_BAPIEXT.

Open new program in ABAP editor and put following lines under last INCLUDE command:

* Extention for BAPI’s

*———————————————————————*
*———————————————————————*
*       FORM ALE_PROCESSING_BAPI                                      *
*———————————————————————*
*       entry-point used from program RSNASTED for medium ‘A’         *
*———————————————————————*
*  –>  US_SCREEN for use in future                                   *
*  <–  RC      returncode                                            *
*———————————————————————*
FORM ALE_PROCESSING_BAPI USING RC
US_SCREEN
.                        “#EC CALLED
DATA: FLAG LIKE TCESYSTDEVTYPE.

RC = 1.
* set the value for basic_system   ‘S’ basic, ‘A’ application
*vh  PERFORM RSEBASIS_DEVTYPE(RSEBSCHK) USING FLAG.
CALL FUNCTION ‘FUNCTION_EXISTS’
EXPORTING
FUNCNAME          
= NAST_UPDATE
EXCEPTIONS
FUNCTION_NOT_EXIST
= 1
OTHERS             = 2.
IF SYSUBRC <> 0.
BASIC_SYSTEM
= ‘S’.
ELSE.
BASIC_SYSTEM
= ‘A’.
ENDIF.

ERROR_IN_LINK = ‘ ‘.

HELP_OBJECT_TYPE = SPACE.

CASE NASTOBJTYPE.
WHEN ‘MSEG’. “Material document – goods movement
PERFORM goods_movement_out
USING nast
CHANGING RC.
WHEN ‘ABCD’. “Dummy
WHEN OTHERS. ” Should not happened but …

ENDCASE.

ENDFORM.
*&———————————————————————*
*&      Form  GOODS_MOVEMENT_OUT
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_NAST  text
*———————————————————————-*
FORM GOODS_MOVEMENT_OUT
USING    IS_NAST LIKE nast
CHANGING IV_RC TYPE I.
DATA:
lt_filterobj_values
like bdi_fobj occurs 0,
lt_filterobj_types
like bdi_fobjtype occurs 0,
lt_bapi_logsys
like bdi_logsys occurs 0.
DATA:
lv_materialdocument
TYPE bapi2017_gm_head_02mat_doc,
lv_matdocumentyear
TYPE bapi2017_gm_head_02doc_year,
ls_goodsmvt_header
TYPE bapi2017_gm_head_02,
lt_goodsmvt_items
TYPE TABLE OF bapi2017_gm_item_show,
lt_return
TYPE TABLE OF bapiret2.

* Get Material document number from NAST structure
lv_materialdocument
= is_nastobjky(10).
lv_matdocumentyear
= is_nastobjky+10(4).

* get receiver from ALE distribution model
CALL FUNCTION ‘ALE_ASYNC_BAPI_GET_RECEIVER’
EXPORTING
object                  
= ‘BUS2017’
method                   = ‘GETDETAIL’
TABLES
receivers               
= lt_bapi_logsys
filterobject_values     
= lt_filterobj_values
EXCEPTIONS
error_in_filterobjects  
= 1
error_in_ale_customizing
= 2.

* call generated ALE interface function module
if sysubrc = 0.
if not lt_bapi_logsys[] is initial.
*     Get GoodsMovement data
CALL FUNCTION ‘BAPI_GOODSMVT_GETDETAIL’
EXPORTING
MATERIALDOCUMENT      
= lv_materialdocument
MATDOCUMENTYEAR       
= lv_matdocumentyear
IMPORTING
GOODSMVT_HEADER       
= ls_goodsmvt_header
TABLES
GOODSMVT_ITEMS        
= lt_goodsmvt_items
RETURN                 = lt_return
.

*     TODO: Deal with errors, put some logic here, use nast_protocol
*           Use form FILL_NAST_PROTOCOL_IDOC from standard RSNASTED include.

* Send out to receivers in case there are no errors reading GoodsMovement
CALL FUNCTION ‘ZALE_GOODSMVT_GETDETAIL’
EXPORTING
MATERIALDOCUMENT             
= lv_materialdocument
MATDOCUMENTYEAR              
= lv_matdocumentyear
OBJ_TYPE                     
= ‘BUS2017’
SERIAL_ID                    
= ‘0’
TABLES
GOODSMVTITEMS                
= lt_goodsmvt_items
RECEIVERS                    
= lt_bapi_logsys
*         COMMUNICATION_DOCUMENTS       =
*         APPLICATION_OBJECTS           =
EXCEPTIONS
ERROR_CREATING_IDOCS         
= 1
OTHERS                        = 2
.
IF SYSUBRC <> 0.
*       TODO: Implement suitable error handling here – also the nast_protocol?
ELSE.
IV_RC
= 0. ” Everything was probably ok.
ENDIF.

endif.
endif.
ENDFORM.                   
” GOODS_MOVEMENT_OUT

Note: The program was extended to provide the basic functionality but exceptional cases are not handled so please feel free to fill gaps where TODO: is.

Activate the program and if successful continue with customizing(yeah, almost there!).

Create new Output Type for application ‘ME’. Example:

BAPI Explorer GoodsMovement.GetDetail 06.png

Detail

BAPI Explorer GoodsMovement.GetDetail 07.png

Note: JRMG is just one of the options for access sequence(condition table). If more criteria are needed, different access sequence can be picked/created.


Are u ready for it? Here is the conclusion!


Setup the Processing routine. This is where we the copy of RSNASTED is to be used:

BAPI Explorer GoodsMovement.GetDetail 08.png

Now it’s just standard customizing in TA NACE.

Set partner functinon.

BAPI Explorer GoodsMovement.GetDetail 09.png

Optional step – setup condition records for the newly created output type if needed.

BAPI Explorer GoodsMovement.GetDetail 10.png

Test

Create new Goods Receipt and check if output IDOC was created. Manual test from existing Goods Movement is also possible from MB02:

BAPI Explorer GoodsMovement.GetDetail 11.pngBAPI Explorer GoodsMovement.GetDetail 12.png

Output IDOC should be generated like in my case:

BAPI Explorer GoodsMovement.GetDetail 13.png

It should fail since we did not maintain Partner Profiles. This part I’ll leave to you since it’s easy and out of this topic.

I hope you find this article useful. Thanks for stopping by 🙂

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Adrián Mejido

    Good document!!

    But why you don’t use the badi implementation and in the method POST call the idoc generation?? In my opinion it might be easier than your solution.

    Best Regards

    (0) 
    1. Martin Dejl Post author

      Hi Adrián,

      I see your point. You’d rather just call the ‘ZALE_GOODSMVT_GETDETAIL’ function from the badi. I think for most cases it would be enough. But using NACE gives you more tracking options and possible error resolution options. You can, for example, repeat just the output(regenerate the IDOC). With badi you have only one shot. That’s why I called it “almost standard way”. It’s implementation including output management features.

      Thanks for stopping by and your opinion,

      Martin

      (0) 

Leave a Reply