Application Development and Automation 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: 
Read only

CDHDR and CDPOS- report code problem.

Former Member
0 Likes
1,344

Hello,

I'm trying to create a program that displays the original document number and what changes have been made to it, when, where and by whom. I found a very helpful bit of code in thread: but I've made certain modifications to it in order to fit our needs. Currently, the code looks the following:


      DATA: I_CDHDR TYPE TABLE OF TY_CDHDR,
            I_CDPOS TYPE TABLE OF TY_CDPOS,
            I_FINAL TYPE TABLE OF TY_FINAL,
            W_CDHDR TYPE TY_CDHDR,
            W_CDPOS TYPE TY_CDPOS,
            W_FINAL TYPE TY_FINAL.


      PARAMETERS: P_OBJECT TYPE CDHDR-OBJECTCLAS,
      P_OBJID TYPE CDHDR-OBJECTID,
      P_UNAME TYPE CDHDR-USERNAME,
      P_UDATE TYPE CDHDR-UDATE,
      UTIME TYPE CDHDR-UTIME,
      TCODE TYPE CDHDR-TCODE,
      P_CHGIND TYPE CDHDR-CHANGE_IND,
      P_FNAME TYPE CDPOS-FNAME.

      SELECT OBJECTCLAS OBJECTID CHANGENR USERNAME UDATE UTIME TCODE ACT_CHNGNO CHANGE_IND FROM CDHDR
        INTO TABLE I_CDHDR WHERE OBJECTCLAS = P_OBJECT AND OBJECTID = P_OBJID.


        SELECT OBJECTCLAS OBJECTID FNAME VALUE_OLD VALUE_NEW FROM CDPOS INTO TABLE I_CDPOS FOR ALL ENTRIES IN I_CDHDR
          WHERE OBJECTCLAS = I_CDHDR-OBJECTCLAS AND OBJECTID = I_CDHDR-OBJECTID AND FNAME = P_FNAME.


          LOOP AT I_CDPOS INTO W_CDPOS.
            READ TABLE I_CDHDR INTO W_CDHDR WITH KEY OBJECTCLAS = CDPOS-OBJECTCLAS OBJECTID = CDPOS-OBJECTID.
            IF SY-SUBRC <> 0.
              WRITE: 'ERROR'.
            ELSEIF SY-SUBRC = 0.
              W_FINAL-CHANGENR = W_CDHDR-CHANGENR.
              W_FINAL-USERNAME = W_CDHDR-USERNAME.
              W_FINAL-UDATE = W_CDHDR-UDATE.
              W_FINAL-UTIME = W_CDHDR-UTIME.
              W_FINAL-TCODE = W_CDHDR-TCODE.
              W_FINAL-CHANGE_IND = W_CDHDR-CHANGE_IND.
              W_FINAL-FNAME = W_CDPOS-FNAME.
              W_FINAL-VALUE_OLD = W_CDPOS-VALUE_OLD.
              W_FINAL-VALUE_NEW = W_CDPOS-VALUE_NEW.
              WRITE: / W_FINAL-CHANGENR, W_FINAL-USERNAME, W_FINAL-UDATE, W_FINAL-UTIME,
              W_FINAL-TCODE, W_FINAL-CHANGE_IND, W_FINAL-FNAME, W_FINAL-VALUE_OLD, W_FINAL-VALUE_NEW.
              APPEND W_FINAL TO I_FINAL.
              ENDIF.
              ENDLOOP.

I believe something is not working in the READ TABLE- section of the code, because it only prints out ERROR. I would greately appreciate any input on this, I am extremely new to ABAP, so please let me know in case you need more information. Also, I did not paste the entire code. Have I missed something integral in the READ TABLE- statement?

Moderator Message: Keshav's posts indicate the question(s) are basic. Thread locked & points unassigned.

Edited by: Suhas Saha on Jan 4, 2012 5:49 PM

9 REPLIES 9
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,184

The error is clearly visible. If i help you then surely Mods will catch my neck !!!! .. Please have a close look.

Kesav

Read only

0 Likes
1,184

Hi Keshav,

Thank you for your reply. I've actually been staring at this bit for quite a while now, I figured it would be something completely obvious but i suppose I've become blind to it.

Now I feel like quite an idiot, because I still don't see it =D

Read only

0 Likes
1,184

Hello again,

Actually I believe I found at least part of it:

Where the original was:


          LOOP AT I_CDPOS INTO W_CDPOS.
            READ TABLE I_CDHDR INTO W_CDHDR WITH KEY OBJECTCLAS = CDPOS-OBJECTCLAS OBJECTID = CDPOS-OBJECTID.

I now have:


          LOOP AT I_CDPOS INTO W_CDPOS.
            READ TABLE I_CDHDR INTO W_CDHDR WITH KEY OBJECTCLAS = W_CDPOS-OBJECTCLAS OBJECTID = W_CDPOS-OBJECTID.

but unfortunately it still doesn't work.

Read only

0 Likes
1,184

No Answering Please read the documentation of for all entries.

Kesav

Read only

0 Likes
1,184

Hi friend,

Just debug and check what is the value you are getting in the W_CDPOS-OBJECTCLAS during the read statement.

And check whether that vale is available in the table or not.

There may be some mis-match in type. Just check this.

If your problem still persist revert back to me i will help you.

Thanks,

Sri Hari

Read only

0 Likes
1,184

Hi again Kesav and Sri Hari,

Thank you for pointing me in the right direction. I'll try solve this now that I think I have a relatively clear picture of where to start looking.

First off I'll see about the documentation for "for all entries" and see if there might be something wrong with my selections. After that I'll have to learn how to use the debugging tool in SAP to see if I can pinpoint the problem.

I'm not kidding when I say I'm new to ABAP

Br,

_jerkku

Read only

0 Likes
1,184

Hello _jerkku,

srihari.kumar is correct, i tested it with a sales order "1" and moved FNAME to select-options.

Please see code bellow:


TYPES: BEGIN OF ty_final,
        changenr TYPE cdhdr-changenr,
        username TYPE cdhdr-username,
        udate    TYPE cdhdr-udate,
        utime    TYPE cdhdr-utime,
        tcode    TYPE cdhdr-tcode,
        change_ind TYPE cdhdr-change_ind,
        fname      TYPE cdpos-fname,
        value_old  TYPE cdpos-value_old,
        value_new  TYPE cdpos-value_new,
      END OF ty_final,
      ty_t_final TYPE STANDARD TABLE OF ty_final.

DATA: i_cdhdr TYPE STANDARD TABLE OF cdhdr,
      w_cdhdr LIKE LINE OF i_cdhdr,
      i_cdpos TYPE STANDARD TABLE OF cdpos,
      w_cdpos LIKE LINE OF i_cdpos,
      i_final TYPE ty_t_final,
      w_final LIKE LINE OF i_final.

PARAMETERS: p_object TYPE cdhdr-objectclas DEFAULT 'VERKBELEG',
            p_objid TYPE cdhdr-objectid   DEFAULT '0000000001',
            p_uname TYPE cdhdr-username,
            p_udate TYPE cdhdr-udate,
            utime TYPE cdhdr-utime,
            tcode TYPE cdhdr-tcode,
            p_chgind TYPE cdhdr-change_ind.
SELECT-OPTIONS s_fname FOR w_cdpos-fname NO INTERVALS.

SELECT objectclas objectid changenr username udate utime tcode act_chngno change_ind FROM cdhdr
  INTO CORRESPONDING FIELDS OF TABLE i_cdhdr WHERE objectclas = p_object AND objectid = p_objid.
IF sy-subrc = 0.
  SELECT objectclas objectid fname value_old value_new FROM cdpos INTO CORRESPONDING FIELDS OF TABLE i_cdpos FOR ALL ENTRIES IN i_cdhdr
    WHERE objectclas = i_cdhdr-objectclas AND objectid = i_cdhdr-objectid AND fname IN s_fname.
ENDIF.

LOOP AT i_cdpos INTO w_cdpos.
  READ TABLE i_cdhdr INTO w_cdhdr
       WITH KEY objectclas = w_cdpos-objectclas
                objectid   = w_cdpos-objectid.
  IF sy-subrc NE 0.
    WRITE: 'ERROR'.
  ELSEIF sy-subrc = 0.
    w_final-changenr = w_cdhdr-changenr.
    w_final-username = w_cdhdr-username.
    w_final-udate = w_cdhdr-udate.
    w_final-utime = w_cdhdr-utime.
    w_final-tcode = w_cdhdr-tcode.
    w_final-change_ind = w_cdhdr-change_ind.
    w_final-fname = w_cdpos-fname.
    w_final-value_old = w_cdpos-value_old.
    w_final-value_new = w_cdpos-value_new.
    WRITE: / w_final-changenr, w_final-username, w_final-udate, w_final-utime,
    w_final-tcode, w_final-change_ind, w_final-fname, w_final-value_old, w_final-value_new.
    APPEND w_final TO i_final.
  ENDIF.
ENDLOOP.

Regards

Bruno.

Edited by: Bruno Xavier on Jan 4, 2012 10:10 AM - Change "<>" by "NE"

Read only

0 Likes
1,184

No Answering Please read the documentation of for all entries.

In addition to these witty one-liners, please hit the "abuse" button if you think that the question is a FAQ.

Read only

Former Member
0 Likes
1,184

Hi Jerkku ,

As far as i understood your problem.First of all the select statement for CDPOS table.

SELECT OBJECTCLAS OBJECTID FNAME VALUE_OLD VALUE_NEW FROM CDPOS INTO TABLE I_CDPOS FOR ALL ENTRIES IN I_CDHDR

WHERE OBJECTCLAS = I_CDHDR-OBJECTCLAS AND OBJECTID = I_CDHDR-OBJECTID AND FNAME = P_FNAME.

The sequence of these fields are not as per the sequence maitained in the table CDPOS.

Rather it should be :

SELECT OBJECTCLAS OBJECTID FNAME VALUE_NEW VALUE_OLD FROM CDPOS INTO TABLE I_CDPOS FOR ALL ENTRIES IN I_CDHDR

WHERE OBJECTCLAS = I_CDHDR-OBJECTCLAS AND OBJECTID = I_CDHDR-OBJECTID AND FNAME = P_FNAME.

Secondly,

you have written

READ TABLE I_CDHDR INTO W_CDHDR WITH KEY OBJECTCLAS = CDPOS-OBJECTCLAS OBJECTID = CDPOS-OBJECTID.

IF SY-SUBRC 0.

WRITE: 'ERROR'.

ELSEIF SY-SUBRC = 0.

I suppose it should be

READ TABLE I_CDHDR INTO W_CDHDR WITH KEY OBJECTCLAS = CDPOS-OBJECTCLAS OBJECTID = CDPOS-OBJECTID.

IF SY-SUBRC ne 0.

WRITE: 'ERROR'.

ELSEIF SY-SUBRC = 0.

Since,you are checking for sy-subrc eq 0 and then writing the Error message,so you are getting the error message.So check for sy-subrc not equal to zero then display the error message.

Reward points if helpful.:)

Edited by: micky prasad on Jan 4, 2012 1:09 PM