Skip to Content
0
Former Member
Jan 10, 2006 at 01:44 PM

Problem in reading Data and Inserting...Urgent help..

27 Views

INITIALIZATION.

AUTHORITY-CHECK OBJECT 'ZZABAP'

ID 'ZZABAP' FIELD 'ZCOU2006'

ID 'ZZAKTI' FIELD '1'.

IF sy-subrc <> 0.

MESSAGE e001(zm) WITH text-001.

ENDIF.

*... Selektionen .......................................................

PARAMETER:

bu AS CHECKBOX,

p_vtweg LIKE zknvh-vtweg OBLIGATORY. ".. Update JA/NEIN ?

START-OF-SELECTION.

*... Löschen ZKNVH .....................................................

IF NOT bu IS INITIAL.

DELETE FROM zknvh WHERE hityp = 'A'.

IF sy-subrc GT 4.

ROLLBACK WORK.

MESSAGE e001(zm) WITH text-002.

ENDIF.

ENDIF.

*Select the Vtweg and perform based on the Vtweg..

*Running two Variants in the BG processing..

IF p_vtweg EQ 'MZ'.

PERFORM form_06.

ELSEIF p_vtweg EQ 'AU'.

PERFORM form_04.

ENDIF.

*----


*

  • FORM form_06 *

*----


*

  • ........ *

*----


*

FORM form_06.

*... Fuellen LKNVH ....................................................

.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lknvh

FROM knvh

WHERE hityp = 'A'

AND datbi GE sy-datum

AND hzuor = '06'.

MESSAGE i002(zm) WITH text-005 sy-dbcnt.

*... Fuellen Knoten KKNVH .............................................

.

SELECT * INTO CORRESPONDING FIELDS OF TABLE kknvh

FROM knvh

WHERE hityp = 'A'

AND datbi GE sy-datum

AND hzuor LT '06'.

*... Aufbau BU_ZKNVH ..................................................

.

LOOP AT lknvh.

CLEAR: bu_zknvh, flag.

MOVE-CORRESPONDING lknvh TO bu_zknvh.

zaehler = 6.

DO 4 TIMES.

zaehler = zaehler - 1.

UNPACK zaehler TO help_hzuor.

bu_zknvh-hier05 = lknvh-hkunnr.

IF sy-index = 1.

READ TABLE kknvh WITH TABLE KEY

mandt = sy-mandt

hzuor = help_hzuor

hityp = lknvh-hityp

kunnr = lknvh-hkunnr

vkorg = lknvh-hvkorg

vtweg = lknvh-hvtweg

spart = lknvh-hspart.

ELSE.

READ TABLE kknvh WITH TABLE KEY

mandt = sy-mandt

hzuor = help_hzuor

hityp = kknvh-hityp

kunnr = kknvh-hkunnr

vkorg = kknvh-hvkorg

vtweg = kknvh-hvtweg

spart = kknvh-hspart.

ENDIF.

IF sy-subrc = 0.

CASE help_hzuor.

WHEN '05'. bu_zknvh-hier04 = kknvh-hkunnr.

WHEN '04'. bu_zknvh-hier03 = kknvh-hkunnr.

WHEN '03'. bu_zknvh-hier02 = kknvh-hkunnr.

WHEN '02'. bu_zknvh-hier01 = kknvh-hkunnr.

ENDCASE.

ELSE.

WRITE: / text-004,

kknvh-hityp,

kknvh-kunnr,

kknvh-vkorg,

kknvh-vtweg,

kknvh-spart,

kknvh-hkunnr,

kknvh-hvkorg,

kknvh-hvtweg,

kknvh-hspart,

kknvh-hzuor.

flag = 'X'.

EXIT.

ENDIF.

ENDDO.

IF flag IS INITIAL.

APPEND bu_zknvh.

ENDIF.

ENDLOOP.

ENDFORM. " form_06

  • Form_4 looks exactly like form_6 just the table name changed and Hier05 and Hier04 fields are Blanks..

INSERT zknvh from Table bu_zknvh.

MESSAGE i002(zm) WITH text-006 sy-dbcnt.

IF sy-subrc <> 0 OR bu IS INITIAL.

ROLLBACK WORK.

MESSAGE e001(zm) WITH text-003.

ELSE.

COMMIT WORK.

ENDIF.

INSERT zknvh from Table au_zknvh.

MESSAGE i002(zm) WITH text-006 sy-dbcnt.

IF sy-subrc <> 0 OR bu IS INITIAL.

ROLLBACK WORK.

MESSAGE e001(zm) WITH text-003.

ELSE.

COMMIT WORK.

ENDIF.

1) When I select VTWEG 'MZ' everything is working without anyproblem...

2) When I select VTWEG 'AU' I can see only one RECORD.. where as their are around 41,000 records.. in this Selection..

Normally with this prog the ZKNVH table should be filled with the specified fields..

Only if the VTWEG is AU the Hier05 and Hier04 is Blank and others are filled with data.. bcoz in the Customer Hierarchy of AU has only 4 levels...

and if VTWEG is MZ all the fields should be filled with data as the Customer Hierarchy of Mz has 6 levels..

Please check the prog and suggest me how I can Fill append the table ZKNVH with data when I select AU..

Thanx in advance...

Preethu

Message was edited by: Preethu