0% found this document useful (0 votes)
87 views4 pages

Conversion Program For KNA1 Table

This document provides steps to create and run a SAP report program that updates customer tax numbers in the SAP system. It includes: 1) Creating a Z report in transaction SE38. 2) Copying ABAP code into the report that selects customer records, moves tax numbers from one field to another, and commits the changes. 3) Saving and activating the report program. 4) Running the report to process the tax number updates for selected clients.

Uploaded by

Erick Vite
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
87 views4 pages

Conversion Program For KNA1 Table

This document provides steps to create and run a SAP report program that updates customer tax numbers in the SAP system. It includes: 1) Creating a Z report in transaction SE38. 2) Copying ABAP code into the report that selects customer records, moves tax numbers from one field to another, and commits the changes. 3) Saving and activating the report program. 4) Running the report to process the tax number updates for selected clients.

Uploaded by

Erick Vite
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

Step1: Goto SE38 transaction.

Step2: Create the Z reports ( name can be as per the customer naming convention)

Step3: Copy below code.


*&---------------------------------------------------------------------*
*& Report ZMTEST_NON_XPRA_EXAMPLE_KNA1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_kna1_correct_chinese_tax.

DATA:
gt_client TYPE mand_type, "#EC NEEDED
gv_client TYPE mandt, "#EC NEEDED
gv_lines TYPE i. "#EC NEEDED

DATA:
lt_deltax TYPE STANDARD TABLE OF kna1, "#EC NEEDED
lt_addtax TYPE STANDARD TABLE OF kna1, "#EC NEEDED
ls_kna1 TYPE kna1, "#EC NEEDED
lv_selcnt TYPE i,
lv_addcnt TYPE i, "#EC NEEDED
lv_cursor TYPE cursor, "#EC NEEDED
lv_ref_kna1 TYPE REF TO kna1. "#EC NEEDED

FIELD-SYMBOLS: <ls_tax> TYPE kna1, "#EC NEEDED


<lv_taxnum5> TYPE tdchar60. "#EC NEEDED

CONSTANTS: lc_land TYPE land1 VALUE 'CN'. "#EC NEEDED

* -------------------------------------------------------------------
* selection screen
* -------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK datasel WITH FRAME TITLE gv_title.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK clients WITH FRAME TITLE gv_clnts.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(7) gv_mandt FOR FIELD s_client.
SELECT-OPTIONS s_client FOR syst-mandt OBLIGATORY DEFAULT sy-
mandt ##SEL_WRONG.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK clients.
SELECTION-SCREEN BEGIN OF BLOCK modus WITH FRAME TITLE gv_mode.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_test TYPE xfeld AS CHECKBOX DEFAULT abap_true ##SEL_WRON
G.
SELECTION-SCREEN COMMENT 5(30) gv_test FOR FIELD p_test.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK modus.
SELECTION-SCREEN END OF BLOCK datasel.

* ---------------------------------------------------------------------------
--
INITIALIZATION.
* ---------------------------------------------------------------------------
--

SELECT mandt INTO TABLE gt_client FROM t000.


SORT gt_client.
DESCRIBE TABLE gt_client LINES gv_lines.
s_client-sign = 'I'.
IF gv_lines GT 1.
s_client-option = 'BT'.
READ TABLE gt_client INTO gv_client INDEX gv_lines.
s_client-high = gv_client.
ELSE.
s_client-option = 'EQ'.
ENDIF.
READ TABLE gt_client INTO gv_client INDEX 1.
s_client-low = gv_client.
MODIFY s_client INDEX 1.

* ---------------------------------------------------------------------------
--
AT SELECTION-SCREEN OUTPUT.
* ---------------------------------------------------------------------------
--
WRITE 'Replace STCEG field Tax Numbers in STCD5 field Tax Numbers' TO gv_ti
tle ##WRITE_MOVE ##NO_TEXT.
WRITE 'Clients to be updated' TO gv_cl
nts ##WRITE_MOVE ##NO_TEXT.
WRITE 'Program Mode' TO gv_mo
de ##WRITE_MOVE ##NO_TEXT.
WRITE 'Test (no DB Changes)' TO gv_te
st ##WRITE_MOVE ##NO_TEXT.

* ---------------------------------------------------------------------------
--
START-OF-SELECTION.
* ---------------------------------------------------------------------------
--
SELECT mandt INTO TABLE gt_client FROM t000
WHERE mandt IN s_client.
IF gt_client IS INITIAL.
WRITE:/ 'Nothing to be done'. "#
NO TEXT
RETURN.
ENDIF.
GET REFERENCE OF ls_kna1 INTO lv_ref_kna1.
ASSIGN COMPONENT 'STCD5' OF STRUCTURE lv_ref_kna1->* TO <lv_taxnum5>.
IF <lv_taxnum5> IS NOT ASSIGNED.
WRITE: / 'STCD5 does not exist, no need to go-on'.
RETURN.
ENDIF.
LOOP AT gt_client INTO gv_client.
CLEAR: lv_selcnt,lv_addcnt.
OPEN CURSOR WITH HOLD lv_cursor FOR
SELECT * FROM kna1 CLIENT SPECIFIED
WHERE mandt = gv_client
AND land1 = lc_land
AND stceg NE space.
DO.
FETCH NEXT CURSOR lv_cursor INTO TABLE lt_deltax
PACKAGE SIZE 1000.
IF sy-subrc <> 0.
CLOSE CURSOR lv_cursor.
EXIT.
ENDIF.
lt_addtax = lt_deltax.
LOOP AT lt_addtax ASSIGNING <ls_tax>.
ASSIGN COMPONENT 'STCD5' OF STRUCTURE <ls_tax> TO <lv_taxnum5>.
IF sy-subrc IS INITIAL.
<lv_taxnum5> = <ls_tax>-stceg.
CLEAR <ls_tax>-stceg.
ENDIF.
ENDLOOP.
DESCRIBE TABLE lt_addtax LINES lv_selcnt.
IF p_test IS INITIAL.
UPDATE kna1 CLIENT SPECIFIED FROM TABLE lt_addtax.
IF sy-subrc <> 0 AND sy-subrc <> 4.
ROLLBACK WORK.
WRITE:/ 'Error in changing data' ##N
O_TEXT.
RETURN.
ENDIF.
CALL FUNCTION 'DB_COMMIT'.
ENDIF.
ADD sy-dbcnt TO lv_addcnt.
ENDDO.
IF p_test IS INITIAL.
COMMIT WORK AND WAIT.
WRITE:/.
WRITE:/ 'Processed client:' ##N
O_TEXT,
gv_client.
WRITE:/ 'Number of updated entires:' ##N
O_TEXT,
lv_addcnt.
WRITE:/.
ELSE.
WRITE:/ 'Processed client:' ##N
O_TEXT,
gv_client.
WRITE:/ 'Number of selected entries:' ##N
O_TEXT,
lv_selcnt.
ENDIF.
ENDLOOP.

Step4: SAVE and Activate Z report program.

Step5: Run the report program.

You might also like