Skip to Content

One of the drawbacks on SCN is that it isn’t so much beginner friendly. There are very little how-to documents and beginners questions are often locked because there are too basic.

So I came with an idea to start a series of documents called ABAP Beginners guide in which will describe in detail, along with complete code, some of the most often programming requirements.

In this first document we will create classical List report for comparing Customer and Vendor master data where one legal subject is both customer and vendor. Because of filling in two different transactions, this data is often inconsistent, so the goal of this report is to mark differences in data for the same legal subject that is both customer and vendor for one company code. 

Tables that will be used are:

  1. KNA1 – General Data in Customer Master
  2. LFA1 – Vendor Master (General Section)
  3. KNB1 – Customer Master (Company Code)
  4. LFB1 – Vendor Master (Company Code)
  5. T001 – Company Codes

First, we are declaring database tables, internal table for data manipulation and some variables:

REPORT  z_scn_cust_vend NO STANDARD PAGE HEADING LINE-SIZE 170. “this means that the list will be 170 characters wide

TABLES: kna1,
        lfa1
,
        lfb1
, “to connect vendors with company code
        knb1
, “to connect customers with company code
        t001
. “to get name of the company

DATA: BEGIN OF final OCCURS 0,

k_stcd1 LIKE kna1stcd1,
k_stkzn
LIKE kna1stkzn,
k_kunnr
LIKE kna1kunnr,
k_anred
LIKE kna1anred,
k_name1
LIKE kna1name1,
k_stras
LIKE kna1stras,
k_pstlz
LIKE kna1pstlz,
k_ort01
LIKE kna1ort01,
k_stcd2
LIKE kna1stcd2,
k_stcd3
LIKE kna1stcd3,
k_stceg
LIKEkna1stceg,

l_stcd1 LIKE lfa1stcd1,
l_stkzn
LIKE lfa1stkzn,
l_lifnr
LIKE lfa1lifnr,
l_anred
LIKE lfa1anred,
l_name1
LIKE lfa1name1,
l_stras
LIKE lfa1stras,
l_pstlz
LIKE lfa1pstlz,
l_ort01
LIKE lfa1ort01,
l_stcd2
LIKE lfa1stcd2,
l_stcd3
LIKE lfa1stcd3,
l_stceg
LIKE lfa1stceg.

DATA: END OF final.

DATA: cursor_field(50), field_value(50).

DATA rec LIKE final.

DATA comp TYPE t001butxt.

DATA count(10) TYPE n VALUE ‘0’.

Next, we need selection screen for defining company code and two radio buttons to select if we look by customers for that company code or by vendors for that company code:

SELECTION-SCREEN BEGIN OF BLOCK first WITH FRAME TITLE text001.

SELECT-OPTIONSbukrs  FOR lfb1bukrs NO INTERVALS NO-EXTENSION.

PARAMETERS: r1 RADIOBUTTON GROUP rad1 DEFAULT ‘X’,
             r2
RADIOBUTTON GROUP rad1.

SELECTION-SCREEN END OF BLOCK first.

Now, we do select statement for both cases:

IF r1 = ‘X’.

SELECT kn~stcd1 AS k_stcd1
kn
~stkzn AS k_stkzn
kn
~kunnr AS k_kunnr
kn
~anred AS k_anred
kn
~name1 AS k_name1
kn
~stras AS k_stras
kn
~pstlz AS k_pstlz
kn
~ort01 AS k_ort01
kn
~stcd2 AS k_stcd2
kn
~stcd3 AS k_stcd3
kn
~stceg AS k_stceg

lf~stcd1 AS l_stcd1
lf
~stkzn AS l_stkzn
lf
~lifnr AS l_lifnr
lf
~anred AS l_anred
lf
~name1 AS l_name1
lf
~stras AS l_stras
lf
~pstlz AS l_pstlz
lf
~ort01 AS l_ort01
lf
~stcd2 AS l_stcd2
lf
~stcd3 AS l_stcd3
lf
~stceg AS l_stceg
INTO CORRESPONDING FIELDS OF TABLE final
FROM kna1 AS kn
INNER
JOIN lfa1 AS lf
ON lf~lifnr = kn~lifnr
INNER
JOIN lfb1 AS lb
ON lb~lifnr = lf~lifnr
WHERE lb~bukrs IN bukrs
AND kn~sperr =
AND lf~sperr = .

ELSE.

SELECT kn~stcd1 AS k_stcd1
kn
~stkzn AS k_stkzn
kn
~kunnr AS k_kunnr
kn
~anred AS k_anred
kn
~name1 AS k_name1
kn
~stras AS k_stras
kn
~pstlz AS k_pstlz
kn
~ort01 AS k_ort01
kn
~stcd2 AS k_stcd2
kn
~stcd3 AS k_stcd3
kn
~stceg AS k_stceg

lf~stcd1 AS l_stcd1
lf
~stkzn AS l_stkzn
lf
~lifnr AS l_lifnr
lf
~anred AS l_anred
lf
~name1 AS l_name1
lf
~stras AS l_stras
lf
~pstlz AS l_pstlz
lf
~ort01 AS l_ort01
lf
~stcd2 AS l_stcd2
lf
~stcd3 AS l_stcd3
lf
~stceg AS l_stceg
INTO CORRESPONDING FIELDS OF TABLE final
FROM kna1 AS kn
INNER
JOIN lfa1 AS lf
ON lf~lifnr = kn~lifnr
INNER
JOIN knb1 AS kb
ON kb~kunnr = kn~kunnr
WHERE kb~bukrs IN bukrs
AND kn~sperr =
AND lf~sperr = .

ENDIF.

SELECT SINGLE butxt INTO comp FROM t001
WHERE t001~bukrs IN bukrs.

And finally, we build our list for data display that will mark with red color those fields that are different for the same legal subject:

TOP-OF-PAGE.
WRITE: / ‘Company name:  ‘, comp.
WRITE: /1 ‘PIB’, 16 ‘ID num.’, 26 ‘Title’, 38 ‘Name’, 69 ‘Street & number’, 98 ‘Postal code’, 109 ‘City’,
132 ‘Tax num.1’ , 144  ‘Tax num.2’ , 158 ‘VAT’.
ULINE.

START-OF-SELECTION.

LOOP AT final INTO rec.
count = count + 1.

IF reck_stcd1 <> recl_stcd1 OR reck_stkzn <> recl_stkzn
OR reck_anred <> recl_anred OR reck_name1 <> recl_name1
OR reck_stras <> recl_stras OR reck_pstlz <> recl_pstlz
OR reck_ort01 <> recl_ort01 OR reck_stcd2 <> recl_stcd2
OR reck_stcd3 <> recl_stcd3 OR reck_stceg <> reck_stceg.

IF reck_stcd1 <> recl_stcd1.
WRITE: reck_stcd1(14) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_stcd1(14).
ENDIF.
WRITE: reck_kunnr COLOR COL_GROUP.
IF reck_anred <> recl_anred.
WRITE: reck_anred(10) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_anred(10).
ENDIF.
IF reck_name1 <> recl_name1.
WRITE: reck_name1(30) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_name1(30).
ENDIF.
IF reck_stras <> recl_stras.
WRITE: reck_stras(30) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_stras(30).
ENDIF.
IF reck_pstlz <> recl_pstlz.
WRITE: reck_pstlz(8) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_pstlz(8).
ENDIF.
IF reck_ort01 <> recl_ort01.
WRITE: reck_ort01(22) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_ort01(22).
ENDIF.
IF reck_stcd2 <> recl_stcd2.
WRITE: reck_stcd2 COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_stcd2.
ENDIF.
IF reck_stcd3 <> recl_stcd3.
WRITE: reck_stcd3(13) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_stcd3(13).
ENDIF.
IF reck_stceg <> reck_stceg.
WRITE: reck_stceg(12) COLOR COL_NEGATIVE.
ELSE.
WRITE: reck_stceg(12).
ENDIF.

NEW-LINE.

IF reck_stcd1 <> recl_stcd1.
WRITE: recl_stcd1(14) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_stcd1(14).
ENDIF.
WRITE: recl_lifnr COLOR COL_GROUP.
IF reck_anred <> recl_anred.
WRITE: recl_anred(10) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_anred(10).
ENDIF.
IF reck_name1 <> recl_name1.
WRITE: recl_name1(30) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_name1(30).
ENDIF.
IF reck_stras <> recl_stras.
WRITE: recl_stras(30) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_stras(30).
ENDIF.
IF reck_pstlz <> recl_pstlz.
WRITE: recl_pstlz(8) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_pstlz(8).
ENDIF.
IF reck_ort01 <> recl_ort01.
WRITE: recl_ort01(22) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_ort01(22).
ENDIF.
IF reck_stcd2 <> recl_stcd2.
WRITE: recl_stcd2 COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_stcd2.
ENDIF.
IF reck_stcd3 <> recl_stcd3.
WRITE: recl_stcd3(13) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_stcd3(13).
ENDIF.
IF reck_stceg <> reck_stceg.
WRITE: recl_stceg(12) COLOR COL_NEGATIVE.
ELSE.
WRITE: recl_stceg(12).
ENDIF.

ULINE.
ENDIF.
ENDLOOP.

SHIFT count LEFT DELETING LEADING ‘0’.
WRITE: ‘Number of records: ‘, count.

If someone start to repair these inconsistent data, it would be ideally to do that through transactions FD02 – Change Customer and XK02 – Change Vendor, so we add shortcuts to these transactions on double click on ID number. Off course, clicked customer or vendor are already loaded in transaction.

AT LINE-SELECTION.

GET CURSOR FIELD cursor_field
VALUE field_value.

CASE cursor_field.
WHEN ‘REC-K_KUNNR’.
READ LINE sylilli FIELD VALUE reck_kunnr.
CHECK NOT reck_kunnr IS INITIAL.
SET PARAMETER ID: ‘KUN’ FIELD reck_kunnr.
SET PARAMETER ID: ‘BUK’ FIELD bukrslow.
CALL TRANSACTION ‘FD02’ AND SKIP FIRST SCREEN.
WHEN ‘REC-L_LIFNR’.
READ LINE sylilli FIELD VALUE recl_lifnr.
CHECK NOT recl_lifnr IS INITIAL.
SET PARAMETER ID: ‘LIF’ FIELD recl_lifnr.
SET PARAMETER ID: ‘BUK’ FIELD bukrslow.
CALL TRANSACTION ‘XK02’ AND SKIP FIRST SCREEN.
ENDCASE.

Only thing left to do is to create transaction for our report. Let’s name it ZCVD (like customer vendor differences). Resulting report looks like this:


/wp-content/uploads/2013/10/list_311499.jpg

In the next document, we will create simple procedural ALV report.

Thank you for reading.


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply