SAP ABAP - Populating IDOC-Segments Based On Partner Function.

This is a sample include program used to populate idoc segments based on the partner functions:


*&----------------------------------------------------------------------------*
*& Include ZTEST_IDOC_SEGMENTS_POPULATE
*&----------------------------------------------------------------------------*

CONSTANTS: lc_e1edka1(7) TYPE C VALUE 'E1EDKA1',
lc_e1edk01(7) TYPE C VALUE 'E1EDK01',
lc_e1edp19(7) TYPE C VALUE  'E1EDP19',
lc_z1maktx(7) TYPE C VALUE  'Z1MAKTX',
lc_e1eds01(7) TYPE C VALUE  'E1EDS01',
lc_e1edk02(7) TYPE C VALUE  'E1EDK02',
lc_ze1edka1_adr(12) TYPE C VALUE  'ZE1EDKA1_ADR',
lc_sp(2)TYPE C VALUE 'SP',            "Carrier Partner Function
lc_re(2) TYPE C VALUE 'RE',
lc_ag(2) TYPE C VALUE 'AG',
lc_we(2) TYPE C VALUE 'WE',
lc_045(3) TYPE C VALUE '045'.

DATA: lv_cnt TYPE sy-tabix,
lv_init TYPE i,
lv_diff TYPE i,
lv_curr TYPE i,
lv_adrnr TYPE adrc-addrnumber,
lwa_ze1edka1_adr TYPE ze1edka1_adr,
lwa_e1edp19 TYPE e1edp19,
lwa_z1maktx TYPE z1maktx,
lwa_e1eds01 TYPE e1eds01,
lv_hu_cnt TYPE i,
li_edidd_tmp TYPE STANDARD TABLE OF edidd.

IF control_record_out-cimtyp EQ lc_cimtyp1
AND control_record_out-mestyp EQ lc_mestyp1.

* POPULATE TRANSPORTATION TYPE

LOOP AT int_edidd ASSIGNING WHERE segnam = lc_e1edk01.
lwa_e1edk01 = -sdata.

SELECT SINGLE vsbed INTO lwa_e1edk01-vsart FROM vbrk
WHERE vbeln = lwa_e1edk01-belnr.

-sdata = lwa_e1edk01.
MODIFY int_edidd FROM.
ENDLOOP.

CLEAR: lv_init, lv_diff, lv_curr.
DESCRIBE TABLE int_edidd LINES lv_init.

li_edidd_tmp[] = int_edidd[].

DESCRIBE TABLE li_edidd_tmp LINES lv_curr.
lv_diff = lv_curr - lv_init.

LOOP AT int_edidd ASSIGNING
WHERE segnam = lc_e1edka1 OR segnam = lc_e1edp19.

CLEAR lwa_ze1edka1_adr.

IF -segnam = lc_e1edka1.
lwa_e1edka1 = -sdata.

* POPULATE SCACD CODE FOR PARTNER FUNCTION SP

IF lwa_e1edka1-parvw = lc_sp.
SELECT SINGLE scacd INTO lwa_ze1edka1_adr-scacd FROM lfa1
WHERE lifnr = lwa_e1edka1-partn.

IF lwa_ze1edka1_adr-scacd IS NOT INITIAL.
lv_cnt = sy-tabix + lv_diff + 1.
lwa_edidd-segnam = lc_ze1edka1_adr.
lwa_edidd-sdata = lwa_ze1edka1_adr.

INSERT lwa_edidd INTO li_edidd_tmp INDEX lv_cnt.
ENDIF.
ENDIF.

DESCRIBE TABLE li_edidd_tmp LINES lv_curr.
lv_diff = lv_curr - lv_init.
CLEAR lv_cnt.

* POPULATE ADDRESS DETAILS FOR PARTNER FUNCTION RE

IF lwa_e1edka1-parvw = lc_re.
CLEAR: lv_adrnr, lwa_ze1edka1_adr.

SELECT SINGLE adrnr INTO lv_adrnr FROM kna1
WHERE kunnr = lwa_e1edka1-partn.

SELECT SINGLE str_suppl2 str_suppl3
INTO (lwa_ze1edka1_adr-zstreet3, lwa_ze1edka1_adr-zstreet4)
FROM adrc WHERE addrnumber = lv_adrnr.

IF lwa_ze1edka1_adr IS NOT INITIAL.
lv_cnt = sy-tabix + lv_diff + 1.
lwa_edidd-segnam = lc_ze1edka1_adr.
lwa_edidd-sdata = lwa_ze1edka1_adr.

INSERT lwa_edidd INTO li_edidd_tmp INDEX lv_cnt.
ENDIF.
ENDIF.

DESCRIBE TABLE li_edidd_tmp LINES lv_curr.
lv_diff = lv_curr - lv_init.
CLEAR lv_cnt.

* POPULATE ADDRESS DETAILS FOR PARTNER FUNCTION AG

IF lwa_e1edka1-parvw = lc_ag.
CLEAR: lv_adrnr, lwa_ze1edka1_adr.

SELECT SINGLE adrnr INTO lv_adrnr FROM kna1
WHERE kunnr = lwa_e1edka1-partn.

SELECT SINGLE str_suppl2 str_suppl3
INTO (lwa_ze1edka1_adr-zstreet3, lwa_ze1edka1_adr-zstreet4)
FROM adrc WHERE addrnumber = lv_adrnr.

IF lwa_ze1edka1_adr IS NOT INITIAL.
lv_cnt = sy-tabix + lv_diff + 1.
lwa_edidd-segnam = lc_ze1edka1_adr.
lwa_edidd-sdata = lwa_ze1edka1_adr.

INSERT lwa_edidd INTO li_edidd_tmp INDEX lv_cnt.
ENDIF.
ENDIF.

DESCRIBE TABLE li_edidd_tmp LINES lv_curr.
lv_diff = lv_curr - lv_init.
CLEAR lv_cnt.


* POPULATE ADDRESS DETAILS FOR PARTNER FUNCTION WE

IF lwa_e1edka1-parvw = lc_we.
CLEAR: lv_adrnr, lwa_ze1edka1_adr.

SELECT SINGLE adrnr INTO lv_adrnr FROM kna1
WHERE kunnr = lwa_e1edka1-partn.

SELECT SINGLE str_suppl2 str_suppl3
INTO (lwa_ze1edka1_adr-zstreet3, lwa_ze1edka1_adr-zstreet4)
FROM adrc WHERE addrnumber = lv_adrnr.

IF lwa_ze1edka1_adr IS NOT INITIAL.
lv_cnt = sy-tabix + lv_diff + 1.
lwa_edidd-segnam = lc_ze1edka1_adr.
lwa_edidd-sdata = lwa_ze1edka1_adr.

INSERT lwa_edidd INTO li_edidd_tmp INDEX lv_cnt.
ENDIF.
ENDIF.
ENDIF.

DESCRIBE TABLE li_edidd_tmp LINES lv_curr.
lv_diff = lv_curr - lv_init.
CLEAR lv_cnt.

* POPULATE THE MATERIAL LONG DESCRIPTION IN SEGMENT Z1MAKTX

IF -segnam = lc_e1edp19.
lwa_e1edp19 = -sdata.

IF lwa_e1edp19-qualf = '002'.
CLEAR lwa_z1maktx.

SELECT SINGLE zzaktx INTO lwa_z1maktx-zzaktx FROM makt
WHERE matnr = lwa_e1edp19-idtnr AND
spras = sy-langu.

IF lwa_z1maktx IS NOT INITIAL.
lv_cnt = sy-tabix + lv_diff + 1.
lwa_edidd-segnam = lc_z1maktx.
lwa_edidd-sdata = lwa_z1maktx.

INSERT lwa_edidd INTO li_edidd_tmp INDEX lv_cnt.
ENDIF.
ENDIF.

ENDIF.

ENDLOOP.

int_edidd[] = li_edidd_tmp[].

* POPULATE TOTAL NUMBER OF HANDLING UNITS FROM TABLE VEPO BASED ON DELIVERY NUMBER.

IF vbdkr-vbeln_vl IS NOT INITIAL.
SELECT COUNT( * ) FROM vepo INTO lv_hu_cnt
WHERE vbeln = vbdkr-vbeln_vl.

CLEAR lwa_e1eds01.

lwa_e1eds01-sumid = lc_045.
lwa_e1eds01-summe = lv_hu_cnt.

CONDENSE: lwa_e1eds01-summe.

lwa_edidd-segnam = lc_e1eds01.
lwa_edidd-sdata = lwa_e1eds01.

APPEND lwa_edidd TO int_edidd.
ENDIF.

ENDIF.


Your suggestions and comments are welcome in this section.


Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.

No comments:

Post a Comment