Application Development 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: 

How to restrict Standard/Custom Segment triggering from Multiple Times

yarnagula_sudhir
Active Participant
0 Kudos

Hi,

Find the piece of code below as per my requirement regarding adding Idoc Zsegments and fields.

Its working fine.

*Getting the Delivery Document Number and assigning it to the Where Clause

FIELD-SYMBOLS: <FS_EDIDD> TYPE EDIDD.

READ TABLE IDOC_DATA ASSIGNING <FS_EDIDD> WITH KEY SEGNAM = 'E1EDL20'.

IF <FS_EDIDD> IS ASSIGNED.

   LS_E1EDL20 = <FS_EDIDD>-SDATA.      "Delivery Document Number

ENDIF.

*1*Fetching the respective fields for IDoc: Delivery header

SELECT SINGLE VBELN LIFNR ZZASNNO ZZINVOIVE_NO ZZREASON FROM LIKP INTO LS_LIKP WHERE VBELN = LS_E1EDL20-VBELN.

CHECK SY-SUBRC = 0.

*1****************************************Delivery header******************************1

READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam = 'E1EDL20'.   "Custom Segment Position

CHECK SY-SUBRC = 0.

lv_tabix = sy-tabix + 1.

CONCATENATE LS_LIKP-ZZASNNO+0(20) LS_LIKP-ZZINVOIVE_NO+0(10) LS_LIKP-ZZREASON+0(20) INTO lv_sdata1.

ls_edidd-sdata = lv_sdata1.

ls_edidd-segnam = co_E1EDL20.

INSERT ls_edidd INTO IDOC_DATA INDEX lv_tabix.

CHECK sy-subrc = 0.

CLEAR: LS_LIKP,

        lv_sdata1,

        ls_edidd.


Doubt: As Respective "Include -   zxtrku02" is triggering multiple times and so my "segment E1EDL20"/Zsegment ZE1EDL20.


How to restrict my standard segment E1EDL20 and its custom segment ZE1EDL20 from triggering mutiple times.

Kindly let me know ASAP.

Idoc Details:

Message Type: DESADV

Basic Type: DELVRY03

Outbound Process Code: DELV

Output Type: OPOD

Function Module - IDOC_OUTPUT_DELVRY

Customer Exit - customer-function '002'

FM Exit name - EXIT_SAPLV56K_002

Include -   zxtrku02

With Regards,

Sudhir.

1 ACCEPTED SOLUTION

yarnagula_sudhir
Active Participant
0 Kudos

As standard segment E1EDL20 and its custom segment ZE1EDL20 triggering mutiple times, the following is the Idoc generated.

Zsegment is adding multiple times. How to restrict it.

With Regards,

Sudhir.

15 REPLIES 15

yarnagula_sudhir
Active Participant
0 Kudos

As standard segment E1EDL20 and its custom segment ZE1EDL20 triggering mutiple times, the following is the Idoc generated.

Zsegment is adding multiple times. How to restrict it.

With Regards,

Sudhir.

0 Kudos

HI Sudhir,

In WE30, set the min and max both as 1 for your zsegment. then it`s a structure, not a itab.

regards,

Archer

0 Kudos

Hi Sudhir,

This exit will trigger for all the segments. In the exit you will see a importing parameter 'SEGMENT_NAME'.

Put the entire logic of yours when the segment name is E1EDL20. This will make it run only once.

Hopefully this will hep you.

Regards,

Aashika

0 Kudos

Can you elaborate more. Where should i change my code. 

My requirement is use to get all the standard segments and my custom segment should trigger once.

But where ever i'm adding Zsegments, its triggering multiple times.

Kindly let me know ASAP.

With Regards,

Sudhir.

0 Kudos

Hi Sudhir,

Since the previous thread is already completed, hence responding on the new one.


SCENARIO 1

SEGMENT_NAME is already declared in Function module as EDIDD-SEGNAM.

You need to use it in your include. Using below code, the customer exit 002 will be called only when segment E1EDL20 is called. For other segments, the same exit is called but due to this check, the code wont be executed and your functionality will be achieved.

IF segment_name = 'E1EDL20'.

     "Your entire piece of code

ENDIF.

SCENARIO 2

If E1EDL20 segment is being triggered multiple times, then please use below code. (Though this scenario might not happen)

IF segment_name = 'E1EDL20'.

READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam = 'ZE1EDL20'.   "Custom Segment

IF sy-subrc = 0.

     EXIT.

ELSE.

     "Your entire piece of code

ENDIF.

ENDIF.

Regards,

Aashika

0 Kudos

Hi,

Thank you so much, your previous logic is working. But some issues.

Scenario 1: Single Segment and Single Values. Working Fine.

Scenario 2: Second Segment and Multiple Line Items. Second Line Item Value/Segment is Missing.

Missing ZSegment

Kindly let me know how to get the above missing Zsegment with its respective field.

Where should i change my code.

With Regards,

Sudhir.

0 Kudos

Hi,

Its not working because you have put an EXIT if the Z segment is already present.

I guess your requirement is - segment E1EDL24 will come multiple times and with it the ZE1EDL24 should also come.

If you want it to come as many times as E1EDL24, then EXIT should be removed.

Also to insert Z segment, i guess LOOP idoc_data is not required. IDOC_DATA must have data only till E1EDL24, so you can just append Zsegment to it.

Regards,

Aashika

0 Kudos

Hi,

Yes! If i remove the following piece of code/EXIT

IF segment_name = 'E1EDL24'.

READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam = 'ZE1EDL24'.   "Custom Segment

IF sy-subrc = 0.

     EXIT.

ELSE.

     "Your entire piece of code

ENDIF.

ENDIF.

Then the same Zsegment is adding multiple times on the First Segment 'E1EDL24' as shown below.

But my requirement is: 1st round

                                         'E1EDL24'

                                         'ZE1EDL24'


                                          2nd round

                                         'E1EDL24'

                                         'ZE1EDL24'

Kindly let me know the solution.

With Regards,

Sudhir.

0 Kudos

please re insert the image since its not visible for better understanding of the issue.

Regards,

Aashika

0 Kudos

Hi,

Yes! If i remove the following piece of code/EXIT

IF segment_name = 'E1EDL24'.

READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam = 'ZE1EDL24'.   "Custom Segment

IF sy-subrc = 0.

     EXIT.

ELSE.

     "Your entire piece of code

ENDIF.

ENDIF.

Then the same Zsegment is adding multiple times on the First Segment 'E1EDL24' as shown below.

But my requirement is: 1st round

                                         'E1EDL24'

                                         'ZE1EDL24'


                                          2nd round

                                         'E1EDL24'

                                         'ZE1EDL24'

Kindly let me know the solution.

With Regards,

Sudhir.

0 Kudos

Hi,

Can you kindly help me with the below code:

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

IF segment_name = 'E1EDL24'.

   READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam = co_E1EDL24.

   IF SY-SUBRC = 0.

     EXIT.

   ELSE.

     LOOP AT IDOC_DATA INTO ls_edidd WHERE segnam = 'E1EDL24'.     "Custom Segment Position

       lv_tabix = sy-tabix + 1.

       LOOP AT LT_LIPS INTO LS_LIPS.

         ls_edidd-sdata = LS_LIPS-ZZSRNO.

         ls_edidd-segnam = co_E1EDL24.

         INSERT ls_edidd INTO IDOC_DATA INDEX lv_tabix.

         CHECK sy-subrc = 0.

         DELETE TABLE lt_LIPS FROM ls_LIPS.

         CHECK SY-SUBRC = 0.

         CLEAR: ls_edidd.

         EXIT.

       ENDLOOP.

     ENDLOOP.

   ENDIF.

ENDIF.

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


With Regards,

Sudhir.

0 Kudos

Hi Sudhir,

1. Never delete a table on which a loop is running. In your piece of code, LT_LIPS is looped through and its being deleted also which is not correct.

Also if you are inserting a Z segment within a LT_LIPS loop, then Z segment will repeat for one E1EDL24 as many times as you have line items in LT_LIPS.

I would suggest that instead of looping through LT_LIPS, READ the table LT_LIPS. E1EDL24 also has LIPS data. Just read data on the basis of document number number and line item and pick ZZSRNO field from LT_LIPS.

2. Instead of looping at IDOC_DATA, just append the required data of Z segment in it. IDOC_DATA is a table with header line so the current data of E1EDL24 can be accessed from its work area directly. Please try this and also u can check the header line data of IDOC_DATA in debugging.

Regards,

Aashika

0 Kudos

Hi,

Note 1: The behavior varies from one FM Exit/Include to other FM Exit/Include.


Example: In my previous object or include, when ever my include code triggers, i can see all the standard segments at once under IDOC_DATA. so i can add the zsegments easily.

But in this present scenario, when ever my include code triggers, i can see the segments one by one. Segment one appears, cursor comes out of the include, cursor goes inside, segment two comes, again comes out and in, segment three comes.

So i'm unable to set tabix value and insert multiple line item values.


2. Note 2: There is a reason i went for LOOP AT LT_LIPS. I have to insert multiple line item values. Through READ TABLE i cannotachieve second line item values.


I went for DELETE  LT_LIPS because when the first line item values been inserted, i will delete first line item and next time second line item values been inserted. cause i cannot do that through READ TABLE.

The following code works fine for multiple line items, only if i get all the segments at once.

With Regards,

Sudhir.

0 Kudos

Hi,

Kindly see the above reply of mine.

The following is the code for Single Line Item

*2*Fetching the respective fields for IDoc: Delivery Item

SELECT SINGLE VBELN

                           POSNR

                           ZZSRNO FROM LIPS

                                          INTO LS_LIPS

                                          WHERE VBELN = LS_E1EDL20-VBELN.

CHECK SY-SUBRC = 0.

*Single Line Item

*2****************************************Delivery Item******************************2

IF segment_name = 'E1EDL24'.

   READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam =co_E1EDL24.

   IF SY-SUBRC = 0.

     EXIT.

   ELSE.

     READ TABLE IDOC_DATA INTO ls_edidd WITH KEY segnam ='E1EDL24'.

     check sy-subrc = 0.

     lv_tabix = sy-tabix + 1.

     ls_edidd-sdata = LS_LIPS-ZZSRNO.

     ls_edidd-segnam = co_E1EDL24.

     INSERT ls_edidd INTO IDOC_DATA INDEX lv_tabix.

     CHECK sy-subrc = 0.

     CLEAR: ls_lips,

            ls_edidd.

   ENDIF.

ENDIF.


Kindly Modify the above code for multiple line items regarding to my requirement. Kindly Modify and send me back.

Requirement: XXXXXXX

                          XXXXXXX

                         E1EDL24

                         ZE1EDL24     001

                         XXXXXX

                   XXXXXXX

                   E1EDL24    

                         ZE1EDL24      002

With Regards,

Sudhir.

0 Kudos

Hi Sudhir,

As mentioned by you, the exit where its present varies and hence their nature varies.

One exit is called when idoc_data is filled completely while other is called at every step while its being filled.

As far as the logic is concerned, I would suggest you to check the behavior of your code in debugging and then rectify it. The exit will help you to insert Z segments as many times as per your requirement. Also you might take help from any senior technical consultant since now it only involves correct insertion of your code. Me writing the code again in forum would not be of much help.

Regards,

Aashika