cancel
Showing results for 
Search instead for 
Did you mean: 

looping problem

Former Member
0 Kudos

Hi Experts,

1. I want to display all content of CDHDR & CDPOS table.But i am getting all data from CDHDR table & only one record from CDPOS.

2. I want to display the output format like this

cdhdr(header)objectclasobjectid^ ...version

cdpos(Item)TabnameTabkey^...Ext_keylen.

eg:

cdhdrKOSTL10000000001000^3261...

cdposCSKSB090100000000010009999123119940101^....

cdhdrKOSTL100000000010222^2788....

cdposCSKSB090100000000010009922222222222^....

...

..

.....

3. Anyone help me to get this format.Please modify the following coding to get the exact result.

*"----


""Local interface:

*" IMPORTING

*" VALUE(TRANSCATIONCODE) LIKE ZBAPI_STRUCT-TCODE OPTIONAL

*" VALUE(DATASIZE) LIKE ZBAPI_STRUCT-OBJECTID OPTIONAL

*" VALUE(NO_OF_DAYS) LIKE ZBAPI_STRUCT-DAYS

*" VALUE(DELIMITOR) LIKE ZBAPI_STRUCT-DELIMI OPTIONAL

*" TABLES

*" OUTPUT STRUCTURE ZBAPI_OUTPUT

*"----


Data: CDHDR like table of CDHDR WITH HEADER LINE,

TCDPOS like table of CDSHW WITH HEADER LINE.

Data : tcdred LIKE TABLE OF cdred WITH HEADER LINE.

data: date_from TYPE sy-datum.

date_from = sy-datum - no_of_days.

CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

EXPORTING

DATE_OF_CHANGE = date_from

OBJECTCLASS = 'KOSTL'

username = ''

DATE_UNTIL = sy-datum

TABLES

I_CDHDR = cdhdr

EXCEPTIONS

NO_POSITION_FOUND = 1

OTHERS = 2

.

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

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

EXPORTING

changenumber = cdhdr-changenr

TABLES

editpos = Tcdpos

editpos_with_header = tcdred

EXCEPTIONS

no_position_found = 4

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.

ENDLOOP.

data: Len type i,

pos type i,

w_kvalue(15) type c,

objid like cdhdr-OBJECTID,

strlen type string.

Len = strlen( cdhdr-objectid ).

pos = Len - datasize.

w_kvalue = cdhdr-objectid+pos(datasize).

loop at cdhdr.

output-OBJECTCLAS = cdhdr-OBJECTCLAS.

output-OBJECTID = cdhdr-OBJECTID.

output-KEYVALUE = w_kvalue.

output-CHANGENR = cdhdr-CHANGENR.

output-USERNAME = cdhdr-USERNAME.

output-UDATE = cdhdr-UDATE.

output-UTIME = cdhdr-UTIME.

output-TCODE = cdhdr-TCODE.

output-PLANCHNGNR = cdhdr-PLANCHNGNR.

output-ACT_CHNGNO = cdhdr-ACT_CHNGNO.

output-WAS_PLANND = cdhdr-WAS_PLANND.

output-CHANGE_IND = cdhdr-CHANGE_IND.

output-LANGU = cdhdr-LANGU.

output-VERSION = cdhdr-VERSION.

output-TABNAME = Tcdpos-TABNAME.

output-TABKEY = Tcdpos-TABKEY.

output-FNAME = Tcdpos-FNAME.

output-CHNGIND = Tcdpos-CHNGIND.

output-TEXT_CASE = Tcdpos-TEXT_CASE.

output-OUTLEN = Tcdpos-OUTLEN.

output-F_OLD = Tcdpos-F_OLD.

output-F_NEW = Tcdpos-F_NEW.

output-KEYGUID = Tcdpos-KEYGUID.

output-TABKEY254 = Tcdpos-TABKEY254.

output-EXT_KEYLEN = Tcdpos-EXT_KEYLEN.

append output.

endloop.

ENDFUNCTION.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member186741
Active Contributor
0 Kudos

by the way, the CDHDR and CDPOS tables can be HUGE so I think you may need to put in some limiting parameters rather than just reading the entire CDHDR and CDPOS tables. It will be very slow unless your site's CDHDR is unusually small.

former_member186741
Active Contributor
0 Kudos

the call to CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

is refreshing the cdpos table each time so when you exit the cdhdr loop you only have the items for the final cdhdr.

either change to populate the output table after each call to 'CHANGEDOCUMENT_READ_POSITIONS' or have another table like the cdpos one. After each call to 'CHANGEDOCUMENT_READ_POSITIONS' do 'append lines of cdpos to cdpos2.'.

Also change your output loop to have another loop at cdpos2 within it.

i.e. change it to something like:

loop at cdhdr.

move-corresponding cdhdr to output.

loop at cdpos2

where OBJECTCLAS = cdhdr-OBJECTCLAS

and OBJECTID = cdhdr-OBJECTID

and CHANGENR = cdhdr-CHANGENR.

move-corresponding cdpos2 to output.

append output.

endloop.

endloop.

Former Member
0 Kudos

Hi Neil,

I have modified the code as u mentioned. But still i dont have any values in TCDPOS while debugging.

The condition is chngind eq ' ' in CDPOS.based on this we have to get all records.

2. I want to display the output format like this

cdhdr(header)objectclasobjectid^ ...version

cdpos(Item)TabnameTabkey^...Ext_keylen.

eg:

cdhdrKOSTL10000000001000^3261...

cdposCSKSB090100000000010009999123119940101^....

cdhdrKOSTL100000000010222^2788....

cdposCSKSB090100000000010009922222222222^....

...

..

Modified code is

.

Data begin of struct.

include structure zbapi_struct.

Data end of struct.

Data begin of struct1 occurs 0.

include structure ZBAPI_output.

Data end of struct1.

Data: CDHDR like table of CDHDR WITH HEADER LINE,

TCDPOS like table of CDSHW WITH HEADER LINe,

TCDPOS1 like table of CDSHW WITH HEADER LINe.

Data : tcdred LIKE TABLE OF cdred WITH HEADER LINE.

Data: date_from TYPE sy-datum.

Date_from = sy-datum - r_days.

CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

EXPORTING

DATE_OF_CHANGE = '19980101'

OBJECTCLASS = 'KOSTL'

username = ''

DATE_UNTIL = sy-datum

TABLES

I_CDHDR = cdhdr

EXCEPTIONS

NO_POSITION_FOUND = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

EXPORTING

changenumber = cdhdr-changenr

TABLES

editpos = Tcdpos

editpos_with_header = tcdred

EXCEPTIONS

no_position_found = 4

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.

append lines of tcdpos to tcdpos1.

loop at cdhdr.

move-corresponding cdhdr to struct1.

loop at tcdpos1 where CHNGIND eq ' '.

move-corresponding tcdpos1 to struct1.

append struct1.

endloop.

endloop.

Former Member
0 Kudos

Check this code -

*"----


""Local interface:

*" IMPORTING

*" VALUE(TRANSCATIONCODE) LIKE ZBAPI_STRUCT-TCODE OPTIONAL

*" VALUE(DATASIZE) LIKE ZBAPI_STRUCT-OBJECTID OPTIONAL

*" VALUE(NO_OF_DAYS) LIKE ZBAPI_STRUCT-DAYS

*" VALUE(DELIMITOR) LIKE ZBAPI_STRUCT-DELIMI OPTIONAL

*" TABLES

*" OUTPUT STRUCTURE ZBAPI_OUTPUT

*"----


Data: CDHDR like table of CDHDR WITH HEADER LINE,

TCDPOS like table of CDSHW WITH HEADER LINE.

Data : tcdred LIKE TABLE OF cdred WITH HEADER LINE.

data: date_from TYPE sy-datum.

date_from = sy-datum - no_of_days.

CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

EXPORTING

DATE_OF_CHANGE = date_from

OBJECTCLASS = 'KOSTL'

username = ''

DATE_UNTIL = sy-datum

TABLES

I_CDHDR = cdhdr

EXCEPTIONS

NO_POSITION_FOUND = 1

OTHERS = 2

.

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

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

EXPORTING

changenumber = cdhdr-changenr

TABLES

editpos = Tcdpos

editpos_with_header = tcdred

EXCEPTIONS

no_position_found = 4

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.

append lines of tcdpos to tfinal_items.

refresh tcdpos.

ENDLOOP.

data: Len type i,

pos type i,

w_kvalue(15) type c,

objid like cdhdr-OBJECTID,

strlen type string.

Len = strlen( cdhdr-objectid ).

pos = Len - datasize.

w_kvalue = cdhdr-objectid+pos(datasize).

loop at cdhdr.

output-OBJECTCLAS = cdhdr-OBJECTCLAS.

output-OBJECTID = cdhdr-OBJECTID.

output-KEYVALUE = w_kvalue.

output-CHANGENR = cdhdr-CHANGENR.

output-USERNAME = cdhdr-USERNAME.

output-UDATE = cdhdr-UDATE.

output-UTIME = cdhdr-UTIME.

output-TCODE = cdhdr-TCODE.

output-PLANCHNGNR = cdhdr-PLANCHNGNR.

output-ACT_CHNGNO = cdhdr-ACT_CHNGNO.

output-WAS_PLANND = cdhdr-WAS_PLANND.

output-CHANGE_IND = cdhdr-CHANGE_IND.

output-LANGU = cdhdr-LANGU.

output-VERSION = cdhdr-VERSION.

loop tfinal_items with keys from cdhdr.

output-TABNAME = Tcdpos-TABNAME.

output-TABKEY = Tcdpos-TABKEY.

output-FNAME = Tcdpos-FNAME.

output-CHNGIND = Tcdpos-CHNGIND.

output-TEXT_CASE = Tcdpos-TEXT_CASE.

output-OUTLEN = Tcdpos-OUTLEN.

output-F_OLD = Tcdpos-F_OLD.

output-F_NEW = Tcdpos-F_NEW.

output-KEYGUID = Tcdpos-KEYGUID.

output-TABKEY254 = Tcdpos-TABKEY254.

output-EXT_KEYLEN = Tcdpos-EXT_KEYLEN.

append output.

endloop.

endloop.

ENDFUNCTION.

Message was edited by: Ashish Gundawar

former_member186741
Active Contributor
0 Kudos

put the call to 'CHANGEDOCUMENT_READ_POSITIONS' in a loop, like:

loop at cdhdr.

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

EXPORTING

changenumber = cdhdr-changenr

TABLES

editpos = Tcdpos

editpos_with_header = tcdred

EXCEPTIONS

no_position_found = 4

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.

append lines of tcdpos to tcdpos1.

endloop.

Former Member
0 Kudos

Hi Asish & Neil,

now i am geting CDPOS table values when i write like this.

loop at cdhdr.

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

EXPORTING

changenumber = cdhdr-changenr

TABLES

editpos = Tcdpos

editpos_with_header = tcdred

EXCEPTIONS

no_position_found = 4

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.

append lines of tcdpos to tcdpos1.

endloop.

Problem:

I want to display the output format like this

cdhdr(header)objectclasobjectid^ ...version

cdpos(Item)TabnameTabkey^...Ext_keylen.

eg:

cdhdrKOSTL10000000001000^3261...

cdposCSKSB090100000000010009999123119940101^....

cdhdrKOSTL100000000010222^2788....

cdposCSKSB090100000000010009922222222222^....

...

..

how can we get this format.

Former Member
0 Kudos

My understanding is you need to concatenate all values from CDHDR and display in one line separated by '^'

Same is the case for item details.

Use statement CONCATENATE to concatenate all required fields and append the record to your final internal table.

You need to use clause 'separated by '^'' while using this command.

I hope this will help you.

Message was edited by: Ashish Gundawar

Former Member
0 Kudos

This is what you need to do, not real code but a pseudo code.


LOOP AT cdhdr_itab.
  CONCATENATE 'cdhdr'
              cdhdr_itab-field1
              cdhdr_itab-field2
              .......
              .......
         INTO myfinalitab-fieldoftypestring SEPARATED BY '^'.
  APPEND myfinalitab.
  LOOP AT cdpos_itab WHERE keys = cdhdr_itab-keys.
     CONCATENATE 'cdpos'
              cdpos_itab-field1
              cdpos_itab-field2
              .......
              .......
         INTO myfinalitab-fieldoftypestring SEPARATED BY '^'.
     APPEND myfinalitab.
  ENDLOOP.
ENDLOOP.

former_member186741
Active Contributor
0 Kudos

you'll need something like this after you have populated your tables:

data ostring type string.

field-symbols <field> type any.

loop at cdhdr.

do.

assign component sy-index of cdhdr to <field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

ostring = <field>.

else.

concatenate ostring <field> into ostring

separated by '^'.

endif.

enddo.

write:/ ostring.

loop at tcdpos1 where objectclas = cdhdr-objectclas

and objectid = cdhdr-objectid

and changenr = cdhdr-changenr.

do.

assign component sy-index of cdpos to <field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

ostring = <field>.

else.

concatenate ostring <field> into ostring

separated by '^'.

endif.

enddo.

write:/ ostring.

endloop.

endloop.

suresh_datti
Active Contributor
0 Kudos

Hi Silivia,

It looks like you did not open the loop for the tcdpos table..

Regards,

Suresh Datti