Application Development 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: 

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

Former Member
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

Hi

It's very hard to say something to you, you should give us the code of FORM_04.

Max

0 Kudos

HERE IS THE FULL CODE:: please help

REPORT zcou2006.

TABLES: zknvh.

*... Datentypen ................................

TYPES:

BEGIN OF t1_knvh, "... Knoten

mandt LIKE knvh-mandt,

hzuor LIKE knvh-hzuor,

hityp LIKE knvh-hityp,

kunnr LIKE knvh-kunnr,

vkorg LIKE knvh-vkorg,

vtweg LIKE knvh-vtweg,

spart LIKE knvh-spart,

hkunnr LIKE knvh-hkunnr,

hvkorg LIKE knvh-hvkorg,

hvtweg LIKE knvh-hvtweg,

hspart LIKE knvh-hspart,

grpno LIKE knvh-grpno,

bokre LIKE knvh-bokre,

prfre LIKE knvh-prfre,

END OF t1_knvh,

t2_knvh LIKE knvh,

t3_zknvh LIKE zknvh,

t4_zknvh LIKE zknvh,

t1_hknvh TYPE HASHED TABLE OF t1_knvh WITH UNIQUE KEY

mandt hzuor hityp kunnr vkorg vtweg spart.

DATA:

lknvh TYPE t2_knvh OCCURS 0 WITH HEADER LINE,

bu_zknvh TYPE t3_zknvh OCCURS 0 WITH HEADER LINE,

au_zknvh TYPE t4_zknvh OCCURS 0 WITH HEADER LINE,

kknvh TYPE t1_hknvh WITH HEADER LINE,

flag(1) TYPE c,

help_hzuor LIKE knvh-hzuor,

zaehler TYPE p.

INITIALIZATION.

AUTHORITY-CHECK OBJECT 'ZZABAP'

ID 'ZZABAP' FIELD 'ZCOU2006'

ID 'ZZAKTI' FIELD '1'.

IF sy-subrc <> 0.

MESSAGE e001(zm) WITH text-001.

ENDIF.

PARAMETER:

bu AS CHECKBOX,

p_vtweg LIKE zknvh-vtweg OBLIGATORY.

START-OF-SELECTION.

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.

IF p_vtweg EQ 'MZ'.

PERFORM form_06.

ELSEIF p_vtweg EQ 'AU'.

PERFORM form_04.

ENDIF.

FORM form_06.

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.

SELECT * INTO CORRESPONDING FIELDS OF TABLE kknvh

FROM knvh

WHERE hityp = 'A'

AND datbi GE sy-datum

AND hzuor LT '06'.

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 form_04.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lknvh

FROM knvh

WHERE hityp = 'A'

AND datbi GE sy-datum

AND hzuor LE '06'.

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

SELECT * INTO CORRESPONDING FIELDS OF TABLE kknvh

FROM knvh

WHERE hityp = 'A'

AND datbi GE sy-datum

AND hzuor LT '06'.

LOOP AT lknvh.

CLEAR: au_zknvh, flag.

MOVE-CORRESPONDING lknvh TO au_zknvh.

zaehler = 6.

DO 4 TIMES.

zaehler = zaehler - 1.

UNPACK zaehler TO help_hzuor.

au_zknvh-hier05 = ' '.

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'. au_zknvh-hier04 = ' '.

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

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

WHEN '02'. au_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 au_zknvh.

ENDIF.

ENDLOOP.

ENDFORM. " form_04

END-OF-SELECTION.

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.

CALL FUNCTION 'Z_SELECT_OPTIONS_PRINT'

EXPORTING

irepid = 'ZCOU2006'

ausgabe = ' '

EXCEPTIONS

OTHERS = 1.

Message was edited by: Preethu

0 Kudos

NO REPLIES

0 Kudos

Hi Preethu!

If you are sure, your program is same for AU and MZ (apart of the number of levels), then you should debug step by step. If there is a select, where less entries as expected are selected -> compare with SE16. Take especially a look at 'additional' restrictions, like HZUOR. Maybe your data is not created as expected.

Regards,

Christian

0 Kudos

Remove MANDT from all of your data definitions. If you have MANDT in your itab, then your sql statements should specify CLIENT SPECIFIED and your SELECT will not select anything into this field without it.

0 Kudos

sorry, I can't see any obvious logic problem but having the two very similar forms makes it difficult for yourself (and others!). I think a better design would be to have one form with slight logic variations where required. This would make it much easier to debug and maintain.