cancel
Showing results for 
Search instead for 
Did you mean: 

after calling FM, how to ensure no redundancy

Former Member
0 Kudos

Hi all again,

If some of you recall my earlier thread on the READ_TEXT FM, i have managed to successfully retrieve the PO texts, thanks to you all...

However, i just realized that it works perfectly fine when i test it using 1 example (lets say i pur 1 item number, MATNR) as my selection criteria. However, when i tried it with 2 or more, it still works as the PO Text for all the material numbers appear but they keep on repeating.

As an example, i choose to query 2 material numbers. The first material number will display the PO text for both the first and second material number and it is also the same for the second material number.

Any hints?

I tried doing a CHECK, ON CHANGE OF and even IF...ENDIF, then REFRESH and CLEAR statements to ensure that each material number will display their own respective PO Text instead of all that was queried but still no changes as each material number is displaying all the PO Text instead of their own.


*&---------------------------------------------------------------------*
*&    FORM WRITE_DATA                                                  *
*&---------------------------------------------------------------------*
FORM WRITE_DATA.

  LOOP AT ITAB.

  IF SY-LINNO >= 65.
    NEW-PAGE.
    PERFORM WRITE_HEADER.
  ENDIF.

*--> ALTERNATE COLORS FOR EACH LINE OF OUTPUT
  IF LINE_CHECK = 0.
    FORMAT COLOR COL_NORMAL INTENSIFIED ON.
    LINE_CHECK = 1.
  ELSE.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
    LINE_CHECK = 0.
  ENDIF.

    CLEAR V_PRICE.
    COMPUTE V_PRICE = ( ITAB-NETPR / ITAB-PEINH ).
    NEW-LINE.
    WRITE:   1 '|',   2 ITAB-MATNR,              "MATERIAL CODE
            15 '|',  16 ITAB-MATKL,              "MATERIAL GROUP
            30 '|',  31(40) ITAB-MAKTX,          "DESCRIPTION
            71 '|', " 71 ITAB-MTEXT,             "MATERIAL PO TEXT
           110 '|', " 111 ITAB-PTEXT,            "ITEM TEXT
           150 '|', 157 ITAB-MENGE,              "PURCHASE QUANTITY
           173 '|', 177 V_PRICE DECIMALS 2,      "PURCHASE PRICE
           193 '|', 198 ITAB-BEDAT,              "PURCHASE DATE
           212 '|', 213 ITAB-NAME1,              "PURCHASE VENDOR
           255 '|'.

  PERFORM READ_TXT.

  ENDLOOP.

  WRITE: SY-ULINE.

ENDFORM.

*&---------------------------------------------------------------------*
*&    FORM READ_TXT                                                    *
*&---------------------------------------------------------------------*
FORM READ_TXT.

DATA: L_NAME LIKE THEAD-TDNAME,
      COUNT TYPE I.

LOOP AT ITAB.
  CLEAR: MAT_TXT, MAT_TXT[].

  L_NAME = ITAB-MATNR.

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      CLIENT                  = SY-MANDT
      ID                      = 'BEST'
      NAME                    = L_NAME
      OBJECT                  = 'MATERIAL'
      LANGUAGE                = SY-LANGU
    TABLES
      LINES                   = MAT_TXT
    EXCEPTIONS
      ID                      = 1
      LANGUAGE                = 2
      NAME                    = 3
      NOT_FOUND               = 4
      OBJECT                  = 5
      REFERENCE_CHECK         = 6
      WRONG_ACCESS_TO_ARCHIVE = 7
      OTHERS                  = 8.

  LOOP AT MAT_TXT.
    MOVE: ITAB-MATNR TO MTXT_TAB-MATNR,
          SY-TABIX TO MTXT_TAB-POSNR,
          MAT_TXT-TDLINE TO MTXT_TAB-LINE.

    APPEND MTXT_TAB.

    WRITE:/72(40) MTXT_TAB-LINE.

  ENDLOOP.

ENDLOOP.

ENDFORM.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

hi, if the TEXT is in the Purchase Order Item level, when call FM 'READ_TEXT', you input parameter should include the PO number and item No, but can't find them in your code.

Please check the input parameter, and the return result. Are they really the one correct?

by the way which PO text do you want to get?

Former Member
0 Kudos

oh...dun worry abt that, i only need to know as to why all of the PO text was displayed rather that the individual ones that corresponds to their respective material number.

Anyway, i've got another question. If you look at my WRITE statement in the FORM READ_TXT subroutine, i had to do it this way:


    WRITE:/72(40) MTXT_TAB-LINE.

This is so that all the PO Text which may comprise of more than 1 line to be displayed (if the PO text has 5 lines, all 5 will be displayed) but in doing so, when the report is generated, the PO text is displayed at the next line, after the earlier data (like ITAB-MATNR, ITAB-MATKL and so on are displayed). If i remove the "/" at the WRITE statement, only the last line of the PO text is displayed. I wonder if i explained it clearly?

Anyway, need your comments on this

Former Member
0 Kudos

try this & check

LOOP AT MAT_TXT.

MOVE: ITAB-MATNR TO MTXT_TAB-MATNR,

SY-TABIX TO MTXT_TAB-POSNR,

MAT_TXT-TDLINE TO MTXT_TAB-LINE.

APPEND MTXT_TAB.

if sy-tabix = 1.

WRITE:72(40) MTXT_TAB-LINE.

else.

WRITE:/72(40) MTXT_TAB-LINE.

endif.

ENDLOOP.

Former Member
0 Kudos

Renjith, thanks alot...many many points for you too

closing the thread now

Former Member
0 Kudos

Oopsy...zhenglin..i guess you were right...i thought that i would only need to do a CONCATENATE ITAB-EBELN ITAB-EBELP into ITAB-PTEXT to find out the Item Text. Then i realized that 1 material number (MATNR) could belong to many POs. Have a look at my earlier SELECT statement:


*&---------------------------------------------------------------------*
*&    FORM SELECT_DATA                                                 *
*&---------------------------------------------------------------------*
FORM SELECT_DATA.

  SELECT A~MATNR A~MATKL B~MAKTX A~MTART A~EXTWG C~WERKS
    INTO CORRESPONDING FIELDS OF TABLE ITAB
    FROM MARA AS A
      INNER JOIN MAKT AS B
        ON A~MATNR = B~MATNR AND
           B~SPRAS = 'EN'
      INNER JOIN MARD AS C
        ON A~MATNR = C~MATNR
    WHERE A~MATNR IN I_MATNR AND
          A~MATKL IN I_MATKL AND
          A~MTART IN I_MTART AND
          A~EXTWG IN I_EXTWG AND
          C~WERKS = I_WERKS.

  SORT ITAB BY MATNR MATKL MTART EXTWG WERKS MAKTX.

  CHECK NOT ITAB[] IS INITIAL.

  SELECT A~MATNR A~MATKL A~WERKS MAX( A~EBELN ) MAX( A~EBELP ) A~BUKRS
A~MENGE A~NETPR A~PEINH A~MTART B~LIFNR B~BEDAT C~NAME1
  INTO TABLE WTAB
    FROM EKPO AS A
      INNER JOIN EKKO AS B
        ON A~EBELN = B~EBELN AND
           A~BUKRS = B~BUKRS AND
           B~BSTYP = 'F'
      INNER JOIN LFA1 AS C
        ON B~LIFNR = C~LIFNR
    WHERE A~MATNR IN I_MATNR AND
          A~MATKL IN I_MATKL AND
          A~WERKS = I_WERKS AND
          A~BUKRS = I_BUKRS AND
          A~MTART IN I_MTART AND
          A~LOEKZ = ' '
    GROUP BY A~MATNR A~MATKL A~WERKS A~EBELN A~EBELP A~BUKRS A~MENGE
A~NETPR A~PEINH A~MTART B~LIFNR B~BEDAT C~NAME1.

  SORT WTAB BY MATNR MATKL MTART WERKS EBELN EBELP MENGE NETPR PEINH
LIFNR BEDAT NAME1.

  LOOP AT WTAB.
    MOVE: WTAB-EBELN TO ITAB-EBELN,
          WTAB-EBELP TO ITAB-EBELP,
          WTAB-BUKRS TO ITAB-BUKRS,
          WTAB-MENGE TO ITAB-MENGE,
          WTAB-NETPR TO ITAB-NETPR,
          WTAB-PEINH TO ITAB-PEINH,
*          WTAB-MTART TO ITAB-MTART,
          WTAB-LIFNR TO ITAB-LIFNR,
          WTAB-BEDAT TO ITAB-BEDAT,
          WTAB-NAME1 TO ITAB-NAME1.

    MODIFY ITAB TRANSPORTING EBELN EBELP BUKRS MENGE NETPR PEINH LIFNR
BEDAT NAME1
      WHERE MATNR = WTAB-MATNR.
  ENDLOOP.

  SORT ITAB BY MATNR MATKL MTART.

  DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

  LINE_CHECK = 0.

ENDFORM.

If you notice, i did a MAX syntax when selecting the EBELN (PO Number) and EBELP (Item Number). So, for the Item Text, i would need to display the data from those 2 fields and CONCATENATE them. Any ideas on how i could ensure that the right PO Number and PO Number (which is the MAX) is selected? I'm considering using the READ_TEXT FM again...

Former Member
0 Kudos

fixed it by myself...it just occurred to me to declare my variable as TYPE STRING, not C

thread is closed now

Former Member
0 Kudos

HI,

remove the loop inside in the form - read_txt.

what is happening is for each outer loop pass..the whole itab is looped again...

remove the lines in bold and try...

FORM READ_TXT.

DATA: L_NAME LIKE THEAD-TDNAME,

COUNT TYPE I.

<b>LOOP AT ITAB.</b>

CLEAR: MAT_TXT, MAT_TXT[].

L_NAME = ITAB-MATNR.

CALL FUNCTION 'READ_TEXT'

EXPORTING

CLIENT = SY-MANDT ID = 'BEST' NAME = L_NAME OBJECT = 'MATERIAL' LANGUAGE = SY-LANGU

TABLES

LINES = MAT_TXT

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

NOT_FOUND = 4

OBJECT = 5

REFERENCE_CHECK = 6

WRONG_ACCESS_TO_ARCHIVE = 7

OTHERS = 8.

LOOP AT MAT_TXT.

MOVE: ITAB-MATNR TO MTXT_TAB-MATNR,

SY-TABIX TO MTXT_TAB-POSNR,

MAT_TXT-TDLINE TO MTXT_TAB-LINE.

APPEND MTXT_TAB.

WRITE:/72(40) MTXT_TAB-LINE.

ENDLOOP.

<b>ENDLOOP.</b>

ENDFORM.

Thanks,

Renjith

Former Member
0 Kudos

oh...thanks...many many points for you