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 populate the data in custom table through an inbound idoc?

Former Member
0 Kudos

i have made the code according to that but it is populating the duplicate data .

idoc struct 1 header (A) with 2 child segments (B and C)

while populate one entry in each segment, it is making one entry in table as per the requirement.

but when i am giving 2 entries in child segment B it should populate 2 entries in Ztable

instead of that 2 entries it is populating 3 entries which the 3rd entry has no data.

LOOP AT idoc_contrl ASSIGNING FIELD-SYMBOL(<ls_idoc_contrl>).

    IF <ls_idoc_contrl>-mestyp NE 'mestyp'.

      RAISE wrong_function_called.

    ENDIF.

* Before reading a new entry, clear application buffer.

    LOOP AT idoc_data[] ASSIGNING FIELD-SYMBOL(<ls_idoc_data>)

                      WHERE docnum EQ idoc_contrl-docnum.

case segmname

when segA

ls_tablefield1 = ls_idocsegfield1,

ls_tablefield2 = ls_idocsegfield2,

ls_tablefield3 = ls_idocsegfield3,

ls_tablefield4 = ls_idocsegfield4,

when segB

ls_tablefield5 = ls_idocsegfield5,

ls_tablefield6 = ls_idocsegfield6,

when segC

ls_tablefield7 = ls_idocsegfield7,

ls_tablefield8 = ls_idocsegfield8,

endcase.

modify  Ztable from ls_idocsegfiled

commit work.

      IF sy-subrc EQ 0.

        lv_edi_status = '53'.

      ELSE.

        lv_edi_status = '51'.

      ENDIF.

endloop.

endloop.

can any one tell what wrong in this code.

8 REPLIES 8

rajkumarnarasimman
Active Contributor
0 Kudos

Hi Akky,

I found issues in the coding, kindly do not add modify statement inside the Loop.  Create the internal table for the Z-table. Update the internal table inside the Loop.

After the Outer loop statement, update Z-table using Internal table instead of Work area.

Before updating the table, you can check with condition, whether we have the entry(IS NOT INITIAL) in Table/work area.

As per the above code, I think the work area LS_DOCSEGFILED is not updating.

Kindly check the same in debugger


ls_tablefield8 = ls_idocsegfield8,

endcase.

modify  Ztable from ls_idocsegfiled

Regards

Rajkumar Narasimman

0 Kudos

hi rajkumar,

ls_docsegfield is updating,

may be the modify is making issue.

could you please elaborate or tell how to update the custom table with any syntax.

because i used Update Ztable set: fields but it is not updating.

if you provide code detailed from the code i mentioned, it would be really helpful.

0 Kudos

Hi Akky,

Please find the sample code for modify statement.


REPORT zscreen03.

PARAMETERS p_carrid TYPE scarr-carrid.

DATA scarr_tab TYPE SORTED TABLE OF scarr

                WITH UNIQUE KEY carrid.

DATA scarr_wa TYPE scarr.

SELECT *

        FROM scarr

        INTO TABLE scarr_tab.

READ TABLE scarr_tab INTO scarr_wa

      WITH TABLE KEY carrid = p_carrid.

scarr_wa-currcode = 'EUR'.

"Update the Internal Table

MODIFY TABLE scarr_tab FROM scarr_wa

        TRANSPORTING currcode.

"Check whether internal table have value

IF SCARR_TAB[] IS NOT INITIAL.

"Update the Ztable using Table instead of Work Area

MODIFY scarr FROM TABLE scarr_tab.


COMMIT WORK.

ENDIF.

I hope, if you debug the above program, you can understand how the modify statement works.

Regards

Rajkumar Narasimman

0 Kudos

hi rajkumar,

i have tried as you said but same result

0 Kudos

Please share the full program code.

0 Kudos

LOOP AT idoc_contrl ASSIGNING FIELD-SYMBOL(<ls_idoc_contrl>).

    IF <ls_idoc_contrl>-mestyp NE 'mestyp'.

      RAISE wrong_function_called.

    ENDIF.

* Before reading a new entry, clear application buffer.

    LOOP AT idoc_data[] ASSIGNING FIELD-SYMBOL(<ls_idoc_data>)

                      WHERE docnum EQ idoc_contrl-docnum.

case segmname

when segA

ls_tablefield1 = ls_idocsegfield1,

ls_tablefield2 = ls_idocsegfield2,

ls_tablefield3 = ls_idocsegfield3,

ls_tablefield4 = ls_idocsegfield4,

when segB

ls_tablefield5 = ls_idocsegfield5,

ls_tablefield6 = ls_idocsegfield6,

when segC

ls_tablefield7 = ls_idocsegfield7,

ls_tablefield8 = ls_idocsegfield8,

endcase.

      MODIFY TABLE lt_tableFROM ls_table

      IF sy-subrc EQ 0.

        lv_edi_status = '53'.

      ELSE.

        lv_edi_status = '51'.

      ENDIF.

endloop.

endloop.

*  IF lt_table[] IS NOT INITIAL.

*

*    MODIFY ztabel FROM TABLE lt_table.

*

*    COMMIT WORK.

*

*  ENDIF.

0 Kudos

Hi Akky,

I requested  the Full code for understanding.

Anyway as per my understanding, i have done the following changes, hope it will work.

DATA: l_flag type i value 0.

  LOOP AT idoc_data[] ASSIGNING FIELD-SYMBOL(<ls_idoc_data>)

                      WHERE docnum EQ idoc_contrl-docnum.

l_flag = 0.

case segmname

when segA

ls_tablefield1 = ls_idocsegfield1,

ls_tablefield2 = ls_idocsegfield2,

ls_tablefield3 = ls_idocsegfield3,

ls_tablefield4 = ls_idocsegfield4,

l_flag = 1.

when segB

ls_tablefield5 = ls_idocsegfield5,

ls_tablefield6 = ls_idocsegfield6,

l_flag = 1.

when segC

ls_tablefield7 = ls_idocsegfield7,

ls_tablefield8 = ls_idocsegfield8,

l_flag = 1.

endcase.

if l_flag = 1. 

      MODIFY TABLE lt_table FROM ls_table

      IF sy-subrc EQ 0.

        lv_edi_status = '53'.

      ELSE.

        lv_edi_status = '51'.

      ENDIF.

endif.

endloop.

endloop.

"Sort the internal table by using some key

SORT LT_TABLE BY <FIELD_NAME>.

"Delete the adjacent duplicates

DELETE ADJACENT DUPLICATES FROM LT_TABLE COMPARING <FIELD_NAME>.


"Also delete the empty value

DELETE LT_TABLE WHERE <FIELD_NAME> = ''.


   IF lt_table[] IS NOT INITIAL.

    MODIFY ztabel FROM TABLE lt_table.

    COMMIT WORK.

  ENDIF.

If you face the problem still, kindly share the full program with debugger screenshots that will help for better understanding.

Regards

Rajkumar Narasimman

0 Kudos

probably clearing the work area ls_table before start of case statement will solve your problem.