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

change pointers cdhdr and cdhsw

Bharath84
Participant
0 Likes
1,319

Hi All,

In my report I am displaying all the Purchase orders that have been changed from CDHDR and CDHSW.

But one PO is not being displayed in the output. Below is my code.

loop at icdshw.

  check icdshw-text_case eq space.

  move-corresponding icdshw to t_final.

  move-corresponding icdhdr to t_final.

  move icdshw-tabkey+3 to t_final-ebeln.

  move : t_ekko-aedat to t_final-aedat,

       t_ekko-lifnr to t_final-lifnr,

       t_ekko-reswk to t_final-reswk,

       t_ekpo-ebelp to t_final-ebelp,

       t_ekko-bsart to t_final-bsart.

In debugging icdshw-text_case is having value X. When I checked the statistics of this Item for the PO it is showing Item text Changed. Why I am not getting this PO details in the output. What this field TEXT_CASE mean? Or should I consider CDPOS instead of CDHSW? Please help me.

Thanks,

Harihta

Hi All,

In my report I am displaying all the Purchase orders that have been changed from CDHDR and CDHSW.

But one PO is not being displayed in the output. Below is my code.

loop at icdshw.

  check icdshw-text_case eq space.

  move-corresponding icdshw to t_final.

  move-corresponding icdhdr to t_final.

  move icdshw-tabkey+3 to t_final-ebeln.

  move : t_ekko-aedat to t_final-aedat,

       t_ekko-lifnr to t_final-lifnr,

       t_ekko-reswk to t_final-reswk,

       t_ekpo-ebelp to t_final-ebelp,

       t_ekko-bsart to t_final-bsart.

In debugging icdshw-text_case is having value X. When I checked the statistics of this Item for the PO it is showing Item text Changed. Why I am not getting this PO details in the output. What this field TEXT_CASE mean? Or should I consider CDPOS instead of CDHSW? Please help me.

Thanks,

Harihta

4 REPLIES 4
Read only

freek_cavens2
Participant
0 Likes
1,134

Hi Haritha,

I don't know what the text_case field means, but for selecting the changes on a PO, this is not relevant.  CDSHW is a structure, not a table (at least in my ECC 6.0 system) so I'm quite surprised you can select data from it.  Normally, to get the changes of an object, you would write a select on CDHDR and CDPOS. 

Something like this (this is only the code from a select method, so selection parameters and screen output is not provided) :

FIELD-SYMBOLS :
       <lw_cdhdr> TYPE cdhdr,
       <lw_cdpos> TYPE cdpos.

     DATA :
       lt_cdhdr TYPE HASHED TABLE OF cdhdr WITH UNIQUE KEY objectclas objectid changenr,
       lt_cdpos TYPE TABLE OF cdpos,
       lw_changelog TYPE ty_outtab.

     SELECT * FROM cdhdr
            INTO CORRESPONDING FIELDS OF TABLE lt_cdhdr
            WHERE objectclas IN class
              AND objectid IN id
              AND changenr IN chgnr
              AND udate IN udate
              AND username IN user
              AND tcode IN tcode.

     CHECK NOT lt_cdhdr[] IS INITIAL.

     SELECT * FROM cdpos
            INTO CORRESPONDING FIELDS OF TABLE lt_cdpos
            FOR ALL ENTRIES IN lt_cdhdr
            WHERE objectclas EQ lt_cdhdr-objectclas
              AND objectid EQ lt_cdhdr-objectid
              AND changenr EQ lt_cdhdr-changenr
              AND tabname IN tabname
              AND tabkey IN tabkey
              AND fname IN fname.

     LOOP AT lt_cdpos ASSIGNING <lw_cdpos>.
       CHECK <lw_cdpos>-value_new IN val_new.
       CHECK <lw_cdpos>-value_old IN val_old.

       READ TABLE lt_cdhdr ASSIGNING <lw_cdhdr>
            WITH TABLE KEY objectclas = <lw_cdpos>-objectclas
                           objectid = <lw_cdpos>-objectid
                           changenr = <lw_cdpos>-changenr.
       MOVE-CORRESPONDING <lw_cdpos> TO lw_changelog.
       MOVE-CORRESPONDING <lw_cdhdr> TO lw_changelog.
       APPEND lw_changelog TO gt_changelog.
     ENDLOOP.

Read only

0 Likes
1,134

Hi,

Below is my code. When I replaced the CDSHW with CDPOS it is showing error FTEXT doesnot exist. Which field I have to replace from CDPOS in place of FTEXT.

REPORT Z_change_pointers NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES: EKKO, EKPO, CDHDR, CDPOS.

DATA: WTEXT(80) TYPE C.

DATA : BEGIN OF T_EKKO OCCURS 0,

       EBELN LIKE EKKO-EBELN,          "Purchasing document number

       BSART LIKE EKKO-BSART,          "Purchasing document type

       AEDAT LIKE EKKO-AEDAT,          "Record was created date

       LIFNR LIKE EKKO-LIFNR,          "Vendor's account number

       RESWK LIKE EKKO-RESWK,          "Supplying (issuing) plant

       END OF T_EKKO.

DATA : BEGIN OF T_EKPO OCCURS 0,

       EBELN LIKE EKPO-EBELN,          "Purchasing document number

       EBELP LIKE EKPO-EBELP,          "Item number of purchasing doc

       AEDAT LIKE EKPO-AEDAT,          "Item change date

       MATNR LIKE EKPO-MATNR,          "Material

       WERKS LIKE EKPO-WERKS,          "Plant

       END OF T_EKPO.

DATA: BEGIN OF ICDHDR OCCURS 50.

        INCLUDE STRUCTURE CDHDR.

DATA: END OF ICDHDR.

DATA: BEGIN OF ICDSHW OCCURS 50.

        INCLUDE STRUCTURE CDSHW.

DATA: END OF ICDSHW.

DATA :  W_EBELN LIKE EKKO-EBELN.

DATA: WCHANGENR LIKE CDHDR-CHANGENR.

DATA: BEGIN OF T_FINAL OCCURS 50,

      EBELN  LIKE EKPO-EBELN,

      AEDAT  LIKE EKKO-AEDAT,

      CHANGENR LIKE CDHDR-CHANGENR,

      UDATE    LIKE CDHDR-UDATE,

      UTIME    LIKE CDHDR-UTIME,

      USERNAME LIKE CDHDR-USERNAME,

      CHNGIND  LIKE CDSHW-CHNGIND,

      FTEXT    LIKE CDSHW-FTEXT,

      OUTLEN   LIKE CDSHW-OUTLEN,

      F_OLD    LIKE CDSHW-F_OLD,

      F_NEW    LIKE CDSHW-F_NEW,

      RESWK    LIKE EKKO-RESWK,

      WERKS    LIKE EKPO-WERKS,

      LIFNR    LIKE EKKO-LIFNR,

      BSART    LIKE EKKO-BSART,

      EBELP    LIKE EKPO-EBELP,

      MATNR    LIKE EKPO-MATNR,

      END OF T_FINAL.

FIELD-SYMBOLS: <VALUE_OLD>, <VALUE_NEW>.

CONSTANTS : C_TCODE LIKE SY-TCODE VALUE 'ZSTOCHANGES'.

SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN,

                 S_RESWK FOR EKKO-RESWK OBLIGATORY,

                 S_BSART FOR EKKO-BSART,

                 S_AEDAT FOR EKKO-AEDAT OBLIGATORY,

                 S_TCODE FOR CDHDR-TCODE DEFAULT 'ME22' TO 'ME23',

                 S_WERKS FOR EKPO-WERKS OBLIGATORY,

                 S_LIFNR FOR EKKO-LIFNR.

TOP-OF-PAGE.

  WRITE: / SY-REPID,

           50 'Changes in the Stock Transfer Order'(007)

           COLOR COL_NORMAL.

  SKIP TO LINE 2.

  ULINE.

*  format intensified on color 1.

  WRITE:/01 'Purchase Order'(001) COLOR COL_HEADING,

         20 'User Name'(002) COLOR COL_HEADING,

         35 'Created Date'(003) COLOR COL_HEADING,

         50 'Change Date'(004) COLOR COL_HEADING,

         65 'Time'(005) COLOR COL_HEADING,

         75 'Changes'(006) COLOR COL_HEADING,

         135 'Suppl Plant'(012) COLOR COL_HEADING,

         148 'Plant'(013) COLOR COL_HEADING,

         155 'Doc.Typ'(014) COLOR COL_HEADING,

         165 'Item'(015) COLOR COL_HEADING,

         178 'Vendor'(016) COLOR COL_HEADING,

         190 'Material no'(017) COLOR COL_HEADING.

  ULINE.

START-OF-SELECTION.

  PERFORM GET_EKKO.

  PERFORM GET_EKPO.

  PERFORM CHANGE_DOCS_READ.

*&---------------------------------------------------------------------*

*&      Form  GET_EKKO

*&---------------------------------------------------------------------*

FORM GET_EKKO.

  SELECT EBELN

         BSART

         AEDAT

         LIFNR

         RESWK

         FROM EKKO

         INTO TABLE T_EKKO

         WHERE EBELN IN S_EBELN

         AND   AEDAT IN S_AEDAT

         AND   LIFNR IN S_LIFNR

         AND   RESWK IN S_RESWK.

  IF SY-SUBRC = 0.

    SORT T_EKKO BY EBELN.

  ENDIF.

ENDFORM.                               " GET_EKKO

*&---------------------------------------------------------------------*

*&      Form  GET_EKPO

*&---------------------------------------------------------------------*

FORM GET_EKPO.

  IF NOT T_EKKO[] IS INITIAL.

    SELECT EBELN

           EBELP

           AEDAT

           MATNR

           WERKS

           FROM EKPO

           INTO TABLE T_EKPO

           FOR ALL ENTRIES IN T_EKKO

           WHERE EBELN = T_EKKO-EBELN

           AND WERKS IN S_WERKS.

    IF SY-SUBRC = 0.

      SORT T_EKPO BY EBELN.

    ENDIF.

ENDIF.

  ENDFORM.                             " GET_EKPO

*&---------------------------------------------------------------------*

*&      Form  CHANGE_DOCS_READ

*&---------------------------------------------------------------------*

FORM CHANGE_DOCS_READ.

  CLEAR T_EKPO.

  LOOP AT T_EKPO.

  READ TABLE T_EKKO WITH KEY EBELN = T_EKPO-EBELN BINARY SEARCH.

  IF SY-SUBRC = 0.

* Get Changes

    PERFORM CHANGEDOCUMENT_READ.

  ENDIF.

  ENDLOOP.

  LOOP AT T_FINAL.

    CLEAR: WTEXT, W_EBELN.

    CASE T_FINAL-CHNGIND.

      WHEN 'U'.

        WTEXT(50) = 'Updated field'(008).

        WTEXT+51  = T_FINAL-FTEXT.

        CONDENSE WTEXT.

      WHEN 'D'.

        WTEXT = TEXT-021.

      WHEN 'E'.

        WTEXT(5) = T_FINAL-FTEXT.

        WTEXT+51 = ' text : E'(009).

        CONDENSE WTEXT.

      WHEN 'I'.

        WTEXT = ' text : I'(010).

    ENDCASE.

    RESERVE 5 LINES.

    IF WCHANGENR NE T_FINAL-CHANGENR.

      WCHANGENR = T_FINAL-CHANGENR.

      W_EBELN = T_FINAL-EBELN.

      WRITE:/ T_FINAL-EBELN    UNDER 'Purchase Order'(001),

              T_FINAL-USERNAME UNDER 'User Name'(002),

              T_FINAL-AEDAT UNDER 'Created Date'(003),

              T_FINAL-UDATE UNDER 'Change Date'(004),

              T_FINAL-UTIME UNDER 'Time'(005),

              WTEXT         UNDER 'Changes'(006),

              T_FINAL-RESWK UNDER 'Suppl Plant'(012),

              T_FINAL-WERKS UNDER 'Plant'(013),

              T_FINAL-BSART UNDER 'Doc.Typ'(014),

              T_FINAL-EBELP UNDER 'Item'(015),

              T_FINAL-LIFNR UNDER 'Vendor'(016),

              T_FINAL-MATNR UNDER 'Material no'(017).

    ELSEIF T_FINAL-EBELN NE W_EBELN.

      WRITE:/ WTEXT         UNDER 'Changes'(006).

    ENDIF.

    CASE T_FINAL-CHNGIND.

      WHEN 'U'.

        ASSIGN T_FINAL-F_OLD(T_FINAL-OUTLEN) TO <VALUE_OLD>.

        ASSIGN T_FINAL-F_NEW(T_FINAL-OUTLEN) TO <VALUE_NEW>.

        WRITE: / TEXT-023  UNDER 'Changes'(006),

                 <VALUE_OLD>.

        WRITE: / TEXT-024 UNDER 'Changes'(006),

                 <VALUE_NEW>.

      WHEN 'E'.

        ASSIGN T_FINAL-F_OLD(T_FINAL-OUTLEN) TO <VALUE_OLD>.

        WRITE: TEXT-023 UNDER 'Changes'(006),

               <VALUE_OLD>.

    ENDCASE.

    SKIP.

  ENDLOOP.

ENDFORM.                               " CHANGE_DOCS_READ

*&--------------------------------------------------------------------*

*&      Form  CHANGEDOCUMENT_READ

*&--------------------------------------------------------------------*

FORM CHANGEDOCUMENT_READ.

  CLEAR CDHDR.

  CLEAR ICDSHW.

  CDHDR-OBJECTCLAS = 'EINKBELEG'.

  CDHDR-OBJECTID   = T_EKPO-EBELN.

  CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'

       EXPORTING

            DATE_OF_CHANGE    = CDHDR-UDATE

            OBJECTCLASS       = CDHDR-OBJECTCLAS

            OBJECTID          = CDHDR-OBJECTID

            TIME_OF_CHANGE    = CDHDR-UTIME

            USERNAME          = CDHDR-USERNAME

       TABLES

            I_CDHDR           = ICDHDR

       EXCEPTIONS

            NO_POSITION_FOUND = 1

            OTHERS            = 2.

  CHECK SY-SUBRC EQ 0.

  DELETE ICDHDR WHERE CHANGE_IND EQ 'I'.

  CHECK NOT ICDHDR[] IS INITIAL.

  LOOP AT ICDHDR.

*    check icdhdr-udate in s_date.

*    check icdhdr-username in s_name.

    CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'

         EXPORTING

              CHANGENUMBER      = ICDHDR-CHANGENR

         IMPORTING

              HEADER            = CDHDR

         TABLES

              EDITPOS           = ICDSHW

         EXCEPTIONS

              NO_POSITION_FOUND = 1

              OTHERS            = 2.

    CHECK SY-SUBRC EQ 0.

    LOOP AT ICDSHW.

      CHECK ICDSHW-TEXT_CASE EQ SPACE.

      MOVE-CORRESPONDING ICDSHW TO T_FINAL.

      MOVE-CORRESPONDING ICDHDR TO T_FINAL.

      MOVE ICDSHW-TABKEY+3 TO T_FINAL-EBELN.

      MOVE : T_EKKO-AEDAT TO T_FINAL-AEDAT,

             T_EKKO-LIFNR TO T_FINAL-LIFNR,

             T_EKKO-RESWK TO T_FINAL-RESWK,

             T_EKPO-EBELP TO T_FINAL-EBELP,

             T_EKKO-BSART TO T_FINAL-BSART,

             T_EKPO-WERKS TO T_FINAL-WERKS,

             T_EKPO-MATNR TO T_FINAL-MATNR.

      APPEND T_FINAL.

    ENDLOOP.

  ENDLOOP.

ENDFORM.                               "CHANGEDOCUMENT_READ

Please help me.

Thanks,

Haritha

Read only

0 Likes
1,134

Hi Haritha,

The ftext is the description of the technical field name that you find in cdpos-fname.  You will need to read this information from the SAP data dictionairy as this field is not available in the CDPOS table.  It's not difficult.  You can use the following function : DDIF_FIELDINFO_GET, where you give cdpos-tabname and cdpos-fnamel as parameters.  In the returned structure, you will get the data element description, which is the ftext (field fieldtext probably.  You also have reptext and scrtext_s, -_M and -_L).

Regards,

Freek

Read only

ronaldo_aparecido
Contributor