Friday, October 2, 2009

SAP > Get Material Long Text

Posted by Aries Wandari

     A little ABAP code showing list of material number, material description, material type, material group, and long text. Material store location, is still on progress.
Result:
image
Preview on the BAPI consumer (using C# .Net):
image
A note on this job:
1. Use refresh to initialize internal table including the body. Clear only initialize work area.
2. SWO1 show error on BAPI. Field is too large for component. But its ok, the BAPI is still can be used.
image
Code:
FUNCTION ZBAPI_MATERIAL_GETLIST03.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(MAX_ROWS) LIKE  BAPIF4A-MAX_ROWS DEFAULT 0
*"  TABLES
*"      MATNRSELECTION STRUCTURE  BAPIMATRAM OPTIONAL
*"      MATERIALSHORTDESCSEL STRUCTURE  BAPIMATRAS OPTIONAL
*"      PLANTSELECTION STRUCTURE  BAPIMATRAW OPTIONAL
*"      MATNRLIST STRUCTURE  ZBAPIMATLST03 OPTIONAL
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------

TABLES: MAKT, MARA, MARC, MARD.
  DATA : lines type TLINE occurs 0 with header line.
  DATA w_row type TLINE.
  DATA MATNUM TYPE THEAD-TDNAME.
  DATA w_string(1024) TYPE C.

SELECT A~MATNR A~MTART A~MATKL A~BISMT A~MEINS A~BSTME C~WERKS T~MAKTX
  INTO (MATNRLIST-MATNR, MATNRLIST-MTART, MATNRLIST-MATKL,
  MATNRLIST-BISMT, MATNRLIST-MEINS, MATNRLIST-BSTME, MATNRLIST-WERKS,
  MATNRLIST-MAKTX)
  FROM MARA AS A
  INNER JOIN MARC AS C ON A~MATNR = C~MATNR
  INNER JOIN MAKT AS T ON C~MATNR = T~MATNR
  WHERE A~MATNR IN MATNRSELECTION
  AND C~WERKS IN PLANTSELECTION
  AND T~MAKTX IN MATERIALSHORTDESCSEL.

  APPEND MATNRLIST.
ENDSELECT.

  LOOP AT MATNRLIST.
*    MOVE MATNRLIST-MATERIAL to MATNUM.
    MATNUM = MATNRLIST-MATNR.
    call function 'READ_TEXT'
      EXPORTING
        id                      = 'GRUN'
        language                = sy-langu
*        name                    = MATNRLIST-MATERIAL
        name                    = MATNUM
        object                  = 'MATERIAL'
      TABLES
        lines                   = lines
      EXCEPTIONS
        id                      = 1
        language                = 2
        name                    = 3
        not_found               = 4
        object                  = 5
        reference_check         = 6
        wrong_access_to_archive = 7.

    clear w_string.
    loop at LINES into w_row.
        IF w_row NE ''.
          concatenate w_string w_row into w_string.
        ENDIF.
    endloop.

    MATNRLIST-MATL_LT = w_string.
*    clear lines. clear only initialize work area
    REFRESH lines.
    MODIFY MATNRLIST.

  ENDLOOP.
ENDFUNCTION.

0 comments:

Post a Comment