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

DELETE ADJACENT DUPLICATES FROM itab

Former Member
0 Likes
3,081

Hi Frends, can any one explain me about

<b>DELETE ADJACENT DUPLICATES FROM itab</b>

and can any one give me sample program using the above statement.

full points will be given for good example

Thanks and Regards

Vijaya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,794

i am sending 2 programs to u:

DESCRIPTION: INTERACTIVE REPORT FOR SALES DOCUMENT

*FOR PRINTING SALES DOCUMENT HEADER, SALES DOCUMENT DETAILS, PARTNER

  • DETAILS, SCHEDULE LINE DATA.

----


  • D A T A D E C L A R A T I O N S *

----


INCLUDE z8vg_isro1.

INITIALIZATION.

v_chkbox = ' '.

v_chkbox1 = ''.

----


  • S T A R T O F S E L E C T I O N *

----


SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-028.

SELECT-OPTIONS: s_vbeln FOR i_vbak-vbeln.

"FOR RANGE OF VALUES.

SELECTION-SCREEN END OF BLOCK bl1.

----


  • A T S E L E C T I O N S C R E E N ( V A L I D A T I O N S ) *

----


AT SELECTION-SCREEN.

  • Check if record exists or not.

PERFORM zf_validations.

----


  • S T A R T O F S E L E C T I O N *

----


START-OF-SELECTION.

*this is event blocks which is executed when the user chooses the

*corresponding function key

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'G002'. " schdl data

APPEND i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm.

" MENU BAR STATUS.

*populating sales order header data , item data , partner data ,

*schedule data

PERFORM zf_select_headerdata.

AT USER-COMMAND.

"This event is executed whenever the user presses a menu option 'execute

"' in the list

CASE sy-ucomm.

WHEN 'EX01'. "Cancel

LEAVE PROGRAM.

WHEN 'GO01'. "for item data

vflag = '0'.

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'GO01'. " item data

APPEND i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm .

PERFORM zf_select_details.

WHEN 'G002'. "for schedule data .

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'G000'.

APPEND i_ucomm.

APPEND 'GO01' TO i_ucomm.

APPEND 'G002' TO i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm .

PERFORM zf_scheduledata .

WHEN 'G000'.

"function code for displaying partner details.

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'G000'.

APPEND i_ucomm.

APPEND 'GO01' TO i_ucomm.

APPEND 'G002' TO i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm .

IF vflag = '1'.

PERFORM zf_partnerdetails.

" FOR PARTNER DETAILS OF HEADER

ELSE.

PERFORM zf_partnerdetails1.

" FOR PARTNER DETAILS OF SALES ORDER ITEMS .

ENDIF.

WHEN 'BACK'.

LEAVE PROGRAM.

ENDCASE.

&----


*& FORM TOP_OF_PAGE

&----


TOP-OF-PAGE DURING LINE-SELECTION.

  • printing header for secondary list of report.

PERFORM zf_tols.

TOP-OF-PAGE.

  • printing hearder for basic list of report

PERFORM zf_top.

&----


*& Form VALIDATIONS

&----


  • subroutine to check whether record exists or not

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_validations .

SELECT SINGLE vbeln FROM vbak

INTO i_vbak-vbeln

WHERE vbeln IN s_vbeln.

EXIT.

  • CHECK IF THE RECORD EXISTS OR NOT.

IF sy-subrc <> 0.

MESSAGE e001.

ENDIF.

ENDFORM. " VALIDATIONS

&----


*& Form SELECT_HEADERDATA

&----


  • subroutine for populating header data and other details.

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_select_headerdata .

*refreshing all the internal tables.

CLEAR i_vbak.

REFRESH i_vbak.

CLEAR i_vbap.

REFRESH i_vbap.

CLEAR i_vbpa.

REFRESH i_vbpa.

CLEAR i_vbep.

REFRESH i_vbep.

*populating sales order header data , item data , partner data ,

*schedule data

SELECT vbeln

erdat

vkorg

FROM vbak

INTO TABLE i_vbak

WHERE vbeln IN s_vbeln.

IF NOT i_vbak[] IS INITIAL.

SELECT vbeln

posnr

matnr FROM vbap

INTO TABLE i_vbap

FOR ALL ENTRIES IN i_vbak

WHERE vbeln = i_vbak-vbeln.

ENDIF.

IF sy-subrc <> 0.

MESSAGE e004.

ENDIF.

SORT i_vbap BY vbeln posnr.

" SORTING TABLE WITH KEY FIELDS .

REFRESH i_mat.

CLEAR i_mat.

  • fetching of unique material numbers corresponding sales orderno.

LOOP AT i_vbap.

i_mat-matnr = i_vbap-matnr.

APPEND i_mat.

ENDLOOP.

SORT i_mat BY matnr. " sorting of material nos.

  • IF sy-SUBRC = 0.

  • deleting duplicate entries from table

DELETE ADJACENT DUPLICATES FROM i_mat

COMPARING matnr.

*endif.

REFRESH i_mat1.

CLEAR i_mat1.

  • populating material no and dscription .

SELECT matnr

maktx FROM makt

INTO TABLE i_mat1

FOR ALL ENTRIES IN i_mat

WHERE matnr = i_mat-matnr.

SELECT vbeln

posnr

parvw

kunnr

FROM vbpa

INTO TABLE i_vbpa

FOR ALL ENTRIES IN i_vbap

WHERE vbeln = i_vbap-vbeln .

SORT i_vbap BY vbeln posnr.

.

REFRESH i_tvbpa.

REFRESH i_tpartf.

CLEAR i_tpartf.

*FOR FETCHING UNIQUE PARTNER FUNCTIONS

LOOP AT i_vbpa.

i_tpartf-parvw = i_vbpa-parvw.

APPEND i_tpartf.

ENDLOOP.

SORT i_tpartf BY parvw.

DELETE ADJACENT DUPLICATES FROM i_tpartf

COMPARING parvw.

SELECT spras

parvw

vtext

FROM tpart

INTO TABLE i_tvbpa

FOR ALL ENTRIES IN i_tpartf

WHERE parvw = i_tpartf-parvw AND spras = sy-langu.

IF NOT i_vbap[] IS INITIAL.

SELECT vbeln

posnr

etenr

ettyp

lfrel

edatu

FROM vbep

INTO TABLE i_vbep

FOR ALL ENTRIES IN i_vbap

WHERE vbeln = i_vbap-vbeln.

ENDIF.

SORT i_vbap BY vbeln posnr.

  • to fetch data from internal table to print report

LOOP AT i_vbak.

WRITE:/1 sy-vline,10 v_chkbox AS CHECKBOX, i_vbak-vbeln,28

sy-vline,

30 i_vbak-erdat,48 sy-vline,

50 i_vbak-vkorg, 132 sy-vline.

ENDLOOP.

ULINE.

ENDFORM. " SELECT_HEADERDATA

&----


*& Form ZF_SELECT_DETAILS

&----


  • SUBROUTINE FOR DISPLAYING SELECTED ITEM DETAILS DATA

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_select_details .

vflag = 0.

WRITE:/1 sy-vline,10 text-006 COLOR 3,28 sy-vline,

30 text-007 COLOR 3, 48 sy-vline,

50 text-008 COLOR 3, 68 sy-vline,

70 text-022 COLOR 3, 132 sy-vline.

ULINE.

CLEAR i_selvbap.

CLEAR i_final.

REFRESH i_selvbap.

REFRESH i_final.

CLEAR i_mat1.

vnline = 7.

DO.

READ LINE vnline FIELD VALUE i_vbak-vbeln v_chkbox.

" READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0. " no lines read.

EXIT.

ENDIF.

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

IF v_chkbox = 'X'.

" checking of selected items from basic list.

*alpha conversion function - During conversion from the external to the

*internal format, the system checks to see

*if input is purely nummeric or not ,if not all spaces to the left of

*the value are filled with zeroes ('0').

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_vbak-vbeln

IMPORTING

output = i_selvbap-vbeln.

APPEND i_selvbap.

" appending values from header line to body.

flag = flag + 1.

" TO CHECK VALUE OF CHECKBOX.

CLEAR i_vbak.

" clearing of header line after appending.

ENDIF.

vnline = vnline + 1.

ENDDO.

IF flag <> 0.

CLEAR i_final.

CHECK NOT i_selvbap[] IS INITIAL.

LOOP AT i_selvbap.

LOOP AT i_vbap WHERE vbeln = i_selvbap-vbeln.

READ TABLE i_mat1 WITH KEY matnr = i_vbap-matnr BINARY SEARCH.

  • IF sy-subrc = 0.

i_final-vbeln = i_vbap-vbeln.

i_final-posnr = i_vbap-posnr.

i_final-matnr = i_vbap-matnr.

i_final-maktx = i_mat1-maktx.

APPEND i_final.

CLEAR i_mat1.

  • ENDIF.

ENDLOOP.

CLEAR i_selvbap.

CLEAR i_vbap.

CLEAR i_final.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

  • to fetch data from internal table to print report

LOOP AT i_final.

WRITE:/1 sy-vline,10 v_chkbox1 AS CHECKBOX,i_final-vbeln,28 sy-vline

,

30 i_final-posnr, 48 sy-vline,

50 i_final-matnr, 68 sy-vline,

70 i_final-maktx,

132 sy-vline.

ENDLOOP.

ULINE.

ENDFORM. " ZF_SELECT_DETAILS

&----


*& Form ZF_TOLS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_tols .

*printing header of secondary list

ULINE.

WRITE:/10 text-023,20 text-001 COLOR 4, 45 text-019 COLOR 4.

WRITE: 80 text-024,90 sy-datum .

WRITE:/10 text-025,20 text-027,80 text-026,90 sy-pagno.

WRITE:/.

ULINE.

ENDFORM. " ZF_TOLS

&----


*& Form ZF_TOP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_top .

*printing header of basic list

ULINE.

WRITE:/10 text-023,20 text-001 COLOR 4 ,45 text-002 COLOR 4.

WRITE: 80 text-024, 90 sy-datum.

WRITE:/10 text-025,20 text-027,80 text-026,90 sy-pagno.

ULINE.

WRITE:/1 sy-vline, 10 text-003 COLOR 3 ,28 sy-vline,

30 text-004 COLOR 3 ,48 sy-vline,

50 text-005 COLOR 3 ,132 sy-vline.

ULINE.

ENDFORM. " ZF_TOP

&----


*& Form ZF_PARTNERDETAILS

&----


  • SUBROUTINE FOR DISPLAYING SELECTED PARTNER DETAILS DATA

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_partnerdetails .

IF vflag = 1.

WRITE:/1 sy-vline,10 text-016 COLOR 3,28 sy-vline,

  • 30 text-017 COLOR 3,48 sy-vline,

30 text-018 COLOR 3,48 sy-vline,

70 text-021 COLOR 3, 132 sy-vline.

ULINE.

CLEAR i_selvbpa.

REFRESH i_selvbpa.

" clearing work area and body of internal tables

REFRESH i_finalpd.

vnline = 7.

DO.

CLEAR i_selvbpa.

READ LINE vnline FIELD VALUE i_vbak-vbeln v_chkbox.

" READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0.

" NO LINES READ

EXIT.

ENDIF.

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

IF v_chkbox = 'X'.

" if any value is selected

*converts any number into a string fill with zeroes, with the number at

*the extreme right.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_vbak-vbeln

IMPORTING

output = i_selvbpa-vbeln.

APPEND i_selvbpa.

CLEAR i_vbak.

flag = flag + 1.

ENDIF.

vnline = vnline + 1.

ENDDO.

IF flag <> 0.

CHECK NOT i_selvbpa[] IS INITIAL.

LOOP AT i_selvbpa.

LOOP AT i_vbpa WHERE vbeln = i_selvbpa-vbeln.

READ TABLE i_tvbpa WITH KEY parvw = i_vbpa-parvw BINARY SEARCH

.

  • IF sy-subrc = 0..

i_finalpd-vbeln = i_vbpa-vbeln.

i_finalpd-posnr = i_vbpa-posnr.

i_finalpd-parvw = i_vbpa-parvw.

i_finalpd-vtext = i_tvbpa-vtext.

APPEND i_finalpd.

CLEAR i_tvbpa.

  • ENDIF.

ENDLOOP.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

LOOP AT i_finalpd.

WRITE:/1 sy-vline,10 i_finalpd-vbeln, 28 sy-vline,

  • 30 i_finalpd-posnr, 48 SY-VLINE,

30 i_finalpd-parvw, 48 sy-vline,

70 i_finalpd-vtext, 132 sy-vline.

ENDLOOP.

ULINE.

ENDIF.

ENDFORM. " ZF_PARTNERDETAILS

&----


*& Form ZF_SCHEDULEDATA

&----


  • SUBROUTINE FOR DISPLAYING SELECTED ITEM SCHEDULE DATA

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_scheduledata .

vflag = 0.

WRITE:/1 sy-vline,10 text-009 COLOR 3,18 sy-vline,

20 text-011 COLOR 3,38 sy-vline,

40 text-012 COLOR 3,58 sy-vline,

60 text-013 COLOR 3,78 sy-vline,

80 text-020 COLOR 3,98 sy-vline,

100 text-015 COLOR 3,132 sy-vline.

ULINE.

CLEAR i_selvbep.

REFRESH i_selvbep.

vnline1 = 5.

CLEAR flag.

CLEAR i_final.

REFRESH i_finalsd.

DO.

READ LINE vnline1 FIELD VALUE i_final-vbeln v_chkbox1 i_final-posnr

. " READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0.

EXIT.

ENDIF.

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

IF v_chkbox1 = 'X'.

*converts any number into a string fill with zeroes, with the number at

*the extreme right

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_final-vbeln

IMPORTING

output = i_selvbep-vbeln.

i_selvbep-posnr = i_final-posnr.

APPEND i_selvbep.

CLEAR i_final.

flag = flag + 1.

ENDIF.

vnline1 = vnline1 + 1.

ENDDO.

IF flag <> 0.

CHECK NOT i_selvbep[] IS INITIAL.

LOOP AT i_selvbep.

LOOP AT i_vbep WHERE vbeln = i_selvbep-vbeln AND posnr =

i_selvbep-posnr.

i_finalsd-vbeln = i_vbep-vbeln.

i_finalsd-posnr = i_vbep-posnr.

i_finalsd-etenr = i_vbep-etenr.

i_finalsd-ettyp = i_vbep-ettyp.

i_finalsd-lfrel = i_vbep-lfrel.

i_finalsd-edatu = i_vbep-edatu.

APPEND i_finalsd.

CLEAR i_selvbep.

CLEAR i_vbep.

CLEAR i_finalsd.

ENDLOOP.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

LOOP AT i_finalsd.

WRITE:/1 sy-vline,10 i_finalsd-vbeln,18 sy-vline,

20 i_finalsd-posnr, 38 sy-vline,

40 i_finalsd-etenr, 58 sy-vline,

60 i_finalsd-ettyp, 78 sy-vline,

80 i_finalsd-lfrel, 98 sy-vline,

100 i_finalsd-edatu,132 sy-vline.

CLEAR i_finalsd.

ENDLOOP.

ULINE.

ENDFORM. " ZF_SCHEDULEDATA

&----


*& Form ZF_PARTNERDETAILS1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_partnerdetails1 .

vflag = 1.

WRITE:/1 sy-vline,10 text-016 COLOR 3,18 sy-vline,

20 text-017 COLOR 3,38 sy-vline,

40 text-018 COLOR 3,58 sy-vline,

60 text-021 COLOR 3,78 sy-vline,

132 sy-vline.

ULINE.

CLEAR i_selvbpa1.

REFRESH i_selvbpa1.

REFRESH i_finalpd1.

vnline1 = 7.

DO.

  • CLEAR I_SELVBEP.

READ LINE vnline1 FIELD VALUE i_final-vbeln v_chkbox1 i_final-posnr

. " READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0.

EXIT.

ENDIF.

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

IF v_chkbox1 = 'X'.

*converts any number into a string fill with zeroes, with the number at

*the extreme right

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_final-vbeln

IMPORTING

output = i_selvbpa1-vbeln.

i_selvbpa1-posnr = i_final-posnr.

APPEND i_selvbpa1.

CLEAR i_final.

flag = flag + 1.

ENDIF.

vnline1 = vnline1 + 1.

ENDDO.

IF flag <> 0.

CLEAR i_vbpa.

CLEAR i_finalpd1.

CHECK NOT i_selvbpa1[] IS INITIAL.

LOOP AT i_selvbpa1.

LOOP AT i_vbpa WHERE vbeln = i_selvbpa1-vbeln.

CLEAR i_finalpd1.

    • IF sy-subrc = 0.

i_finalpd1-vbeln = i_vbpa-vbeln.

IF i_vbpa-posnr = 0 OR i_vbpa-posnr = ''.

i_finalpd1-parvw1 = 'NO DATA EXISTS'.

ELSE.

i_finalpd1-posnr = i_vbpa-posnr.

i_finalpd1-parvw = i_vbpa-parvw.

i_finalpd1-vtext = i_vbpa-vtext.

i_finalpd1-kunnr = i_vbpa-kunnr.

ENDIF.

APPEND i_finalpd1.

IF i_finalpd1-vbeln = i_selvbpa1-vbeln.

EXIT.

ENDIF.

CLEAR i_vbpa.

CLEAR i_finalpd1.

  • ENDIF.

ENDLOOP.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

  • fetching data from internal table for printing.

LOOP AT i_finalpd1.

WRITE:/1 sy-vline,10 i_finalpd1-vbeln,18 sy-vline,

  • 20 I_FINALPD1-POSNR, 38 SY-VLINE,

40 i_finalpd1-parvw1,

  • 58 SY-VLINE,

60 i_finalpd1-vtext,

  • 78 SY-VLINE,

80 i_finalpd1-kunnr,

132 sy-vline.

ENDLOOP.

ULINE.

ENDFORM. " ZF_PARTNERDETAILS1

2nd is :-

REPORT Z8NB_SHA10_1

NO STANDARD PAGE HEADING

LINE-COUNT 30

LINE-SIZE 170

MESSAGE-ID Z8NBSHADOW.

----


  • T A B L E D E C L A R A T I O N *

----


TABLES : LIKP. " Delivery Header.

----


  • T Y P E D E C L A R A T I O N *

----


**-- Type decleration for Delivery Header

TYPES : BEGIN OF T_LIKP,

VBELN LIKE LIKP-VBELN, " Delivery Number

ERDAT LIKE LIKP-ERDAT, " Date on which record was craeted

KUNNR LIKE LIKP-KUNNR, " Sold-to-party

KUNAG LIKE LIKP-KUNAG, " Ship-to-party

TRMTYP LIKE LIKP-TRMTYP, " Means of transport

END OF T_LIKP.

**-- Type decleration for Delivery Items

TYPES : BEGIN OF T_LIPS,

VBELN LIKE LIPS-VBELN, " Delivery Number

POSNR LIKE LIPS-POSNR, " Delivery Item Number

MATNR LIKE LIPS-MATNR, " Material Number

LFIMG LIKE LIPS-LFIMG , " DELIVERED QTY

MEINS LIKE LIPS-MEINS, " Unit of Measurement

BRGEW LIKE LIPS-BRGEW, " Gross Weight

GEWEI LIKE LIPS-GEWEI, " Weight Unit

VOLUM LIKE LIPS-VOLUM, " Volumn

VOLEH LIKE LIPS-VOLEH, " Volumn Unit

END OF T_LIPS.

**-- Type decleration for Customer Details

TYPES : BEGIN OF T_KNA1,

KUNNR LIKE KNA1-KUNNR, " Customer Number

NAME1 LIKE KNA1-NAME1, " Name1

NAME2 LIKE KNA1-NAME2, " Name2

STRAS LIKE KNA1-STRAS, " House/ Street Number

REGIO LIKE KNA1-REGIO, " Region

ORT01 LIKE KNA1-ORT01, " City

LAND1 LIKE KNA1-LAND1, " Country Key

TELF1 LIKE KNA1-TELF1, " First Telephone Number

END OF T_KNA1.

**-- Type decleration for Partner Function

TYPES : BEGIN OF T_KNVP,

KUNNR LIKE KNVP-KUNNR, " Customer Number

PARVW LIKE KNVP-PARVW, " Partner Function

KUNN2 LIKE KNVP-KUNN2, " Cust no of business partner

END OF T_KNVP.

**-- Type decleration for Shipment Header

TYPES : BEGIN OF T_VTTK,

TKNUM LIKE VTTK-TKNUM, " Shipment Number

TNDR_CRNM LIKE VTTK-TNDR_CRNM, " Carrier

END OF T_VTTK.

**-- Type decleration for Shipment Item

TYPES : BEGIN OF T_VTTP,

TKNUM LIKE VTTP-TKNUM, " Shipment Number

VBELN LIKE VTTP-VBELN, " Order Number

END OF T_VTTP.

**-- Type decleration for Material Description

TYPES : BEGIN OF T_MAKT,

MATNR LIKE MAKT-MATNR, " Material Number

MAKTX LIKE MAKT-MAKTX, " Material Description

END OF T_MAKT.

**-- Type decleration for Final table containing all item details

TYPES : BEGIN OF T_FINAL,

VBELN LIKE LIPS-VBELN, " Delivery Number

POSNR LIKE LIPS-POSNR, " Delivery Item Number

MATNR LIKE LIPS-MATNR, " Material Number

LFIMG LIKE LIPS-LFIMG , " DELIVERED QTY

MEINS LIKE LIPS-MEINS, " Unit of Measurement

BRGEW LIKE LIPS-BRGEW, " Gross Weight

GEWEI LIKE LIPS-GEWEI, " Weight Unit

VOLUM LIKE LIPS-VOLUM, " Volumn

VOLEH LIKE LIPS-VOLEH, " Volumn Unit

MAKTX LIKE MAKT-MAKTX, " Material Description

END OF T_FINAL.

----


  • C O N S T A N T D E C E L E R A T I O N *

----


CONSTANTS: C_RE(4) TYPE C VALUE 'RE', "Bill-to-party

C_EQ(4) TYPE C VALUE 'EQ', "Equal To

C_I(2) TYPE C VALUE 'I'. "Inclusion

----


  • V A R I A B L E D E C E L E R A T I O N *

----


DATA : V_SUM TYPE LIPS-LFIMG, "For calculating total of Quantity.

V_SUM_FINAL TYPE LIPS-LFIMG, "For displaying total

V_DESC TYPE C LENGTH 20. "Storing Description

----


  • I N T E R N A L D E C L A R A T I O N *

----


**-- Internal table for delivery header data

DATA: IT_LIKP TYPE STANDARD TABLE OF T_LIKP WITH HEADER LINE,

**-- Internal table for delivery item data

IT_LIPS TYPE STANDARD TABLE OF T_LIPS WITH HEADER LINE,

**-- Internal table for bill-to-party details

IT_KNA1 TYPE STANDARD TABLE OF T_KNA1 WITH HEADER LINE,

**-- Internal table to store partner function data

IT_KVNP TYPE STANDARD TABLE OF T_KNVP WITH HEADER LINE,

**-- Internal table for shipment header data

IT_VTTK TYPE STANDARD TABLE OF T_VTTK WITH HEADER LINE,

**-- Internal table for shipmant item data

IT_VTTP TYPE STANDARD TABLE OF T_VTTP WITH HEADER LINE,

**-- Internal table for material description

IT_MAKT TYPE STANDARD TABLE OF T_MAKT WITH HEADER LINE,

**-- Internal table for final item details

IT_FINAL TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE,

**-- Temporary internal table for Shipment Item

IT_VTTP_TEMP TYPE STANDARD TABLE OF T_VTTP WITH HEADER LINE,

**-- Temporary internal table for delivery item

IT_LIPS_TEMP TYPE STANDARD TABLE OF T_LIPS WITH HEADER LINE,

**-- Temporary internal table for delivery header

IT_LIKP_TEMP TYPE STANDARD TABLE OF T_LIKP WITH HEADER LINE.

**-- Ranges for Inquiry/Quotation

RANGES R_CUSTOMER FOR KNA1-KUNNR.

----


  • S E L C T I O N S C R E E N *

----


**-- Selection screen containing Delivery no as the obligatory field

SELECTION-SCREEN BEGIN OF BLOCK CHARLY WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_VBELN FOR LIKP-VBELN OBLIGATORY.

SELECTION-SCREEN END OF BLOCK CHARLY.

----


  • I N I T I A L I Z A T I O N *

----


INITIALIZATION.

**-- Clear all internal tables

CLEAR : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL,

IT_VTTP_TEMP,

R_CUSTOMER,

V_SUM,

V_SUM_FINAL,

V_DESC.

**-- Refresh all internal tables

REFRESH : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL,

IT_VTTP_TEMP,

R_CUSTOMER.

----


  • A T S E L E C T I O N S C R E E N ( V A L I D A T I O N S ) *

----


AT SELECTION-SCREEN.

**-- Check the sales order number exists in the database table or not

SELECT SINGLE VBELN

FROM LIKP

INTO IT_LIKP

WHERE VBELN IN S_VBELN.

**-- If no single data selected display error message.

IF SY-SUBRC <> 0.

MESSAGE E000.

ENDIF.

----


  • S T A R T O F S E L E C T I O N *

----


START-OF-SELECTION.

**-- Fetch data from the transprant tables into the internal tables

PERFORM GET_DATA.

**-- Final table for complete item data

PERFORM FINAL_DATA.

----


  • E N D O F S E L E C T I O N *

----


END-OF-SELECTION.

**-- Display of Delivery Note

PERFORM DISPLAY_DATA.

&----


*& Form GET_DATA

&----


  • text

----


FORM GET_DATA .

**-- Fetch data from Delivery Header Table ( LIKP )

SELECT VBELN

ERDAT

KUNNR

KUNAG

TRMTYP

FROM LIKP

INTO TABLE IT_LIKP

WHERE VBELN IN S_VBELN

ORDER BY VBELN.

**-- Check SY_SUBRC.

IF SY-SUBRC <> 0 .

ENDIF.

**-- If record is present in IT_LIKP internal table then fetch data from

**-- Delivery Item table (LIPS)

IF NOT IT_LIKP[] IS INITIAL.

SELECT VBELN

POSNR

MATNR

LFIMG

MEINS

BRGEW

GEWEI

VOLUM

VOLEH

FROM LIPS

INTO TABLE IT_LIPS

FOR ALL ENTRIES IN IT_LIKP

WHERE VBELN = IT_LIKP-VBELN.

**-- If record found, sort the internal table on delivery no and item no

IF SY-SUBRC = 0.

SORT IT_LIPS BY VBELN POSNR.

ENDIF.

ENDIF.

**-- If record present in IT_LIPS internal table then fetch data from

**-- Shipment Item Table where delivery number is same

IF NOT IT_LIPS[] IS INITIAL.

SELECT TKNUM

VBELN

FROM VTTP

INTO TABLE IT_VTTP

FOR ALL ENTRIES IN IT_LIPS

WHERE VBELN = IT_LIPS-VBELN.

**-- If record found, sort the internal table on shipment no

IF SY-SUBRC = 0.

SORT IT_VTTP BY TKNUM.

ENDIF.

ENDIF.

**-- Move records in IT_LIPS to an temporary internal table for

**-- removing the duplicate entries of material number.

IT_LIPS_TEMP[] = IT_LIPS[].

SORT IT_LIPS_TEMP BY MATNR.

DELETE ADJACENT DUPLICATES FROM IT_LIPS_TEMP

COMPARING MATNR.

IF NOT IT_LIPS_TEMP[] IS INITIAL.

**-- Fetch Material description from MAKT for all materials in

**-- IT_LIPS_TEMP

SELECT MATNR

MAKTX

INTO TABLE IT_MAKT

FROM MAKT FOR ALL ENTRIES IN IT_LIPS_TEMP

WHERE MATNR = IT_LIPS_TEMP-MATNR.

**-- If record found, sort the internal table on Matreial No.

IF SY-SUBRC = 0.

SORT IT_MAKT BY MATNR.

ENDIF.

ENDIF.

**-- Transfer data in shipment item internal table to a temporary

**-- internal table to delete duplicate entries of shipment number.

IT_VTTP_TEMP[] = IT_VTTP[].

SORT IT_VTTP_TEMP BY TKNUM.

DELETE ADJACENT DUPLICATES FROM IT_VTTP_TEMP

COMPARING TKNUM.

**-- If record found in IT_VTTP_TEMP then fetch shipment no and carrier

**--from Shipment Header Table(VTTK).

IF NOT IT_VTTP_TEMP[] IS INITIAL.

SELECT TKNUM

TNDR_CRNM

FROM VTTK

INTO TABLE IT_VTTK

FOR ALL ENTRIES IN IT_VTTP_TEMP

WHERE TKNUM = IT_VTTP_TEMP-TKNUM.

**-- If record found, sort the internal table on shipment no

IF SY-SUBRC = 0.

SORT IT_VTTK BY TKNUM.

ENDIF.

ENDIF.

**-- Move the data of IT_LIKP to an internal table to remove the

**-- duplicate entries of sold-to-party number.

IT_LIKP_TEMP[] = IT_LIKP[].

SORT IT_LIKP_TEMP BY KUNAG.

DELETE ADJACENT DUPLICATES FROM IT_LIKP_TEMP

COMPARING KUNAG.

**-- If record present in IT_LIKP then fetch data from Partner Function

**-- Table where Partner function value should be eq to Bill-to-party

IF NOT IT_LIKP_TEMP[] IS INITIAL.

SELECT KUNNR

PARVW

KUNN2

FROM KNVP

INTO TABLE IT_KVNP

FOR ALL ENTRIES IN IT_LIKP_TEMP

WHERE KUNNR = IT_LIKP_TEMP-KUNAG

AND PARVW = C_RE.

**-- If record found, sort the internal table on Customer no

IF SY-SUBRC = 0.

SORT IT_KVNP BY KUNNR.

ENDIF.

ENDIF.

**-- Putting Customer Number into the ranges

**-- Ship-to-party

LOOP AT IT_LIKP.

R_CUSTOMER-SIGN = C_I.

R_CUSTOMER-OPTION = C_EQ.

R_CUSTOMER-LOW = IT_LIKP-KUNNR.

APPEND R_CUSTOMER.

CLEAR R_CUSTOMER.

**-- Sold-to-party

SORT R_CUSTOMER BY LOW.

READ TABLE R_CUSTOMER WITH KEY LOW = IT_LIKP-KUNAG

BINARY SEARCH.

IF SY-SUBRC <> 0.

R_CUSTOMER-SIGN = C_I.

R_CUSTOMER-OPTION = C_EQ.

R_CUSTOMER-LOW = IT_LIKP-KUNAG.

APPEND R_CUSTOMER.

CLEAR R_CUSTOMER.

ENDIF.

ENDLOOP.

**-- Bill-to-party.

SORT R_CUSTOMER BY LOW.

LOOP AT IT_KVNP WHERE PARVW = C_RE.

READ TABLE R_CUSTOMER WITH KEY LOW = IT_KVNP-KUNN2

BINARY SEARCH.

IF SY-SUBRC <> 0.

R_CUSTOMER-SIGN = C_I.

R_CUSTOMER-OPTION = C_EQ.

R_CUSTOMER-LOW = IT_KVNP-KUNN2.

APPEND R_CUSTOMER.

CLEAR R_CUSTOMER.

ENDIF.

ENDLOOP.

**-- If record found in R_CUSTOMER then fetch data from Customer Master

**-- (KNA1) where customer number is same.

IF NOT R_CUSTOMER[] IS INITIAL.

SELECT KUNNR

NAME1

NAME2

STRAS

REGIO

ORT01

LAND1

TELF1

FROM KNA1

INTO TABLE IT_KNA1

FOR ALL ENTRIES IN R_CUSTOMER

WHERE KUNNR = R_CUSTOMER-LOW.

**-- If record found, sort the internal table on Customer no

IF SY-SUBRC = 0.

SORT IT_KNA1 BY KUNNR.

ENDIF.

ENDIF.

ENDFORM. " GET_DATA

&----


*& Form FINAL_DATA

&----


  • All Item Details

----


FORM FINAL_DATA .

**-- Clear all internal tables.

CLEAR : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL.

**-- Loop at the item table and put all the data into the final table

**-- then read the material description table and append all into the

**-- final table.

LOOP AT IT_LIPS.

CLEAR IT_MAKT.

IT_FINAL = IT_LIPS.

READ TABLE IT_MAKT WITH KEY MATNR = IT_LIPS-MATNR

BINARY SEARCH.

IF SY-SUBRC = 0.

IT_FINAL-MAKTX = IT_MAKT-MAKTX.

ENDIF.

**-- Append records into final internal table

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

ENDFORM. " FINAL_DATA

&----


*& Form DISPLAY_DATA

&----


  • Printing of SAP SCRIPT

----


FORM DISPLAY_DATA .

**-- Clear all internal table header

CLEAR : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL.

**-- Call OPEN_FORM function to open script

CALL FUNCTION 'OPEN_FORM'

EXPORTING

DEVICE = 'PRINTER'

LANGUAGE = SY-LANGU

EXCEPTIONS

CANCELED = 1

DEVICE = 2

FORM = 3

OPTIONS = 4

UNCLOSED = 5

MAIL_OPTIONS = 6

ARCHIVE_ERROR = 7

INVALID_FAX_NUMBER = 8

MORE_PARAMS_NEEDED_IN_BATCH = 9

SPOOL_ERROR = 10

CODEPAGE = 11

OTHERS = 12.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**-- Loop at final internal table whose data is to be displayed in

**-- the main window.

LOOP AT IT_FINAL.

**-- Move the material description into a fixed length variable so that

**-- the data do not over flow

V_DESC = IT_FINAL-MAKTX.

**-- For every new delivery number.

AT NEW VBELN.

**-- Start a new script form for every new delivery number

CALL FUNCTION 'START_FORM'

EXPORTING

FORM = 'Z8NB_SHA10_2'

LANGUAGE = SY-LANGU

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

CODEPAGE = 7

OTHERS = 8.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**-- Clear internal tables

CLEAR : IT_LIKP,

IT_VTTP,

IT_VTTK,

IT_KNA1.

**-- Read table IT_LIKP, IT_VTTP, IT_VTTK and IT_KNA1 to fetch the

**-- records to be displayed in sold-to-party window.

READ TABLE IT_LIKP WITH KEY VBELN = IT_FINAL-VBELN

BINARY SEARCH.

IF SY-SUBRC = 0.

***-- Shipment header

READ TABLE IT_VTTP WITH KEY VBELN = IT_LIKP-VBELN.

IF SY-SUBRC = 0.

READ TABLE IT_VTTK WITH KEY TKNUM = IT_VTTP-TKNUM.

IF SY-SUBRC = 0.

**-- Sold-to-party

READ TABLE IT_KNA1 WITH KEY KUNNR = IT_LIKP-KUNAG

BINARY SEARCH.

IF SY-SUBRC = 0.

**-- Call WRITE_FORM function to display records.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'SOLD_TO'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

CLEAR IT_KNA1.

**-- Read table IT_KNA1 for fetching Ship-to-party details

**-- and display them in SHIP window

READ TABLE IT_KNA1 WITH KEY KUNNR = IT_LIKP-KUNNR

BINARY SEARCH.

IF SY-SUBRC = 0.

**-- Call function WRITE_FORM to display data

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'SHIP'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

CLEAR : IT_KVNP,

IT_KNA1.

**-- Bill-to-party

READ TABLE IT_KVNP WITH KEY KUNNR = IT_LIKP-KUNAG

PARVW = C_RE

BINARY SEARCH.

IF SY-SUBRC = 0.

READ TABLE IT_KNA1 WITH KEY KUNNR = IT_KVNP-KUNN2

BINARY SEARCH.

IF SY-SUBRC = 0.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'BILL_TO'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

ENDIF.

ENDAT.

**-- Writing header of main window

PERFORM WRITE_HEADER.

**-- Writing item details in main window body

PERFORM WRITE_BODY.

**-- Calculating total quantity

V_SUM = V_SUM + IT_FINAL-LFIMG.

AT END OF VBELN.

**-- Putting sum value into a variabe for final total display

V_SUM_FINAL = V_SUM.

CLEAR V_SUM.

**-- Printing total value

PERFORM WRITE_TOTAL.

**-- Calling END_FORM

CALL FUNCTION 'END_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

CODEPAGE = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDAT.

ENDLOOP.

**-- Close SAP SCRIPT

CALL FUNCTION 'CLOSE_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

CODEPAGE = 5

OTHERS = 6.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " DISPLAY_DATA

&----


*& Form WRITE_HEADER

&----


  • Main Window Heading

----


FORM WRITE_HEADER .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'HEAD'

TYPE = 'TOP'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " WRITE_HEADER

&----


*& Form WRITE_BODY

&----


  • Main window body

----


FORM WRITE_BODY .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'BODY'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " WRITE_BODY

&----


*& Form write_total

&----


  • Tatal

----


FORM WRITE_TOTAL .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'TOTAL'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " write_total

Reward points if helpful

Regards

Nilesh

Hi Frends, can any one explain me about

<b>DELETE ADJACENT DUPLICATES FROM itab</b>

and can any one give me sample program using the above statement.

full points will be given for good example

Thanks and Regards

Vijaya

11 REPLIES 11
Read only

Former Member
0 Likes
1,794

Hai,

If an internal table contains duplicates and you don;t want them.

You can delete them as foloows:

<b>SORT ITAB.

DELETE ADJACENT DUPLICATES FROM ITAB.</b>

Here is the Example:

REPORT Z_DELETE_DULPICATES.

DATA off TYPE i.

DATA: BEGIN OF line,

col1 TYPE i,

col2(1) TYPE c,

END OF line.

DATA itab LIKE STANDARD TABLE OF line

WITH NON-UNIQUE KEY col2.

line-col1 = 1. line-col2 = 'A'. APPEND line TO itab.

line-col1 = 1. line-col2 = 'A'. APPEND line TO itab.

line-col1 = 1. line-col2 = 'B'. APPEND line TO itab.

line-col1 = 2. line-col2 = 'B'. APPEND line TO itab.

line-col1 = 3. line-col2 = 'B'. APPEND line TO itab.

line-col1 = 4. line-col2 = 'B'. APPEND line TO itab.

line-col1 = 5. line-col2 = 'A'. APPEND line TO itab.

off = 0. PERFORM list.

DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.

off = 14. PERFORM list.

DELETE ADJACENT DUPLICATES FROM itab COMPARING col1.

off = 28. PERFORM list.

DELETE ADJACENT DUPLICATES FROM itab.

off = 42. PERFORM list.

FORM list.

SKIP TO LINE 3.

LOOP AT itab INTO line.

WRITE: AT /off line-col1, line-col2.

ENDLOOP.

ENDFORM.

Regds,

Rama.Pammi

Read only

Former Member
0 Likes
1,794

hi,

it will remove duplicates recrd from itab

DELETE ADJACENT DUPLICATES FROM itab COMPARING ernam.

this above line will companre ernam and remove the records with same names which r repeating 2nd time .

reward if helpful

ravi

Message was edited by:

ravi r

Read only

Former Member
0 Likes
1,794

Hi,

itab_vmvaa[] = record_tab[].

SORT itab_vmvaa BY vbeln posnr.

DELETE ADJACENT DUPLICATES FROM itab_vmvaa COMPARING vbeln posnr.

SORT itab_vmvaa BY vbeln posnr.

CLEAR record_tab[].

record_tab[] = itab_vmvaa[].

Regards

Nicole

Read only

Former Member
0 Likes
1,794

Hi,

let your internal table be..

itab:

matnr werks lgort

-


11 nl09 1001

12 nl09 1001

11 nl09 1001

11 nl09 1002

*Query

DELETE Adjacent duplicates from itab comparing all fields

output

matnr werks lgort

-


11 nl09 1001

12 nl09 1001

11 nl09 1002

reward if useful

regards,

nazeer

Read only

Former Member
0 Likes
1,794

Hi Vijaya Laxmi,

The statement 'DELETE ADJACENT DUPLICATES FROM itab' is used to delete the duplicates entries from the internal table.

In most of the cases this statement is used with the option 'COMPARING field1 field2 ...'.

Read only

h_senden2
Active Contributor
0 Likes
1,794

This statement check all records in an internal table on all fields or the given fields, and deletes a record if it is simular to the previous one based on all field or the given fields.

This will only work when you sort the internal table on the relevant fields.

SORT ITAB BY f1 f2.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING F1 F2.

regards,

Hans

Please reward all helpful answers !!!!!

Read only

Former Member
0 Likes
1,795

i am sending 2 programs to u:

DESCRIPTION: INTERACTIVE REPORT FOR SALES DOCUMENT

*FOR PRINTING SALES DOCUMENT HEADER, SALES DOCUMENT DETAILS, PARTNER

  • DETAILS, SCHEDULE LINE DATA.

----


  • D A T A D E C L A R A T I O N S *

----


INCLUDE z8vg_isro1.

INITIALIZATION.

v_chkbox = ' '.

v_chkbox1 = ''.

----


  • S T A R T O F S E L E C T I O N *

----


SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-028.

SELECT-OPTIONS: s_vbeln FOR i_vbak-vbeln.

"FOR RANGE OF VALUES.

SELECTION-SCREEN END OF BLOCK bl1.

----


  • A T S E L E C T I O N S C R E E N ( V A L I D A T I O N S ) *

----


AT SELECTION-SCREEN.

  • Check if record exists or not.

PERFORM zf_validations.

----


  • S T A R T O F S E L E C T I O N *

----


START-OF-SELECTION.

*this is event blocks which is executed when the user chooses the

*corresponding function key

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'G002'. " schdl data

APPEND i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm.

" MENU BAR STATUS.

*populating sales order header data , item data , partner data ,

*schedule data

PERFORM zf_select_headerdata.

AT USER-COMMAND.

"This event is executed whenever the user presses a menu option 'execute

"' in the list

CASE sy-ucomm.

WHEN 'EX01'. "Cancel

LEAVE PROGRAM.

WHEN 'GO01'. "for item data

vflag = '0'.

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'GO01'. " item data

APPEND i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm .

PERFORM zf_select_details.

WHEN 'G002'. "for schedule data .

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'G000'.

APPEND i_ucomm.

APPEND 'GO01' TO i_ucomm.

APPEND 'G002' TO i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm .

PERFORM zf_scheduledata .

WHEN 'G000'.

"function code for displaying partner details.

REFRESH i_ucomm.

CLEAR i_ucomm.

i_ucomm-ucomm = 'G000'.

APPEND i_ucomm.

APPEND 'GO01' TO i_ucomm.

APPEND 'G002' TO i_ucomm.

SET PF-STATUS 'MENU2' EXCLUDING i_ucomm .

IF vflag = '1'.

PERFORM zf_partnerdetails.

" FOR PARTNER DETAILS OF HEADER

ELSE.

PERFORM zf_partnerdetails1.

" FOR PARTNER DETAILS OF SALES ORDER ITEMS .

ENDIF.

WHEN 'BACK'.

LEAVE PROGRAM.

ENDCASE.

&----


*& FORM TOP_OF_PAGE

&----


TOP-OF-PAGE DURING LINE-SELECTION.

  • printing header for secondary list of report.

PERFORM zf_tols.

TOP-OF-PAGE.

  • printing hearder for basic list of report

PERFORM zf_top.

&----


*& Form VALIDATIONS

&----


  • subroutine to check whether record exists or not

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_validations .

SELECT SINGLE vbeln FROM vbak

INTO i_vbak-vbeln

WHERE vbeln IN s_vbeln.

EXIT.

  • CHECK IF THE RECORD EXISTS OR NOT.

IF sy-subrc <> 0.

MESSAGE e001.

ENDIF.

ENDFORM. " VALIDATIONS

&----


*& Form SELECT_HEADERDATA

&----


  • subroutine for populating header data and other details.

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_select_headerdata .

*refreshing all the internal tables.

CLEAR i_vbak.

REFRESH i_vbak.

CLEAR i_vbap.

REFRESH i_vbap.

CLEAR i_vbpa.

REFRESH i_vbpa.

CLEAR i_vbep.

REFRESH i_vbep.

*populating sales order header data , item data , partner data ,

*schedule data

SELECT vbeln

erdat

vkorg

FROM vbak

INTO TABLE i_vbak

WHERE vbeln IN s_vbeln.

IF NOT i_vbak[] IS INITIAL.

SELECT vbeln

posnr

matnr FROM vbap

INTO TABLE i_vbap

FOR ALL ENTRIES IN i_vbak

WHERE vbeln = i_vbak-vbeln.

ENDIF.

IF sy-subrc <> 0.

MESSAGE e004.

ENDIF.

SORT i_vbap BY vbeln posnr.

" SORTING TABLE WITH KEY FIELDS .

REFRESH i_mat.

CLEAR i_mat.

  • fetching of unique material numbers corresponding sales orderno.

LOOP AT i_vbap.

i_mat-matnr = i_vbap-matnr.

APPEND i_mat.

ENDLOOP.

SORT i_mat BY matnr. " sorting of material nos.

  • IF sy-SUBRC = 0.

  • deleting duplicate entries from table

DELETE ADJACENT DUPLICATES FROM i_mat

COMPARING matnr.

*endif.

REFRESH i_mat1.

CLEAR i_mat1.

  • populating material no and dscription .

SELECT matnr

maktx FROM makt

INTO TABLE i_mat1

FOR ALL ENTRIES IN i_mat

WHERE matnr = i_mat-matnr.

SELECT vbeln

posnr

parvw

kunnr

FROM vbpa

INTO TABLE i_vbpa

FOR ALL ENTRIES IN i_vbap

WHERE vbeln = i_vbap-vbeln .

SORT i_vbap BY vbeln posnr.

.

REFRESH i_tvbpa.

REFRESH i_tpartf.

CLEAR i_tpartf.

*FOR FETCHING UNIQUE PARTNER FUNCTIONS

LOOP AT i_vbpa.

i_tpartf-parvw = i_vbpa-parvw.

APPEND i_tpartf.

ENDLOOP.

SORT i_tpartf BY parvw.

DELETE ADJACENT DUPLICATES FROM i_tpartf

COMPARING parvw.

SELECT spras

parvw

vtext

FROM tpart

INTO TABLE i_tvbpa

FOR ALL ENTRIES IN i_tpartf

WHERE parvw = i_tpartf-parvw AND spras = sy-langu.

IF NOT i_vbap[] IS INITIAL.

SELECT vbeln

posnr

etenr

ettyp

lfrel

edatu

FROM vbep

INTO TABLE i_vbep

FOR ALL ENTRIES IN i_vbap

WHERE vbeln = i_vbap-vbeln.

ENDIF.

SORT i_vbap BY vbeln posnr.

  • to fetch data from internal table to print report

LOOP AT i_vbak.

WRITE:/1 sy-vline,10 v_chkbox AS CHECKBOX, i_vbak-vbeln,28

sy-vline,

30 i_vbak-erdat,48 sy-vline,

50 i_vbak-vkorg, 132 sy-vline.

ENDLOOP.

ULINE.

ENDFORM. " SELECT_HEADERDATA

&----


*& Form ZF_SELECT_DETAILS

&----


  • SUBROUTINE FOR DISPLAYING SELECTED ITEM DETAILS DATA

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_select_details .

vflag = 0.

WRITE:/1 sy-vline,10 text-006 COLOR 3,28 sy-vline,

30 text-007 COLOR 3, 48 sy-vline,

50 text-008 COLOR 3, 68 sy-vline,

70 text-022 COLOR 3, 132 sy-vline.

ULINE.

CLEAR i_selvbap.

CLEAR i_final.

REFRESH i_selvbap.

REFRESH i_final.

CLEAR i_mat1.

vnline = 7.

DO.

READ LINE vnline FIELD VALUE i_vbak-vbeln v_chkbox.

" READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0. " no lines read.

EXIT.

ENDIF.

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

IF v_chkbox = 'X'.

" checking of selected items from basic list.

*alpha conversion function - During conversion from the external to the

*internal format, the system checks to see

*if input is purely nummeric or not ,if not all spaces to the left of

*the value are filled with zeroes ('0').

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_vbak-vbeln

IMPORTING

output = i_selvbap-vbeln.

APPEND i_selvbap.

" appending values from header line to body.

flag = flag + 1.

" TO CHECK VALUE OF CHECKBOX.

CLEAR i_vbak.

" clearing of header line after appending.

ENDIF.

vnline = vnline + 1.

ENDDO.

IF flag <> 0.

CLEAR i_final.

CHECK NOT i_selvbap[] IS INITIAL.

LOOP AT i_selvbap.

LOOP AT i_vbap WHERE vbeln = i_selvbap-vbeln.

READ TABLE i_mat1 WITH KEY matnr = i_vbap-matnr BINARY SEARCH.

  • IF sy-subrc = 0.

i_final-vbeln = i_vbap-vbeln.

i_final-posnr = i_vbap-posnr.

i_final-matnr = i_vbap-matnr.

i_final-maktx = i_mat1-maktx.

APPEND i_final.

CLEAR i_mat1.

  • ENDIF.

ENDLOOP.

CLEAR i_selvbap.

CLEAR i_vbap.

CLEAR i_final.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

  • to fetch data from internal table to print report

LOOP AT i_final.

WRITE:/1 sy-vline,10 v_chkbox1 AS CHECKBOX,i_final-vbeln,28 sy-vline

,

30 i_final-posnr, 48 sy-vline,

50 i_final-matnr, 68 sy-vline,

70 i_final-maktx,

132 sy-vline.

ENDLOOP.

ULINE.

ENDFORM. " ZF_SELECT_DETAILS

&----


*& Form ZF_TOLS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_tols .

*printing header of secondary list

ULINE.

WRITE:/10 text-023,20 text-001 COLOR 4, 45 text-019 COLOR 4.

WRITE: 80 text-024,90 sy-datum .

WRITE:/10 text-025,20 text-027,80 text-026,90 sy-pagno.

WRITE:/.

ULINE.

ENDFORM. " ZF_TOLS

&----


*& Form ZF_TOP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_top .

*printing header of basic list

ULINE.

WRITE:/10 text-023,20 text-001 COLOR 4 ,45 text-002 COLOR 4.

WRITE: 80 text-024, 90 sy-datum.

WRITE:/10 text-025,20 text-027,80 text-026,90 sy-pagno.

ULINE.

WRITE:/1 sy-vline, 10 text-003 COLOR 3 ,28 sy-vline,

30 text-004 COLOR 3 ,48 sy-vline,

50 text-005 COLOR 3 ,132 sy-vline.

ULINE.

ENDFORM. " ZF_TOP

&----


*& Form ZF_PARTNERDETAILS

&----


  • SUBROUTINE FOR DISPLAYING SELECTED PARTNER DETAILS DATA

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_partnerdetails .

IF vflag = 1.

WRITE:/1 sy-vline,10 text-016 COLOR 3,28 sy-vline,

  • 30 text-017 COLOR 3,48 sy-vline,

30 text-018 COLOR 3,48 sy-vline,

70 text-021 COLOR 3, 132 sy-vline.

ULINE.

CLEAR i_selvbpa.

REFRESH i_selvbpa.

" clearing work area and body of internal tables

REFRESH i_finalpd.

vnline = 7.

DO.

CLEAR i_selvbpa.

READ LINE vnline FIELD VALUE i_vbak-vbeln v_chkbox.

" READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0.

" NO LINES READ

EXIT.

ENDIF.

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

IF v_chkbox = 'X'.

" if any value is selected

*converts any number into a string fill with zeroes, with the number at

*the extreme right.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_vbak-vbeln

IMPORTING

output = i_selvbpa-vbeln.

APPEND i_selvbpa.

CLEAR i_vbak.

flag = flag + 1.

ENDIF.

vnline = vnline + 1.

ENDDO.

IF flag <> 0.

CHECK NOT i_selvbpa[] IS INITIAL.

LOOP AT i_selvbpa.

LOOP AT i_vbpa WHERE vbeln = i_selvbpa-vbeln.

READ TABLE i_tvbpa WITH KEY parvw = i_vbpa-parvw BINARY SEARCH

.

  • IF sy-subrc = 0..

i_finalpd-vbeln = i_vbpa-vbeln.

i_finalpd-posnr = i_vbpa-posnr.

i_finalpd-parvw = i_vbpa-parvw.

i_finalpd-vtext = i_tvbpa-vtext.

APPEND i_finalpd.

CLEAR i_tvbpa.

  • ENDIF.

ENDLOOP.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

LOOP AT i_finalpd.

WRITE:/1 sy-vline,10 i_finalpd-vbeln, 28 sy-vline,

  • 30 i_finalpd-posnr, 48 SY-VLINE,

30 i_finalpd-parvw, 48 sy-vline,

70 i_finalpd-vtext, 132 sy-vline.

ENDLOOP.

ULINE.

ENDIF.

ENDFORM. " ZF_PARTNERDETAILS

&----


*& Form ZF_SCHEDULEDATA

&----


  • SUBROUTINE FOR DISPLAYING SELECTED ITEM SCHEDULE DATA

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_scheduledata .

vflag = 0.

WRITE:/1 sy-vline,10 text-009 COLOR 3,18 sy-vline,

20 text-011 COLOR 3,38 sy-vline,

40 text-012 COLOR 3,58 sy-vline,

60 text-013 COLOR 3,78 sy-vline,

80 text-020 COLOR 3,98 sy-vline,

100 text-015 COLOR 3,132 sy-vline.

ULINE.

CLEAR i_selvbep.

REFRESH i_selvbep.

vnline1 = 5.

CLEAR flag.

CLEAR i_final.

REFRESH i_finalsd.

DO.

READ LINE vnline1 FIELD VALUE i_final-vbeln v_chkbox1 i_final-posnr

. " READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0.

EXIT.

ENDIF.

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

IF v_chkbox1 = 'X'.

*converts any number into a string fill with zeroes, with the number at

*the extreme right

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_final-vbeln

IMPORTING

output = i_selvbep-vbeln.

i_selvbep-posnr = i_final-posnr.

APPEND i_selvbep.

CLEAR i_final.

flag = flag + 1.

ENDIF.

vnline1 = vnline1 + 1.

ENDDO.

IF flag <> 0.

CHECK NOT i_selvbep[] IS INITIAL.

LOOP AT i_selvbep.

LOOP AT i_vbep WHERE vbeln = i_selvbep-vbeln AND posnr =

i_selvbep-posnr.

i_finalsd-vbeln = i_vbep-vbeln.

i_finalsd-posnr = i_vbep-posnr.

i_finalsd-etenr = i_vbep-etenr.

i_finalsd-ettyp = i_vbep-ettyp.

i_finalsd-lfrel = i_vbep-lfrel.

i_finalsd-edatu = i_vbep-edatu.

APPEND i_finalsd.

CLEAR i_selvbep.

CLEAR i_vbep.

CLEAR i_finalsd.

ENDLOOP.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

LOOP AT i_finalsd.

WRITE:/1 sy-vline,10 i_finalsd-vbeln,18 sy-vline,

20 i_finalsd-posnr, 38 sy-vline,

40 i_finalsd-etenr, 58 sy-vline,

60 i_finalsd-ettyp, 78 sy-vline,

80 i_finalsd-lfrel, 98 sy-vline,

100 i_finalsd-edatu,132 sy-vline.

CLEAR i_finalsd.

ENDLOOP.

ULINE.

ENDFORM. " ZF_SCHEDULEDATA

&----


*& Form ZF_PARTNERDETAILS1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM zf_partnerdetails1 .

vflag = 1.

WRITE:/1 sy-vline,10 text-016 COLOR 3,18 sy-vline,

20 text-017 COLOR 3,38 sy-vline,

40 text-018 COLOR 3,58 sy-vline,

60 text-021 COLOR 3,78 sy-vline,

132 sy-vline.

ULINE.

CLEAR i_selvbpa1.

REFRESH i_selvbpa1.

REFRESH i_finalpd1.

vnline1 = 7.

DO.

  • CLEAR I_SELVBEP.

READ LINE vnline1 FIELD VALUE i_final-vbeln v_chkbox1 i_final-posnr

. " READING LINES FROM BASIC LIST.

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

IF sy-subrc <> 0.

EXIT.

ENDIF.

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

IF v_chkbox1 = 'X'.

*converts any number into a string fill with zeroes, with the number at

*the extreme right

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = i_final-vbeln

IMPORTING

output = i_selvbpa1-vbeln.

i_selvbpa1-posnr = i_final-posnr.

APPEND i_selvbpa1.

CLEAR i_final.

flag = flag + 1.

ENDIF.

vnline1 = vnline1 + 1.

ENDDO.

IF flag <> 0.

CLEAR i_vbpa.

CLEAR i_finalpd1.

CHECK NOT i_selvbpa1[] IS INITIAL.

LOOP AT i_selvbpa1.

LOOP AT i_vbpa WHERE vbeln = i_selvbpa1-vbeln.

CLEAR i_finalpd1.

    • IF sy-subrc = 0.

i_finalpd1-vbeln = i_vbpa-vbeln.

IF i_vbpa-posnr = 0 OR i_vbpa-posnr = ''.

i_finalpd1-parvw1 = 'NO DATA EXISTS'.

ELSE.

i_finalpd1-posnr = i_vbpa-posnr.

i_finalpd1-parvw = i_vbpa-parvw.

i_finalpd1-vtext = i_vbpa-vtext.

i_finalpd1-kunnr = i_vbpa-kunnr.

ENDIF.

APPEND i_finalpd1.

IF i_finalpd1-vbeln = i_selvbpa1-vbeln.

EXIT.

ENDIF.

CLEAR i_vbpa.

CLEAR i_finalpd1.

  • ENDIF.

ENDLOOP.

ENDLOOP.

ENDIF.

IF flag = 0.

MESSAGE e005.

ENDIF.

  • fetching data from internal table for printing.

LOOP AT i_finalpd1.

WRITE:/1 sy-vline,10 i_finalpd1-vbeln,18 sy-vline,

  • 20 I_FINALPD1-POSNR, 38 SY-VLINE,

40 i_finalpd1-parvw1,

  • 58 SY-VLINE,

60 i_finalpd1-vtext,

  • 78 SY-VLINE,

80 i_finalpd1-kunnr,

132 sy-vline.

ENDLOOP.

ULINE.

ENDFORM. " ZF_PARTNERDETAILS1

2nd is :-

REPORT Z8NB_SHA10_1

NO STANDARD PAGE HEADING

LINE-COUNT 30

LINE-SIZE 170

MESSAGE-ID Z8NBSHADOW.

----


  • T A B L E D E C L A R A T I O N *

----


TABLES : LIKP. " Delivery Header.

----


  • T Y P E D E C L A R A T I O N *

----


**-- Type decleration for Delivery Header

TYPES : BEGIN OF T_LIKP,

VBELN LIKE LIKP-VBELN, " Delivery Number

ERDAT LIKE LIKP-ERDAT, " Date on which record was craeted

KUNNR LIKE LIKP-KUNNR, " Sold-to-party

KUNAG LIKE LIKP-KUNAG, " Ship-to-party

TRMTYP LIKE LIKP-TRMTYP, " Means of transport

END OF T_LIKP.

**-- Type decleration for Delivery Items

TYPES : BEGIN OF T_LIPS,

VBELN LIKE LIPS-VBELN, " Delivery Number

POSNR LIKE LIPS-POSNR, " Delivery Item Number

MATNR LIKE LIPS-MATNR, " Material Number

LFIMG LIKE LIPS-LFIMG , " DELIVERED QTY

MEINS LIKE LIPS-MEINS, " Unit of Measurement

BRGEW LIKE LIPS-BRGEW, " Gross Weight

GEWEI LIKE LIPS-GEWEI, " Weight Unit

VOLUM LIKE LIPS-VOLUM, " Volumn

VOLEH LIKE LIPS-VOLEH, " Volumn Unit

END OF T_LIPS.

**-- Type decleration for Customer Details

TYPES : BEGIN OF T_KNA1,

KUNNR LIKE KNA1-KUNNR, " Customer Number

NAME1 LIKE KNA1-NAME1, " Name1

NAME2 LIKE KNA1-NAME2, " Name2

STRAS LIKE KNA1-STRAS, " House/ Street Number

REGIO LIKE KNA1-REGIO, " Region

ORT01 LIKE KNA1-ORT01, " City

LAND1 LIKE KNA1-LAND1, " Country Key

TELF1 LIKE KNA1-TELF1, " First Telephone Number

END OF T_KNA1.

**-- Type decleration for Partner Function

TYPES : BEGIN OF T_KNVP,

KUNNR LIKE KNVP-KUNNR, " Customer Number

PARVW LIKE KNVP-PARVW, " Partner Function

KUNN2 LIKE KNVP-KUNN2, " Cust no of business partner

END OF T_KNVP.

**-- Type decleration for Shipment Header

TYPES : BEGIN OF T_VTTK,

TKNUM LIKE VTTK-TKNUM, " Shipment Number

TNDR_CRNM LIKE VTTK-TNDR_CRNM, " Carrier

END OF T_VTTK.

**-- Type decleration for Shipment Item

TYPES : BEGIN OF T_VTTP,

TKNUM LIKE VTTP-TKNUM, " Shipment Number

VBELN LIKE VTTP-VBELN, " Order Number

END OF T_VTTP.

**-- Type decleration for Material Description

TYPES : BEGIN OF T_MAKT,

MATNR LIKE MAKT-MATNR, " Material Number

MAKTX LIKE MAKT-MAKTX, " Material Description

END OF T_MAKT.

**-- Type decleration for Final table containing all item details

TYPES : BEGIN OF T_FINAL,

VBELN LIKE LIPS-VBELN, " Delivery Number

POSNR LIKE LIPS-POSNR, " Delivery Item Number

MATNR LIKE LIPS-MATNR, " Material Number

LFIMG LIKE LIPS-LFIMG , " DELIVERED QTY

MEINS LIKE LIPS-MEINS, " Unit of Measurement

BRGEW LIKE LIPS-BRGEW, " Gross Weight

GEWEI LIKE LIPS-GEWEI, " Weight Unit

VOLUM LIKE LIPS-VOLUM, " Volumn

VOLEH LIKE LIPS-VOLEH, " Volumn Unit

MAKTX LIKE MAKT-MAKTX, " Material Description

END OF T_FINAL.

----


  • C O N S T A N T D E C E L E R A T I O N *

----


CONSTANTS: C_RE(4) TYPE C VALUE 'RE', "Bill-to-party

C_EQ(4) TYPE C VALUE 'EQ', "Equal To

C_I(2) TYPE C VALUE 'I'. "Inclusion

----


  • V A R I A B L E D E C E L E R A T I O N *

----


DATA : V_SUM TYPE LIPS-LFIMG, "For calculating total of Quantity.

V_SUM_FINAL TYPE LIPS-LFIMG, "For displaying total

V_DESC TYPE C LENGTH 20. "Storing Description

----


  • I N T E R N A L D E C L A R A T I O N *

----


**-- Internal table for delivery header data

DATA: IT_LIKP TYPE STANDARD TABLE OF T_LIKP WITH HEADER LINE,

**-- Internal table for delivery item data

IT_LIPS TYPE STANDARD TABLE OF T_LIPS WITH HEADER LINE,

**-- Internal table for bill-to-party details

IT_KNA1 TYPE STANDARD TABLE OF T_KNA1 WITH HEADER LINE,

**-- Internal table to store partner function data

IT_KVNP TYPE STANDARD TABLE OF T_KNVP WITH HEADER LINE,

**-- Internal table for shipment header data

IT_VTTK TYPE STANDARD TABLE OF T_VTTK WITH HEADER LINE,

**-- Internal table for shipmant item data

IT_VTTP TYPE STANDARD TABLE OF T_VTTP WITH HEADER LINE,

**-- Internal table for material description

IT_MAKT TYPE STANDARD TABLE OF T_MAKT WITH HEADER LINE,

**-- Internal table for final item details

IT_FINAL TYPE STANDARD TABLE OF T_FINAL WITH HEADER LINE,

**-- Temporary internal table for Shipment Item

IT_VTTP_TEMP TYPE STANDARD TABLE OF T_VTTP WITH HEADER LINE,

**-- Temporary internal table for delivery item

IT_LIPS_TEMP TYPE STANDARD TABLE OF T_LIPS WITH HEADER LINE,

**-- Temporary internal table for delivery header

IT_LIKP_TEMP TYPE STANDARD TABLE OF T_LIKP WITH HEADER LINE.

**-- Ranges for Inquiry/Quotation

RANGES R_CUSTOMER FOR KNA1-KUNNR.

----


  • S E L C T I O N S C R E E N *

----


**-- Selection screen containing Delivery no as the obligatory field

SELECTION-SCREEN BEGIN OF BLOCK CHARLY WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_VBELN FOR LIKP-VBELN OBLIGATORY.

SELECTION-SCREEN END OF BLOCK CHARLY.

----


  • I N I T I A L I Z A T I O N *

----


INITIALIZATION.

**-- Clear all internal tables

CLEAR : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL,

IT_VTTP_TEMP,

R_CUSTOMER,

V_SUM,

V_SUM_FINAL,

V_DESC.

**-- Refresh all internal tables

REFRESH : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL,

IT_VTTP_TEMP,

R_CUSTOMER.

----


  • A T S E L E C T I O N S C R E E N ( V A L I D A T I O N S ) *

----


AT SELECTION-SCREEN.

**-- Check the sales order number exists in the database table or not

SELECT SINGLE VBELN

FROM LIKP

INTO IT_LIKP

WHERE VBELN IN S_VBELN.

**-- If no single data selected display error message.

IF SY-SUBRC <> 0.

MESSAGE E000.

ENDIF.

----


  • S T A R T O F S E L E C T I O N *

----


START-OF-SELECTION.

**-- Fetch data from the transprant tables into the internal tables

PERFORM GET_DATA.

**-- Final table for complete item data

PERFORM FINAL_DATA.

----


  • E N D O F S E L E C T I O N *

----


END-OF-SELECTION.

**-- Display of Delivery Note

PERFORM DISPLAY_DATA.

&----


*& Form GET_DATA

&----


  • text

----


FORM GET_DATA .

**-- Fetch data from Delivery Header Table ( LIKP )

SELECT VBELN

ERDAT

KUNNR

KUNAG

TRMTYP

FROM LIKP

INTO TABLE IT_LIKP

WHERE VBELN IN S_VBELN

ORDER BY VBELN.

**-- Check SY_SUBRC.

IF SY-SUBRC <> 0 .

ENDIF.

**-- If record is present in IT_LIKP internal table then fetch data from

**-- Delivery Item table (LIPS)

IF NOT IT_LIKP[] IS INITIAL.

SELECT VBELN

POSNR

MATNR

LFIMG

MEINS

BRGEW

GEWEI

VOLUM

VOLEH

FROM LIPS

INTO TABLE IT_LIPS

FOR ALL ENTRIES IN IT_LIKP

WHERE VBELN = IT_LIKP-VBELN.

**-- If record found, sort the internal table on delivery no and item no

IF SY-SUBRC = 0.

SORT IT_LIPS BY VBELN POSNR.

ENDIF.

ENDIF.

**-- If record present in IT_LIPS internal table then fetch data from

**-- Shipment Item Table where delivery number is same

IF NOT IT_LIPS[] IS INITIAL.

SELECT TKNUM

VBELN

FROM VTTP

INTO TABLE IT_VTTP

FOR ALL ENTRIES IN IT_LIPS

WHERE VBELN = IT_LIPS-VBELN.

**-- If record found, sort the internal table on shipment no

IF SY-SUBRC = 0.

SORT IT_VTTP BY TKNUM.

ENDIF.

ENDIF.

**-- Move records in IT_LIPS to an temporary internal table for

**-- removing the duplicate entries of material number.

IT_LIPS_TEMP[] = IT_LIPS[].

SORT IT_LIPS_TEMP BY MATNR.

DELETE ADJACENT DUPLICATES FROM IT_LIPS_TEMP

COMPARING MATNR.

IF NOT IT_LIPS_TEMP[] IS INITIAL.

**-- Fetch Material description from MAKT for all materials in

**-- IT_LIPS_TEMP

SELECT MATNR

MAKTX

INTO TABLE IT_MAKT

FROM MAKT FOR ALL ENTRIES IN IT_LIPS_TEMP

WHERE MATNR = IT_LIPS_TEMP-MATNR.

**-- If record found, sort the internal table on Matreial No.

IF SY-SUBRC = 0.

SORT IT_MAKT BY MATNR.

ENDIF.

ENDIF.

**-- Transfer data in shipment item internal table to a temporary

**-- internal table to delete duplicate entries of shipment number.

IT_VTTP_TEMP[] = IT_VTTP[].

SORT IT_VTTP_TEMP BY TKNUM.

DELETE ADJACENT DUPLICATES FROM IT_VTTP_TEMP

COMPARING TKNUM.

**-- If record found in IT_VTTP_TEMP then fetch shipment no and carrier

**--from Shipment Header Table(VTTK).

IF NOT IT_VTTP_TEMP[] IS INITIAL.

SELECT TKNUM

TNDR_CRNM

FROM VTTK

INTO TABLE IT_VTTK

FOR ALL ENTRIES IN IT_VTTP_TEMP

WHERE TKNUM = IT_VTTP_TEMP-TKNUM.

**-- If record found, sort the internal table on shipment no

IF SY-SUBRC = 0.

SORT IT_VTTK BY TKNUM.

ENDIF.

ENDIF.

**-- Move the data of IT_LIKP to an internal table to remove the

**-- duplicate entries of sold-to-party number.

IT_LIKP_TEMP[] = IT_LIKP[].

SORT IT_LIKP_TEMP BY KUNAG.

DELETE ADJACENT DUPLICATES FROM IT_LIKP_TEMP

COMPARING KUNAG.

**-- If record present in IT_LIKP then fetch data from Partner Function

**-- Table where Partner function value should be eq to Bill-to-party

IF NOT IT_LIKP_TEMP[] IS INITIAL.

SELECT KUNNR

PARVW

KUNN2

FROM KNVP

INTO TABLE IT_KVNP

FOR ALL ENTRIES IN IT_LIKP_TEMP

WHERE KUNNR = IT_LIKP_TEMP-KUNAG

AND PARVW = C_RE.

**-- If record found, sort the internal table on Customer no

IF SY-SUBRC = 0.

SORT IT_KVNP BY KUNNR.

ENDIF.

ENDIF.

**-- Putting Customer Number into the ranges

**-- Ship-to-party

LOOP AT IT_LIKP.

R_CUSTOMER-SIGN = C_I.

R_CUSTOMER-OPTION = C_EQ.

R_CUSTOMER-LOW = IT_LIKP-KUNNR.

APPEND R_CUSTOMER.

CLEAR R_CUSTOMER.

**-- Sold-to-party

SORT R_CUSTOMER BY LOW.

READ TABLE R_CUSTOMER WITH KEY LOW = IT_LIKP-KUNAG

BINARY SEARCH.

IF SY-SUBRC <> 0.

R_CUSTOMER-SIGN = C_I.

R_CUSTOMER-OPTION = C_EQ.

R_CUSTOMER-LOW = IT_LIKP-KUNAG.

APPEND R_CUSTOMER.

CLEAR R_CUSTOMER.

ENDIF.

ENDLOOP.

**-- Bill-to-party.

SORT R_CUSTOMER BY LOW.

LOOP AT IT_KVNP WHERE PARVW = C_RE.

READ TABLE R_CUSTOMER WITH KEY LOW = IT_KVNP-KUNN2

BINARY SEARCH.

IF SY-SUBRC <> 0.

R_CUSTOMER-SIGN = C_I.

R_CUSTOMER-OPTION = C_EQ.

R_CUSTOMER-LOW = IT_KVNP-KUNN2.

APPEND R_CUSTOMER.

CLEAR R_CUSTOMER.

ENDIF.

ENDLOOP.

**-- If record found in R_CUSTOMER then fetch data from Customer Master

**-- (KNA1) where customer number is same.

IF NOT R_CUSTOMER[] IS INITIAL.

SELECT KUNNR

NAME1

NAME2

STRAS

REGIO

ORT01

LAND1

TELF1

FROM KNA1

INTO TABLE IT_KNA1

FOR ALL ENTRIES IN R_CUSTOMER

WHERE KUNNR = R_CUSTOMER-LOW.

**-- If record found, sort the internal table on Customer no

IF SY-SUBRC = 0.

SORT IT_KNA1 BY KUNNR.

ENDIF.

ENDIF.

ENDFORM. " GET_DATA

&----


*& Form FINAL_DATA

&----


  • All Item Details

----


FORM FINAL_DATA .

**-- Clear all internal tables.

CLEAR : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL.

**-- Loop at the item table and put all the data into the final table

**-- then read the material description table and append all into the

**-- final table.

LOOP AT IT_LIPS.

CLEAR IT_MAKT.

IT_FINAL = IT_LIPS.

READ TABLE IT_MAKT WITH KEY MATNR = IT_LIPS-MATNR

BINARY SEARCH.

IF SY-SUBRC = 0.

IT_FINAL-MAKTX = IT_MAKT-MAKTX.

ENDIF.

**-- Append records into final internal table

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

ENDFORM. " FINAL_DATA

&----


*& Form DISPLAY_DATA

&----


  • Printing of SAP SCRIPT

----


FORM DISPLAY_DATA .

**-- Clear all internal table header

CLEAR : IT_LIKP,

IT_LIPS,

IT_KNA1,

IT_KVNP,

IT_VTTK,

IT_VTTP,

IT_MAKT,

IT_FINAL.

**-- Call OPEN_FORM function to open script

CALL FUNCTION 'OPEN_FORM'

EXPORTING

DEVICE = 'PRINTER'

LANGUAGE = SY-LANGU

EXCEPTIONS

CANCELED = 1

DEVICE = 2

FORM = 3

OPTIONS = 4

UNCLOSED = 5

MAIL_OPTIONS = 6

ARCHIVE_ERROR = 7

INVALID_FAX_NUMBER = 8

MORE_PARAMS_NEEDED_IN_BATCH = 9

SPOOL_ERROR = 10

CODEPAGE = 11

OTHERS = 12.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**-- Loop at final internal table whose data is to be displayed in

**-- the main window.

LOOP AT IT_FINAL.

**-- Move the material description into a fixed length variable so that

**-- the data do not over flow

V_DESC = IT_FINAL-MAKTX.

**-- For every new delivery number.

AT NEW VBELN.

**-- Start a new script form for every new delivery number

CALL FUNCTION 'START_FORM'

EXPORTING

FORM = 'Z8NB_SHA10_2'

LANGUAGE = SY-LANGU

EXCEPTIONS

FORM = 1

FORMAT = 2

UNENDED = 3

UNOPENED = 4

UNUSED = 5

SPOOL_ERROR = 6

CODEPAGE = 7

OTHERS = 8.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**-- Clear internal tables

CLEAR : IT_LIKP,

IT_VTTP,

IT_VTTK,

IT_KNA1.

**-- Read table IT_LIKP, IT_VTTP, IT_VTTK and IT_KNA1 to fetch the

**-- records to be displayed in sold-to-party window.

READ TABLE IT_LIKP WITH KEY VBELN = IT_FINAL-VBELN

BINARY SEARCH.

IF SY-SUBRC = 0.

***-- Shipment header

READ TABLE IT_VTTP WITH KEY VBELN = IT_LIKP-VBELN.

IF SY-SUBRC = 0.

READ TABLE IT_VTTK WITH KEY TKNUM = IT_VTTP-TKNUM.

IF SY-SUBRC = 0.

**-- Sold-to-party

READ TABLE IT_KNA1 WITH KEY KUNNR = IT_LIKP-KUNAG

BINARY SEARCH.

IF SY-SUBRC = 0.

**-- Call WRITE_FORM function to display records.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'SOLD_TO'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

CLEAR IT_KNA1.

**-- Read table IT_KNA1 for fetching Ship-to-party details

**-- and display them in SHIP window

READ TABLE IT_KNA1 WITH KEY KUNNR = IT_LIKP-KUNNR

BINARY SEARCH.

IF SY-SUBRC = 0.

**-- Call function WRITE_FORM to display data

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'SHIP'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

CLEAR : IT_KVNP,

IT_KNA1.

**-- Bill-to-party

READ TABLE IT_KVNP WITH KEY KUNNR = IT_LIKP-KUNAG

PARVW = C_RE

BINARY SEARCH.

IF SY-SUBRC = 0.

READ TABLE IT_KNA1 WITH KEY KUNNR = IT_KVNP-KUNN2

BINARY SEARCH.

IF SY-SUBRC = 0.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'BILL_TO'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

ENDIF.

ENDAT.

**-- Writing header of main window

PERFORM WRITE_HEADER.

**-- Writing item details in main window body

PERFORM WRITE_BODY.

**-- Calculating total quantity

V_SUM = V_SUM + IT_FINAL-LFIMG.

AT END OF VBELN.

**-- Putting sum value into a variabe for final total display

V_SUM_FINAL = V_SUM.

CLEAR V_SUM.

**-- Printing total value

PERFORM WRITE_TOTAL.

**-- Calling END_FORM

CALL FUNCTION 'END_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SPOOL_ERROR = 3

CODEPAGE = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDAT.

ENDLOOP.

**-- Close SAP SCRIPT

CALL FUNCTION 'CLOSE_FORM'

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

CODEPAGE = 5

OTHERS = 6.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " DISPLAY_DATA

&----


*& Form WRITE_HEADER

&----


  • Main Window Heading

----


FORM WRITE_HEADER .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'HEAD'

TYPE = 'TOP'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " WRITE_HEADER

&----


*& Form WRITE_BODY

&----


  • Main window body

----


FORM WRITE_BODY .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'BODY'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " WRITE_BODY

&----


*& Form write_total

&----


  • Tatal

----


FORM WRITE_TOTAL .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'TOTAL'

TYPE = 'BODY'

WINDOW = 'MAIN'

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " write_total

Reward points if helpful

Regards

Nilesh

Read only

Former Member
0 Likes
1,794

Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.

Two lines are regarded as duplicates if their keys are identical.

The return code is set as follows:

SY-SUBRC = 0:

At least one duplicate was found, and at least one entry was deleted.

SY-SUBRC = 4:

No duplicates found, no entries deleted.

Read only

learnsap
Active Participant
0 Likes
1,794

Hi Vijaya Laxmi,

To Delete adjacent duplicates from itab....

initially the internal table should be sorted with the field that you want to use as a reference field for deleting the adjacent duplicates....

*to retrieve all the documents related to purchase requisition from eket table

*and this contains all the item details also

select ebeln field2 from eket into table itab

where banfn = p_banfn.

*sorting the internal table with respect to ebeln

sort itab ascending by ebeln.

delete adjacent duplicates from itab comparing ebeln.

so you will get all the reference documents related to the given purchase requisition...

Correct if I am wrong...

Regards,

Ramesh

*award points if reply is useful

Read only

Former Member
0 Likes
1,794

Hi

That command is used to delete the records with the same keys (char fields) loaded in an internal table.

Max

Read only

Former Member
0 Likes
1,794

Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.

Two lines are regarded as duplicates if their keys are identical.

The Return Code is set as follows:

SY-SUBRC = 0:

At least one duplicate was found, and at least one entry was deleted.

SY-SUBRC = 4:

No duplicates found, no entries deleted.

Addition 1

... COMPARING f1 f2 ...

Effect

Two lines of the internal table itab are regarded as duplicates if they have identical contents in the fields f1, f2, ...

Addition 2

... COMPARING ALL FIELDS

Effect

Two lines of the internal table are regarded as duplicates if all of their field contents are identical.

Notes

The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.

If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.

You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.

Eg:

SORT ITAB.

DELETE ADJACENT DUPLICATES FROM ITAB.