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

about IDOC

former_member577909
Participant
0 Likes
632

How to send data [ records ]to a perticular segment's field in an IDOC.

How to send data [ records ]to a perticular segment's field in an IDOC.

3 REPLIES 3
Read only

Former Member
0 Likes
588

Hi,

Try with this simple example.

*If segment is E1KNVP fill the custom segment Z1KNVP.

WHEN gc_e1knvpm.

e1knvpm = idoc_data-sdata.

IF e1knvpm-kunn2 IS NOT INITIAL.

*Get Partner Function Customer name(KNVP-KUNN2).

SELECT SINGLE name1

FROM kna1

INTO gs_knvp-name1

WHERE kunnr = e1knvpm-kunn2.

IF sy-subrc EQ 0.

ENDIF.

ENDIF.

*Get Partner Function Description

IF e1knvpm-parvw IS NOT INITIAL.

SELECT SINGLE vtext

FROM tpart

INTO gs_knvp-partner_fun_des

WHERE spras EQ gc_en AND

parvw EQ e1knvpm-parvw.

IF sy-subrc EQ 0.

ENDIF.

ENDIF.

*Fill the custom segment Z1KNVP.

z1knvp = gs_knvp.

gs_idoc_data-segnam = gc_z1knvp.

gs_idoc_data-sdata = z1knvp.

APPEND gs_idoc_data TO idoc_data.

CLEAR: gs_idoc_data,

gs_knvp.

Read only

Clemenss
Active Contributor
0 Likes
588

Hi,

IDOCs are transported as unstructured character records. IDOC records have a segment name segnam and a data part sdata.

If you want to access a particular segment field, the best way is to transfer the data stored in sdata to a structured field with the actual segment's structure. Then you can access it by name, store a value and tranport it back into sdata.

If you are familiar with field-symbols, you can speed up the process a lot, see this symbolic code:

field-symbols: 
  <segment> type any,
  <field>        type any.

assign [sdata](segment_length) to <segment> casting type (segment).
assign component (field) of structure <segment> to <field>.
<field> = [value].

This will maintain the value directly in the sdata part of the idoc segment data record. Especially in mass processing, you will gain 1000 % speed because nothging is copied back and forth.

Regards,

Clemens

Read only

abdul_hakim
Active Contributor
0 Likes
588

hi

for standard SAP program you dont need to worry about filling the segments with data

but for your customized program you need to fill it.

Jus go thru the book "ALE/EDI and IDoc Technologies for SAP" By Arvind Nagpal.

You can gain tons of knowledge from it..

Cheers,

Abdul Hakim